dom/system/gonk/tests/test_ril_worker_cellbroadcast.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

     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 add_test(function test_ril_consts_cellbroadcast_misc() {
    11   // Must be 16 for indexing.
    12   do_check_eq(CB_DCS_LANG_GROUP_1.length, 16);
    13   do_check_eq(CB_DCS_LANG_GROUP_2.length, 16);
    15   // Array length must be even.
    16   do_check_eq(CB_NON_MMI_SETTABLE_RANGES.length & 0x01, 0);
    17   for (let i = 0; i < CB_NON_MMI_SETTABLE_RANGES.length;) {
    18     let from = CB_NON_MMI_SETTABLE_RANGES[i++];
    19     let to = CB_NON_MMI_SETTABLE_RANGES[i++];
    20     do_check_eq(from < to, true);
    21   }
    23   run_next_test();
    24 });
    26 add_test(function test_ril_worker_GsmPDUHelper_readCbDataCodingScheme() {
    27   let worker = newWorker({
    28     postRILMessage: function(data) {
    29       // Do nothing
    30     },
    31     postMessage: function(message) {
    32       // Do nothing
    33     }
    34   });
    36   let context = worker.ContextPool._contexts[0];
    37   function test_dcs(dcs, encoding, language, hasLanguageIndicator, messageClass) {
    38     context.Buf.readUint8 = function() {
    39       return dcs;
    40     };
    42     let msg = {};
    43     context.GsmPDUHelper.readCbDataCodingScheme(msg);
    45     do_check_eq(msg.dcs, dcs);
    46     do_check_eq(msg.encoding, encoding);
    47     do_check_eq(msg.language, language);
    48     do_check_eq(msg.hasLanguageIndicator, hasLanguageIndicator);
    49     do_check_eq(msg.messageClass, messageClass);
    50   }
    52   function test_dcs_throws(dcs) {
    53     context.Buf.readUint8 = function() {
    54       return dcs;
    55     };
    57     do_check_throws(function() {
    58       context.GsmPDUHelper.readCbDataCodingScheme({});
    59     }, "Unsupported CBS data coding scheme: " + dcs);
    60   }
    62   // Group 0000
    63   for (let i = 0; i < 16; i++) {
    64     test_dcs(i, PDU_DCS_MSG_CODING_7BITS_ALPHABET, CB_DCS_LANG_GROUP_1[i],
    65              false, GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]);
    66   }
    68   // Group 0001
    69   //   0000 GSM 7 bit default alphabet; message preceded by language indication.
    70   test_dcs(0x10, PDU_DCS_MSG_CODING_7BITS_ALPHABET, null, true,
    71            GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]);
    72   //   0001 UCS2; message preceded by language indication.
    73   test_dcs(0x11, PDU_DCS_MSG_CODING_16BITS_ALPHABET, null, true,
    74            GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]);
    76   // Group 0010
    77   //   0000..0100
    78   for (let i = 0; i < 5; i++) {
    79     test_dcs(0x20 + i, PDU_DCS_MSG_CODING_7BITS_ALPHABET,
    80              CB_DCS_LANG_GROUP_2[i], false,
    81              GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]);
    82   }
    83   //   0101..1111 Reserved
    84   for (let i = 5; i < 16; i++) {
    85     test_dcs(0x20 + i, PDU_DCS_MSG_CODING_7BITS_ALPHABET, null, false,
    86              GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]);
    87   }
    89   // Group 0100, 0101, 1001
    90   for (let group of [0x40, 0x50, 0x90]) {
    91     for (let i = 0; i < 16; i++) {
    92       let encoding = i & 0x0C;
    93       if (encoding == 0x0C) {
    94         encoding = PDU_DCS_MSG_CODING_7BITS_ALPHABET;
    95       }
    96       let messageClass = GECKO_SMS_MESSAGE_CLASSES[i & PDU_DCS_MSG_CLASS_BITS];
    97       test_dcs(group + i, encoding, null, false, messageClass);
    98     }
    99   }
   101   // Group 1111
   102   for (let i = 0; i < 16; i ++) {
   103     let encoding = i & 0x04 ? PDU_DCS_MSG_CODING_8BITS_ALPHABET
   104                             : PDU_DCS_MSG_CODING_7BITS_ALPHABET;
   105     let messageClass;
   106     switch(i & PDU_DCS_MSG_CLASS_BITS) {
   107       case 0x01: messageClass = PDU_DCS_MSG_CLASS_USER_1; break;
   108       case 0x02: messageClass = PDU_DCS_MSG_CLASS_USER_2; break;
   109       case 0x03: messageClass = PDU_DCS_MSG_CLASS_3; break;
   110       default: messageClass = PDU_DCS_MSG_CLASS_NORMAL; break;
   111     }
   112     test_dcs(0xF0 + i, encoding, null, false,
   113              GECKO_SMS_MESSAGE_CLASSES[messageClass]);
   114   }
   116   // Group 0011, 1000, 1010, 1011, 1100
   117   //   0000..1111 Reserved
   118   for (let group of [0x30, 0x80, 0xA0, 0xB0, 0xC0]) {
   119     for (let i = 0; i < 16; i++) {
   120       test_dcs(group + i, PDU_DCS_MSG_CODING_7BITS_ALPHABET, null, false,
   121                GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]);
   122     }
   123   }
   125   // Group 0110, 0111, 1101, 1110
   126   //   TODO: unsupported
   127   for (let group of [0x60, 0x70, 0xD0, 0xE0]) {
   128     for (let i = 0; i < 16; i++) {
   129       test_dcs_throws(group + i);
   130     }
   131   }
   133   run_next_test();
   134 });
   136 add_test(function test_ril_worker_GsmPDUHelper_readGsmCbData() {
   137   let worker = newWorker({
   138     postRILMessage: function(data) {
   139       // Do nothing
   140     },
   141     postMessage: function(message) {
   142       // Do nothing
   143     }
   144   });
   146   let context = worker.ContextPool._contexts[0];
   147   function test_data(options, expected) {
   148     let readIndex = 0;
   149     context.Buf.readUint8 = function() {
   150       return options[3][readIndex++];
   151     };
   152     context.Buf.readUint8Array = function(length) {
   153       let array = new Uint8Array(length);
   154       for (let i = 0; i < length; i++) {
   155         array[i] = this.readUint8();
   156       }
   157       return array;
   158     };
   160     let msg = {
   161       encoding: options[0],
   162       language: options[1],
   163       hasLanguageIndicator: options[2]
   164     };
   165     context.GsmPDUHelper.readGsmCbData(msg, options[3].length);
   167     do_check_eq(msg.body, expected[0]);
   168     do_check_eq(msg.data == null, expected[1] == null);
   169     if (expected[1] != null) {
   170       do_check_eq(msg.data.length, expected[1].length);
   171       for (let i = 0; i < expected[1].length; i++) {
   172         do_check_eq(msg.data[i], expected[1][i]);
   173       }
   174     }
   175     do_check_eq(msg.language, expected[2]);
   176   }
   178   // We're testing Cell Broadcast message body with all zeros octet stream. As
   179   // shown in 3GPP TS 23.038, septet 0x00 will be decoded as '@' when both
   180   // langTableIndex and langShiftTableIndex equal to
   181   // PDU_DCS_MSG_CODING_7BITS_ALPHABET.
   183   // PDU_DCS_MSG_CODING_7BITS_ALPHABET
   184   test_data([PDU_DCS_MSG_CODING_7BITS_ALPHABET, null, false,
   185               [0]],
   186             ["@", null, null]);
   187   test_data([PDU_DCS_MSG_CODING_7BITS_ALPHABET, null, true,
   188               [0, 0, 0, 0]],
   189             ["@", null, "@@"]);
   190   test_data([PDU_DCS_MSG_CODING_7BITS_ALPHABET, "@@", false,
   191               [0]],
   192             ["@", null, "@@"]);
   194   // PDU_DCS_MSG_CODING_8BITS_ALPHABET
   195   test_data([PDU_DCS_MSG_CODING_8BITS_ALPHABET, null, false,
   196               [0]],
   197             [null, [0], null]);
   199   // PDU_DCS_MSG_CODING_16BITS_ALPHABET
   200   test_data([PDU_DCS_MSG_CODING_16BITS_ALPHABET, null, false,
   201               [0x00, 0x40]],
   202             ["@", null, null]);
   203   test_data([PDU_DCS_MSG_CODING_16BITS_ALPHABET, null, true,
   204               [0x00, 0x00, 0x00, 0x40]],
   205             ["@", null, "@@"]);
   206   test_data([PDU_DCS_MSG_CODING_16BITS_ALPHABET, "@@", false,
   207               [0x00, 0x40]],
   208             ["@", null, "@@"]);
   210   run_next_test();
   211 });
   213 add_test(function test_ril_worker__checkCellBroadcastMMISettable() {
   214   let worker = newWorker({
   215     postRILMessage: function(data) {
   216       // Do nothing
   217     },
   218     postMessage: function(message) {
   219       // Do nothing
   220     }
   221   });
   223   let context = worker.ContextPool._contexts[0];
   224   let ril = context.RIL;
   226   function test(from, to, expected) {
   227     do_check_eq(expected, ril._checkCellBroadcastMMISettable(from, to));
   228   }
   230   test(-2, -1, false);
   231   test(-1, 0, false);
   232   test(0, 1, true);
   233   test(1, 1, false);
   234   test(2, 1, false);
   235   test(65536, 65537, false);
   237   // We have both [4096, 4224), [4224, 4352), so it's actually [4096, 4352),
   238   // and [61440, 65536), [65535, 65536), so it's actually [61440, 65536).
   239   for (let i = 0; i < CB_NON_MMI_SETTABLE_RANGES.length;) {
   240     let from = CB_NON_MMI_SETTABLE_RANGES[i++];
   241     let to = CB_NON_MMI_SETTABLE_RANGES[i++];
   242     if ((from != 4224) && (from != 65535)) {
   243       test(from - 1, from, true);
   244     }
   245     test(from - 1, from + 1, false);
   246     test(from - 1, to, false);
   247     test(from - 1, to + 1, false);
   248     test(from, from + 1, false);
   249     test(from, to, false);
   250     test(from, to + 1, false);
   251     if ((from + 1) < to) {
   252       test(from + 1, to, false);
   253       test(from + 1, to + 1, false);
   254     }
   255     if ((to != 4224) && (to < 65535)) {
   256       test(to, to + 1, true);
   257       test(to + 1, to + 2, true);
   258     }
   259   }
   261   run_next_test();
   262 });
   264 add_test(function test_ril_worker__mergeCellBroadcastConfigs() {
   265   let worker = newWorker({
   266     postRILMessage: function(data) {
   267       // Do nothing
   268     },
   269     postMessage: function(message) {
   270       // Do nothing
   271     }
   272   });
   274   let context = worker.ContextPool._contexts[0];
   275   let ril = context.RIL;
   277   function test(olist, from, to, expected) {
   278     let result = ril._mergeCellBroadcastConfigs(olist, from, to);
   279     do_check_eq(JSON.stringify(expected), JSON.stringify(result));
   280   }
   282   test(null, 0, 1, [0, 1]);
   284   test([10, 13],  7,  8, [ 7,  8, 10, 13]);
   285   test([10, 13],  7,  9, [ 7,  9, 10, 13]);
   286   test([10, 13],  7, 10, [ 7, 13]);
   287   test([10, 13],  7, 11, [ 7, 13]);
   288   test([10, 13],  7, 12, [ 7, 13]);
   289   test([10, 13],  7, 13, [ 7, 13]);
   290   test([10, 13],  7, 14, [ 7, 14]);
   291   test([10, 13],  7, 15, [ 7, 15]);
   292   test([10, 13],  7, 16, [ 7, 16]);
   293   test([10, 13],  8,  9, [ 8,  9, 10, 13]);
   294   test([10, 13],  8, 10, [ 8, 13]);
   295   test([10, 13],  8, 11, [ 8, 13]);
   296   test([10, 13],  8, 12, [ 8, 13]);
   297   test([10, 13],  8, 13, [ 8, 13]);
   298   test([10, 13],  8, 14, [ 8, 14]);
   299   test([10, 13],  8, 15, [ 8, 15]);
   300   test([10, 13],  8, 16, [ 8, 16]);
   301   test([10, 13],  9, 10, [ 9, 13]);
   302   test([10, 13],  9, 11, [ 9, 13]);
   303   test([10, 13],  9, 12, [ 9, 13]);
   304   test([10, 13],  9, 13, [ 9, 13]);
   305   test([10, 13],  9, 14, [ 9, 14]);
   306   test([10, 13],  9, 15, [ 9, 15]);
   307   test([10, 13],  9, 16, [ 9, 16]);
   308   test([10, 13], 10, 11, [10, 13]);
   309   test([10, 13], 10, 12, [10, 13]);
   310   test([10, 13], 10, 13, [10, 13]);
   311   test([10, 13], 10, 14, [10, 14]);
   312   test([10, 13], 10, 15, [10, 15]);
   313   test([10, 13], 10, 16, [10, 16]);
   314   test([10, 13], 11, 12, [10, 13]);
   315   test([10, 13], 11, 13, [10, 13]);
   316   test([10, 13], 11, 14, [10, 14]);
   317   test([10, 13], 11, 15, [10, 15]);
   318   test([10, 13], 11, 16, [10, 16]);
   319   test([10, 13], 12, 13, [10, 13]);
   320   test([10, 13], 12, 14, [10, 14]);
   321   test([10, 13], 12, 15, [10, 15]);
   322   test([10, 13], 12, 16, [10, 16]);
   323   test([10, 13], 13, 14, [10, 14]);
   324   test([10, 13], 13, 15, [10, 15]);
   325   test([10, 13], 13, 16, [10, 16]);
   326   test([10, 13], 14, 15, [10, 13, 14, 15]);
   327   test([10, 13], 14, 16, [10, 13, 14, 16]);
   328   test([10, 13], 15, 16, [10, 13, 15, 16]);
   330   test([10, 13, 14, 17],  7,  8, [ 7,  8, 10, 13, 14, 17]);
   331   test([10, 13, 14, 17],  7,  9, [ 7,  9, 10, 13, 14, 17]);
   332   test([10, 13, 14, 17],  7, 10, [ 7, 13, 14, 17]);
   333   test([10, 13, 14, 17],  7, 11, [ 7, 13, 14, 17]);
   334   test([10, 13, 14, 17],  7, 12, [ 7, 13, 14, 17]);
   335   test([10, 13, 14, 17],  7, 13, [ 7, 13, 14, 17]);
   336   test([10, 13, 14, 17],  7, 14, [ 7, 17]);
   337   test([10, 13, 14, 17],  7, 15, [ 7, 17]);
   338   test([10, 13, 14, 17],  7, 16, [ 7, 17]);
   339   test([10, 13, 14, 17],  7, 17, [ 7, 17]);
   340   test([10, 13, 14, 17],  7, 18, [ 7, 18]);
   341   test([10, 13, 14, 17],  7, 19, [ 7, 19]);
   342   test([10, 13, 14, 17],  8,  9, [ 8,  9, 10, 13, 14, 17]);
   343   test([10, 13, 14, 17],  8, 10, [ 8, 13, 14, 17]);
   344   test([10, 13, 14, 17],  8, 11, [ 8, 13, 14, 17]);
   345   test([10, 13, 14, 17],  8, 12, [ 8, 13, 14, 17]);
   346   test([10, 13, 14, 17],  8, 13, [ 8, 13, 14, 17]);
   347   test([10, 13, 14, 17],  8, 14, [ 8, 17]);
   348   test([10, 13, 14, 17],  8, 15, [ 8, 17]);
   349   test([10, 13, 14, 17],  8, 16, [ 8, 17]);
   350   test([10, 13, 14, 17],  8, 17, [ 8, 17]);
   351   test([10, 13, 14, 17],  8, 18, [ 8, 18]);
   352   test([10, 13, 14, 17],  8, 19, [ 8, 19]);
   353   test([10, 13, 14, 17],  9, 10, [ 9, 13, 14, 17]);
   354   test([10, 13, 14, 17],  9, 11, [ 9, 13, 14, 17]);
   355   test([10, 13, 14, 17],  9, 12, [ 9, 13, 14, 17]);
   356   test([10, 13, 14, 17],  9, 13, [ 9, 13, 14, 17]);
   357   test([10, 13, 14, 17],  9, 14, [ 9, 17]);
   358   test([10, 13, 14, 17],  9, 15, [ 9, 17]);
   359   test([10, 13, 14, 17],  9, 16, [ 9, 17]);
   360   test([10, 13, 14, 17],  9, 17, [ 9, 17]);
   361   test([10, 13, 14, 17],  9, 18, [ 9, 18]);
   362   test([10, 13, 14, 17],  9, 19, [ 9, 19]);
   363   test([10, 13, 14, 17], 10, 11, [10, 13, 14, 17]);
   364   test([10, 13, 14, 17], 10, 12, [10, 13, 14, 17]);
   365   test([10, 13, 14, 17], 10, 13, [10, 13, 14, 17]);
   366   test([10, 13, 14, 17], 10, 14, [10, 17]);
   367   test([10, 13, 14, 17], 10, 15, [10, 17]);
   368   test([10, 13, 14, 17], 10, 16, [10, 17]);
   369   test([10, 13, 14, 17], 10, 17, [10, 17]);
   370   test([10, 13, 14, 17], 10, 18, [10, 18]);
   371   test([10, 13, 14, 17], 10, 19, [10, 19]);
   372   test([10, 13, 14, 17], 11, 12, [10, 13, 14, 17]);
   373   test([10, 13, 14, 17], 11, 13, [10, 13, 14, 17]);
   374   test([10, 13, 14, 17], 11, 14, [10, 17]);
   375   test([10, 13, 14, 17], 11, 15, [10, 17]);
   376   test([10, 13, 14, 17], 11, 16, [10, 17]);
   377   test([10, 13, 14, 17], 11, 17, [10, 17]);
   378   test([10, 13, 14, 17], 11, 18, [10, 18]);
   379   test([10, 13, 14, 17], 11, 19, [10, 19]);
   380   test([10, 13, 14, 17], 12, 13, [10, 13, 14, 17]);
   381   test([10, 13, 14, 17], 12, 14, [10, 17]);
   382   test([10, 13, 14, 17], 12, 15, [10, 17]);
   383   test([10, 13, 14, 17], 12, 16, [10, 17]);
   384   test([10, 13, 14, 17], 12, 17, [10, 17]);
   385   test([10, 13, 14, 17], 12, 18, [10, 18]);
   386   test([10, 13, 14, 17], 12, 19, [10, 19]);
   387   test([10, 13, 14, 17], 13, 14, [10, 17]);
   388   test([10, 13, 14, 17], 13, 15, [10, 17]);
   389   test([10, 13, 14, 17], 13, 16, [10, 17]);
   390   test([10, 13, 14, 17], 13, 17, [10, 17]);
   391   test([10, 13, 14, 17], 13, 18, [10, 18]);
   392   test([10, 13, 14, 17], 13, 19, [10, 19]);
   393   test([10, 13, 14, 17], 14, 15, [10, 13, 14, 17]);
   394   test([10, 13, 14, 17], 14, 16, [10, 13, 14, 17]);
   395   test([10, 13, 14, 17], 14, 17, [10, 13, 14, 17]);
   396   test([10, 13, 14, 17], 14, 18, [10, 13, 14, 18]);
   397   test([10, 13, 14, 17], 14, 19, [10, 13, 14, 19]);
   398   test([10, 13, 14, 17], 15, 16, [10, 13, 14, 17]);
   399   test([10, 13, 14, 17], 15, 17, [10, 13, 14, 17]);
   400   test([10, 13, 14, 17], 15, 18, [10, 13, 14, 18]);
   401   test([10, 13, 14, 17], 15, 19, [10, 13, 14, 19]);
   402   test([10, 13, 14, 17], 16, 17, [10, 13, 14, 17]);
   403   test([10, 13, 14, 17], 16, 18, [10, 13, 14, 18]);
   404   test([10, 13, 14, 17], 16, 19, [10, 13, 14, 19]);
   405   test([10, 13, 14, 17], 17, 18, [10, 13, 14, 18]);
   406   test([10, 13, 14, 17], 17, 19, [10, 13, 14, 19]);
   407   test([10, 13, 14, 17], 18, 19, [10, 13, 14, 17, 18, 19]);
   409   test([10, 13, 16, 19],  7, 14, [ 7, 14, 16, 19]);
   410   test([10, 13, 16, 19],  7, 15, [ 7, 15, 16, 19]);
   411   test([10, 13, 16, 19],  7, 16, [ 7, 19]);
   412   test([10, 13, 16, 19],  8, 14, [ 8, 14, 16, 19]);
   413   test([10, 13, 16, 19],  8, 15, [ 8, 15, 16, 19]);
   414   test([10, 13, 16, 19],  8, 16, [ 8, 19]);
   415   test([10, 13, 16, 19],  9, 14, [ 9, 14, 16, 19]);
   416   test([10, 13, 16, 19],  9, 15, [ 9, 15, 16, 19]);
   417   test([10, 13, 16, 19],  9, 16, [ 9, 19]);
   418   test([10, 13, 16, 19], 10, 14, [10, 14, 16, 19]);
   419   test([10, 13, 16, 19], 10, 15, [10, 15, 16, 19]);
   420   test([10, 13, 16, 19], 10, 16, [10, 19]);
   421   test([10, 13, 16, 19], 11, 14, [10, 14, 16, 19]);
   422   test([10, 13, 16, 19], 11, 15, [10, 15, 16, 19]);
   423   test([10, 13, 16, 19], 11, 16, [10, 19]);
   424   test([10, 13, 16, 19], 12, 14, [10, 14, 16, 19]);
   425   test([10, 13, 16, 19], 12, 15, [10, 15, 16, 19]);
   426   test([10, 13, 16, 19], 12, 16, [10, 19]);
   427   test([10, 13, 16, 19], 13, 14, [10, 14, 16, 19]);
   428   test([10, 13, 16, 19], 13, 15, [10, 15, 16, 19]);
   429   test([10, 13, 16, 19], 13, 16, [10, 19]);
   430   test([10, 13, 16, 19], 14, 15, [10, 13, 14, 15, 16, 19]);
   431   test([10, 13, 16, 19], 14, 16, [10, 13, 14, 19]);
   432   test([10, 13, 16, 19], 15, 16, [10, 13, 15, 19]);
   434   run_next_test();
   435 });

mercurial