Bug 913313: Part 2, Add Unit Test to verify the parsing of CDMA SMS Delivery Report and the flag of enabling Delivery Report. r=gene

This commit is contained in:
Bevis Tseng 2013-11-04 09:59:12 +08:00
parent d04d2debc1
commit 0b9e45a661
3 changed files with 175 additions and 0 deletions

View File

@ -0,0 +1,100 @@
/* 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();
}
function _getWorker() {
let _postedMessage;
let _worker = newWorker({
postRILMessage: function fakePostRILMessage(data) {
},
postMessage: function fakePostMessage(message) {
_postedMessage = message;
}
});
return {
get postedMessage() {
return _postedMessage;
},
get worker() {
return _worker;
}
};
}
/**
* Verify CDMA SMS Delivery ACK Message.
*/
add_test(function test_processCdmaSmsStatusReport() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
function test_StatusReport(errorClass, msgStatus) {
let msgId = 0;
let sentSmsMap = worker.RIL._pendingSentSmsMap;
sentSmsMap[msgId] = {};
let message = {
SMSC: "",
mti: 0,
udhi: 0,
sender: "0987654321",
recipient: null,
pid: PDU_PID_DEFAULT,
epid: PDU_PID_DEFAULT,
dcs: 0,
mwi: null,
replace: false,
header: null,
body: "Status: Sent, Dest: 0987654321",
data: null,
timestamp: new Date().valueOf(),
language: null,
status: null,
scts: null,
dt: null,
encoding: PDU_CDMA_MSG_CODING_7BITS_ASCII,
messageClass: GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL],
messageType: PDU_CDMA_MSG_TYPE_P2P,
serviceCategory: 0,
subMsgType: PDU_CDMA_MSG_TYPE_DELIVER_ACK,
msgId: msgId,
errorClass: errorClass,
msgStatus: msgStatus
};
worker.RIL._processCdmaSmsStatusReport(message);
let postedMessage = workerHelper.postedMessage;
// Check if pending token is removed.
do_check_true((errorClass === 2)? !!sentSmsMap[msgId]: !sentSmsMap[msgId]);
// Check the response message accordingly.
if (errorClass === -1) {
// Check if the report is treated as normal incoming SMS
do_check_eq("sms-received", postedMessage.rilMessageType);
} else if (errorClass === 2) {
// Do nothing.
} else {
// Check Delivery Status
if (errorClass === 0) {
do_check_eq(postedMessage.deliveryStatus, GECKO_SMS_DELIVERY_STATUS_SUCCESS);
} else {
do_check_eq(postedMessage.deliveryStatus, GECKO_SMS_DELIVERY_STATUS_ERROR);
}
}
}
test_StatusReport(-1, -1); // Message Status Sub-parameter is absent.
test_StatusReport(0, 0); // 00|000000: no error|Message accepted
test_StatusReport(2, 4); // 10|000100: temporary condition|Network congestion
test_StatusReport(3, 5); // 11|000101: permanent condition|Network error
run_next_test();
});

View File

@ -0,0 +1,73 @@
/* 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();
}
/**
* Verify CdmaPDUHelper#encodeUserDataReplyOption.
*/
add_test(function test_CdmaPDUHelper_encodeUserDataReplyOption() {
let worker = newWorker({
postRILMessage: function fakePostRILMessage(data) {
// Do nothing
},
postMessage: function fakePostMessage(message) {
// Do nothing
}
});
let testDataBuffer = [];
worker.BitBufferHelper.startWrite(testDataBuffer);
let helper = worker.CdmaPDUHelper;
helper.encodeUserDataReplyOption({requestStatusReport: true});
let expectedDataBuffer = [PDU_CDMA_MSG_USERDATA_REPLY_OPTION, 0x01, 0x40];
do_check_eq(testDataBuffer.length, expectedDataBuffer.length);
for (let i = 0; i < expectedDataBuffer.length; i++) {
do_check_eq(testDataBuffer[i], expectedDataBuffer[i]);
}
run_next_test();
});
/**
* Verify CdmaPDUHelper#cdma_decodeUserDataMsgStatus.
*/
add_test(function test_CdmaPDUHelper_decodeUserDataMsgStatus() {
let worker = newWorker({
postRILMessage: function fakePostRILMessage(data) {
// Do nothing
},
postMessage: function fakePostMessage(message) {
// Do nothing
}
});
let helper = worker.CdmaPDUHelper;
function test_MsgStatus(octet) {
let testDataBuffer = [octet];
worker.BitBufferHelper.startRead(testDataBuffer);
let result = helper.decodeUserDataMsgStatus();
do_check_eq(result.errorClass, octet >>> 6);
do_check_eq(result.msgStatus, octet & 0x3F);
}
// 00|000000: no error|Message accepted
test_MsgStatus(0x00);
// 10|000100: temporary condition|Network congestion
test_MsgStatus(0x84);
// 11|000101: permanent condition|Network error
test_MsgStatus(0xC5);
run_next_test();
});

View File

@ -7,6 +7,8 @@ tail =
[test_ril_worker_sms.js]
# Bug 916067 - B2G RIL: test_ril_worker_sms.js takes too long to finish
skip-if = true
[test_ril_worker_sms_cdma.js]
[test_ril_worker_sms_cdmapduhelper.js]
[test_ril_worker_sms_nl_tables.js]
[test_ril_worker_sms_gsmpduhelper.js]
[test_ril_worker_sms_segment_info.js]