Bug 1235110 - Part 2: Add Test Coverage. r=echen

This commit is contained in:
Bevis Tseng 2015-12-30 16:22:21 +08:00
parent f0e4043247
commit 78c916b9ff
6 changed files with 62 additions and 20 deletions

View File

@ -91,7 +91,7 @@ function testReceiving_ETWS_MessageId() {
// Message Identifier has 16 bits, but no bitwise operation is needed.
// Test some selected values only.
let messageIds = [
0x0000, 0x0001, 0x0010, 0x0100, 0x1000, 0x1111, 0x8888, 0x8811,
0x0000, 0x0001, 0x0010, 0x0100, 0x1111, 0x8888, 0x8811,
];
let verifyCBMessage = (aMessage, aMessageId) => {

View File

@ -90,7 +90,7 @@ function testReceiving_GSM_MessageId() {
// Message Identifier has 16 bits, but no bitwise operation is needed.
// Test some selected values only.
let messageIds = [
0x0000, 0x0001, 0x0010, 0x0100, 0x1000, 0x1111, 0x8888, 0x8811,
0x0000, 0x0001, 0x0010, 0x0100, 0x1111, 0x8888, 0x8811,
];
let verifyCBMessage = (aMessage, aMessageId) => {

View File

@ -102,7 +102,7 @@ function testReceiving_UMTS_MessageId() {
// Message Identifier has 16 bits, but no bitwise operation is needed.
// Test some selected values only.
let messageIds = [
0x0000, 0x0001, 0x0010, 0x0100, 0x1000, 0x1111, 0x8888, 0x8811,
0x0000, 0x0001, 0x0010, 0x0100, 0x1111, 0x8888, 0x8811,
];
let verifyCBMessage = (aMessage, aMessageId) => {

View File

@ -191,3 +191,27 @@ function newIncomingParcel(fakeParcelSize, response, request, data) {
return bytes;
}
/**
* Create a parcel buffer which represents the hex string.
*
* @param hexString
* The HEX string to be converted.
*
* @return an Uint8Array carrying all parcel data.
*/
function hexStringToParcelByteArrayData(hexString) {
let length = Math.ceil((hexString.length / 2));
let bytes = new Uint8Array(4 + length);
bytes[0] = length & 0xFF;
bytes[1] = (length >> 8) & 0xFF;
bytes[2] = (length >> 16) & 0xFF;
bytes[3] = (length >> 24) & 0xFF;
for (let i = 0; i < length; i ++) {
bytes[i + 4] = Number.parseInt(hexString.substr(i * 2, 2), 16);
}
return bytes;
}

View File

@ -193,3 +193,38 @@ add_test(function test_ril_worker_GsmPDUHelper_readGsmCbData() {
run_next_test();
});
add_test(function test_ril_worker_Sim_Download_Message() {
let worker = newWorker({
postRILMessage: function(data) {
// Do nothing
},
postMessage: function(message) {
ok(message.rilMessageType !== "cellbroadcast-received",
"Data-Download message shall be ignored.");
}
});
function buildPdu(aMessageId) {
return "C002" + aMessageId + "011154741914AFA7C76B9058" +
"FEBEBB41E6371EA4AEB7E173D0DB5E96" +
"83E8E832881DD6E741E4F7B9D168341A" +
"8D46A3D168341A8D46A3D168341A8D46" +
"A3D168341A8D46A3D168341A8D46A3D1" +
"68341A8D46A3D100";
}
["1000", "107F", "1080", "10FF"].forEach(aMessageId => {
worker.onRILMessage(
0,
newIncomingParcel(
-1,
RESPONSE_TYPE_UNSOLICITED,
UNSOLICITED_RESPONSE_NEW_BROADCAST_SMS,
hexStringToParcelByteArrayData(buildPdu(aMessageId))));
});
ok(true, "All Data-Download Messages are ingored.");
run_next_test();
});

View File

@ -15,23 +15,6 @@ function buildHexStr(aNum, aNumSemiOctets) {
return str;
}
function hexStringToParcelByteArrayData(hexString) {
let bytes = [];
let length = hexString.length / 2;
bytes.push(length & 0xFF);
bytes.push((length >> 8) & 0xFF);
bytes.push((length >> 16) & 0xFF);
bytes.push((length >> 24) & 0xFF);
for (let i = 0; i < hexString.length; i += 2) {
bytes.push(Number.parseInt(hexString.substr(i, 2), 16));
}
return bytes;
}
/**
* Verify GsmPDUHelper#readUmtsCbMessage with numOfPages from 1 to 15.
*/