Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 63346c4b12
Fetching contributors…

Cannot retrieve contributors at this time

381 lines (365 sloc) 12.985 kB
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>
<input id="pdu" type="text" value="0791889653784434040c91889678674542000011211181027023044f74380d">
<button id="parseButton" onclick="parse(); return false;">Parse PDU</button>
<button id="testButton" onclick="runBlackBoxTests(); return false;">Run tests</button>
<button id="testButton" onclick="loopTests(); return false;">Run 100 tests</button>
</div>
<div id="result">
</div>
<div id="tests">
</div>
<script type="application/javascript;version=1.8">
function importScripts() {}
</script>
<script type="application/javascript;version=1.8" src="ril_consts.js"></script>
<script type="application/javascript;version=1.8" src="ril_worker.js"></script>
<script type="application/javascript;version=1.8" src="pdu.js"></script>
<script type="application/javascript;version=1.8">
function debug(msg) {
console.log(msg);
}
function AssertException(message) { this.message = message; }
AssertException.prototype.toString = function () {
return 'AssertException: ' + this.message;
};
function assert(exp, message) {
if (!exp) {
throw new AssertException(message);
}
}
function printTest(testId) {
//console.info(testId);
let testsDiv = document.getElementById("tests");
let testp = document.createElement("p");
testp.setAttribute("id",testId);
testsDiv.appendChild(testp);
let test = document.createElement("h2");
let testStr = document.createTextNode(testId);
test.appendChild(testStr);
testp.appendChild(test);
}
function printTestError(testId, errorMsg) {
let test = document.getElementById(testId);
let error = document.createElement("h4");
let errorStr = document.createTextNode(errorMsg);
error.style.color = "red";
error.appendChild(errorStr);
test.appendChild(error);
}
function printTestOk(testId) {
let test = document.getElementById(testId);
let ok = document.createElement("h4");
ok.style.color = "green";
let okStr = document.createTextNode("OK");
ok.appendChild(okStr);
test.appendChild(ok);
}
// Overwrite 'Buf' object from ril_worker.js with this test dummy.
let Buf = {
pdu: null,
current: null,
init: function init(pdu) {
this.pdu = pdu;
this.buffer = [chr.charCodeAt() for each (chr in pdu)];
this.current = 0;
},
readUint16: function readUint16() {
if (this.current >= this.buffer.length) {
if (DEBUG) debug("Ran out of data.");
throw "End of buffer!";
}
return this.buffer[this.current++];
},
readString: function readString() {
if (this.current >= this.pdu.length) {
if (DEBUG) debug("Ran out of data.");
throw "End of buffer!";
}
return this.pdu[this.current++];
}
};
function parse() {
Buf.init(document.getElementById("pdu").value);
let parsedPDU = GsmPDUHelper.readMessage();
if(typeof(parsedPDU) != "undefined") {
var resultDiv = document.getElementById("result");
var resultList = document.createElement("ul");
var smsc = document.createElement("li");
smsc.innerHTML = "SMSC: " + parsedPDU.SMSC;
var sender = document.createElement("li");
sender.innerHTML = "Sender: " + parsedPDU.sender;
var message = document.createElement("li");
message.innerHTML = "Message: " + parsedPDU.body;
var tsv = document.createElement("li");
if(typeof(parsedPDU.timestamp) != "undefined") {
tsv.innerHTML = "Timestamp: " + parsedPDU.timestamp;
}
resultList.appendChild(sender);
resultList.appendChild(smsc);
resultList.appendChild(message);
resultList.appendChild(tsv);
resultDiv.appendChild(resultList);
}
}
function parsePDU(pdu) {
Buf.init(pdu);
return GsmPDUHelper.readMessage();
}
function runBlackBoxTests() {
{
// Test 0
// Actual SMS as received on the device in Taiwan.
printTest("Test0");
let parsed = parsePDU("0791889653784434040c91889678674542000011211181027023044f74380d");
try {
assert(parsed != null, "parsed = null");
assert(parsed.SMSC == "+886935874443", "Wrong SMSC: " + parsed.SMSC);
assert(parsed.sender == "+886987765424", "Wrong sender: " + parsed.sender);
assert(parsed.body == "Ohai", "Wrong message: " + parsed.body);
assert(parsed.timestamp == 1323566346000);
printTestOk("Test0");
} catch (err) {
printTestError("Test0", err.body);
}
}
{
// TEST 1
// SMS-SUBMIT
// SMSC: international 11 chars
// Receiver: international 11 chars
// Alphabet size: 7
// Message class: 0
// "Hi there..."
printTest("Test1");
let parsed = parsePDU("07914366060088F801000B914366161177F700000BC834888E2ECBCB2E970B");
try {
assert(parsed != null, "parsed = null");
assert(parsed.SMSC == "+34666000888", "Wrong SMSC: " + parsed.SMSC);
assert(parsed.sender == "+34666111777", "Wrong sender: " + parsed.sender);
assert(parsed.body == "Hi there...", "Wrong message: " + parsed.body);
printTestOk("Test1");
} catch(err) {
printTestError("Test1",err.body);
}
}
{
// TEST 2
// SMS-SUBMIT
// SMSC: national 9 chars
// Receiver: international 11 chars
// Alphabet size: 7
// Message class: 0
// "Hi there..."
printTest("Test2");
let parsed = parsePDU("068166060088F801000B914366161177F700000BC834888E2ECBCB2E970B");
try {
assert(parsed != null, "parsed = null");
assert(parsed.SMSC == "666000888", "Wrong SMSC: " + parsed.SMSC);
assert(parsed.sender == "+34666111777", "Wrong sender: " + parsed.sender);
assert(parsed.body == "Hi there...", "Wrong message: " + parsed.body);
printTestOk("Test2");
} catch(err) {
printTestError("Test2",err.body);
}
}
{
// TEST 3
// SMS-SUBMIT
// SMSC: national 9 chars
// Receiver: national 9 chars
// Alphabet size: 7
// Message class: 0
// "Hi there..."
printTest("Test3");
let parsed = parsePDU("068166060088F80100098166161177F700000BC834888E2ECBCB2E970B");
try {
assert(parsed != null, "parsed = null");
assert(parsed.SMSC == "666000888", "Wrong SMSC: " + parsed.SMSC);
assert(parsed.sender == "666111777", "Wrong sender: " + parsed.sender);
assert(parsed.body == "Hi there...", "Wrong message: " + parsed.body);
printTestOk("Test3");
} catch(err) {
printTestError("Test3",err.body);
}
}
{
// TEST 4
// SMS-SUBMIT
// SMSC: international 5 chars
// Receiver: national 9 chars
// Alphabet size: 7
// Message class: 0
// "Hi there..."
printTest("Test4");
let parsed = parsePDU("04914366F60100098166161177F700000BC834888E2ECBCB2E970B");
try {
assert(parsed != null, "parsed = null");
assert(parsed.SMSC == "+34666", "Wrong SMSC: " + parsed.SMSC);
assert(parsed.sender == "666111777", "Wrong sender: " + parsed.sender);
assert(parsed.body == "Hi there...", "Wrong message: " + parsed.body);
printTestOk("Test4");
} catch(err) {
printTestError("Test4",err.body);
}
}
{
// TEST 5
// SMS-SUBMIT
// SMSC: international 5 chars
// Receiver: international 5 chars
// Alphabet size: 7
// Message class: 0
// "Hi there..."
printTest("Test5");
let parsed = parsePDU("04914366F6010005914366F600000BC834888E2ECBCB2E970B");
try {
assert(parsed != null, "parsed = null");
assert(parsed.SMSC == "+34666", "Wrong SMSC: " + parsed.SMSC);
assert(parsed.sender == "+34666", "Wrong sender: " + parsed.sender);
assert(parsed.body == "Hi there...", "Wrong message: " + parsed.body);
printTestOk("Test5");
} catch(err) {
printTestError("Test5",err.body);
}
}
{
// TEST 6
// SMS-SUBMIT
// SMSC: null
// Receiver: international 11 chars
// Alphabet size: 7
// Message class: 0
// "Hi there..."
printTest("Test6");
let parsed = parsePDU("0001000B914366060033F300000BC834888E2ECBCB2E970B");
try {
assert(parsed != null, "parsed = null");
assert(parsed.SMSC == undefined, "Wrong SMSC: " + parsed.SMSC);
assert(parsed.sender == "+34666000333", "Wrong sender: " + parsed.sender);
assert(parsed.body == "Hi there...", "Wrong message: " + parsed.body);
printTestOk("Test6");
} catch(err) {
printTestError("Test6",err.body);
}
}
{
// TEST 7
// SMS-SUBMIT
// SMSC: international 11 chars
// Receiver: null
// Alphabet size: 7
// Message class: 0
// "Hi there..."
printTest("Test7");
let parsed = parsePDU("07914366060033F30100009100000BC834888E2ECBCB2E970B");
try {
assert(parsed == null, "parsed != null");
printTestOk("Test7");
} catch(err) {
printTestError("Test7",err.body);
}
}
{
// TEST 8
// SMS-SUBMIT
// SMSC: international 11 chars
// Receiver: international 11 chars
// Alphabet size: 8
// Message class: 0
// "Hi there..."
printTest("Test8");
let parsed = parsePDU("07914366060033F301000B914366060055F500040B48692074686572652E2E2E");
try {
assert(parsed != null, "parsed = null");
assert(parsed.SMSC == "+34666000333", "Wrong SMSC: " + parsed.SMSC);
assert(parsed.sender == "+34666000555", "Wrong sender: " + parsed.sender);
//TODO
assert(parsed.body == null, "Wrong message: " + parsed.body);
printTestOk("Test8");
} catch(err) {
printTestError("Test8",err.body);
}
}
{
// TEST 9
// SMS-SUBMIT
// SMSC: international 11 chars
// Receiver: international 11 chars
// Alphabet size: 16
// Message class: 0
// "Hi there..."
printTest("Test9");
let parsed = parsePDU("07914366060033F301000B914366060055F500081600480069002000740068006500720065002E002E002E");
try {
assert(parsed != null, "parsed = null");
assert(parsed.SMSC == "+34666000333", "Wrong SMSC: " + parsed.SMSC);
assert(parsed.sender == "+34666000555", "Wrong sender: " + parsed.sender);
//TODO
assert(parsed.body == null, "Wrong message: " + parsed.body);
printTestOk("Test9");
} catch(err) {
printTestError("Test9",err.body);
}
}
{
// TEST 10
// Empty pdu
printTest("Test10");
let parsed = null; //parsePDU("");
try {
assert(parsed == null, "parsed != null");
printTestOk("Test10");
} catch(err) {
printTestError("Test10",err.body);
}
}
{
// TEST 11
// SMS-SUBMIT with spaces
// SMSC: international 11 chars
// Receiver: international 11 chars
// Alphabet size: 7
// Message class: 0
// "Hi there..."
printTest("Test11");
let parsed = null; //parsePDU(" 079143 66060088F801000B914366 161177F70 0000BC834888E2ECBCB2E970 B ");
try {
assert(parsed == null, "parsed = null");
printTestOk("Test11");
} catch(err) {
printTestError("Test11",err.body);
}
}
{
// TEST 12
// SMS-SUBMIT with not allowed characters
// SMSC: international 11 chars
// Receiver: international 11 chars
// Alphabet size: 7
// Message class: 0
// "Hi there..."
printTest("Test12");
let parsed = null; //parsePDU("xyz07914366060088F801000B914366161177F700000BC834888E2ECBCB2E970B");
try {
assert(parsed == null, "parsed != null");
printTestOk("Test12");
} catch(err) {
printTestError("Test12",err.body);
}
}
}
function loopTests() {
var start = Date.now();
for (var i = 0; i < 100; i++) {
runBlackBoxTests();
}
console.log("Tests took " + (Date.now() - start));
}
</script>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.