Bug 768441 - Part 2: Test Case to Verify the Access of EF_MWIS. r=vyang

This commit is contained in:
Bevis Tseng 2013-12-10 19:24:27 +08:00
parent 38d566c7a4
commit ef480d31cc

View File

@ -2330,6 +2330,10 @@ add_test(function test_reading_optional_efs() {
testEf.splice(testEf.indexOf("MDN"), 1);
};
record.readMWIS = function fakeReadMWIS() {
testEf.splice(testEf.indexOf("MWIS"), 1);
};
io.loadTransparentEF = function fakeLoadTransparentEF(options) {
// Write data size
buf.writeInt32(sst.length * 2);
@ -2356,7 +2360,7 @@ add_test(function test_reading_optional_efs() {
}
// TODO: Add all necessary optional EFs eventually
let supportedEf = ["MSISDN", "MDN"];
let supportedEf = ["MSISDN", "MDN", "MWIS"];
ril.appType = CARD_APPTYPE_SIM;
do_test(buildSST(supportedEf), supportedEf);
ril.appType = CARD_APPTYPE_USIM;
@ -2435,3 +2439,174 @@ add_test(function test_fetch_icc_recodes() {
run_next_test();
});
add_test(function test_read_mwis() {
let worker = newUint8Worker();
let helper = worker.GsmPDUHelper;
let recordHelper = worker.SimRecordHelper;
let buf = worker.Buf;
let io = worker.ICCIOHelper;
let mwisData;
let postedMessage;
worker.postMessage = function fakePostMessage(message) {
postedMessage = message;
};
io.loadLinearFixedEF = function fakeLoadLinearFixedEF(options) {
if (mwisData) {
// Write data size
buf.writeInt32(mwisData.length * 2);
// Write MWIS
for (let i = 0; i < mwisData.length; i++) {
helper.writeHexOctet(mwisData[i]);
}
// Write string delimiter
buf.writeStringDelimiter(mwisData.length * 2);
options.recordSize = mwisData.length;
if (options.callback) {
options.callback(options);
}
} else {
do_print("mwisData[] is not set.");
}
};
function buildMwisData(isActive, msgCount) {
if (msgCount < 0 || msgCount === GECKO_VOICEMAIL_MESSAGE_COUNT_UNKNOWN) {
msgCount = 0;
} else if (msgCount > 255) {
msgCount = 255;
}
mwisData = [ (isActive) ? 0x01 : 0x00,
msgCount,
0xFF, 0xFF, 0xFF ];
}
function do_test(isActive, msgCount) {
buildMwisData(isActive, msgCount);
recordHelper.readMWIS();
do_check_eq("iccmwis", postedMessage.rilMessageType);
do_check_eq(isActive, postedMessage.mwi.active);
do_check_eq((isActive) ? msgCount : 0, postedMessage.mwi.msgCount);
}
do_test(true, GECKO_VOICEMAIL_MESSAGE_COUNT_UNKNOWN);
do_test(true, 1);
do_test(true, 255);
do_test(false, 0);
do_test(false, 255); // Test the corner case when mwi is disable with incorrect msgCount.
run_next_test();
});
add_test(function test_update_mwis() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let ril = worker.RIL;
ril.appType = CARD_APPTYPE_USIM;
ril.iccInfoPrivate.mwis = [0x00, 0x00, 0x00, 0x00, 0x00];
let recordHelper = worker.SimRecordHelper;
let buf = worker.Buf;
let ioHelper = worker.ICCIOHelper;
let recordSize = ril.iccInfoPrivate.mwis.length;
let recordNum = 1;
ioHelper.updateLinearFixedEF = function (options) {
options.pathId = worker.ICCFileHelper.getEFPath(options.fileId);
options.command = ICC_COMMAND_UPDATE_RECORD;
options.p1 = options.recordNumber;
options.p2 = READ_RECORD_ABSOLUTE_MODE;
options.p3 = recordSize;
ril.iccIO(options);
};
function do_test(isActive, count) {
let mwis = ril.iccInfoPrivate.mwis;
let isUpdated = false;
function buildMwisData() {
let result = mwis.slice(0);
result[0] = isActive? (mwis[0] | 0x01) : (mwis[0] & 0xFE);
result[1] = (count === GECKO_VOICEMAIL_MESSAGE_COUNT_UNKNOWN) ? 0 : count;
return result;
}
buf.sendParcel = function () {
isUpdated = true;
// Request Type.
do_check_eq(this.readInt32(), REQUEST_SIM_IO);
// Token : we don't care
this.readInt32();
// command.
do_check_eq(this.readInt32(), ICC_COMMAND_UPDATE_RECORD);
// fileId.
do_check_eq(this.readInt32(), ICC_EF_MWIS);
// pathId.
do_check_eq(this.readString(),
EF_PATH_MF_SIM + ((ril.appType === CARD_APPTYPE_USIM) ? EF_PATH_ADF_USIM : EF_PATH_DF_GSM));
// p1.
do_check_eq(this.readInt32(), recordNum);
// p2.
do_check_eq(this.readInt32(), READ_RECORD_ABSOLUTE_MODE);
// p3.
do_check_eq(this.readInt32(), recordSize);
// data.
let strLen = this.readInt32();
do_check_eq(recordSize * 2, strLen);
let expectedMwis = buildMwisData();
for (let i = 0; i < recordSize; i++) {
do_check_eq(expectedMwis[i], pduHelper.readHexOctet());
}
this.readStringDelimiter(strLen);
// pin2.
do_check_eq(this.readString(), null);
if (!worker.RILQUIRKS_V5_LEGACY) {
// AID. Ignore because it's from modem.
this.readInt32();
}
};
do_check_false(isUpdated);
recordHelper.updateMWIS({ active: isActive,
msgCount: count });
do_check_true((ril.iccInfoPrivate.mwis) ? isUpdated : !isUpdated);
}
do_test(true, GECKO_VOICEMAIL_MESSAGE_COUNT_UNKNOWN);
do_test(true, 1);
do_test(true, 255);
do_test(false, 0);
// Test if Path ID is correct for SIM.
ril.appType = CARD_APPTYPE_SIM;
do_test(false, 0);
// Test if loadLinearFixedEF() is not invoked in updateMWIS() when
// EF_MWIS is not loaded/available.
delete ril.iccInfoPrivate.mwis;
do_test(false, 0);
run_next_test();
});