Bug 788441: Add alphanumeric parsing. r=vyang
authorChia-hung Tai <ctai@mozilla.com>
Tue, 13 Nov 2012 11:57:25 +0800
changeset 113062 34903538f4588b0f6174970bfb1d64a592ad30a7
parent 113061 24babe39cd7e49b531f003478eab98f9e29060bc
child 113063 a2cdd1e642672e54533648fabb01c2f4a20c4122
push id17920
push uservyang@mozilla.com
push dateTue, 13 Nov 2012 05:48:59 +0000
treeherdermozilla-inbound@34903538f458 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvyang
bugs788441
milestone19.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 788441: Add alphanumeric parsing. r=vyang
dom/system/gonk/ril_worker.js
dom/system/gonk/tests/test_ril_worker_sms.js
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -5889,30 +5889,35 @@ let GsmPDUHelper = {
     }
     if (len % 2 == 1) {
       len += 1;
     }
     if (DEBUG) debug("PDU: Going to read address: " + len);
 
     // Type-of-Address
     let toa = this.readHexOctet();
-
-    // Address-Value
-    let addr = this.readSwappedNibbleBcdString(len / 2);
+    let addr = "";
+
+    if ((toa & 0xF0) == PDU_TOA_ALPHANUMERIC) {
+      addr = this.readSeptetsToString(Math.floor(len * 4 / 7), 0,
+          PDU_NL_IDENTIFIER_DEFAULT , PDU_NL_IDENTIFIER_DEFAULT );
+      return addr;
+    }
+    addr = this.readSwappedNibbleBcdString(len / 2);
     if (addr.length <= 0) {
       if (DEBUG) debug("PDU error: no number provided");
       return null;
     }
-    if ((toa >> 4) == (PDU_TOA_INTERNATIONAL >> 4)) {
+    if ((toa & 0xF0) == (PDU_TOA_INTERNATIONAL)) {
       addr = '+' + addr;
     }
 
     return addr;
   },
-  
+
   /**
    * Read Alpha Identifier.
    *
    * @see TS 131.102
    *
    * @param numOctets
    *        Number of octets to be read.
    *
--- a/dom/system/gonk/tests/test_ril_worker_sms.js
+++ b/dom/system/gonk/tests/test_ril_worker_sms.js
@@ -709,8 +709,54 @@ for (let lst = 0; lst < PDU_NL_LOCKING_S
 
     if (lst == 0) {
       ucs2str += PDU_NL_SINGLE_SHIFT_TABLES[sst];
     }
   }
 }
 test_receiving_ucs2_alphabets(ucs2str);
 
+/**
+ * Verify GsmPDUHelper#readAddress
+ */
+add_test(function test_GsmPDUHelper_readAddress() {
+  let worker = newWorker({
+    postRILMessage: function fakePostRILMessage(data) {
+      // Do nothing
+    },
+    postMessage: function fakePostMessage(message) {
+      // Do nothing
+    }
+
+  });
+
+  let helper = worker.GsmPDUHelper;
+  function test_address(addrHex, addrString) {
+    let uint16Array = [];
+    let ix = 0;
+    for (let i = 0; i < addrHex.length; ++i) {
+      uint16Array[i] = addrHex[i].charCodeAt();
+    }
+
+    worker.Buf.readUint16 = function (){
+      if(ix >= uint16Array.length) {
+        do_throw("out of range in uint16Array");
+      }
+      return uint16Array[ix++];
+    }
+    let length = helper.readHexOctet();
+    let parsedAddr = helper.readAddress(length);
+    do_check_eq(parsedAddr, addrString);
+  }
+
+  // For AlphaNumeric
+  test_address("04D01100", "_@");
+  test_address("04D01000", "\u0394@");
+
+  // Direct prepand
+  test_address("0B914151245584F6", "+14154255486");
+  test_address("0E914151245584B633", "+14154255486#33");
+
+  // PDU_TOA_NATIONAL
+  test_address("0BA14151245584F6", "14154255486");
+
+  run_next_test();
+});