Bug 790547 - Part 4: xpcshell test case for writing Location Info
authorYoshi Huang <allstars.chh@mozilla.com>
Tue, 25 Sep 2012 10:25:08 +0800
changeset 108707 48d10ef28d529be510ad6771a5e4d8d6a50493d7
parent 108706 c249961afd99b2a287794402309046ad767ffc08
child 108708 9698936945c6159814a7246231856fb47cc20102
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
bugs790547
milestone18.0a1
Bug 790547 - Part 4: xpcshell test case for writing Location Info
dom/system/gonk/tests/test_ril_worker_icc.js
--- a/dom/system/gonk/tests/test_ril_worker_icc.js
+++ b/dom/system/gonk/tests/test_ril_worker_icc.js
@@ -137,8 +137,98 @@ add_test(function test_write_dialling_nu
   number = "9876543";
   len = 5;
   helper.writeDiallingNumber(number);
   do_check_eq(helper.readDiallingNumber(len), number);
 
   run_next_test();
 });
 
+/**
+ * Verify ComprehensionTlvHelper.writeLocationInfoTlv
+ */
+add_test(function test_write_location_info_tlv() {
+  let worker = newUint8Worker();
+  let pduHelper = worker.GsmPDUHelper;
+  let tlvHelper = worker.ComprehensionTlvHelper;
+
+  // Test with 2-digit mnc, and gsmCellId obtained from UMTS network.
+  let loc = {
+    mcc: 466,
+    mnc: 92,
+    gsmLocationAreaCode : 10291,
+    gsmCellId: 19072823
+  };
+  tlvHelper.writeLocationInfoTlv(loc);
+
+  let tag = pduHelper.readHexOctet();
+  do_check_eq(tag, COMPREHENSIONTLV_TAG_LOCATION_INFO |
+                   COMPREHENSIONTLV_FLAG_CR);
+
+  let length = pduHelper.readHexOctet();
+  do_check_eq(length, 9);
+
+  let mcc_mnc = pduHelper.readSwappedNibbleBcdString(3);
+  do_check_eq(mcc_mnc, "46692");
+
+  let lac = (pduHelper.readHexOctet() << 8) | pduHelper.readHexOctet();
+  do_check_eq(lac, 10291);
+
+  let cellId = (pduHelper.readHexOctet() << 24) |
+               (pduHelper.readHexOctet() << 16) |
+               (pduHelper.readHexOctet() << 8)  |
+               (pduHelper.readHexOctet());
+  do_check_eq(cellId, 19072823);
+
+  // Test with 1-digit mnc, and gsmCellId obtained from GSM network.
+  loc = {
+    mcc: 466,
+    mnc: 2,
+    gsmLocationAreaCode : 10291,
+    gsmCellId: 65534
+  };
+  tlvHelper.writeLocationInfoTlv(loc);
+
+  tag = pduHelper.readHexOctet();
+  do_check_eq(tag, COMPREHENSIONTLV_TAG_LOCATION_INFO |
+                   COMPREHENSIONTLV_FLAG_CR);
+
+  length = pduHelper.readHexOctet();
+  do_check_eq(length, 7);
+
+  mcc_mnc = pduHelper.readSwappedNibbleBcdString(3);
+  do_check_eq(mcc_mnc, "46602");
+
+  lac = (pduHelper.readHexOctet() << 8) | pduHelper.readHexOctet();
+  do_check_eq(lac, 10291);
+
+  cellId = (pduHelper.readHexOctet() << 8)  |
+               (pduHelper.readHexOctet());
+  do_check_eq(cellId, 65534);
+
+  // Test with 3-digit mnc, and gsmCellId obtained from GSM network.
+  loc = {
+    mcc: 466,
+    mnc: 222,
+    gsmLocationAreaCode : 10291,
+    gsmCellId: 65534
+  };
+  tlvHelper.writeLocationInfoTlv(loc);
+
+  tag = pduHelper.readHexOctet();
+  do_check_eq(tag, COMPREHENSIONTLV_TAG_LOCATION_INFO |
+                   COMPREHENSIONTLV_FLAG_CR);
+
+  length = pduHelper.readHexOctet();
+  do_check_eq(length, 7);
+
+  mcc_mnc = pduHelper.readSwappedNibbleBcdString(3);
+  do_check_eq(mcc_mnc, "466222");
+
+  lac = (pduHelper.readHexOctet() << 8) | pduHelper.readHexOctet();
+  do_check_eq(lac, 10291);
+
+  cellId = (pduHelper.readHexOctet() << 8) |
+           (pduHelper.readHexOctet());
+  do_check_eq(cellId, 65534);
+
+  run_next_test();
+});