dom/system/gonk/tests/test_ril_worker_sms_gsmpduhelper.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial