Bug 816082 - Part 4/4: correct xpcshell test cases. r=hsinyi
authorVicamo Yang <vyang@mozilla.com>
Mon, 17 Dec 2012 18:48:02 +0800
changeset 125367 f0d7097db4216b067c359521221facfe8e8e8aa4
parent 125366 2a616878a5b16cee2813b7eaaba3e6848d287846
child 125368 b62655d36be4374ee89c7be4a2493da0aef59c02
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsinyi
bugs816082
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 816082 - Part 4/4: correct xpcshell test cases. r=hsinyi
dom/system/gonk/tests/test_ril_worker_sms.js
--- a/dom/system/gonk/tests/test_ril_worker_sms.js
+++ b/dom/system/gonk/tests/test_ril_worker_sms.js
@@ -51,26 +51,31 @@ add_test(function test_nl_single_shift_t
     do_check_eq(table[PDU_NL_RESERVED_CONTROL], RESCTL);
   }
 
   run_next_test();
 });
 
 add_test(function test_gsm_sms_strict_7bit_charmap_validity() {
   let defaultTable = PDU_NL_LOCKING_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
+  let defaultShiftTable = PDU_NL_SINGLE_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
   for (let from in GSM_SMS_STRICT_7BIT_CHARMAP) {
     let to = GSM_SMS_STRICT_7BIT_CHARMAP[from];
     do_print("Verifying GSM_SMS_STRICT_7BIT_CHARMAP[\"\\u0x"
              + from.charCodeAt(0).toString(16) + "\"] => \"\\u"
              + to.charCodeAt(0).toString(16) + "\"");
 
     // Make sure "from" is not in default table
     do_check_eq(defaultTable.indexOf(from), -1);
+    do_check_eq(defaultShiftTable.indexOf(from), -1);
     // Make sure "to" is in default table
-    do_check_eq(defaultTable.indexOf(to) >= 0, true);
+    if ((defaultTable.indexOf(to) < 0)
+        && (defaultShiftTable.indexOf(to) < 0)) {
+      do_check_eq(false, true);
+    }
   }
 
   run_next_test();
 });
 
 /**
  * Verify GsmPDUHelper#readDataCodingScheme.
  */
