|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this); |
|
5 |
|
6 function run_test() { |
|
7 run_next_test(); |
|
8 } |
|
9 |
|
10 /** |
|
11 * Verify GsmPDUHelper#readDataCodingScheme. |
|
12 */ |
|
13 add_test(function test_GsmPDUHelper_readDataCodingScheme() { |
|
14 let worker = newWorker({ |
|
15 postRILMessage: function(data) { |
|
16 // Do nothing |
|
17 }, |
|
18 postMessage: function(message) { |
|
19 // Do nothing |
|
20 } |
|
21 }); |
|
22 |
|
23 let context = worker.ContextPool._contexts[0]; |
|
24 let helper = context.GsmPDUHelper; |
|
25 function test_dcs(dcs, encoding, messageClass, mwi) { |
|
26 helper.readHexOctet = function() { |
|
27 return dcs; |
|
28 } |
|
29 |
|
30 let msg = {}; |
|
31 helper.readDataCodingScheme(msg); |
|
32 |
|
33 do_check_eq(msg.dcs, dcs); |
|
34 do_check_eq(msg.encoding, encoding); |
|
35 do_check_eq(msg.messageClass, messageClass); |
|
36 do_check_eq(msg.mwi == null, mwi == null); |
|
37 if (mwi != null) { |
|
38 do_check_eq(msg.mwi.active, mwi.active); |
|
39 do_check_eq(msg.mwi.discard, mwi.discard); |
|
40 do_check_eq(msg.mwi.msgCount, mwi.msgCount); |
|
41 } |
|
42 } |
|
43 |
|
44 // Group 00xx |
|
45 // Bit 3 and 2 indicate the character set being used. |
|
46 test_dcs(0x00, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
47 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]); |
|
48 test_dcs(0x04, PDU_DCS_MSG_CODING_8BITS_ALPHABET, |
|
49 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]); |
|
50 test_dcs(0x08, PDU_DCS_MSG_CODING_16BITS_ALPHABET, |
|
51 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]); |
|
52 test_dcs(0x0C, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
53 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]); |
|
54 // Bit 4, if set to 0, indicates that bits 1 to 0 are reserved and have no |
|
55 // message class meaning. |
|
56 test_dcs(0x01, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
57 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]); |
|
58 test_dcs(0x02, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
59 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]); |
|
60 test_dcs(0x03, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
61 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]); |
|
62 // Bit 4, if set to 1, indicates that bits 1 to 0 have a message class meaning. |
|
63 test_dcs(0x10, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
64 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_0]); |
|
65 test_dcs(0x11, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
66 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_1]); |
|
67 test_dcs(0x12, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
68 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_2]); |
|
69 test_dcs(0x13, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
70 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_3]); |
|
71 |
|
72 // Group 01xx |
|
73 test_dcs(0x50, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
74 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_0]); |
|
75 |
|
76 // Group 1000..1011: reserved |
|
77 test_dcs(0x8F, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
78 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]); |
|
79 test_dcs(0x9F, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
80 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]); |
|
81 test_dcs(0xAF, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
82 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]); |
|
83 test_dcs(0xBF, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
84 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]); |
|
85 |
|
86 // Group 1100: Message Waiting Indication Group: Discard Message |
|
87 // Bit 3 indicates Indication Sense: |
|
88 test_dcs(0xC0, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
89 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL], |
|
90 {active: false, discard: true, msgCount: 0}); |
|
91 test_dcs(0xC8, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
92 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL], |
|
93 {active: true, discard: true, msgCount: -1}); |
|
94 // Bit 2 is reserved, and set to 0: |
|
95 test_dcs(0xCC, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
96 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL], |
|
97 {active: true, discard: true, msgCount: -1}); |
|
98 |
|
99 // Group 1101: Message Waiting Indication Group: Store Message |
|
100 // Bit 3 indicates Indication Sense: |
|
101 test_dcs(0xD0, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
102 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL], |
|
103 {active: false, discard: false, msgCount: 0}); |
|
104 test_dcs(0xD8, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
105 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL], |
|
106 {active: true, discard: false, msgCount: -1}); |
|
107 // Bit 2 is reserved, and set to 0: |
|
108 test_dcs(0xDC, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
109 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL], |
|
110 {active: true, discard: false, msgCount: -1}); |
|
111 |
|
112 // Group 1110: Message Waiting Indication Group: Store Message, UCS2 |
|
113 // Bit 3 indicates Indication Sense: |
|
114 test_dcs(0xE0, PDU_DCS_MSG_CODING_16BITS_ALPHABET, |
|
115 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL], |
|
116 {active: false, discard: false, msgCount: 0}); |
|
117 test_dcs(0xE8, PDU_DCS_MSG_CODING_16BITS_ALPHABET, |
|
118 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL], |
|
119 {active: true, discard: false, msgCount: -1}); |
|
120 // Bit 2 is reserved, and set to 0: |
|
121 test_dcs(0xEC, PDU_DCS_MSG_CODING_16BITS_ALPHABET, |
|
122 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL], |
|
123 {active: true, discard: false, msgCount: -1}); |
|
124 |
|
125 // Group 1111 |
|
126 test_dcs(0xF0, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
127 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_0]); |
|
128 test_dcs(0xF1, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
129 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_1]); |
|
130 test_dcs(0xF2, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
131 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_2]); |
|
132 test_dcs(0xF3, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
133 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_3]); |
|
134 test_dcs(0xF4, PDU_DCS_MSG_CODING_8BITS_ALPHABET, |
|
135 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_0]); |
|
136 test_dcs(0xF5, PDU_DCS_MSG_CODING_8BITS_ALPHABET, |
|
137 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_1]); |
|
138 test_dcs(0xF6, PDU_DCS_MSG_CODING_8BITS_ALPHABET, |
|
139 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_2]); |
|
140 test_dcs(0xF7, PDU_DCS_MSG_CODING_8BITS_ALPHABET, |
|
141 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_3]); |
|
142 // Bit 3 is reserved and should be set to 0, but if it doesn't we should |
|
143 // ignore it. |
|
144 test_dcs(0xF8, PDU_DCS_MSG_CODING_7BITS_ALPHABET, |
|
145 GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_0]); |
|
146 |
|
147 run_next_test(); |
|
148 }); |
|
149 |
|
150 /** |
|
151 * Verify GsmPDUHelper#writeStringAsSeptets() padding bits handling. |
|
152 */ |
|
153 add_test(function test_GsmPDUHelper_writeStringAsSeptets() { |
|
154 let worker = newWorker({ |
|
155 postRILMessage: function(data) { |
|
156 // Do nothing |
|
157 }, |
|
158 postMessage: function(message) { |
|
159 // Do nothing |
|
160 } |
|
161 }); |
|
162 |
|
163 let context = worker.ContextPool._contexts[0]; |
|
164 let helper = context.GsmPDUHelper; |
|
165 helper.resetOctetWritten = function() { |
|
166 helper.octetsWritten = 0; |
|
167 }; |
|
168 helper.writeHexOctet = function() { |
|
169 helper.octetsWritten++; |
|
170 }; |
|
171 |
|
172 let base = "AAAAAAAA"; // Base string of 8 characters long |
|
173 for (let len = 0; len < 8; len++) { |
|
174 let str = base.substring(0, len); |
|
175 |
|
176 for (let paddingBits = 0; paddingBits < 8; paddingBits++) { |
|
177 do_print("Verifying GsmPDUHelper.writeStringAsSeptets(" |
|
178 + str + ", " + paddingBits + ", <default>, <default>)"); |
|
179 helper.resetOctetWritten(); |
|
180 helper.writeStringAsSeptets(str, paddingBits, PDU_NL_IDENTIFIER_DEFAULT, |
|
181 PDU_NL_IDENTIFIER_DEFAULT); |
|
182 do_check_eq(Math.ceil(((len * 7) + paddingBits) / 8), |
|
183 helper.octetsWritten); |
|
184 } |
|
185 } |
|
186 |
|
187 run_next_test(); |
|
188 }); |
|
189 |
|
190 /** |
|
191 * Verify GsmPDUHelper#readAddress |
|
192 */ |
|
193 add_test(function test_GsmPDUHelper_readAddress() { |
|
194 let worker = newWorker({ |
|
195 postRILMessage: function(data) { |
|
196 // Do nothing |
|
197 }, |
|
198 postMessage: function(message) { |
|
199 // Do nothing |
|
200 } |
|
201 }); |
|
202 |
|
203 let context = worker.ContextPool._contexts[0]; |
|
204 let helper = context.GsmPDUHelper; |
|
205 function test_address(addrHex, addrString) { |
|
206 let uint16Array = []; |
|
207 let ix = 0; |
|
208 for (let i = 0; i < addrHex.length; ++i) { |
|
209 uint16Array[i] = addrHex[i].charCodeAt(); |
|
210 } |
|
211 |
|
212 context.Buf.readUint16 = function(){ |
|
213 if(ix >= uint16Array.length) { |
|
214 do_throw("out of range in uint16Array"); |
|
215 } |
|
216 return uint16Array[ix++]; |
|
217 } |
|
218 let length = helper.readHexOctet(); |
|
219 let parsedAddr = helper.readAddress(length); |
|
220 do_check_eq(parsedAddr, addrString); |
|
221 } |
|
222 |
|
223 // For AlphaNumeric |
|
224 test_address("04D01100", "_@"); |
|
225 test_address("04D01000", "\u0394@"); |
|
226 |
|
227 // Direct prepand |
|
228 test_address("0B914151245584F6", "+14154255486"); |
|
229 test_address("0E914151245584B633", "+14154255486#33"); |
|
230 |
|
231 // PDU_TOA_NATIONAL |
|
232 test_address("0BA14151245584F6", "14154255486"); |
|
233 |
|
234 run_next_test(); |
|
235 }); |