blob: a93a34364dffe81a6c53d2cdf3a673c792624d32 [file] [log] [blame]
<html>
<head>
<meta charset='utf-8'>
<style>
.pass {
font-weight: bold;
color: green;
}
.fail {
font-weight: bold;
color: red;
}
</style>
<script>
if (window.testRunner)
testRunner.dumpAsText();
function SputnikError(message)
{
this.message = message;
}
SputnikError.prototype.toString = function ()
{
return 'SputnikError: ' + this.message;
};
var sputnikException;
function testPrint(msg)
{
var span = document.createElement("span");
document.getElementById("console").appendChild(span); // insert it first so XHTML knows the namespace
span.innerHTML = msg + '<br />';
}
function escapeHTML(text)
{
return text.toString().replace(/&/g, "&amp;").replace(/</g, "&lt;");
}
function printTestPassed(msg)
{
testPrint('<span><span class="pass">PASS</span> ' + escapeHTML(msg) + '</span>');
}
function printTestFailed(msg)
{
testPrint('<span><span class="fail">FAIL</span> ' + escapeHTML(msg) + '</span>');
}
function testFailed(msg)
{
throw new SputnikError(msg);
}
var successfullyParsed = false;
</script>
</head>
<body>
<p>S15.1.3.2_A1.15_T1</p>
<div id='console'></div>
<script>
try {
/**
* @name: S15.1.3.2_A1.15_T1;
* @section: 15.1.3.2;
* @assertion: If B = 11110xxx (n = 4) and C != 10xxxxxx (C - first of octets after B), throw URIError;
* @description: Complex tests. B = [0xF0 - 0x0F7], C = [0x00, 0x7F];
*/
errorCount = 0;
count = 0;
var indexP;
var indexO = 0;
for (indexB = 0xF0; indexB <= 0xF7; indexB++) {
count++;
hexB = decimalToHexString(indexB);
result = true;
for (indexC = 0x00; indexC <= 0x7F; indexC++) {
hexC = decimalToHexString(indexC);
try {
decodeURIComponent("%" + hexB.substring(2) + "%" + hexC.substring(2) + "%A0%A0");
} catch (e) {
if ((e instanceof URIError) === true) continue;
}
result = false;
}
if (result !== true) {
if (indexO === 0) {
indexO = indexB;
} else {
if ((indexB - indexP) !== 1) {
if ((indexP - indexO) !== 0) {
var hexP = decimalToHexString(indexP);
var hexO = decimalToHexString(indexO);
testFailed('#' + hexO + '-' + hexP + ' ');
}
else {
var hexP = decimalToHexString(indexP);
testFailed('#' + hexP + ' ');
}
indexO = indexB;
}
}
indexP = indexB;
errorCount++;
}
}
if (errorCount > 0) {
if ((indexP - indexO) !== 0) {
var hexP = decimalToHexString(indexP);
var hexO = decimalToHexString(indexO);
testFailed('#' + hexO + '-' + hexP + ' ');
} else {
var hexP = decimalToHexString(indexP);
testFailed('#' + hexP + ' ');
}
testFailed('Total error: ' + errorCount + ' bad Unicode character in ' + count + ' ');
}
function decimalToHexString(n) {
n = Number(n);
var h = "";
for (var i = 3; i >= 0; i--) {
if (n >= Math.pow(16, i)) {
var t = Math.floor(n / Math.pow(16, i));
n -= t * Math.pow(16, i);
if ( t >= 10 ) {
if ( t == 10 ) { h += "A"; }
if ( t == 11 ) { h += "B"; }
if ( t == 12 ) { h += "C"; }
if ( t == 13 ) { h += "D"; }
if ( t == 14 ) { h += "E"; }
if ( t == 15 ) { h += "F"; }
} else {
h += String(t);
}
} else {
h += "0";
}
}
return h;
}
} catch (ex) {
sputnikException = ex;
}
var successfullyParsed = true;
</script>
<script>
if (!successfullyParsed)
printTestFailed('successfullyParsed is not set');
else if (sputnikException)
printTestFailed(sputnikException);
else
printTestPassed("");
testPrint('<br /><span class="pass">TEST COMPLETE</span>');
</script>
</body>
</html>