From: Ms2ger diff --git a/tests/submission/PhilipTaylor/common/canvas-tests.js b/tests/submission/PhilipTaylor/common/canvas-tests.js --- a/tests/submission/PhilipTaylor/common/canvas-tests.js +++ b/tests/submission/PhilipTaylor/common/canvas-tests.js @@ -19,48 +19,57 @@ function _fail(text) _failed = true; } function _assert(cond, text) { _asserted = true; if (! cond) _fail('Failed assertion: ' + text); + assert_true(!!cond, 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) + ')'); + assert_equals(a, b, 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) + ')'); + assert_true(a !== b, 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) + ')'); + assert_true(a == b, 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) + ')'); + assert_true(!!a.match(b), text_a + ' matches ' + text_b + + ' (got ' + _valToString(a) + ')') } var _manual_check = false; function _requireManualCheck() { _manual_check = true; @@ -89,49 +98,55 @@ function _getPixel(canvas, x,y) } 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+']'); + assert_true(!c || (c[0] == r && c[1] == g && c[2] == b && c[3] == a), + '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); } + assert_true(!c || Math.max(Math.abs(c[0]-r), Math.abs(c[1]-g), Math.abs(c[2]-b), Math.abs(c[3]-a)) <= tolerance, + 'got pixel [' + c + '] at ('+x+','+y+'), expected ['+r+','+g+','+b+','+a+']') } -function _addTest(test) +function _addTest(testFn) { var deferred = false; window.deferTest = function () { deferred = true; }; function endTest() { if (_failed) // test failed { + t.done() document.documentElement.className += ' fail'; window._testStatus = ['fail', document.getElementById('d').innerHTML]; } else if (_manual_check || !_asserted) { // test case explicitly asked for a manual check, or no automatic assertions were performed document.getElementById('d').innerHTML += '
  • Cannot automatically verify result'; document.documentElement.className += ' needs_check'; window._testStatus = ['check', document.getElementById('d').innerHTML]; } else // test succeeded { + t.done() document.getElementById('d').innerHTML += '
  • Passed'; document.documentElement.className += ' pass'; window._testStatus = ['pass', document.getElementById('d').innerHTML]; } }; window.endTest = endTest; window.wrapFunction = function (f) { @@ -144,27 +159,27 @@ function _addTest(test) catch (e) { _fail('Aborted with exception: ' + e.message); } endTest(); }; }; - window.onload = function () + on_event(window, "load", function() { try { var canvas = document.getElementById('c'); var ctx = canvas.getContext('2d'); - test(canvas, ctx); + t.step(testFn, window, canvas, ctx); } catch (e) { _fail('Aborted with exception: ' + e.message); deferred = false; // cancel any deference } if (! deferred) endTest(); - }; + }); } diff --git a/tests/submission/PhilipTaylor/tools/canvas/templates.yaml b/tests/submission/PhilipTaylor/tools/canvas/templates.yaml --- a/tests/submission/PhilipTaylor/tools/canvas/templates.yaml +++ b/tests/submission/PhilipTaylor/tools/canvas/templates.yaml @@ -81,16 +81,18 @@ minimal: | }); %(images)s w3c: | Canvas test: %(name)s + + %(fonts)s

    %(backrefs)s

    %(desc)s

    Spec references: @@ -98,16 +100,17 @@ w3c: | %(refs)s
    %(notes)s %(fonthack)s

    Actual output:

    %(fallback)s %(expected)s %(images)s