1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/system/gonk/tests/test_ril_worker_sms_cdmapduhelper.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,210 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this); 1.8 + 1.9 +function run_test() { 1.10 + run_next_test(); 1.11 +} 1.12 + 1.13 +/** 1.14 + * Verify CdmaPDUHelper#encodeUserDataReplyOption. 1.15 + */ 1.16 +add_test(function test_CdmaPDUHelper_encodeUserDataReplyOption() { 1.17 + let worker = newWorker({ 1.18 + postRILMessage: function(data) { 1.19 + // Do nothing 1.20 + }, 1.21 + postMessage: function(message) { 1.22 + // Do nothing 1.23 + } 1.24 + }); 1.25 + let context = worker.ContextPool._contexts[0]; 1.26 + 1.27 + let testDataBuffer = []; 1.28 + context.BitBufferHelper.startWrite(testDataBuffer); 1.29 + 1.30 + let helper = context.CdmaPDUHelper; 1.31 + helper.encodeUserDataReplyOption({requestStatusReport: true}); 1.32 + 1.33 + let expectedDataBuffer = [PDU_CDMA_MSG_USERDATA_REPLY_OPTION, 0x01, 0x40]; 1.34 + 1.35 + do_check_eq(testDataBuffer.length, expectedDataBuffer.length); 1.36 + 1.37 + for (let i = 0; i < expectedDataBuffer.length; i++) { 1.38 + do_check_eq(testDataBuffer[i], expectedDataBuffer[i]); 1.39 + } 1.40 + 1.41 + run_next_test(); 1.42 +}); 1.43 + 1.44 +/** 1.45 + * Verify CdmaPDUHelper#cdma_decodeUserDataMsgStatus. 1.46 + */ 1.47 +add_test(function test_CdmaPDUHelper_decodeUserDataMsgStatus() { 1.48 + let worker = newWorker({ 1.49 + postRILMessage: function(data) { 1.50 + // Do nothing 1.51 + }, 1.52 + postMessage: function(message) { 1.53 + // Do nothing 1.54 + } 1.55 + }); 1.56 + let context = worker.ContextPool._contexts[0]; 1.57 + 1.58 + let helper = context.CdmaPDUHelper; 1.59 + function test_MsgStatus(octet) { 1.60 + let testDataBuffer = [octet]; 1.61 + context.BitBufferHelper.startRead(testDataBuffer); 1.62 + let result = helper.decodeUserDataMsgStatus(); 1.63 + 1.64 + do_check_eq(result.errorClass, octet >>> 6); 1.65 + do_check_eq(result.msgStatus, octet & 0x3F); 1.66 + } 1.67 + 1.68 + // 00|000000: no error|Message accepted 1.69 + test_MsgStatus(0x00); 1.70 + 1.71 + // 10|000100: temporary condition|Network congestion 1.72 + test_MsgStatus(0x84); 1.73 + 1.74 + // 11|000101: permanent condition|Network error 1.75 + test_MsgStatus(0xC5); 1.76 + 1.77 + run_next_test(); 1.78 +}); 1.79 + 1.80 +/** 1.81 + * Verify CdmaPDUHelper#decodeCdmaPDUMsg. 1.82 + * - encoding by shift-jis 1.83 + */ 1.84 +add_test(function test_CdmaPDUHelper_decodeCdmaPDUMsg_Shift_jis() { 1.85 + let worker = newWorker({ 1.86 + postRILMessage: function(data) { 1.87 + // Do nothing 1.88 + }, 1.89 + postMessage: function(message) { 1.90 + // Do nothing 1.91 + } 1.92 + }); 1.93 + let context = worker.ContextPool._contexts[0]; 1.94 + 1.95 + let helper = context.CdmaPDUHelper; 1.96 + function test_decodePDUMsg(testDataBuffer, expected, encoding, msgType, msgBodySize) { 1.97 + context.BitBufferHelper.startRead(testDataBuffer); 1.98 + let result = helper.decodeCdmaPDUMsg(encoding, msgType, msgBodySize); 1.99 + do_check_eq(result, expected); 1.100 + } 1.101 + 1.102 + // Shift-JIS has 1 byte and 2 byte code for one character and has some types of characters: 1.103 + // Hiragana, Kanji, Katakana(fullwidth, halfwidth)... 1.104 + // This test is a combination of 1 byte and 2 byte code and types of characters. 1.105 + 1.106 + // test case 1 1.107 + let testDataBuffer1 = [0x82, 0x58, 0x33, 0x41, 0x61, 0x33, 0x82, 0x60, 1.108 + 0x82, 0x81, 0x33, 0xB1, 0xAF, 0x33, 0x83, 0x41, 1.109 + 0x83, 0x96, 0x33, 0x82, 0xA0, 0x33, 0x93, 0xFA, 1.110 + 0x33, 0x3A, 0x3C, 0x33, 0x81, 0x80, 0x81, 0x8E, 1.111 + 0x33, 0x31, 0x82, 0x51, 0x41, 0x61, 0x82, 0x51, 1.112 + 0x82, 0x60, 0x82, 0x81, 0x82, 0x51, 0xB1, 0xAF, 1.113 + 0x82, 0x51, 0x83, 0x41, 0x83, 0x96, 0x82, 0x51, 1.114 + 0x82, 0xA0, 0x82, 0x51, 0x93, 0xFA, 0x82, 0x51, 1.115 + 0x3A, 0x3C, 0x82, 0x51, 0x81, 0x80, 0x81, 0x8E, 1.116 + 0x82, 0x51]; 1.117 + 1.118 + test_decodePDUMsg( 1.119 + testDataBuffer1, 1.120 + "\uFF19\u0033\u0041\u0061\u0033\uFF21\uFF41\u0033\uFF71\uFF6F\u0033\u30A2\u30F6\u0033\u3042\u0033\u65E5\u0033\u003A\u003C\u0033\u00F7\u2103\u0033\u0031\uFF12\u0041\u0061\uFF12\uFF21\uFF41\uFF12\uFF71\uFF6F\uFF12\u30A2\u30F6\uFF12\u3042\uFF12\u65E5\uFF12\u003A\u003C\uFF12\u00F7\u2103\uFF12", 1.121 + PDU_CDMA_MSG_CODING_SHIFT_JIS, 1.122 + undefined, 1.123 + testDataBuffer1.length 1.124 + ); 1.125 + 1.126 + // test case 2 1.127 + let testDataBuffer2 = [0x31, 0x51, 0x63, 0x82, 0x58, 0x51, 0x63, 0x82, 1.128 + 0x60, 0x82, 0x81, 0x51, 0x63, 0xB1, 0xAF, 0x51, 1.129 + 0x63, 0x83, 0x41, 0x83, 0x96, 0x51, 0x63, 0x82, 1.130 + 0xA0, 0x51, 0x63, 0x93, 0xFA, 0x51, 0x63, 0x3A, 1.131 + 0x3C, 0x51, 0x63, 0x81, 0x80, 0x81, 0x8E, 0x51, 1.132 + 0x63, 0x31, 0x82, 0x70, 0x82, 0x85, 0x82, 0x58, 1.133 + 0x82, 0x70, 0x82, 0x85, 0x41, 0x61, 0x82, 0x70, 1.134 + 0x82, 0x85, 0xB1, 0xAF, 0x82, 0x70, 0x82, 0x85, 1.135 + 0x83, 0x41, 0x83, 0x96, 0x82, 0x70, 0x82, 0x85, 1.136 + 0x82, 0xA0, 0x82, 0x70, 0x82, 0x85, 0x93, 0xFA, 1.137 + 0x82, 0x70, 0x82, 0x85, 0x3A, 0x3C, 0x82, 0x70, 1.138 + 0x82, 0x85, 0x81, 0x80, 0x81, 0x8E, 0x82, 0x70, 1.139 + 0x82, 0x85]; 1.140 + 1.141 + test_decodePDUMsg( 1.142 + testDataBuffer2, 1.143 + "\u0031\u0051\u0063\uFF19\u0051\u0063\uFF21\uFF41\u0051\u0063\uFF71\uFF6F\u0051\u0063\u30A2\u30F6\u0051\u0063\u3042\u0051\u0063\u65E5\u0051\u0063\u003A\u003C\u0051\u0063\u00F7\u2103\u0051\u0063\u0031\uFF31\uFF45\uFF19\uFF31\uFF45\u0041\u0061\uFF31\uFF45\uFF71\uFF6F\uFF31\uFF45\u30A2\u30F6\uFF31\uFF45\u3042\uFF31\uFF45\u65E5\uFF31\uFF45\u003A\u003C\uFF31\uFF45\u00F7\u2103\uFF31\uFF45", 1.144 + PDU_CDMA_MSG_CODING_SHIFT_JIS, 1.145 + undefined, 1.146 + testDataBuffer2.length 1.147 + ); 1.148 + 1.149 + // test case 3 1.150 + let testDataBuffer3 = [0x31, 0xC2, 0xDF, 0x82, 0x58, 0xC2, 0xDF, 0x41, 1.151 + 0x61, 0xC2, 0xDF, 0x82, 0x60, 0x82, 0x81, 0xC2, 1.152 + 0xDF, 0x83, 0x41, 0x83, 0x96, 0xC2, 0xDF, 0x82, 1.153 + 0xA0, 0xC2, 0xDF, 0x93, 0xFA, 0xC2, 0xDF, 0x3A, 1.154 + 0x3C, 0xC2, 0xDF, 0x81, 0x80, 0x81, 0x8E, 0xC2, 1.155 + 0xDF, 0x31, 0x83, 0x51, 0x83, 0x87, 0x82, 0x58, 1.156 + 0x83, 0x51, 0x83, 0x87, 0x41, 0x61, 0x83, 0x51, 1.157 + 0x83, 0x87, 0x82, 0x60, 0x82, 0x81, 0x83, 0x51, 1.158 + 0x83, 0x87, 0xB1, 0xAF, 0x83, 0x51, 0x83, 0x87, 1.159 + 0x82, 0xA0, 0x83, 0x51, 0x83, 0x87, 0x93, 0xFA, 1.160 + 0x83, 0x51, 0x83, 0x87, 0x3A, 0x3C, 0x83, 0x51, 1.161 + 0x83, 0x87, 0x81, 0x80, 0x81, 0x8E, 0x83, 0x51, 1.162 + 0x83, 0x87]; 1.163 + 1.164 + test_decodePDUMsg( 1.165 + testDataBuffer3, 1.166 + "\u0031\uFF82\uFF9F\uFF19\uFF82\uFF9F\u0041\u0061\uFF82\uFF9F\uFF21\uFF41\uFF82\uFF9F\u30A2\u30F6\uFF82\uFF9F\u3042\uFF82\uFF9F\u65E5\uFF82\uFF9F\u003A\u003C\uFF82\uFF9F\u00F7\u2103\uFF82\uFF9F\u0031\u30B2\u30E7\uFF19\u30B2\u30E7\u0041\u0061\u30B2\u30E7\uFF21\uFF41\u30B2\u30E7\uFF71\uFF6F\u30B2\u30E7\u3042\u30B2\u30E7\u65E5\u30B2\u30E7\u003A\u003C\u30B2\u30E7\u00F7\u2103\u30B2\u30E7", 1.167 + PDU_CDMA_MSG_CODING_SHIFT_JIS, 1.168 + undefined, 1.169 + testDataBuffer3.length 1.170 + ); 1.171 + 1.172 + // test case 4 1.173 + let testDataBuffer4 = [0x31, 0x82, 0xB0, 0x82, 0x58, 0x82, 0xB0, 0x41, 1.174 + 0x61, 0x82, 0xB0, 0x82, 0x60, 0x82, 0x81, 0x82, 1.175 + 0xB0, 0xB1, 0xAF, 0x82, 0xB0, 0x83, 0x41, 0x83, 1.176 + 0x96, 0x82, 0xB0, 0x93, 0xFA, 0x82, 0xB0, 0x3A, 1.177 + 0x3C, 0x82, 0xB0, 0x81, 0x80, 0x81, 0x8E, 0x82, 1.178 + 0xB0, 0x31, 0x88, 0xA4, 0x82, 0x58, 0x88, 0xA4, 1.179 + 0x41, 0x61, 0x88, 0xA4, 0x82, 0x60, 0x82, 0x81, 1.180 + 0x88, 0xA4, 0xB1, 0xAF, 0x88, 0xA4, 0x83, 0x41, 1.181 + 0x83, 0x96, 0x88, 0xA4, 0x82, 0xA0, 0x88, 0xA4, 1.182 + 0x3A, 0x3C, 0x88, 0xA4, 0x81, 0x80, 0x81, 0x8E, 1.183 + 0x88, 0xA4]; 1.184 + 1.185 + test_decodePDUMsg( 1.186 + testDataBuffer4, 1.187 + "\u0031\u3052\uFF19\u3052\u0041\u0061\u3052\uFF21\uFF41\u3052\uFF71\uFF6F\u3052\u30A2\u30F6\u3052\u65E5\u3052\u003A\u003C\u3052\u00F7\u2103\u3052\u0031\u611B\uFF19\u611B\u0041\u0061\u611B\uFF21\uFF41\u611B\uFF71\uFF6F\u611B\u30A2\u30F6\u611B\u3042\u611B\u003A\u003C\u611B\u00F7\u2103\u611B", 1.188 + PDU_CDMA_MSG_CODING_SHIFT_JIS, 1.189 + undefined, 1.190 + testDataBuffer4.length 1.191 + ); 1.192 + 1.193 + // test case 5 1.194 + let testDataBuffer5 = [0x31, 0x40, 0x82, 0x58, 0x40, 0x41, 0x61, 0x40, 1.195 + 0x82, 0x60, 0x82, 0x81, 0x40, 0xB1, 0xAF, 0x40, 1.196 + 0x83, 0x41, 0x83, 0x96, 0x40, 0x82, 0xA0, 0x40, 1.197 + 0x93, 0xFA, 0x40, 0x81, 0x80, 0x81, 0x8E, 0x40, 1.198 + 0x31, 0x81, 0x9B, 0x82, 0x58, 0x81, 0x9B, 0x41, 1.199 + 0x61, 0x81, 0x9B, 0x82, 0x60, 0x82, 0x81, 0x81, 1.200 + 0x9B, 0xB1, 0xAF, 0x81, 0x9B, 0x83, 0x41, 0x83, 1.201 + 0x96, 0x81, 0x9B, 0x82, 0xA0, 0x81, 0x9B, 0x93, 1.202 + 0xFA, 0x81, 0x9B, 0x3A, 0x3C, 0x81, 0x9B]; 1.203 + 1.204 + test_decodePDUMsg( 1.205 + testDataBuffer5, 1.206 + "\u0031\u0040\uFF19\u0040\u0041\u0061\u0040\uFF21\uFF41\u0040\uFF71\uFF6F\u0040\u30A2\u30F6\u0040\u3042\u0040\u65E5\u0040\u00F7\u2103\u0040\u0031\u25CB\uFF19\u25CB\u0041\u0061\u25CB\uFF21\uFF41\u25CB\uFF71\uFF6F\u25CB\u30A2\u30F6\u25CB\u3042\u25CB\u65E5\u25CB\u003A\u003C\u25CB", 1.207 + PDU_CDMA_MSG_CODING_SHIFT_JIS, 1.208 + undefined, 1.209 + testDataBuffer5.length 1.210 + ); 1.211 + 1.212 + run_next_test(); 1.213 +});