Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
6 function run_test() {
7 run_next_test();
8 }
10 /**
11 * Verify CdmaPDUHelper#encodeUserDataReplyOption.
12 */
13 add_test(function test_CdmaPDUHelper_encodeUserDataReplyOption() {
14 let worker = newWorker({
15 postRILMessage: function(data) {
16 // Do nothing
17 },
18 postMessage: function(message) {
19 // Do nothing
20 }
21 });
22 let context = worker.ContextPool._contexts[0];
24 let testDataBuffer = [];
25 context.BitBufferHelper.startWrite(testDataBuffer);
27 let helper = context.CdmaPDUHelper;
28 helper.encodeUserDataReplyOption({requestStatusReport: true});
30 let expectedDataBuffer = [PDU_CDMA_MSG_USERDATA_REPLY_OPTION, 0x01, 0x40];
32 do_check_eq(testDataBuffer.length, expectedDataBuffer.length);
34 for (let i = 0; i < expectedDataBuffer.length; i++) {
35 do_check_eq(testDataBuffer[i], expectedDataBuffer[i]);
36 }
38 run_next_test();
39 });
41 /**
42 * Verify CdmaPDUHelper#cdma_decodeUserDataMsgStatus.
43 */
44 add_test(function test_CdmaPDUHelper_decodeUserDataMsgStatus() {
45 let worker = newWorker({
46 postRILMessage: function(data) {
47 // Do nothing
48 },
49 postMessage: function(message) {
50 // Do nothing
51 }
52 });
53 let context = worker.ContextPool._contexts[0];
55 let helper = context.CdmaPDUHelper;
56 function test_MsgStatus(octet) {
57 let testDataBuffer = [octet];
58 context.BitBufferHelper.startRead(testDataBuffer);
59 let result = helper.decodeUserDataMsgStatus();
61 do_check_eq(result.errorClass, octet >>> 6);
62 do_check_eq(result.msgStatus, octet & 0x3F);
63 }
65 // 00|000000: no error|Message accepted
66 test_MsgStatus(0x00);
68 // 10|000100: temporary condition|Network congestion
69 test_MsgStatus(0x84);
71 // 11|000101: permanent condition|Network error
72 test_MsgStatus(0xC5);
74 run_next_test();
75 });
77 /**
78 * Verify CdmaPDUHelper#decodeCdmaPDUMsg.
79 * - encoding by shift-jis
80 */
81 add_test(function test_CdmaPDUHelper_decodeCdmaPDUMsg_Shift_jis() {
82 let worker = newWorker({
83 postRILMessage: function(data) {
84 // Do nothing
85 },
86 postMessage: function(message) {
87 // Do nothing
88 }
89 });
90 let context = worker.ContextPool._contexts[0];
92 let helper = context.CdmaPDUHelper;
93 function test_decodePDUMsg(testDataBuffer, expected, encoding, msgType, msgBodySize) {
94 context.BitBufferHelper.startRead(testDataBuffer);
95 let result = helper.decodeCdmaPDUMsg(encoding, msgType, msgBodySize);
96 do_check_eq(result, expected);
97 }
99 // Shift-JIS has 1 byte and 2 byte code for one character and has some types of characters:
100 // Hiragana, Kanji, Katakana(fullwidth, halfwidth)...
101 // This test is a combination of 1 byte and 2 byte code and types of characters.
103 // test case 1
104 let testDataBuffer1 = [0x82, 0x58, 0x33, 0x41, 0x61, 0x33, 0x82, 0x60,
105 0x82, 0x81, 0x33, 0xB1, 0xAF, 0x33, 0x83, 0x41,
106 0x83, 0x96, 0x33, 0x82, 0xA0, 0x33, 0x93, 0xFA,
107 0x33, 0x3A, 0x3C, 0x33, 0x81, 0x80, 0x81, 0x8E,
108 0x33, 0x31, 0x82, 0x51, 0x41, 0x61, 0x82, 0x51,
109 0x82, 0x60, 0x82, 0x81, 0x82, 0x51, 0xB1, 0xAF,
110 0x82, 0x51, 0x83, 0x41, 0x83, 0x96, 0x82, 0x51,
111 0x82, 0xA0, 0x82, 0x51, 0x93, 0xFA, 0x82, 0x51,
112 0x3A, 0x3C, 0x82, 0x51, 0x81, 0x80, 0x81, 0x8E,
113 0x82, 0x51];
115 test_decodePDUMsg(
116 testDataBuffer1,
117 "\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",
118 PDU_CDMA_MSG_CODING_SHIFT_JIS,
119 undefined,
120 testDataBuffer1.length
121 );
123 // test case 2
124 let testDataBuffer2 = [0x31, 0x51, 0x63, 0x82, 0x58, 0x51, 0x63, 0x82,
125 0x60, 0x82, 0x81, 0x51, 0x63, 0xB1, 0xAF, 0x51,
126 0x63, 0x83, 0x41, 0x83, 0x96, 0x51, 0x63, 0x82,
127 0xA0, 0x51, 0x63, 0x93, 0xFA, 0x51, 0x63, 0x3A,
128 0x3C, 0x51, 0x63, 0x81, 0x80, 0x81, 0x8E, 0x51,
129 0x63, 0x31, 0x82, 0x70, 0x82, 0x85, 0x82, 0x58,
130 0x82, 0x70, 0x82, 0x85, 0x41, 0x61, 0x82, 0x70,
131 0x82, 0x85, 0xB1, 0xAF, 0x82, 0x70, 0x82, 0x85,
132 0x83, 0x41, 0x83, 0x96, 0x82, 0x70, 0x82, 0x85,
133 0x82, 0xA0, 0x82, 0x70, 0x82, 0x85, 0x93, 0xFA,
134 0x82, 0x70, 0x82, 0x85, 0x3A, 0x3C, 0x82, 0x70,
135 0x82, 0x85, 0x81, 0x80, 0x81, 0x8E, 0x82, 0x70,
136 0x82, 0x85];
138 test_decodePDUMsg(
139 testDataBuffer2,
140 "\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",
141 PDU_CDMA_MSG_CODING_SHIFT_JIS,
142 undefined,
143 testDataBuffer2.length
144 );
146 // test case 3
147 let testDataBuffer3 = [0x31, 0xC2, 0xDF, 0x82, 0x58, 0xC2, 0xDF, 0x41,
148 0x61, 0xC2, 0xDF, 0x82, 0x60, 0x82, 0x81, 0xC2,
149 0xDF, 0x83, 0x41, 0x83, 0x96, 0xC2, 0xDF, 0x82,
150 0xA0, 0xC2, 0xDF, 0x93, 0xFA, 0xC2, 0xDF, 0x3A,
151 0x3C, 0xC2, 0xDF, 0x81, 0x80, 0x81, 0x8E, 0xC2,
152 0xDF, 0x31, 0x83, 0x51, 0x83, 0x87, 0x82, 0x58,
153 0x83, 0x51, 0x83, 0x87, 0x41, 0x61, 0x83, 0x51,
154 0x83, 0x87, 0x82, 0x60, 0x82, 0x81, 0x83, 0x51,
155 0x83, 0x87, 0xB1, 0xAF, 0x83, 0x51, 0x83, 0x87,
156 0x82, 0xA0, 0x83, 0x51, 0x83, 0x87, 0x93, 0xFA,
157 0x83, 0x51, 0x83, 0x87, 0x3A, 0x3C, 0x83, 0x51,
158 0x83, 0x87, 0x81, 0x80, 0x81, 0x8E, 0x83, 0x51,
159 0x83, 0x87];
161 test_decodePDUMsg(
162 testDataBuffer3,
163 "\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",
164 PDU_CDMA_MSG_CODING_SHIFT_JIS,
165 undefined,
166 testDataBuffer3.length
167 );
169 // test case 4
170 let testDataBuffer4 = [0x31, 0x82, 0xB0, 0x82, 0x58, 0x82, 0xB0, 0x41,
171 0x61, 0x82, 0xB0, 0x82, 0x60, 0x82, 0x81, 0x82,
172 0xB0, 0xB1, 0xAF, 0x82, 0xB0, 0x83, 0x41, 0x83,
173 0x96, 0x82, 0xB0, 0x93, 0xFA, 0x82, 0xB0, 0x3A,
174 0x3C, 0x82, 0xB0, 0x81, 0x80, 0x81, 0x8E, 0x82,
175 0xB0, 0x31, 0x88, 0xA4, 0x82, 0x58, 0x88, 0xA4,
176 0x41, 0x61, 0x88, 0xA4, 0x82, 0x60, 0x82, 0x81,
177 0x88, 0xA4, 0xB1, 0xAF, 0x88, 0xA4, 0x83, 0x41,
178 0x83, 0x96, 0x88, 0xA4, 0x82, 0xA0, 0x88, 0xA4,
179 0x3A, 0x3C, 0x88, 0xA4, 0x81, 0x80, 0x81, 0x8E,
180 0x88, 0xA4];
182 test_decodePDUMsg(
183 testDataBuffer4,
184 "\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",
185 PDU_CDMA_MSG_CODING_SHIFT_JIS,
186 undefined,
187 testDataBuffer4.length
188 );
190 // test case 5
191 let testDataBuffer5 = [0x31, 0x40, 0x82, 0x58, 0x40, 0x41, 0x61, 0x40,
192 0x82, 0x60, 0x82, 0x81, 0x40, 0xB1, 0xAF, 0x40,
193 0x83, 0x41, 0x83, 0x96, 0x40, 0x82, 0xA0, 0x40,
194 0x93, 0xFA, 0x40, 0x81, 0x80, 0x81, 0x8E, 0x40,
195 0x31, 0x81, 0x9B, 0x82, 0x58, 0x81, 0x9B, 0x41,
196 0x61, 0x81, 0x9B, 0x82, 0x60, 0x82, 0x81, 0x81,
197 0x9B, 0xB1, 0xAF, 0x81, 0x9B, 0x83, 0x41, 0x83,
198 0x96, 0x81, 0x9B, 0x82, 0xA0, 0x81, 0x9B, 0x93,
199 0xFA, 0x81, 0x9B, 0x3A, 0x3C, 0x81, 0x9B];
201 test_decodePDUMsg(
202 testDataBuffer5,
203 "\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",
204 PDU_CDMA_MSG_CODING_SHIFT_JIS,
205 undefined,
206 testDataBuffer5.length
207 );
209 run_next_test();
210 });