Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added tests to iOS, still a lot more to do #35

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
137 changes: 137 additions & 0 deletions platforms/ios/www/test/common/tests.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
html.fail {
background: #f66;
}
html.pass {
background: #6f6;
}
html.needs_check {
background: #99f;
}

body {
font-size: small;
font-family: sans-serif;
color: black;
padding: 0;
margin: 0;
}

a:link {
color: #00c;
}
a:visited {
color: #808;
}

body.framed {
font-size: x-small;
}

h1 {
font-size: larger;
margin: 0;
padding-left: 0.5em;
text-indent: -0.5em;
}

p {
margin: 0;
}

p.notes {
margin-bottom: 0.5em;
font-style: italic;
}

ul {
margin: 0;
margin-left: 5px;
margin-bottom: 0.5em;
padding: 0;
padding-left: 1em;
}

.refs {
font-style: italic;
margin-bottom: 0.5em;
}

.refs ul {
display: inline;
margin: 0;
padding: 0;
}

.refs li {
display: inline;
list-style-type: none;
margin: 0;
padding: 0;
}

canvas {
display: none;
visibility: hidden;
border: 2px #f0f solid;
background: url(images/background.png);
}

img.expected {
display: none;
border: 2px #f0f solid;
background: url(images/background.png);
}

iframe {
border: 2px #f0f solid;
}

.output {
display: none;
}

.show_output .output, .needs_check .output {
display: block !important;
visibility: visible !important;
}

.show_output #show_output {
display: none;
}

.resource {
visibility: hidden;
height: 0;
}

.fallback {
font-size: 2em;
font-weight: bold;
color: #a00;
}


html.minimal body {
color: white;
}
html.fail.minimal {
background: #f00;
}
html.pass.minimal {
background: #080;
}
html.needs_check.minimal {
background: #008;
}
.minimal #d {
display: none !important;
}
.minimal .expectedtext {
visibility: hidden !important;
}
#passtext, #failtext {
display: none;
}
.minimal.pass #passtext, .minimal.fail #failtext {
display: block;
}
192 changes: 192 additions & 0 deletions platforms/ios/www/test/common/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
function _valToString(val)
{
if (val === undefined || val === null)
return '[' + typeof(val) + ']';
return val.toString() + '[' + typeof(val) + ']';
}

var _failed = false;
var _failedMessage = "";
var _asserted = false;
function _warn(text)
{
_failedMessage = text;
// TODO stack warnings incase multiple tests
}
function _fail(text)
{
_warn(text);
_failed = true;
}

function _assert(cond, text)
{
_asserted = true;
if (! cond)
_fail('Failed assertion: ' + text);
}

function _assertSame(a, b, text_a, text_b)
{
_asserted = true;
if (a !== b)
_fail('Failed assertion ' + text_a + ' === ' + text_b +
' (got ' + _valToString(a) + ', expected ' + _valToString(b) + ')');
}

function _assertDifferent(a, b, text_a, text_b)
{
_asserted = true;
if (a === b)
_fail('Failed assertion ' + text_a + ' !== ' + text_b +
' (got ' + _valToString(a) + ', expected not ' + _valToString(b) + ')');
}

function _assertEqual(a, b, text_a, text_b)
{
_asserted = true;
if (a != b)
_fail('Failed assertion ' + text_a + ' == ' + text_b +
' (got ' + _valToString(a) + ', expected ' + _valToString(b) + ')');
}

function _assertMatch(a, b, text_a, text_b)
{
_asserted = true;
if (! a.match(b))
_fail('Failed assertion ' + text_a + ' matches ' + text_b +
' (got ' + _valToString(a) + ')');
}


var _manual_check = false;

function _requireManualCheck()
{
_manual_check = true;
}

function _crash()
{
_fail('Aborted due to predicted crash');
}

function _getPixel(canvas, x,y)
{
try {
var ctx = canvas.getContext('2d');
var imgdata = ctx.getImageData(x, y, 1, 1);
return [ imgdata.data[0], imgdata.data[1], imgdata.data[2], imgdata.data[3] ];
} catch (e) {
// probably a security exception caused by having drawn
// data: URLs onto the canvas
_manual_check = true;
return undefined;
}
}

function _assertPixel(canvas, x,y, r,g,b,a, pos, colour)
{
_asserted = true;
var c = _getPixel(canvas, x,y);
if (c && ! (c[0] == r && c[1] == g && c[2] == b && c[3] == a))
_fail('Failed assertion: got pixel [' + c + '] at ('+x+','+y+'), expected ['+r+','+g+','+b+','+a+']');
}

function _assertPixelApprox(canvas, x,y, r,g,b,a, pos, colour, tolerance)
{
_asserted = true;
var c = _getPixel(canvas, x,y);
if (c)
{
var diff = Math.max(Math.abs(c[0]-r), Math.abs(c[1]-g), Math.abs(c[2]-b), Math.abs(c[3]-a));
if (diff > tolerance)
_fail('Failed assertion: got pixel [' + c + '] at ('+x+','+y+'), expected ['+r+','+g+','+b+','+a+'] +/- '+tolerance);
}
}

function _addTest(test)
{
_failed = false;
_manual_check = false;
_asserted = false;
var deferred = false;
window.deferTest = function () { deferred = true; };
function endTest()
{

if (_failed) // test failed
{
var msg = { result: "fail", message: "[" + tests[currentTest] + "] " + _failedMessage, testId: currentTest };
wizCanvasMessenger.postMessage(msg, "mainView");
}
else if (_manual_check || !_asserted)
{ // test case explicitly asked for a manual check, or no automatic assertions were performed

// TODO - alert checker
console.log("TEST REQUIRES MANUAL CHECK");
/*
document.getElementById('d').innerHTML += '<li>Cannot automatically verify result';
document.documentElement.className += ' needs_check';
window._testStatus = ['check', document.getElementById('d').innerHTML];
*/

// For now, skip
var msg = { result: "success", testId: currentTest };
wizCanvasMessenger.postMessage(msg, "mainView");

}
else // test succeeded
{
var msg = { result: "success", testId: currentTest };
wizCanvasMessenger.postMessage(msg, "mainView");
}
}
window.endTest = endTest;
window.wrapFunction = function (f)
{
return function()
{
try
{
f.apply(null, arguments);
}
catch (e)
{
_fail('Aborted with exception: ' + e.message);
}
endTest();
}
}

function loadTest() {

try
{
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
// Prepare and clear canvas

ctx.restore();
ctx.globalAlpha = 1;
ctx.fillStyle = "#000";
ctx.fillRect(0, 0, window.innerWidth, window.innerHeight);
ctx.save();

test(canvas, ctx);
}
catch (e)
{
_fail('Aborted with exception: ' + e.message);
deferred = false; // cancel any deference
}

if (!deferred) {
endTest();
}

};

loadTest();
}

Loading