dom/system/gonk/tests/test_ril_worker_sms_cdmapduhelper.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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 CdmaPDUHelper#encodeUserDataReplyOption.
michael@0 12 */
michael@0 13 add_test(function test_CdmaPDUHelper_encodeUserDataReplyOption() {
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 let context = worker.ContextPool._contexts[0];
michael@0 23
michael@0 24 let testDataBuffer = [];
michael@0 25 context.BitBufferHelper.startWrite(testDataBuffer);
michael@0 26
michael@0 27 let helper = context.CdmaPDUHelper;
michael@0 28 helper.encodeUserDataReplyOption({requestStatusReport: true});
michael@0 29
michael@0 30 let expectedDataBuffer = [PDU_CDMA_MSG_USERDATA_REPLY_OPTION, 0x01, 0x40];
michael@0 31
michael@0 32 do_check_eq(testDataBuffer.length, expectedDataBuffer.length);
michael@0 33
michael@0 34 for (let i = 0; i < expectedDataBuffer.length; i++) {
michael@0 35 do_check_eq(testDataBuffer[i], expectedDataBuffer[i]);
michael@0 36 }
michael@0 37
michael@0 38 run_next_test();
michael@0 39 });
michael@0 40
michael@0 41 /**
michael@0 42 * Verify CdmaPDUHelper#cdma_decodeUserDataMsgStatus.
michael@0 43 */
michael@0 44 add_test(function test_CdmaPDUHelper_decodeUserDataMsgStatus() {
michael@0 45 let worker = newWorker({
michael@0 46 postRILMessage: function(data) {
michael@0 47 // Do nothing
michael@0 48 },
michael@0 49 postMessage: function(message) {
michael@0 50 // Do nothing
michael@0 51 }
michael@0 52 });
michael@0 53 let context = worker.ContextPool._contexts[0];
michael@0 54
michael@0 55 let helper = context.CdmaPDUHelper;
michael@0 56 function test_MsgStatus(octet) {
michael@0 57 let testDataBuffer = [octet];
michael@0 58 context.BitBufferHelper.startRead(testDataBuffer);
michael@0 59 let result = helper.decodeUserDataMsgStatus();
michael@0 60
michael@0 61 do_check_eq(result.errorClass, octet >>> 6);
michael@0 62 do_check_eq(result.msgStatus, octet & 0x3F);
michael@0 63 }
michael@0 64
michael@0 65 // 00|000000: no error|Message accepted
michael@0 66 test_MsgStatus(0x00);
michael@0 67
michael@0 68 // 10|000100: temporary condition|Network congestion
michael@0 69 test_MsgStatus(0x84);
michael@0 70
michael@0 71 // 11|000101: permanent condition|Network error
michael@0 72 test_MsgStatus(0xC5);
michael@0 73
michael@0 74 run_next_test();
michael@0 75 });
michael@0 76
michael@0 77 /**
michael@0 78 * Verify CdmaPDUHelper#decodeCdmaPDUMsg.
michael@0 79 * - encoding by shift-jis
michael@0 80 */
michael@0 81 add_test(function test_CdmaPDUHelper_decodeCdmaPDUMsg_Shift_jis() {
michael@0 82 let worker = newWorker({
michael@0 83 postRILMessage: function(data) {
michael@0 84 // Do nothing
michael@0 85 },
michael@0 86 postMessage: function(message) {
michael@0 87 // Do nothing
michael@0 88 }
michael@0 89 });
michael@0 90 let context = worker.ContextPool._contexts[0];
michael@0 91
michael@0 92 let helper = context.CdmaPDUHelper;
michael@0 93 function test_decodePDUMsg(testDataBuffer, expected, encoding, msgType, msgBodySize) {
michael@0 94 context.BitBufferHelper.startRead(testDataBuffer);
michael@0 95 let result = helper.decodeCdmaPDUMsg(encoding, msgType, msgBodySize);
michael@0 96 do_check_eq(result, expected);
michael@0 97 }
michael@0 98
michael@0 99 // Shift-JIS has 1 byte and 2 byte code for one character and has some types of characters:
michael@0 100 // Hiragana, Kanji, Katakana(fullwidth, halfwidth)...
michael@0 101 // This test is a combination of 1 byte and 2 byte code and types of characters.
michael@0 102
michael@0 103 // test case 1
michael@0 104 let testDataBuffer1 = [0x82, 0x58, 0x33, 0x41, 0x61, 0x33, 0x82, 0x60,
michael@0 105 0x82, 0x81, 0x33, 0xB1, 0xAF, 0x33, 0x83, 0x41,
michael@0 106 0x83, 0x96, 0x33, 0x82, 0xA0, 0x33, 0x93, 0xFA,
michael@0 107 0x33, 0x3A, 0x3C, 0x33, 0x81, 0x80, 0x81, 0x8E,
michael@0 108 0x33, 0x31, 0x82, 0x51, 0x41, 0x61, 0x82, 0x51,
michael@0 109 0x82, 0x60, 0x82, 0x81, 0x82, 0x51, 0xB1, 0xAF,
michael@0 110 0x82, 0x51, 0x83, 0x41, 0x83, 0x96, 0x82, 0x51,
michael@0 111 0x82, 0xA0, 0x82, 0x51, 0x93, 0xFA, 0x82, 0x51,
michael@0 112 0x3A, 0x3C, 0x82, 0x51, 0x81, 0x80, 0x81, 0x8E,
michael@0 113 0x82, 0x51];
michael@0 114
michael@0 115 test_decodePDUMsg(
michael@0 116 testDataBuffer1,
michael@0 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",
michael@0 118 PDU_CDMA_MSG_CODING_SHIFT_JIS,
michael@0 119 undefined,
michael@0 120 testDataBuffer1.length
michael@0 121 );
michael@0 122
michael@0 123 // test case 2
michael@0 124 let testDataBuffer2 = [0x31, 0x51, 0x63, 0x82, 0x58, 0x51, 0x63, 0x82,
michael@0 125 0x60, 0x82, 0x81, 0x51, 0x63, 0xB1, 0xAF, 0x51,
michael@0 126 0x63, 0x83, 0x41, 0x83, 0x96, 0x51, 0x63, 0x82,
michael@0 127 0xA0, 0x51, 0x63, 0x93, 0xFA, 0x51, 0x63, 0x3A,
michael@0 128 0x3C, 0x51, 0x63, 0x81, 0x80, 0x81, 0x8E, 0x51,
michael@0 129 0x63, 0x31, 0x82, 0x70, 0x82, 0x85, 0x82, 0x58,
michael@0 130 0x82, 0x70, 0x82, 0x85, 0x41, 0x61, 0x82, 0x70,
michael@0 131 0x82, 0x85, 0xB1, 0xAF, 0x82, 0x70, 0x82, 0x85,
michael@0 132 0x83, 0x41, 0x83, 0x96, 0x82, 0x70, 0x82, 0x85,
michael@0 133 0x82, 0xA0, 0x82, 0x70, 0x82, 0x85, 0x93, 0xFA,
michael@0 134 0x82, 0x70, 0x82, 0x85, 0x3A, 0x3C, 0x82, 0x70,
michael@0 135 0x82, 0x85, 0x81, 0x80, 0x81, 0x8E, 0x82, 0x70,
michael@0 136 0x82, 0x85];
michael@0 137
michael@0 138 test_decodePDUMsg(
michael@0 139 testDataBuffer2,
michael@0 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",
michael@0 141 PDU_CDMA_MSG_CODING_SHIFT_JIS,
michael@0 142 undefined,
michael@0 143 testDataBuffer2.length
michael@0 144 );
michael@0 145
michael@0 146 // test case 3
michael@0 147 let testDataBuffer3 = [0x31, 0xC2, 0xDF, 0x82, 0x58, 0xC2, 0xDF, 0x41,
michael@0 148 0x61, 0xC2, 0xDF, 0x82, 0x60, 0x82, 0x81, 0xC2,
michael@0 149 0xDF, 0x83, 0x41, 0x83, 0x96, 0xC2, 0xDF, 0x82,
michael@0 150 0xA0, 0xC2, 0xDF, 0x93, 0xFA, 0xC2, 0xDF, 0x3A,
michael@0 151 0x3C, 0xC2, 0xDF, 0x81, 0x80, 0x81, 0x8E, 0xC2,
michael@0 152 0xDF, 0x31, 0x83, 0x51, 0x83, 0x87, 0x82, 0x58,
michael@0 153 0x83, 0x51, 0x83, 0x87, 0x41, 0x61, 0x83, 0x51,
michael@0 154 0x83, 0x87, 0x82, 0x60, 0x82, 0x81, 0x83, 0x51,
michael@0 155 0x83, 0x87, 0xB1, 0xAF, 0x83, 0x51, 0x83, 0x87,
michael@0 156 0x82, 0xA0, 0x83, 0x51, 0x83, 0x87, 0x93, 0xFA,
michael@0 157 0x83, 0x51, 0x83, 0x87, 0x3A, 0x3C, 0x83, 0x51,
michael@0 158 0x83, 0x87, 0x81, 0x80, 0x81, 0x8E, 0x83, 0x51,
michael@0 159 0x83, 0x87];
michael@0 160
michael@0 161 test_decodePDUMsg(
michael@0 162 testDataBuffer3,
michael@0 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",
michael@0 164 PDU_CDMA_MSG_CODING_SHIFT_JIS,
michael@0 165 undefined,
michael@0 166 testDataBuffer3.length
michael@0 167 );
michael@0 168
michael@0 169 // test case 4
michael@0 170 let testDataBuffer4 = [0x31, 0x82, 0xB0, 0x82, 0x58, 0x82, 0xB0, 0x41,
michael@0 171 0x61, 0x82, 0xB0, 0x82, 0x60, 0x82, 0x81, 0x82,
michael@0 172 0xB0, 0xB1, 0xAF, 0x82, 0xB0, 0x83, 0x41, 0x83,
michael@0 173 0x96, 0x82, 0xB0, 0x93, 0xFA, 0x82, 0xB0, 0x3A,
michael@0 174 0x3C, 0x82, 0xB0, 0x81, 0x80, 0x81, 0x8E, 0x82,
michael@0 175 0xB0, 0x31, 0x88, 0xA4, 0x82, 0x58, 0x88, 0xA4,
michael@0 176 0x41, 0x61, 0x88, 0xA4, 0x82, 0x60, 0x82, 0x81,
michael@0 177 0x88, 0xA4, 0xB1, 0xAF, 0x88, 0xA4, 0x83, 0x41,
michael@0 178 0x83, 0x96, 0x88, 0xA4, 0x82, 0xA0, 0x88, 0xA4,
michael@0 179 0x3A, 0x3C, 0x88, 0xA4, 0x81, 0x80, 0x81, 0x8E,
michael@0 180 0x88, 0xA4];
michael@0 181
michael@0 182 test_decodePDUMsg(
michael@0 183 testDataBuffer4,
michael@0 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",
michael@0 185 PDU_CDMA_MSG_CODING_SHIFT_JIS,
michael@0 186 undefined,
michael@0 187 testDataBuffer4.length
michael@0 188 );
michael@0 189
michael@0 190 // test case 5
michael@0 191 let testDataBuffer5 = [0x31, 0x40, 0x82, 0x58, 0x40, 0x41, 0x61, 0x40,
michael@0 192 0x82, 0x60, 0x82, 0x81, 0x40, 0xB1, 0xAF, 0x40,
michael@0 193 0x83, 0x41, 0x83, 0x96, 0x40, 0x82, 0xA0, 0x40,
michael@0 194 0x93, 0xFA, 0x40, 0x81, 0x80, 0x81, 0x8E, 0x40,
michael@0 195 0x31, 0x81, 0x9B, 0x82, 0x58, 0x81, 0x9B, 0x41,
michael@0 196 0x61, 0x81, 0x9B, 0x82, 0x60, 0x82, 0x81, 0x81,
michael@0 197 0x9B, 0xB1, 0xAF, 0x81, 0x9B, 0x83, 0x41, 0x83,
michael@0 198 0x96, 0x81, 0x9B, 0x82, 0xA0, 0x81, 0x9B, 0x93,
michael@0 199 0xFA, 0x81, 0x9B, 0x3A, 0x3C, 0x81, 0x9B];
michael@0 200
michael@0 201 test_decodePDUMsg(
michael@0 202 testDataBuffer5,
michael@0 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",
michael@0 204 PDU_CDMA_MSG_CODING_SHIFT_JIS,
michael@0 205 undefined,
michael@0 206 testDataBuffer5.length
michael@0 207 );
michael@0 208
michael@0 209 run_next_test();
michael@0 210 });

mercurial