Bug 882985 - 0002. Test case for CDMA information record decoder. r=vicamo
authorChuck Lee <chulee@mozilla.com>
Mon, 09 Sep 2013 23:19:51 +0800
changeset 146617 3e66d6106662dc93fa4230441c2877c96c1957ee
parent 146616 cccdb7f084a40ce98d927e40a2560569378148ff
child 146618 7940f317643d59a1db5f08c9fd7d8a6d0e1eb742
push id25267
push userryanvm@gmail.com
push dateThu, 12 Sep 2013 00:58:25 +0000
treeherdermozilla-central@2f11fad2f307 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvicamo
bugs882985
milestone26.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 882985 - 0002. Test case for CDMA information record decoder. r=vicamo
dom/system/gonk/tests/test_ril_worker_cdma_info_rec.js
dom/system/gonk/tests/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/dom/system/gonk/tests/test_ril_worker_cdma_info_rec.js
@@ -0,0 +1,119 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
+
+function run_test() {
+  run_next_test();
+}
+
+/**
+ * Helper function.
+ */
+function newWorkerWithParcel(parcelBuf) {
+  let worker = newWorker({
+    postRILMessage: function fakePostRILMessage(data) {
+      // Do nothing
+    },
+    postMessage: function fakePostMessage(message) {
+      // Do nothing
+    }
+  });
+
+  let index = 0; // index for read
+  let buf = parcelBuf;
+
+  worker.Buf.readUint8 = function () {
+    return buf[index++];
+  };
+
+  worker.Buf.readUint16 = function () {
+    return buf[index++];
+  };
+
+  worker.Buf.readUint32 = function () {
+    return buf[index++];
+  };
+
+  return worker;
+}
+
+// Test CDMA information record decoder.
+
+/**
+ * Verify decoder for type DISPLAY
+ */
+add_test(function test_display() {
+  let worker = newWorkerWithParcel([
+                0x01, // one inforemation record
+                0x00, // type: display
+                0x09, // length: 9
+                0x54, 0x65, 0x73, 0x74, 0x20, 0x49, 0x6E, 0x66,
+                0x6F, 0x00]);
+  let helper = worker.CdmaPDUHelper;
+  let record = helper.decodeInformationRecord();
+
+  do_check_eq(record.display, "Test Info");
+
+  run_next_test();
+});
+
+/**
+ * Verify decoder for type EXTENDED DISPLAY
+ */
+add_test(function test_extended_display() {
+  let worker = newWorkerWithParcel([
+                0x01, // one inforemation record
+                0x07, // type: extended display
+                0x0E, // length: 14
+                0x80, // header byte
+                0x80, // Blank
+                0x81, // Skip
+                0x9B, // Text
+                0x09, 0x54, 0x65, 0x73, 0x74, 0x20, 0x49, 0x6E,
+                0x66, 0x6F, 0x00]);
+  let helper = worker.CdmaPDUHelper;
+  let record = helper.decodeInformationRecord();
+
+  do_check_eq(record.extendedDisplay.indicator, 1);
+  do_check_eq(record.extendedDisplay.type, 0);
+  do_check_eq(record.extendedDisplay.records.length, 3);
+  do_check_eq(record.extendedDisplay.records[0].tag, 0x80);
+  do_check_eq(record.extendedDisplay.records[1].tag, 0x81);
+  do_check_eq(record.extendedDisplay.records[2].tag, 0x9B);
+  do_check_eq(record.extendedDisplay.records[2].content, "Test Info");
+
+  run_next_test();
+});
+/**
+ * Verify decoder for mixed type
+ */
+add_test(function test_mixed() {
+  let worker = newWorkerWithParcel([
+                0x02, // two inforemation record
+                0x00, // type: display
+                0x09, // length: 9
+                0x54, 0x65, 0x73, 0x74, 0x20, 0x49, 0x6E, 0x66,
+                0x6F, 0x00,
+                0x07, // type: extended display
+                0x0E, // length: 14
+                0x80, // header byte
+                0x80, // Blank
+                0x81, // Skip
+                0x9B, // Text
+                0x09, 0x54, 0x65, 0x73, 0x74, 0x20, 0x49, 0x6E,
+                0x66, 0x6F, 0x00]);
+  let helper = worker.CdmaPDUHelper;
+  let record = helper.decodeInformationRecord();
+
+  do_check_eq(record.display, "Test Info");
+  do_check_eq(record.extendedDisplay.indicator, 1);
+  do_check_eq(record.extendedDisplay.type, 0);
+  do_check_eq(record.extendedDisplay.records.length, 3);
+  do_check_eq(record.extendedDisplay.records[0].tag, 0x80);
+  do_check_eq(record.extendedDisplay.records[1].tag, 0x81);
+  do_check_eq(record.extendedDisplay.records[2].tag, 0x9B);
+  do_check_eq(record.extendedDisplay.records[2].content, "Test Info");
+
+  run_next_test();
+});
--- a/dom/system/gonk/tests/xpcshell.ini
+++ b/dom/system/gonk/tests/xpcshell.ini
@@ -13,8 +13,9 @@ tail =
 [test_ril_worker_cw.js]
 [test_ril_worker_clir.js]
 [test_ril_worker_clip.js]
 [test_ril_worker_ssn.js]
 [test_ril_worker_voiceprivacy.js]
 [test_ril_worker_ecm.js]
 [test_ril_worker_stk.js]
 [test_ril_worker_barring_password.js]
+[test_ril_worker_cdma_info_rec.js]