@@ -229,25 +234,26 @@ add_test(function test_RadioInterfaceLay
   let helper = worker.GsmPDUHelper;
   helper.resetOctetWritten = function () {
     helper.octetsWritten = 0;
   };
   helper.writeHexOctet = function () {
     helper.octetsWritten++;
   };
 
-  function do_check_calc(str, expectedCalcLen, lst, sst, strict7BitEncoding) {
+  function do_check_calc(str, expectedCalcLen, lst, sst, strict7BitEncoding, strToWrite) {
     do_check_eq(expectedCalcLen,
                 ril._countGsm7BitSeptets(str,
                                          PDU_NL_LOCKING_SHIFT_TABLES[lst],
                                          PDU_NL_SINGLE_SHIFT_TABLES[sst],
                                          strict7BitEncoding));
 
     helper.resetOctetWritten();
-    helper.writeStringAsSeptets(str, 0, lst, sst, strict7BitEncoding);
+    strToWrite = strToWrite || str;
+    helper.writeStringAsSeptets(strToWrite, 0, lst, sst);
     do_check_eq(Math.ceil(expectedCalcLen * 7 / 8), helper.octetsWritten);
   }
 
   // Test calculation encoded message length using both locking/single shift tables.
   for (let lst = 0; lst < PDU_NL_LOCKING_SHIFT_TABLES.length; lst++) {
     let langTable = PDU_NL_LOCKING_SHIFT_TABLES[lst];
 
     let str = langTable.substring(0, PDU_NL_EXTENDED_ESCAPE)
@@ -282,40 +288,49 @@ add_test(function test_RadioInterfaceLay
 
       // Characters found only in single shift tables should be encoded as
       // <escape><code>, therefore doubles its original length.
       do_check_calc(str2, str2.length * 2, lst, sst);
     }
   }
 
   // Bug 790192: support strict GSM SMS 7-Bit encoding
-  let str = "\u00c1\u00e1\u00cd\u00ed\u00d3\u00f3\u00da\u00fa\u00e7";
-  do_check_calc(str, str.length, PDU_NL_IDENTIFIER_DEFAULT, PDU_NL_IDENTIFIER_DEFAULT, true);
+  let str = "", strToWrite = "", gsmLen = 0;
+  for (let c in GSM_SMS_STRICT_7BIT_CHARMAP) {
+    str += c;
+    strToWrite += GSM_SMS_STRICT_7BIT_CHARMAP[c];
+    if (PDU_NL_LOCKING_SHIFT_TABLES.indexOf(GSM_SMS_STRICT_7BIT_CHARMAP[c])) {
+      gsmLen += 1;
+    } else {
+      gsmLen += 2;
+    }
+  }
+  do_check_calc(str, gsmLen,
+                PDU_NL_IDENTIFIER_DEFAULT, PDU_NL_IDENTIFIER_DEFAULT,
+                true, strToWrite);
 
   run_next_test();
 });
 
 /**
  * Verify RadioInterfaceLayer#calculateUserDataLength handles national language
  * selection correctly.
  */
 add_test(function test_RadioInterfaceLayer__calculateUserDataLength() {
   let ril = newRadioInterfaceLayer();
 
-  function test_calc(str, expected, enabledGsmTableTuples) {
+  function test_calc(str, expected, enabledGsmTableTuples, strict7BitEncoding) {
     ril.enabledGsmTableTuples = enabledGsmTableTuples;
-    let options = ril._calculateUserDataLength(str, expected[5]);
+    let options = ril._calculateUserDataLength(str, strict7BitEncoding);
 
-    do_check_eq(str, options.fullBody);
     do_check_eq(expected[0], options.dcs);
     do_check_eq(expected[1], options.encodedFullBodyLength);
     do_check_eq(expected[2], options.userDataHeaderLength);
     do_check_eq(expected[3], options.langIndex);
     do_check_eq(expected[4], options.langShiftIndex);
-    do_check_eq(expected[5], options.strict7BitEncoding);
   }
 
   // Test UCS fallback
   // - No any default enabled nl tables
   test_calc("A", [PDU_DCS_MSG_CODING_16BITS_ALPHABET, 2, 0,], []);
   // - Character not defined in enabled nl tables
   test_calc("A", [PDU_DCS_MSG_CODING_16BITS_ALPHABET, 2, 0,], [[2, 2]]);
 
@@ -359,19 +374,30 @@ add_test(function test_RadioInterfaceLay
             [PDU_DCS_MSG_CODING_7BITS_ALPHABET, 14, 0, 0, 0], [[3, 1], [0, 0]]);
   // - Case 2, possible early return non-best choice. The original code will
   //   get total cost 6 in the first run and returns immediately. With correct
   //   fix, the best choice should be the second one.
   test_calc(ESCAPE + ESCAPE + ESCAPE + ESCAPE + ESCAPE + "\\",
             [PDU_DCS_MSG_CODING_7BITS_ALPHABET, 2, 0, 0, 0], [[3, 0], [0, 0]]);
 
   // Test Bug 790192: support strict GSM SMS 7-Bit encoding
-  let str = "\u00c1\u00e1\u00cd\u00ed\u00d3\u00f3\u00da\u00fa\u00e7";
-  test_calc(str, [PDU_DCS_MSG_CODING_7BITS_ALPHABET, str.length, 0, 0, 0, true], [[0, 0]]);
-  test_calc(str, [PDU_DCS_MSG_CODING_16BITS_ALPHABET, str.length * 2, 0], [[0, 0]]);
+  let str = "", gsmLen = 0, udhl = 0;
+  for (let c in GSM_SMS_STRICT_7BIT_CHARMAP) {
+    str += c;
+    if (PDU_NL_LOCKING_SHIFT_TABLES.indexOf(GSM_SMS_STRICT_7BIT_CHARMAP[c])) {
+      gsmLen += 1;
+    } else {
+      gsmLen += 2;
+    }
+  }
+  if (str.length > PDU_MAX_USER_DATA_UCS2) {
+    udhl = 5;
+  }
+  test_calc(str, [PDU_DCS_MSG_CODING_7BITS_ALPHABET, gsmLen, 0, 0, 0], [[0, 0]], true);
+  test_calc(str, [PDU_DCS_MSG_CODING_16BITS_ALPHABET, str.length * 2, udhl], [[0, 0]]);
 
   run_next_test();
 });
 
 function generateStringOfLength(str, length) {
   while (str.length < length) {
     if (str.length < (length / 2)) {
       str = str + str;
@@ -406,30 +432,25 @@ add_test(function test_RadioInterfaceLay
 });
 
 /**
  * Verify RadioInterfaceLayer#_fragmentText().
  */
 add_test(function test_RadioInterfaceLayer__fragmentText7Bit() {
   let ril = newRadioInterfaceLayer();
 
-  function test_calc(str, strict7BitEncoding, expected) {
+  function test_calc(str, strict7BitEncoding, expectedSegments) {
+    expectedSegments = expectedSegments || 1;
     let options = ril._fragmentText(str, null, strict7BitEncoding);
-    if (expected) {
-      do_check_eq(expected, options.segments.length);
-    } else {
-      do_check_eq(null, options.segments);
-    }
+    do_check_eq(expectedSegments, options.segments.length);
   }
 
   // 7-Bit
 
   // Boundary checks
-  test_calc("", false);
-  test_calc("", true);
   test_calc(generateStringOfLength("A", PDU_MAX_USER_DATA_7BIT), false);
   test_calc(generateStringOfLength("A", PDU_MAX_USER_DATA_7BIT), true);
   test_calc(generateStringOfLength("A", PDU_MAX_USER_DATA_7BIT + 1), false, 2);
   test_calc(generateStringOfLength("A", PDU_MAX_USER_DATA_7BIT + 1), true, 2);
 
   // Escaped character
   test_calc(generateStringOfLength("{", PDU_MAX_USER_DATA_7BIT / 2), false);
   test_calc(generateStringOfLength("{", PDU_MAX_USER_DATA_7BIT / 2 + 1), false, 2);
@@ -442,27 +463,27 @@ add_test(function test_RadioInterfaceLay
   test_calc(generateStringOfLength("A", (PDU_MAX_USER_DATA_7BIT - 7) * 3), false, 3);
 
   // UCS-2
 
   // Boundary checks
   test_calc(generateStringOfLength("\ua2db", PDU_MAX_USER_DATA_UCS2));
   test_calc(generateStringOfLength("\ua2db", PDU_MAX_USER_DATA_UCS2), true);
   test_calc(generateStringOfLength("\ua2db", PDU_MAX_USER_DATA_UCS2 + 1), false, 2);
-  test_calc(generateStringOfLength("\ua2db", PDU_MAX_USER_DATA_UCS2 + 1), true, 2);
+  // Bug 816082: when strict GSM SMS 7-Bit encoding is enabled, replace unicode
+  // chars with '*'.
+  test_calc(generateStringOfLength("\ua2db", PDU_MAX_USER_DATA_UCS2 + 1), true, 1);
 
   // UCS2 character cannot be separated
   ril.segmentRef16Bit = true;
   test_calc(generateStringOfLength("\ua2db", (PDU_MAX_USER_DATA_UCS2 * 2 - 7) * 2 / 2), false, 3);
   ril.segmentRef16Bit = false;
 
   // Test Bug 790192: support strict GSM SMS 7-Bit encoding
-  let str = "\u00c1\u00e1\u00cd\u00ed\u00d3\u00f3\u00da\u00fa\u00e7";
-  for (let i = 0; i < str.length; i++) {
-    let c = str.charAt(i);
+  for (let c in GSM_SMS_STRICT_7BIT_CHARMAP) {
     test_calc(generateStringOfLength(c, PDU_MAX_USER_DATA_7BIT), false, 3);
     test_calc(generateStringOfLength(c, PDU_MAX_USER_DATA_7BIT), true);
     test_calc(generateStringOfLength(c, PDU_MAX_USER_DATA_UCS2), false);
   }
 
   run_next_test();
 });
 
@@ -497,23 +518,16 @@ add_test(function test_GsmPDUHelper_writ
       helper.resetOctetWritten();
       helper.writeStringAsSeptets(str, paddingBits, PDU_NL_IDENTIFIER_DEFAULT,
                                   PDU_NL_IDENTIFIER_DEFAULT);
       do_check_eq(Math.ceil(((len * 7) + paddingBits) / 8),
                   helper.octetsWritten);
     }
   }
 
-  // Test Bug 790192: support strict GSM SMS 7-Bit encoding
-  let str = "\u00c1\u00e1\u00cd\u00ed\u00d3\u00f3\u00da\u00fa\u00e7";
-  helper.resetOctetWritten();
-  do_print("Verifying GsmPDUHelper.writeStringAsSeptets(" + str + ", 0, <default>, <default>, true)");
-  helper.writeStringAsSeptets(str, 0, PDU_NL_IDENTIFIER_DEFAULT, PDU_NL_IDENTIFIER_DEFAULT, true);
-  do_check_eq(Math.ceil(str.length * 7 / 8), helper.octetsWritten);
-
   run_next_test();
 });
 
 /**
  * Verify receiving SMS-DELIVERY messages
  */
 
 function hexToNibble(nibble) {
@@ -741,17 +755,16 @@ add_test(function test_sendSMS_UCS2_with
 
   worker.RIL.sendSMS({
     number: "1",
     segmentMaxSeq: 2,
     fullBody: "Hello World!",
     dcs: PDU_DCS_MSG_CODING_16BITS_ALPHABET,
     segmentRef16Bit: false,
     userDataHeaderLength: 5,
-    strict7BitEncoding: false,
     requestStatusReport: true,
     segments: [
       {
         body: "Hello ",
         encodedBodyLength: 12,
       }, {
         body: "World!",
         encodedBodyLength: 12,