Bug 1138841 - Part 3: Add an XPCShell and a Marionette test case for encoding and decoding examination, respectively. r=btseng

--HG--
extra : rebase_source : 2b52ec77288115d4434e30a65accccc451829c3c
extra : histedit_source : fee6e436e2a68f521a7edabea65341daece62e27
This commit is contained in:
Samael Wang 2015-03-16 15:44:34 +08:00
Родитель 3a0d622bec
Коммит c197b32f36
3 изменённых файлов: 100 добавлений и 0 удалений

Просмотреть файл

@ -50,3 +50,4 @@ qemu = true
[test_error_of_mms_send.js]
[test_error_of_sms_send.js]
[test_ondeleted_event.js]
[test_decode_spanish_fallback.js]

Просмотреть файл

@ -0,0 +1,52 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 60000;
MARIONETTE_HEAD_JS = 'head.js';
const PDU_SMSC_NONE = "00"; // no SMSC Address
// | TP-RP|TP-UDHI| TP-SRI| Unused | TP-MMS| TP-MTI |
// | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | => 0x40
const PDU_FIRST_OCTET = "40";
// | | <= TON => | <=== NOI ===> |
// | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | => 0xa8
const PDU_OA = "0AA89021436587"; // 0912345678
const PDU_PID_NORMAL = "00";
const PDU_DCS_GSM_7BIT = "00";
const PDU_TIMESTAMP = "51302151740020"; // 2015/3/12 15:47:00 UTC+8
// ==> | <========== G ==========> |
// | 1 | 1 | 0 | 0 | 0 | 1 | 1 | 1 | => 0xc7
// ======> | <========== S =========
// | 0 | 1 | 1 | 0 | 1 | 0 | 0 | 1 | => 0x69
// |<=padding=>| <========== M =====
// | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | => 0x13
const PDU_UD_GSM = "C76913";
const IE_USE_SPANISH_LOCKING_SHIFT_TABLE = "250102";
const IE_USE_SPANISH_SINGLE_SHIFT_TABLE = "240102";
const PDU_UDHL = "06";
const PDU_UDL = "0B"; // UDH occupies 7 octets = 8 septets, plus 3 septets data.
const PDU = PDU_SMSC_NONE + PDU_FIRST_OCTET + PDU_OA + PDU_PID_NORMAL
+ PDU_DCS_GSM_7BIT + PDU_TIMESTAMP + PDU_UDL + PDU_UDHL
+ IE_USE_SPANISH_LOCKING_SHIFT_TABLE + IE_USE_SPANISH_SINGLE_SHIFT_TABLE
+ PDU_UD_GSM;
function verifyMessage(aMessage) {
is(aMessage.body, "GSM", "SmsMessage body");
}
/**
* Test and verify that user data encoded in GSM default alphabet can be
* correctly decoded with Spanish locking shift table. See bug 1138841.
*/
startTestCommon(function testCaseMain() {
return Promise.resolve()
.then(() => sendMultipleRawSmsToEmulatorAndWait([PDU]))
.then(results => verifyMessage(results[0].message));
});

Просмотреть файл

@ -187,6 +187,53 @@ add_test(function test_GsmPDUHelper_writeStringAsSeptets() {
run_next_test();
});
/**
* Verify that encoding with Spanish locking shift table generates the same
* septets as with GSM default alphabet table.
*
* Bug 1138841 - Incorrect Spanish national language locking shift table
* definition.
*/
add_test(function test_GsmPDUHelper_writeStringAsSeptets_spanish_fallback() {
let worker = newWorker({
postRILMessage: function(data) {
// Do nothing
},
postMessage: function(message) {
// Do nothing
}
});
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let buf = [];
helper.writeHexOctet = function(octet) {
buf.push(octet);
}
// Simple message string which is covered by GSM default alphabet.
let msg = "The quick brown fox jumps over the lazy dog";
// Encoded with GSM default alphabet.
helper.writeStringAsSeptets(msg, 0 /* paddingBits */,
PDU_NL_IDENTIFIER_DEFAULT, PDU_NL_IDENTIFIER_DEFAULT);
let octetsWithDefaultTable = buf;
buf = [];
// Encoded with Spanish locking shift table.
helper.writeStringAsSeptets(msg, 0 /* paddingBits */,
PDU_NL_IDENTIFIER_SPANISH, PDU_NL_IDENTIFIER_SPANISH);
// The length and content should be equal to what encoded with GSM default
// alphabet.
equal(octetsWithDefaultTable.length, buf.length);
for (let i = 0; i < buf.length; i++) {
equal(octetsWithDefaultTable[i], buf[i]);
}
run_next_test();
});
/**
* Verify GsmPDUHelper#readAddress
*/