michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this); michael@0: michael@0: function run_test() { michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_test(function test_ril_consts_cellbroadcast_misc() { michael@0: // Must be 16 for indexing. michael@0: do_check_eq(CB_DCS_LANG_GROUP_1.length, 16); michael@0: do_check_eq(CB_DCS_LANG_GROUP_2.length, 16); michael@0: michael@0: // Array length must be even. michael@0: do_check_eq(CB_NON_MMI_SETTABLE_RANGES.length & 0x01, 0); michael@0: for (let i = 0; i < CB_NON_MMI_SETTABLE_RANGES.length;) { michael@0: let from = CB_NON_MMI_SETTABLE_RANGES[i++]; michael@0: let to = CB_NON_MMI_SETTABLE_RANGES[i++]; michael@0: do_check_eq(from < to, true); michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: add_test(function test_ril_worker_GsmPDUHelper_readCbDataCodingScheme() { michael@0: let worker = newWorker({ michael@0: postRILMessage: function(data) { michael@0: // Do nothing michael@0: }, michael@0: postMessage: function(message) { michael@0: // Do nothing michael@0: } michael@0: }); michael@0: michael@0: let context = worker.ContextPool._contexts[0]; michael@0: function test_dcs(dcs, encoding, language, hasLanguageIndicator, messageClass) { michael@0: context.Buf.readUint8 = function() { michael@0: return dcs; michael@0: }; michael@0: michael@0: let msg = {}; michael@0: context.GsmPDUHelper.readCbDataCodingScheme(msg); michael@0: michael@0: do_check_eq(msg.dcs, dcs); michael@0: do_check_eq(msg.encoding, encoding); michael@0: do_check_eq(msg.language, language); michael@0: do_check_eq(msg.hasLanguageIndicator, hasLanguageIndicator); michael@0: do_check_eq(msg.messageClass, messageClass); michael@0: } michael@0: michael@0: function test_dcs_throws(dcs) { michael@0: context.Buf.readUint8 = function() { michael@0: return dcs; michael@0: }; michael@0: michael@0: do_check_throws(function() { michael@0: context.GsmPDUHelper.readCbDataCodingScheme({}); michael@0: }, "Unsupported CBS data coding scheme: " + dcs); michael@0: } michael@0: michael@0: // Group 0000 michael@0: for (let i = 0; i < 16; i++) { michael@0: test_dcs(i, PDU_DCS_MSG_CODING_7BITS_ALPHABET, CB_DCS_LANG_GROUP_1[i], michael@0: false, GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]); michael@0: } michael@0: michael@0: // Group 0001 michael@0: // 0000 GSM 7 bit default alphabet; message preceded by language indication. michael@0: test_dcs(0x10, PDU_DCS_MSG_CODING_7BITS_ALPHABET, null, true, michael@0: GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]); michael@0: // 0001 UCS2; message preceded by language indication. michael@0: test_dcs(0x11, PDU_DCS_MSG_CODING_16BITS_ALPHABET, null, true, michael@0: GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]); michael@0: michael@0: // Group 0010 michael@0: // 0000..0100 michael@0: for (let i = 0; i < 5; i++) { michael@0: test_dcs(0x20 + i, PDU_DCS_MSG_CODING_7BITS_ALPHABET, michael@0: CB_DCS_LANG_GROUP_2[i], false, michael@0: GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]); michael@0: } michael@0: // 0101..1111 Reserved michael@0: for (let i = 5; i < 16; i++) { michael@0: test_dcs(0x20 + i, PDU_DCS_MSG_CODING_7BITS_ALPHABET, null, false, michael@0: GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]); michael@0: } michael@0: michael@0: // Group 0100, 0101, 1001 michael@0: for (let group of [0x40, 0x50, 0x90]) { michael@0: for (let i = 0; i < 16; i++) { michael@0: let encoding = i & 0x0C; michael@0: if (encoding == 0x0C) { michael@0: encoding = PDU_DCS_MSG_CODING_7BITS_ALPHABET; michael@0: } michael@0: let messageClass = GECKO_SMS_MESSAGE_CLASSES[i & PDU_DCS_MSG_CLASS_BITS]; michael@0: test_dcs(group + i, encoding, null, false, messageClass); michael@0: } michael@0: } michael@0: michael@0: // Group 1111 michael@0: for (let i = 0; i < 16; i ++) { michael@0: let encoding = i & 0x04 ? PDU_DCS_MSG_CODING_8BITS_ALPHABET michael@0: : PDU_DCS_MSG_CODING_7BITS_ALPHABET; michael@0: let messageClass; michael@0: switch(i & PDU_DCS_MSG_CLASS_BITS) { michael@0: case 0x01: messageClass = PDU_DCS_MSG_CLASS_USER_1; break; michael@0: case 0x02: messageClass = PDU_DCS_MSG_CLASS_USER_2; break; michael@0: case 0x03: messageClass = PDU_DCS_MSG_CLASS_3; break; michael@0: default: messageClass = PDU_DCS_MSG_CLASS_NORMAL; break; michael@0: } michael@0: test_dcs(0xF0 + i, encoding, null, false, michael@0: GECKO_SMS_MESSAGE_CLASSES[messageClass]); michael@0: } michael@0: michael@0: // Group 0011, 1000, 1010, 1011, 1100 michael@0: // 0000..1111 Reserved michael@0: for (let group of [0x30, 0x80, 0xA0, 0xB0, 0xC0]) { michael@0: for (let i = 0; i < 16; i++) { michael@0: test_dcs(group + i, PDU_DCS_MSG_CODING_7BITS_ALPHABET, null, false, michael@0: GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]); michael@0: } michael@0: } michael@0: michael@0: // Group 0110, 0111, 1101, 1110 michael@0: // TODO: unsupported michael@0: for (let group of [0x60, 0x70, 0xD0, 0xE0]) { michael@0: for (let i = 0; i < 16; i++) { michael@0: test_dcs_throws(group + i); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: add_test(function test_ril_worker_GsmPDUHelper_readGsmCbData() { michael@0: let worker = newWorker({ michael@0: postRILMessage: function(data) { michael@0: // Do nothing michael@0: }, michael@0: postMessage: function(message) { michael@0: // Do nothing michael@0: } michael@0: }); michael@0: michael@0: let context = worker.ContextPool._contexts[0]; michael@0: function test_data(options, expected) { michael@0: let readIndex = 0; michael@0: context.Buf.readUint8 = function() { michael@0: return options[3][readIndex++]; michael@0: }; michael@0: context.Buf.readUint8Array = function(length) { michael@0: let array = new Uint8Array(length); michael@0: for (let i = 0; i < length; i++) { michael@0: array[i] = this.readUint8(); michael@0: } michael@0: return array; michael@0: }; michael@0: michael@0: let msg = { michael@0: encoding: options[0], michael@0: language: options[1], michael@0: hasLanguageIndicator: options[2] michael@0: }; michael@0: context.GsmPDUHelper.readGsmCbData(msg, options[3].length); michael@0: michael@0: do_check_eq(msg.body, expected[0]); michael@0: do_check_eq(msg.data == null, expected[1] == null); michael@0: if (expected[1] != null) { michael@0: do_check_eq(msg.data.length, expected[1].length); michael@0: for (let i = 0; i < expected[1].length; i++) { michael@0: do_check_eq(msg.data[i], expected[1][i]); michael@0: } michael@0: } michael@0: do_check_eq(msg.language, expected[2]); michael@0: } michael@0: michael@0: // We're testing Cell Broadcast message body with all zeros octet stream. As michael@0: // shown in 3GPP TS 23.038, septet 0x00 will be decoded as '@' when both michael@0: // langTableIndex and langShiftTableIndex equal to michael@0: // PDU_DCS_MSG_CODING_7BITS_ALPHABET. michael@0: michael@0: // PDU_DCS_MSG_CODING_7BITS_ALPHABET michael@0: test_data([PDU_DCS_MSG_CODING_7BITS_ALPHABET, null, false, michael@0: [0]], michael@0: ["@", null, null]); michael@0: test_data([PDU_DCS_MSG_CODING_7BITS_ALPHABET, null, true, michael@0: [0, 0, 0, 0]], michael@0: ["@", null, "@@"]); michael@0: test_data([PDU_DCS_MSG_CODING_7BITS_ALPHABET, "@@", false, michael@0: [0]], michael@0: ["@", null, "@@"]); michael@0: michael@0: // PDU_DCS_MSG_CODING_8BITS_ALPHABET michael@0: test_data([PDU_DCS_MSG_CODING_8BITS_ALPHABET, null, false, michael@0: [0]], michael@0: [null, [0], null]); michael@0: michael@0: // PDU_DCS_MSG_CODING_16BITS_ALPHABET michael@0: test_data([PDU_DCS_MSG_CODING_16BITS_ALPHABET, null, false, michael@0: [0x00, 0x40]], michael@0: ["@", null, null]); michael@0: test_data([PDU_DCS_MSG_CODING_16BITS_ALPHABET, null, true, michael@0: [0x00, 0x00, 0x00, 0x40]], michael@0: ["@", null, "@@"]); michael@0: test_data([PDU_DCS_MSG_CODING_16BITS_ALPHABET, "@@", false, michael@0: [0x00, 0x40]], michael@0: ["@", null, "@@"]); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: add_test(function test_ril_worker__checkCellBroadcastMMISettable() { michael@0: let worker = newWorker({ michael@0: postRILMessage: function(data) { michael@0: // Do nothing michael@0: }, michael@0: postMessage: function(message) { michael@0: // Do nothing michael@0: } michael@0: }); michael@0: michael@0: let context = worker.ContextPool._contexts[0]; michael@0: let ril = context.RIL; michael@0: michael@0: function test(from, to, expected) { michael@0: do_check_eq(expected, ril._checkCellBroadcastMMISettable(from, to)); michael@0: } michael@0: michael@0: test(-2, -1, false); michael@0: test(-1, 0, false); michael@0: test(0, 1, true); michael@0: test(1, 1, false); michael@0: test(2, 1, false); michael@0: test(65536, 65537, false); michael@0: michael@0: // We have both [4096, 4224), [4224, 4352), so it's actually [4096, 4352), michael@0: // and [61440, 65536), [65535, 65536), so it's actually [61440, 65536). michael@0: for (let i = 0; i < CB_NON_MMI_SETTABLE_RANGES.length;) { michael@0: let from = CB_NON_MMI_SETTABLE_RANGES[i++]; michael@0: let to = CB_NON_MMI_SETTABLE_RANGES[i++]; michael@0: if ((from != 4224) && (from != 65535)) { michael@0: test(from - 1, from, true); michael@0: } michael@0: test(from - 1, from + 1, false); michael@0: test(from - 1, to, false); michael@0: test(from - 1, to + 1, false); michael@0: test(from, from + 1, false); michael@0: test(from, to, false); michael@0: test(from, to + 1, false); michael@0: if ((from + 1) < to) { michael@0: test(from + 1, to, false); michael@0: test(from + 1, to + 1, false); michael@0: } michael@0: if ((to != 4224) && (to < 65535)) { michael@0: test(to, to + 1, true); michael@0: test(to + 1, to + 2, true); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: add_test(function test_ril_worker__mergeCellBroadcastConfigs() { michael@0: let worker = newWorker({ michael@0: postRILMessage: function(data) { michael@0: // Do nothing michael@0: }, michael@0: postMessage: function(message) { michael@0: // Do nothing michael@0: } michael@0: }); michael@0: michael@0: let context = worker.ContextPool._contexts[0]; michael@0: let ril = context.RIL; michael@0: michael@0: function test(olist, from, to, expected) { michael@0: let result = ril._mergeCellBroadcastConfigs(olist, from, to); michael@0: do_check_eq(JSON.stringify(expected), JSON.stringify(result)); michael@0: } michael@0: michael@0: test(null, 0, 1, [0, 1]); michael@0: michael@0: test([10, 13], 7, 8, [ 7, 8, 10, 13]); michael@0: test([10, 13], 7, 9, [ 7, 9, 10, 13]); michael@0: test([10, 13], 7, 10, [ 7, 13]); michael@0: test([10, 13], 7, 11, [ 7, 13]); michael@0: test([10, 13], 7, 12, [ 7, 13]); michael@0: test([10, 13], 7, 13, [ 7, 13]); michael@0: test([10, 13], 7, 14, [ 7, 14]); michael@0: test([10, 13], 7, 15, [ 7, 15]); michael@0: test([10, 13], 7, 16, [ 7, 16]); michael@0: test([10, 13], 8, 9, [ 8, 9, 10, 13]); michael@0: test([10, 13], 8, 10, [ 8, 13]); michael@0: test([10, 13], 8, 11, [ 8, 13]); michael@0: test([10, 13], 8, 12, [ 8, 13]); michael@0: test([10, 13], 8, 13, [ 8, 13]); michael@0: test([10, 13], 8, 14, [ 8, 14]); michael@0: test([10, 13], 8, 15, [ 8, 15]); michael@0: test([10, 13], 8, 16, [ 8, 16]); michael@0: test([10, 13], 9, 10, [ 9, 13]); michael@0: test([10, 13], 9, 11, [ 9, 13]); michael@0: test([10, 13], 9, 12, [ 9, 13]); michael@0: test([10, 13], 9, 13, [ 9, 13]); michael@0: test([10, 13], 9, 14, [ 9, 14]); michael@0: test([10, 13], 9, 15, [ 9, 15]); michael@0: test([10, 13], 9, 16, [ 9, 16]); michael@0: test([10, 13], 10, 11, [10, 13]); michael@0: test([10, 13], 10, 12, [10, 13]); michael@0: test([10, 13], 10, 13, [10, 13]); michael@0: test([10, 13], 10, 14, [10, 14]); michael@0: test([10, 13], 10, 15, [10, 15]); michael@0: test([10, 13], 10, 16, [10, 16]); michael@0: test([10, 13], 11, 12, [10, 13]); michael@0: test([10, 13], 11, 13, [10, 13]); michael@0: test([10, 13], 11, 14, [10, 14]); michael@0: test([10, 13], 11, 15, [10, 15]); michael@0: test([10, 13], 11, 16, [10, 16]); michael@0: test([10, 13], 12, 13, [10, 13]); michael@0: test([10, 13], 12, 14, [10, 14]); michael@0: test([10, 13], 12, 15, [10, 15]); michael@0: test([10, 13], 12, 16, [10, 16]); michael@0: test([10, 13], 13, 14, [10, 14]); michael@0: test([10, 13], 13, 15, [10, 15]); michael@0: test([10, 13], 13, 16, [10, 16]); michael@0: test([10, 13], 14, 15, [10, 13, 14, 15]); michael@0: test([10, 13], 14, 16, [10, 13, 14, 16]); michael@0: test([10, 13], 15, 16, [10, 13, 15, 16]); michael@0: michael@0: test([10, 13, 14, 17], 7, 8, [ 7, 8, 10, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 7, 9, [ 7, 9, 10, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 7, 10, [ 7, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 7, 11, [ 7, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 7, 12, [ 7, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 7, 13, [ 7, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 7, 14, [ 7, 17]); michael@0: test([10, 13, 14, 17], 7, 15, [ 7, 17]); michael@0: test([10, 13, 14, 17], 7, 16, [ 7, 17]); michael@0: test([10, 13, 14, 17], 7, 17, [ 7, 17]); michael@0: test([10, 13, 14, 17], 7, 18, [ 7, 18]); michael@0: test([10, 13, 14, 17], 7, 19, [ 7, 19]); michael@0: test([10, 13, 14, 17], 8, 9, [ 8, 9, 10, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 8, 10, [ 8, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 8, 11, [ 8, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 8, 12, [ 8, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 8, 13, [ 8, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 8, 14, [ 8, 17]); michael@0: test([10, 13, 14, 17], 8, 15, [ 8, 17]); michael@0: test([10, 13, 14, 17], 8, 16, [ 8, 17]); michael@0: test([10, 13, 14, 17], 8, 17, [ 8, 17]); michael@0: test([10, 13, 14, 17], 8, 18, [ 8, 18]); michael@0: test([10, 13, 14, 17], 8, 19, [ 8, 19]); michael@0: test([10, 13, 14, 17], 9, 10, [ 9, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 9, 11, [ 9, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 9, 12, [ 9, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 9, 13, [ 9, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 9, 14, [ 9, 17]); michael@0: test([10, 13, 14, 17], 9, 15, [ 9, 17]); michael@0: test([10, 13, 14, 17], 9, 16, [ 9, 17]); michael@0: test([10, 13, 14, 17], 9, 17, [ 9, 17]); michael@0: test([10, 13, 14, 17], 9, 18, [ 9, 18]); michael@0: test([10, 13, 14, 17], 9, 19, [ 9, 19]); michael@0: test([10, 13, 14, 17], 10, 11, [10, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 10, 12, [10, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 10, 13, [10, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 10, 14, [10, 17]); michael@0: test([10, 13, 14, 17], 10, 15, [10, 17]); michael@0: test([10, 13, 14, 17], 10, 16, [10, 17]); michael@0: test([10, 13, 14, 17], 10, 17, [10, 17]); michael@0: test([10, 13, 14, 17], 10, 18, [10, 18]); michael@0: test([10, 13, 14, 17], 10, 19, [10, 19]); michael@0: test([10, 13, 14, 17], 11, 12, [10, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 11, 13, [10, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 11, 14, [10, 17]); michael@0: test([10, 13, 14, 17], 11, 15, [10, 17]); michael@0: test([10, 13, 14, 17], 11, 16, [10, 17]); michael@0: test([10, 13, 14, 17], 11, 17, [10, 17]); michael@0: test([10, 13, 14, 17], 11, 18, [10, 18]); michael@0: test([10, 13, 14, 17], 11, 19, [10, 19]); michael@0: test([10, 13, 14, 17], 12, 13, [10, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 12, 14, [10, 17]); michael@0: test([10, 13, 14, 17], 12, 15, [10, 17]); michael@0: test([10, 13, 14, 17], 12, 16, [10, 17]); michael@0: test([10, 13, 14, 17], 12, 17, [10, 17]); michael@0: test([10, 13, 14, 17], 12, 18, [10, 18]); michael@0: test([10, 13, 14, 17], 12, 19, [10, 19]); michael@0: test([10, 13, 14, 17], 13, 14, [10, 17]); michael@0: test([10, 13, 14, 17], 13, 15, [10, 17]); michael@0: test([10, 13, 14, 17], 13, 16, [10, 17]); michael@0: test([10, 13, 14, 17], 13, 17, [10, 17]); michael@0: test([10, 13, 14, 17], 13, 18, [10, 18]); michael@0: test([10, 13, 14, 17], 13, 19, [10, 19]); michael@0: test([10, 13, 14, 17], 14, 15, [10, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 14, 16, [10, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 14, 17, [10, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 14, 18, [10, 13, 14, 18]); michael@0: test([10, 13, 14, 17], 14, 19, [10, 13, 14, 19]); michael@0: test([10, 13, 14, 17], 15, 16, [10, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 15, 17, [10, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 15, 18, [10, 13, 14, 18]); michael@0: test([10, 13, 14, 17], 15, 19, [10, 13, 14, 19]); michael@0: test([10, 13, 14, 17], 16, 17, [10, 13, 14, 17]); michael@0: test([10, 13, 14, 17], 16, 18, [10, 13, 14, 18]); michael@0: test([10, 13, 14, 17], 16, 19, [10, 13, 14, 19]); michael@0: test([10, 13, 14, 17], 17, 18, [10, 13, 14, 18]); michael@0: test([10, 13, 14, 17], 17, 19, [10, 13, 14, 19]); michael@0: test([10, 13, 14, 17], 18, 19, [10, 13, 14, 17, 18, 19]); michael@0: michael@0: test([10, 13, 16, 19], 7, 14, [ 7, 14, 16, 19]); michael@0: test([10, 13, 16, 19], 7, 15, [ 7, 15, 16, 19]); michael@0: test([10, 13, 16, 19], 7, 16, [ 7, 19]); michael@0: test([10, 13, 16, 19], 8, 14, [ 8, 14, 16, 19]); michael@0: test([10, 13, 16, 19], 8, 15, [ 8, 15, 16, 19]); michael@0: test([10, 13, 16, 19], 8, 16, [ 8, 19]); michael@0: test([10, 13, 16, 19], 9, 14, [ 9, 14, 16, 19]); michael@0: test([10, 13, 16, 19], 9, 15, [ 9, 15, 16, 19]); michael@0: test([10, 13, 16, 19], 9, 16, [ 9, 19]); michael@0: test([10, 13, 16, 19], 10, 14, [10, 14, 16, 19]); michael@0: test([10, 13, 16, 19], 10, 15, [10, 15, 16, 19]); michael@0: test([10, 13, 16, 19], 10, 16, [10, 19]); michael@0: test([10, 13, 16, 19], 11, 14, [10, 14, 16, 19]); michael@0: test([10, 13, 16, 19], 11, 15, [10, 15, 16, 19]); michael@0: test([10, 13, 16, 19], 11, 16, [10, 19]); michael@0: test([10, 13, 16, 19], 12, 14, [10, 14, 16, 19]); michael@0: test([10, 13, 16, 19], 12, 15, [10, 15, 16, 19]); michael@0: test([10, 13, 16, 19], 12, 16, [10, 19]); michael@0: test([10, 13, 16, 19], 13, 14, [10, 14, 16, 19]); michael@0: test([10, 13, 16, 19], 13, 15, [10, 15, 16, 19]); michael@0: test([10, 13, 16, 19], 13, 16, [10, 19]); michael@0: test([10, 13, 16, 19], 14, 15, [10, 13, 14, 15, 16, 19]); michael@0: test([10, 13, 16, 19], 14, 16, [10, 13, 14, 19]); michael@0: test([10, 13, 16, 19], 15, 16, [10, 13, 15, 19]); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: