Bug 962995 - xpcshell tests for write ICC UCS2 characters for 0x81 and 0x82 encoding. r=echen
authorJohn Dai <jdai@mozilla.com>
Wed, 15 Apr 2015 19:07:00 -0400
changeset 239576 2ad3b224ad1cced3d77545a6cdc2fb8098515351
parent 239575 e8dbd3b93ddc2bd89e175523139d3b87b5158a35
child 239577 16a88961ecdee142cd315fa9cbd3c5a906a7b9af
push id12444
push userryanvm@gmail.com
push dateFri, 17 Apr 2015 20:04:42 +0000
treeherderfx-team@560a202db924 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersechen
bugs962995
milestone40.0a1
Bug 962995 - xpcshell tests for write ICC UCS2 characters for 0x81 and 0x82 encoding. r=echen
dom/system/gonk/tests/test_ril_worker_icc_ICCPDUHelper.js
--- a/dom/system/gonk/tests/test_ril_worker_icc_ICCPDUHelper.js
+++ b/dom/system/gonk/tests/test_ril_worker_icc_ICCPDUHelper.js
@@ -43,16 +43,69 @@ add_test(function test_read_icc_ucs2_str
     helper.writeHexOctet(array2[i]);
   }
   equal(iccHelper.readICCUCS2String(0x82, len2), "Mozilla\u694a");
 
   run_next_test();
 });
 
 /**
+ * Verify ICCPDUHelper#writeICCUCS2String()
+ */
+add_test(function test_write_icc_ucs2_string() {
+  let worker = newUint8Worker();
+  let context = worker.ContextPool._contexts[0];
+  let helper = context.GsmPDUHelper;
+  let iccHelper = context.ICCPDUHelper;
+  let alphaLen = 18;
+  let test_data = [
+    {
+      encode: 0x80,
+      // string only contain one character.
+      data: "\u82b3"
+    }, {
+      encode: 0x80,
+      // 2 UCS2 character not located in the same half-page.
+      data: "Fire \u82b3\u8233"
+    }, {
+      encode: 0x80,
+      // 2 UCS2 character not located in the same half-page.
+      data: "\u694a\u704a"
+    }, {
+      encode: 0x81,
+      // 2 UCS2 character within same half-page.
+      data: "Fire \u6901\u697f"
+    }, {
+      encode: 0x81,
+      // 2 UCS2 character within same half-page.
+      data: "Fire \u6980\u69ff"
+    }, {
+      encode: 0x82,
+      // 2 UCS2 character within same half-page, but bit 8 is different.
+      data: "Fire \u0514\u0593"
+    }, {
+      encode: 0x82,
+      // 2 UCS2 character over 0x81 can encode range.
+      data: "Fire \u8000\u8001"
+    }, {
+      encode: 0x82,
+      // 2 UCS2 character over 0x81 can encode range.
+      data: "Fire \ufffd\ufffe"
+    }];
+
+  for (let i = 0; i < test_data.length; i++) {
+    let test = test_data[i];
+    iccHelper.writeICCUCS2String(alphaLen, test.data);
+    equal(helper.readHexOctet(), test.encode);
+    equal(iccHelper.readICCUCS2String(test.encode, alphaLen - 1), test.data);
+  }
+
+  run_next_test();
+});
+/**
  * Verify ICCPDUHelper#readDiallingNumber
  */
 add_test(function test_read_dialling_number() {
   let worker = newUint8Worker();
   let context = worker.ContextPool._contexts[0];
   let helper = context.GsmPDUHelper;
   let iccHelper = context.ICCPDUHelper;
   let str = "123456789";
@@ -287,30 +340,30 @@ add_test(function test_write_alpha_ident
   equal(iccHelper.readAlphaIdentifier(10), "");
 
   // GSM 8 bit
   let str = "Mozilla";
   iccHelper.writeAlphaIdentifier(str.length + ffLen, str);
   equal(iccHelper.readAlphaIdentifier(str.length + ffLen), str);
 
   // UCS2
-  str = "Mozilla\u694a";
+  str = "Mozilla\u8000";
   iccHelper.writeAlphaIdentifier(str.length * 2 + ffLen, str);
   // * 2 for each character will be encoded to UCS2 alphabets.
   equal(iccHelper.readAlphaIdentifier(str.length * 2 + ffLen), str);
 
   // Test with maximum octets written.
   // 1 coding scheme (0x80) and 1 UCS2 character, total 3 octets.
   str = "\u694a";
   iccHelper.writeAlphaIdentifier(3, str);
   equal(iccHelper.readAlphaIdentifier(3), str);
 
   // 1 coding scheme (0x80) and 2 UCS2 characters, total 5 octets.
   // numOctets is limited to 4, so only 1 UCS2 character can be written.
-  str = "\u694a\u694a";
+  str = "\u694a\u69ca";
   iccHelper.writeAlphaIdentifier(4, str);
   helper.writeHexOctet(0xff); // dummy octet.
   equal(iccHelper.readAlphaIdentifier(5), str.substring(0, 1));
 
   // Write 0 octet.
   iccHelper.writeAlphaIdentifier(0, "1");
   helper.writeHexOctet(0xff); // dummy octet.
   equal(iccHelper.readAlphaIdentifier(1), "");