From 6318560eca7e3247a63620ce24d2d7e291dd5d84 Mon Sep 17 00:00:00 2001 From: Charles Yin Date: Thu, 3 May 2012 15:21:08 +1000 Subject: Refactor canvas item unit tests Change-Id: I99ba84889ce360d2def27834f15af43c2bdf29bc Reviewed-by: Michael Brasser --- .../qquickcanvasitem/data/CanvasComponent.qml | 31 + .../quick/qquickcanvasitem/data/CanvasTestCase.qml | 46 + .../auto/quick/qquickcanvasitem/data/testhelper.js | 18 - tests/auto/quick/qquickcanvasitem/data/tst_arc.qml | 259 +-- .../auto/quick/qquickcanvasitem/data/tst_arcto.qml | 804 ++++---- .../quick/qquickcanvasitem/data/tst_canvas.qml | 472 +++-- .../quick/qquickcanvasitem/data/tst_composite.qml | 721 ++++---- .../quick/qquickcanvasitem/data/tst_drawimage.qml | 667 ------- .../quick/qquickcanvasitem/data/tst_fillStyle.qml | 208 ++- .../quick/qquickcanvasitem/data/tst_fillrect.qml | 39 +- .../quick/qquickcanvasitem/data/tst_gradient.qml | 1949 ++++++++++---------- .../auto/quick/qquickcanvasitem/data/tst_image.qml | 695 +++++++ .../auto/quick/qquickcanvasitem/data/tst_line.qml | 1633 ++++++++-------- .../auto/quick/qquickcanvasitem/data/tst_path.qml | 348 ++-- .../quick/qquickcanvasitem/data/tst_pattern.qml | 73 +- .../auto/quick/qquickcanvasitem/data/tst_pixel.qml | 63 +- .../quick/qquickcanvasitem/data/tst_shadow.qml | 120 +- .../auto/quick/qquickcanvasitem/data/tst_state.qml | 776 ++++---- .../qquickcanvasitem/data/tst_strokeStyle.qml | 84 +- .../auto/quick/qquickcanvasitem/data/tst_text.qml | 74 +- .../quick/qquickcanvasitem/data/tst_transform.qml | 973 +++++----- 21 files changed, 5122 insertions(+), 4931 deletions(-) create mode 100644 tests/auto/quick/qquickcanvasitem/data/CanvasComponent.qml create mode 100644 tests/auto/quick/qquickcanvasitem/data/CanvasTestCase.qml delete mode 100644 tests/auto/quick/qquickcanvasitem/data/testhelper.js delete mode 100644 tests/auto/quick/qquickcanvasitem/data/tst_drawimage.qml create mode 100644 tests/auto/quick/qquickcanvasitem/data/tst_image.qml diff --git a/tests/auto/quick/qquickcanvasitem/data/CanvasComponent.qml b/tests/auto/quick/qquickcanvasitem/data/CanvasComponent.qml new file mode 100644 index 0000000000..12c1c89212 --- /dev/null +++ b/tests/auto/quick/qquickcanvasitem/data/CanvasComponent.qml @@ -0,0 +1,31 @@ +import QtQuick 2.0 +import QtTest 1.0 + +Component { + id:canvas + Canvas { + id:c + width:100;height:100 + smooth:false //this line is needed for some tests (smooth painting can change the colors and alpha channel values) + onPaint :{} //this line is needed for some tests (make sure onPaint handler always called + property alias paintCount:spyPaint.count + property alias paintedCount:spyPainted.count + property alias canvasSizeChangedCount:spyCanvasSizeChanged.count + property alias tileSizeChangedCount:spyTileSizeChanged.count + property alias renderStrategyChangedCount:spyRenderStrategyChanged.count + property alias canvasWindowChangedCount:spyCanvasWindowChanged.count + property alias renderTargetChangedCount:spyRenderTargetChanged.count + property alias imageLoadedCount:spyImageLoaded.count + property alias availableChangedCount:spyAvailableChanged.count + + SignalSpy {id: spyPaint;target:c;signalName: "paint"} + SignalSpy {id: spyPainted;target:c;signalName: "painted"} + SignalSpy {id: spyCanvasSizeChanged;target:c;signalName: "canvasSizeChanged"} + SignalSpy {id: spyTileSizeChanged;target:c;signalName: "tileSizeChanged"} + SignalSpy {id: spyRenderStrategyChanged;target:c;signalName: "renderStrategyChanged"} + SignalSpy {id: spyCanvasWindowChanged;target:c;signalName: "canvasWindowChanged"} + SignalSpy {id: spyRenderTargetChanged;target:c;signalName: "renderTargetChanged"} + SignalSpy {id: spyImageLoaded;target:c;signalName: "imageLoaded"} + SignalSpy {id: spyAvailableChanged;target:c;signalName: "availableChanged"} + } +} \ No newline at end of file diff --git a/tests/auto/quick/qquickcanvasitem/data/CanvasTestCase.qml b/tests/auto/quick/qquickcanvasitem/data/CanvasTestCase.qml new file mode 100644 index 0000000000..4aae317a7a --- /dev/null +++ b/tests/auto/quick/qquickcanvasitem/data/CanvasTestCase.qml @@ -0,0 +1,46 @@ +import QtQuick 2.0 +import QtTest 1.0 + +TestCase { + id:testCase + when:windowShown + width:100 + height:100 + property Component component:CanvasComponent{} + function cleanupTestCase() { + wait(100) //wait for a short while to make sure no leaked textures + } + function testData(type) { + if (type === "2d") + return [ + { tag:"image threaded", properties:{width:100, height:100, renderTarget:Canvas.Image, renderStrategy:Canvas.Threaded}} + //TODO: Enable the followings later + //{ tag:"image cooperative", properties:{width:100, height:100, renderTarget:Canvas.Image, renderStrategy:Canvas.Cooperative}}, + //{ tag:"image immediate", properties:{width:100, height:100, renderTarget:Canvas.Image, renderStrategy:Canvas.Immediate}}, + //{ tag:"fbo cooperative", properties:{width:100, height:100, renderTarget:Canvas.FramebufferObject, renderStrategy:Canvas.Cooperative}}, + //{ tag:"fbo immediate", properties:{width:100, height:100, renderTarget:Canvas.FramebufferObject, renderStrategy:Canvas.Immediate}}, + //{ tag:"fbo threaded", properties:{width:100, height:100, renderTarget:Canvas.FramebufferObject, renderStrategy:Canvas.Threaded}} + ]; + return []; + } + + function createCanvasObject(data) { + return component.createObject(testCase, data.properties); + } + + function comparePixel(ctx,x,y,r,g,b,a, d) + { + var c = ctx.getImageData(x,y,1,1).data; + if (d === undefined) + d = 0; + r = Math.round(r); + g = Math.round(g); + b = Math.round(b); + a = Math.round(a); + + var notSame = Math.abs(c[0]-r)>d || Math.abs(c[1]-g)>d || Math.abs(c[2]-b)>d || Math.abs(c[3]-a)>d; + if (notSame) + qtest_fail('Pixel compare fail:\nactual :[' + c[0]+','+c[1]+','+c[2]+','+c[3] + ']\nexpected:['+r+','+g+','+b+','+a+'] +/- '+d, 1); + } + +} \ No newline at end of file diff --git a/tests/auto/quick/qquickcanvasitem/data/testhelper.js b/tests/auto/quick/qquickcanvasitem/data/testhelper.js deleted file mode 100644 index bac0210e16..0000000000 --- a/tests/auto/quick/qquickcanvasitem/data/testhelper.js +++ /dev/null @@ -1,18 +0,0 @@ -function comparePixel(ctx,x,y,r,g,b,a, d) -{ - var c = ctx.getImageData(x,y,1,1).data; - if (d === undefined) - d = 0; - r = Math.round(r); - g = Math.round(g); - b = Math.round(b); - a = Math.round(a); - - if (Math.abs(c[0]-r)>d || Math.abs(c[1]-g)>d || Math.abs(c[2]-b)>d || Math.abs(c[3]-a)>d) { - console.log('Pixel compare fail:\nactual :[' + c[0]+','+c[1]+','+c[2]+','+c[3] + ']\nexpected:['+r+','+g+','+b+','+a+'] +/- '+d); - return false; - } - return true; -} - - diff --git a/tests/auto/quick/qquickcanvasitem/data/tst_arc.qml b/tests/auto/quick/qquickcanvasitem/data/tst_arc.qml index 10bc37e82d..33fffd4cb1 100644 --- a/tests/auto/quick/qquickcanvasitem/data/tst_arc.qml +++ b/tests/auto/quick/qquickcanvasitem/data/tst_arc.qml @@ -1,13 +1,11 @@ import QtQuick 2.0 -import QtTest 1.0 -import "testhelper.js" as Helper - -Canvas { - id:canvas; width:100;height:50; renderTarget: Canvas.Image; renderStrategy:Canvas.Threaded - smooth: false - TestCase { - name: "arc"; when: windowShown - function test_angle_1() { + +CanvasTestCase { + id:testCase + name: "arc" + function init_data() { return testData("2d"); } + function test_angle_1(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); @@ -18,9 +16,11 @@ Canvas { ctx.moveTo(100, 0); ctx.arc(100, 0, 150, Math.PI/2, -Math.PI, true); ctx.fill(); - verify(Helper.comparePixel(ctx,50,25, 0,255,0,255)); + comparePixel(ctx,50,25, 0,255,0,255); + canvas.destroy(); } - function test_angle_2() { + function test_angle_2(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); @@ -31,9 +31,11 @@ Canvas { ctx.moveTo(100, 0); ctx.arc(100, 0, 150, -3*Math.PI/2, -Math.PI, true); ctx.fill(); - verify(Helper.comparePixel(ctx,50,25, 0,255,0,255)); + comparePixel(ctx,50,25, 0,255,0,255); + canvas.destroy(); } - function test_angle_3() { + function test_angle_3(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); ctx.fillStyle = '#0f0'; @@ -45,10 +47,12 @@ Canvas { ctx.fill(); /*FIXME: from: http://www.w3.org/TR/2dcontext/#dom-context-2d-arc If the anticlockwise argument is omitted or false and endAngle-startAngle is equal to or greater than 2π, or, if the anticlockwise argument is true and startAngle-endAngle is equal to or greater than 2π, then the arc is the whole circumference of this circle. - //verify(Helper.comparePixel(ctx,50,25, 0,255,0,255)); + //comparePixel(ctx,50,25, 0,255,0,255); */ + canvas.destroy(); } - function test_angle_4() { + function test_angle_4(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); @@ -59,12 +63,14 @@ Canvas { ctx.moveTo(50, 25); ctx.arc(50, 25, 60, (512+1/2)*Math.PI, (1024-1)*Math.PI, false); ctx.fill(); - verify(Helper.comparePixel(ctx,1,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx,98,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx,1,48, 0,255,0,255)); - verify(Helper.comparePixel(ctx,98,48, 0,255,0,255)); + comparePixel(ctx,1,1, 0,255,0,255); + comparePixel(ctx,98,1, 0,255,0,255); + comparePixel(ctx,1,48, 0,255,0,255); + comparePixel(ctx,98,48, 0,255,0,255); + canvas.destroy(); } - function test_angle_5() { + function test_angle_5(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); @@ -77,11 +83,13 @@ Canvas { ctx.fill(); /*FIXME: from: http://www.w3.org/TR/2dcontext/#dom-context-2d-arc If the anticlockwise argument is omitted or false and endAngle-startAngle is equal to or greater than 2π, or, if the anticlockwise argument is true and startAngle-endAngle is equal to or greater than 2π, then the arc is the whole circumference of this circle. - //verify(Helper.comparePixel(ctx,50,25, 0,255,0,255)); + //comparePixel(ctx,50,25, 0,255,0,255); */ + canvas.destroy(); } - function test_angle_6() { + function test_angle_6(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); @@ -93,13 +101,15 @@ Canvas { ctx.arc(50, 25, 60, (1024-1)*Math.PI, (512+1/2)*Math.PI, true); ctx.fill(); - verify(Helper.comparePixel(ctx,1,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx,98,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx,1,48, 0,255,0,255)); - verify(Helper.comparePixel(ctx,98,48, 0,255,0,255)); + comparePixel(ctx,1,1, 0,255,0,255); + comparePixel(ctx,98,1, 0,255,0,255); + comparePixel(ctx,1,48, 0,255,0,255); + comparePixel(ctx,98,48, 0,255,0,255); + canvas.destroy(); } - function test_empty() { + function test_empty(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); @@ -110,9 +120,11 @@ Canvas { ctx.beginPath(); ctx.arc(200, 25, 5, 0, 2*Math.PI, true); ctx.stroke(); - verify(Helper.comparePixel(ctx,50,25, 0,255,0,255)); + comparePixel(ctx,50,25, 0,255,0,255); + canvas.destroy(); } - function test_nonempty() { + function test_nonempty(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); @@ -124,9 +136,11 @@ Canvas { ctx.moveTo(0, 25); ctx.arc(200, 25, 5, 0, 2*Math.PI, true); ctx.stroke(); - verify(Helper.comparePixel(ctx,50,25, 0,255,0,255)); + comparePixel(ctx,50,25, 0,255,0,255); + canvas.destroy(); } - function test_nonfinite() { + function test_nonfinite(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); @@ -179,10 +193,12 @@ Canvas { ctx.lineTo(0, 50); ctx.fillStyle = '#0f0'; ctx.fill(); - verify(Helper.comparePixel(ctx,50,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx,90,45, 0,255,0,255)); + comparePixel(ctx,50,25, 0,255,0,255); + comparePixel(ctx,90,45, 0,255,0,255); + canvas.destroy(); } - function test_end() { + function test_end(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); @@ -195,9 +211,11 @@ Canvas { ctx.arc(-100, 0, 25, -Math.PI/2, Math.PI/2, true); ctx.lineTo(100, 25); ctx.stroke(); - verify(Helper.comparePixel(ctx,50,25, 0,255,0,255)); + comparePixel(ctx,50,25, 0,255,0,255); + canvas.destroy(); } - function test_negative() { + function test_negative(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); @@ -211,9 +229,11 @@ Canvas { verify(err, "should throw exception of type INDEX_SIZE_ERR: ctx.arc(0, 0, -1, 0, 0, true)"); } + canvas.destroy(); } - function test_scale_1() { + function test_scale_1(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); @@ -236,18 +256,20 @@ Canvas { ctx.arc(25, 125, 24, 0, 2*Math.PI, false); ctx.fill(); - verify(Helper.comparePixel(ctx, 0,0, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 50,0, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 99,0, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 0,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 99,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 0,49, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 50,49, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 99,49, 0,255,0,255)); + comparePixel(ctx, 0,0, 0,255,0,255); + comparePixel(ctx, 50,0, 0,255,0,255); + comparePixel(ctx, 99,0, 0,255,0,255); + comparePixel(ctx, 0,25, 0,255,0,255); + comparePixel(ctx, 50,25, 0,255,0,255); + comparePixel(ctx, 99,25, 0,255,0,255); + comparePixel(ctx, 0,49, 0,255,0,255); + comparePixel(ctx, 50,49, 0,255,0,255); + comparePixel(ctx, 99,49, 0,255,0,255); + canvas.destroy(); } - function test_scale_2() { + function test_scale_2(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); @@ -260,18 +282,20 @@ Canvas { ctx.arc(0, 0, 0.6, 0, Math.PI/2, false); ctx.stroke(); - verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + comparePixel(ctx, 1,1, 0,255,0,255); + comparePixel(ctx, 50,1, 0,255,0,255); + comparePixel(ctx, 98,1, 0,255,0,255); + comparePixel(ctx, 1,25, 0,255,0,255); + comparePixel(ctx, 50,25, 0,255,0,255); + comparePixel(ctx, 98,25, 0,255,0,255); + comparePixel(ctx, 1,48, 0,255,0,255); + comparePixel(ctx, 50,48, 0,255,0,255); + comparePixel(ctx, 98,48, 0,255,0,255); + canvas.destroy(); } - function test_selfintersect_1() { + function test_selfintersect_1(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); @@ -285,11 +309,13 @@ Canvas { ctx.beginPath(); ctx.arc(0, 0, 25, 0, -Math.PI/2, true); ctx.stroke(); - verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + comparePixel(ctx, 1,1, 0,255,0,255); + comparePixel(ctx, 50,25, 0,255,0,255); + canvas.destroy(); } - function test_selfintersect_2() { + function test_selfintersect_2(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); @@ -303,15 +329,17 @@ Canvas { ctx.beginPath(); ctx.arc(100, 0, 25, 0, -Math.PI/2, true); ctx.stroke(); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 90,10, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 97,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 97,2, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 97,3, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 2,48, 0,255,0,255)); + comparePixel(ctx, 50,25, 0,255,0,255); + comparePixel(ctx, 90,10, 0,255,0,255); + comparePixel(ctx, 97,1, 0,255,0,255); + comparePixel(ctx, 97,2, 0,255,0,255); + comparePixel(ctx, 97,3, 0,255,0,255); + comparePixel(ctx, 2,48, 0,255,0,255); + canvas.destroy(); } - function test_shape_1() { + function test_shape_1(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); @@ -322,15 +350,17 @@ Canvas { ctx.beginPath(); ctx.arc(50, 50, 50, 0, Math.PI, false); ctx.stroke(); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 20,48, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + comparePixel(ctx, 50,25, 0,255,0,255); + comparePixel(ctx, 1,1, 0,255,0,255); + comparePixel(ctx, 98,1, 0,255,0,255); + comparePixel(ctx, 1,48, 0,255,0,255); + comparePixel(ctx, 20,48, 0,255,0,255); + comparePixel(ctx, 98,48, 0,255,0,255); + canvas.destroy(); } - function test_shape_2() { + function test_shape_2(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); @@ -341,14 +371,16 @@ Canvas { ctx.beginPath(); ctx.arc(50, 50, 50, 0, Math.PI, true); ctx.stroke(); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 20,48, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + comparePixel(ctx, 50,25, 0,255,0,255); + comparePixel(ctx, 1,1, 0,255,0,255); + comparePixel(ctx, 98,1, 0,255,0,255); + comparePixel(ctx, 1,48, 0,255,0,255); + comparePixel(ctx, 20,48, 0,255,0,255); + comparePixel(ctx, 98,48, 0,255,0,255); + canvas.destroy(); } - function test_shape_3() { + function test_shape_3(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); @@ -359,14 +391,16 @@ Canvas { ctx.beginPath(); ctx.arc(0, 50, 50, 0, -Math.PI/2, false); ctx.stroke(); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + comparePixel(ctx, 50,25, 0,255,0,255); + comparePixel(ctx, 1,1, 0,255,0,255); + comparePixel(ctx, 98,1, 0,255,0,255); + comparePixel(ctx, 1,48, 0,255,0,255); + comparePixel(ctx, 98,48, 0,255,0,255); + canvas.destroy(); } - function test_shape_4() { + function test_shape_4(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); @@ -377,14 +411,16 @@ Canvas { ctx.beginPath(); ctx.arc(-50, 50, 100, 0, -Math.PI/2, true); ctx.stroke(); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + comparePixel(ctx, 50,25, 0,255,0,255); + comparePixel(ctx, 1,1, 0,255,0,255); + comparePixel(ctx, 98,1, 0,255,0,255); + comparePixel(ctx, 1,48, 0,255,0,255); + comparePixel(ctx, 98,48, 0,255,0,255); + canvas.destroy(); } - function test_shape_5() { + function test_shape_5(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); @@ -395,14 +431,16 @@ Canvas { ctx.beginPath(); ctx.arc(300, 0, 100, 0, 5*Math.PI, false); ctx.stroke(); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + comparePixel(ctx, 50,25, 0,255,0,255); + comparePixel(ctx, 1,1, 0,255,0,255); + comparePixel(ctx, 98,1, 0,255,0,255); + comparePixel(ctx, 1,48, 0,255,0,255); + comparePixel(ctx, 98,48, 0,255,0,255); + canvas.destroy(); } - function test_twopie() { + function test_twopie(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); @@ -413,7 +451,7 @@ Canvas { ctx.beginPath(); ctx.arc(50, 25, 50, 0, 2*Math.PI - 1e-4, true); ctx.stroke(); - verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255)); + comparePixel(ctx, 50,20, 0,255,0,255); ctx.reset(); ctx.fillStyle = '#f00'; @@ -423,7 +461,7 @@ Canvas { ctx.beginPath(); ctx.arc(50, 25, 50, 0, 2*Math.PI - 1e-4, false); ctx.stroke(); - verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255)); + comparePixel(ctx, 50,20, 0,255,0,255); ctx.reset(); ctx.fillStyle = '#f00'; @@ -434,7 +472,7 @@ Canvas { ctx.arc(50, 25, 50, 0, 2*Math.PI + 1e-4, true); ctx.stroke(); //FIXME:still different behavior from browsers, > 2pi span issue - //verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255)); + //comparePixel(ctx, 50,20, 0,255,0,255); ctx.reset(); ctx.fillStyle = '#f00'; @@ -444,10 +482,12 @@ Canvas { ctx.beginPath(); ctx.arc(50, 25, 50, 0, 2*Math.PI + 1e-4, false); ctx.stroke(); - verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255)); + comparePixel(ctx, 50,20, 0,255,0,255); + canvas.destroy(); } - function test_zero() { + function test_zero(row) { + var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); ctx.reset(); @@ -458,7 +498,7 @@ Canvas { ctx.beginPath(); ctx.arc(50, 25, 50, 0, 0, true); ctx.stroke(); - verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255)); + comparePixel(ctx, 50,20, 0,255,0,255); ctx.reset(); ctx.fillStyle = '#0f0'; @@ -468,7 +508,7 @@ Canvas { ctx.beginPath(); ctx.arc(50, 25, 50, 0, 0, false); ctx.stroke(); - verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255)); + comparePixel(ctx, 50,20, 0,255,0,255); ctx.reset(); ctx.fillStyle = '#f00' @@ -479,8 +519,7 @@ Canvas { ctx.moveTo(0, 25); ctx.arc(200, 25, 0, 0, Math.PI, true); ctx.stroke(); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - + comparePixel(ctx, 50,25, 0,255,0,255); + canvas.destroy(); } - } -} +} \ No newline at end of file diff --git a/tests/auto/quick/qquickcanvasitem/data/tst_arcto.qml b/tests/auto/quick/qquickcanvasitem/data/tst_arcto.qml index 188d538d29..d9017150a4 100644 --- a/tests/auto/quick/qquickcanvasitem/data/tst_arcto.qml +++ b/tests/auto/quick/qquickcanvasitem/data/tst_arcto.qml @@ -1,409 +1,417 @@ import QtQuick 2.0 -import QtTest 1.0 -import "testhelper.js" as Helper - -Canvas { - id:canvas; width:100;height:50; renderTarget: Canvas.Image; renderStrategy:Canvas.Threaded - smooth: false - TestCase { - name: "arcTo"; when: windowShown - function test_coincide() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - ctx.lineWidth = 50; - - ctx.strokeStyle = '#0f0'; - ctx.beginPath(); - ctx.moveTo(0, 25); - ctx.arcTo(0, 25, 50, 1000, 1); - ctx.lineTo(100, 25); - ctx.stroke(); - - ctx.strokeStyle = '#f00'; - ctx.beginPath(); - ctx.moveTo(50, 25); - ctx.arcTo(50, 25, 100, 25, 1); - ctx.stroke(); - - verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255)); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - ctx.lineWidth = 50; - ctx.strokeStyle = '#0f0'; - ctx.beginPath(); - ctx.moveTo(0, 25); - ctx.arcTo(100, 25, 100, 25, 1); - ctx.stroke(); - - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - } - function test_collinear() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - ctx.lineWidth = 50; - - ctx.strokeStyle = '#0f0'; - ctx.beginPath(); - ctx.moveTo(0, 25); - ctx.arcTo(100, 25, 200, 25, 1); - ctx.stroke(); - - ctx.strokeStyle = '#f00'; - ctx.beginPath(); - ctx.moveTo(-100, 25); - ctx.arcTo(0, 25, 100, 25, 1); - ctx.stroke(); - - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - ctx.lineWidth = 50; - - ctx.strokeStyle = '#0f0'; - ctx.beginPath(); - ctx.moveTo(0, 25); - ctx.arcTo(100, 25, 10, 25, 1); - ctx.stroke(); - - ctx.strokeStyle = '#f00'; - ctx.beginPath(); - ctx.moveTo(100, 25); - ctx.arcTo(200, 25, 110, 25, 1); - ctx.stroke(); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - ctx.lineWidth = 50; - - ctx.strokeStyle = '#0f0'; - ctx.beginPath(); - ctx.moveTo(0, 25); - ctx.arcTo(100, 25, -100, 25, 1); - ctx.stroke(); - - ctx.strokeStyle = '#f00'; - ctx.beginPath(); - ctx.moveTo(100, 25); - ctx.arcTo(200, 25, 0, 25, 1); - ctx.stroke(); - - ctx.beginPath(); - ctx.moveTo(-100, 25); - ctx.arcTo(0, 25, -200, 25, 1); - ctx.stroke(); - - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - } - function test_subpath() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - - ctx.fillStyle = '#0f0'; - ctx.fillRect(0, 0, 100, 50); - ctx.lineWidth = 50; - ctx.strokeStyle = '#f00'; - ctx.beginPath(); - ctx.arcTo(100, 50, 200, 50, 0.1); - ctx.stroke(); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - ctx.lineWidth = 50; - ctx.strokeStyle = '#0f0'; - ctx.beginPath(); - ctx.arcTo(0, 25, 50, 250, 0.1); - ctx.lineTo(100, 25); - ctx.stroke(); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - } - function test_negative() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - - try { var err = false; - ctx.arcTo(0, 0, 0, 0, -1); - } catch (e) { - if (e.code != DOMException.INDEX_SIZE_ERR) - fail("expectes INDEX_SIZE_ERR, got: "+e.message); - err = true; - } - finally { - verify(err, "should throw INDEX_SIZE_ERR: ctx.arcTo(0, 0, 0, 0, -1)"); - } - } - - function test_nonfinite() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - - ctx.moveTo(0, 0); - ctx.lineTo(100, 0); - ctx.arcTo(Infinity, 50, 0, 50, 0); - ctx.arcTo(-Infinity, 50, 0, 50, 0); - ctx.arcTo(NaN, 50, 0, 50, 0); - ctx.arcTo(0, Infinity, 0, 50, 0); - ctx.arcTo(0, -Infinity, 0, 50, 0); - ctx.arcTo(0, NaN, 0, 50, 0); - ctx.arcTo(0, 50, Infinity, 50, 0); - ctx.arcTo(0, 50, -Infinity, 50, 0); - ctx.arcTo(0, 50, NaN, 50, 0); - ctx.arcTo(0, 50, 0, Infinity, 0); - ctx.arcTo(0, 50, 0, -Infinity, 0); - ctx.arcTo(0, 50, 0, NaN, 0); - ctx.arcTo(0, 50, 0, 50, Infinity); - ctx.arcTo(0, 50, 0, 50, -Infinity); - ctx.arcTo(0, 50, 0, 50, NaN); - ctx.arcTo(Infinity, Infinity, 0, 50, 0); - ctx.arcTo(Infinity, Infinity, Infinity, 50, 0); - ctx.arcTo(Infinity, Infinity, Infinity, Infinity, 0); - ctx.arcTo(Infinity, Infinity, Infinity, Infinity, Infinity); - ctx.arcTo(Infinity, Infinity, Infinity, 50, Infinity); - ctx.arcTo(Infinity, Infinity, 0, Infinity, 0); - ctx.arcTo(Infinity, Infinity, 0, Infinity, Infinity); - ctx.arcTo(Infinity, Infinity, 0, 50, Infinity); - ctx.arcTo(Infinity, 50, Infinity, 50, 0); - ctx.arcTo(Infinity, 50, Infinity, Infinity, 0); - ctx.arcTo(Infinity, 50, Infinity, Infinity, Infinity); - ctx.arcTo(Infinity, 50, Infinity, 50, Infinity); - ctx.arcTo(Infinity, 50, 0, Infinity, 0); - ctx.arcTo(Infinity, 50, 0, Infinity, Infinity); - ctx.arcTo(Infinity, 50, 0, 50, Infinity); - ctx.arcTo(0, Infinity, Infinity, 50, 0); - ctx.arcTo(0, Infinity, Infinity, Infinity, 0); - ctx.arcTo(0, Infinity, Infinity, Infinity, Infinity); - ctx.arcTo(0, Infinity, Infinity, 50, Infinity); - ctx.arcTo(0, Infinity, 0, Infinity, 0); - ctx.arcTo(0, Infinity, 0, Infinity, Infinity); - ctx.arcTo(0, Infinity, 0, 50, Infinity); - ctx.arcTo(0, 50, Infinity, Infinity, 0); - ctx.arcTo(0, 50, Infinity, Infinity, Infinity); - ctx.arcTo(0, 50, Infinity, 50, Infinity); - ctx.arcTo(0, 50, 0, Infinity, Infinity); - ctx.lineTo(100, 50); - ctx.lineTo(0, 50); - ctx.fillStyle = '#0f0'; - ctx.fill(); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 90,45, 0,255,0,255)); +CanvasTestCase { + id:testCase + name: "arcTo" + function init_data() { return testData("2d"); } + + function test_coincide(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(0, 25); + ctx.arcTo(0, 25, 50, 1000, 1); + ctx.lineTo(100, 25); + ctx.stroke(); + + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(50, 25); + ctx.arcTo(50, 25, 100, 25, 1); + ctx.stroke(); + + comparePixel(ctx, 50,1, 0,255,0,255); + comparePixel(ctx, 50,25, 0,255,0,255); + comparePixel(ctx, 50,48, 0,255,0,255); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(0, 25); + ctx.arcTo(100, 25, 100, 25, 1); + ctx.stroke(); + + comparePixel(ctx, 50,25, 0,255,0,255); + } + function test_collinear(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(0, 25); + ctx.arcTo(100, 25, 200, 25, 1); + ctx.stroke(); + + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(-100, 25); + ctx.arcTo(0, 25, 100, 25, 1); + ctx.stroke(); + + comparePixel(ctx, 50,25, 0,255,0,255); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(0, 25); + ctx.arcTo(100, 25, 10, 25, 1); + ctx.stroke(); + + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(100, 25); + ctx.arcTo(200, 25, 110, 25, 1); + ctx.stroke(); + comparePixel(ctx, 50,25, 0,255,0,255); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(0, 25); + ctx.arcTo(100, 25, -100, 25, 1); + ctx.stroke(); + + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(100, 25); + ctx.arcTo(200, 25, 0, 25, 1); + ctx.stroke(); + + ctx.beginPath(); + ctx.moveTo(-100, 25); + ctx.arcTo(0, 25, -200, 25, 1); + ctx.stroke(); + + comparePixel(ctx, 50,25, 0,255,0,255); + } + function test_subpath(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.arcTo(100, 50, 200, 50, 0.1); + ctx.stroke(); + comparePixel(ctx, 50,25, 0,255,0,255); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.arcTo(0, 25, 50, 250, 0.1); + ctx.lineTo(100, 25); + ctx.stroke(); + comparePixel(ctx, 50,25, 0,255,0,255); + } + function test_negative(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + try { var err = false; + ctx.arcTo(0, 0, 0, 0, -1); + } catch (e) { + if (e.code != DOMException.INDEX_SIZE_ERR) + fail("expectes INDEX_SIZE_ERR, got: "+e.message); + err = true; } - function test_scale() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - - ctx.fillStyle = '#0f0'; - ctx.beginPath(); - ctx.moveTo(0, 50); - ctx.translate(100, 0); - ctx.scale(0.1, 1); - ctx.arcTo(50, 50, 50, 0, 50); - ctx.lineTo(-1000, 0); - ctx.fill(); - - //FIXME - //verify(Helper.comparePixel(ctx, 0,0, 0,255,0,255)); - //verify(Helper.comparePixel(ctx, 50,0, 0,255,0,255)); - //verify(Helper.comparePixel(ctx, 99,0, 0,255,0,255)); - //verify(Helper.comparePixel(ctx, 0,25, 0,255,0,255)); - //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - //verify(Helper.comparePixel(ctx, 99,25, 0,255,0,255)); - //verify(Helper.comparePixel(ctx, 0,49, 0,255,0,255)); - //verify(Helper.comparePixel(ctx, 50,49, 0,255,0,255)); - //verify(Helper.comparePixel(ctx, 99,49, 0,255,0,255)); + finally { + verify(err, "should throw INDEX_SIZE_ERR: ctx.arcTo(0, 0, 0, 0, -1)"); } + } - function test_shape() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - - var tol = 1.5; // tolerance to avoid antialiasing artifacts - - ctx.fillStyle = '#0f0'; - ctx.fillRect(0, 0, 100, 50); - - ctx.strokeStyle = '#f00'; - ctx.lineWidth = 10; - ctx.beginPath(); - ctx.moveTo(10, 25); - ctx.arcTo(75, 25, 75, 60, 20); - ctx.stroke(); - - ctx.fillStyle = '#0f0'; - ctx.beginPath(); - ctx.rect(10, 20, 45, 10); - ctx.moveTo(80, 45); - ctx.arc(55, 45, 25+tol, 0, -Math.PI/2, true); - ctx.arc(55, 45, 15-tol, -Math.PI/2, 0, false); - ctx.fill(); - - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 55,19, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 55,20, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 55,21, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 64,22, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 65,21, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 72,28, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 73,27, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 78,36, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 79,35, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 80,44, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 80,45, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 80,46, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 65,45, 0,255,0,255)); - ctx.reset(); - - ctx.fillStyle = '#0f0'; - ctx.fillRect(0, 0, 100, 50); - - ctx.fillStyle = '#f00'; - ctx.beginPath(); - ctx.rect(10, 20, 45, 10); - ctx.moveTo(80, 45); - ctx.arc(55, 45, 25-tol, 0, -Math.PI/2, true); - ctx.arc(55, 45, 15+tol, -Math.PI/2, 0, false); - ctx.fill(); - - ctx.strokeStyle = '#0f0'; - ctx.lineWidth = 10; - ctx.beginPath(); - ctx.moveTo(10, 25); - ctx.arcTo(75, 25, 75, 60, 20); - ctx.stroke(); - - //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 55,19, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 55,20, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 55,21, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 64,22, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 65,21, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 72,28, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 73,27, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 78,36, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 79,35, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 80,44, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 80,45, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 80,46, 0,255,0,255)); - ctx.reset(); - - - ctx.fillStyle = '#0f0'; - ctx.fillRect(0, 0, 100, 50); - ctx.strokeStyle = '#f00'; - ctx.lineWidth = 50; - ctx.beginPath(); - ctx.moveTo(-100, -100); - ctx.arcTo(-100, 25, 200, 25, 10); - ctx.stroke(); - - verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - ctx.strokeStyle = '#0f0'; - ctx.lineWidth = 50; - ctx.beginPath(); - ctx.moveTo(0, 25); - ctx.arcTo(200, 25, 200, 50, 10); - ctx.stroke(); - - //FIXME - //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); - //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); - //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); - //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); - } + function test_nonfinite(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.moveTo(0, 0); + ctx.lineTo(100, 0); + ctx.arcTo(Infinity, 50, 0, 50, 0); + ctx.arcTo(-Infinity, 50, 0, 50, 0); + ctx.arcTo(NaN, 50, 0, 50, 0); + ctx.arcTo(0, Infinity, 0, 50, 0); + ctx.arcTo(0, -Infinity, 0, 50, 0); + ctx.arcTo(0, NaN, 0, 50, 0); + ctx.arcTo(0, 50, Infinity, 50, 0); + ctx.arcTo(0, 50, -Infinity, 50, 0); + ctx.arcTo(0, 50, NaN, 50, 0); + ctx.arcTo(0, 50, 0, Infinity, 0); + ctx.arcTo(0, 50, 0, -Infinity, 0); + ctx.arcTo(0, 50, 0, NaN, 0); + ctx.arcTo(0, 50, 0, 50, Infinity); + ctx.arcTo(0, 50, 0, 50, -Infinity); + ctx.arcTo(0, 50, 0, 50, NaN); + ctx.arcTo(Infinity, Infinity, 0, 50, 0); + ctx.arcTo(Infinity, Infinity, Infinity, 50, 0); + ctx.arcTo(Infinity, Infinity, Infinity, Infinity, 0); + ctx.arcTo(Infinity, Infinity, Infinity, Infinity, Infinity); + ctx.arcTo(Infinity, Infinity, Infinity, 50, Infinity); + ctx.arcTo(Infinity, Infinity, 0, Infinity, 0); + ctx.arcTo(Infinity, Infinity, 0, Infinity, Infinity); + ctx.arcTo(Infinity, Infinity, 0, 50, Infinity); + ctx.arcTo(Infinity, 50, Infinity, 50, 0); + ctx.arcTo(Infinity, 50, Infinity, Infinity, 0); + ctx.arcTo(Infinity, 50, Infinity, Infinity, Infinity); + ctx.arcTo(Infinity, 50, Infinity, 50, Infinity); + ctx.arcTo(Infinity, 50, 0, Infinity, 0); + ctx.arcTo(Infinity, 50, 0, Infinity, Infinity); + ctx.arcTo(Infinity, 50, 0, 50, Infinity); + ctx.arcTo(0, Infinity, Infinity, 50, 0); + ctx.arcTo(0, Infinity, Infinity, Infinity, 0); + ctx.arcTo(0, Infinity, Infinity, Infinity, Infinity); + ctx.arcTo(0, Infinity, Infinity, 50, Infinity); + ctx.arcTo(0, Infinity, 0, Infinity, 0); + ctx.arcTo(0, Infinity, 0, Infinity, Infinity); + ctx.arcTo(0, Infinity, 0, 50, Infinity); + ctx.arcTo(0, 50, Infinity, Infinity, 0); + ctx.arcTo(0, 50, Infinity, Infinity, Infinity); + ctx.arcTo(0, 50, Infinity, 50, Infinity); + ctx.arcTo(0, 50, 0, Infinity, Infinity); + ctx.lineTo(100, 50); + ctx.lineTo(0, 50); + ctx.fillStyle = '#0f0'; + ctx.fill(); + comparePixel(ctx, 50,25, 0,255,0,255); + comparePixel(ctx, 90,45, 0,255,0,255); - function test_transform() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - - ctx.fillStyle = '#0f0'; - ctx.beginPath(); - ctx.moveTo(0, 50); - ctx.translate(100, 0); - ctx.arcTo(50, 50, 50, 0, 50); - ctx.lineTo(-100, 0); - ctx.fill(); - - verify(Helper.comparePixel(ctx, 0,0, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 50,0, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 99,0, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 0,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 99,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 0,49, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 50,49, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 99,49, 0,255,0,255)); - } - function test_zero() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - ctx.lineWidth = 50; - - ctx.strokeStyle = '#0f0'; - ctx.beginPath(); - ctx.moveTo(0, 25); - ctx.arcTo(100, 25, 100, 100, 0); - ctx.stroke(); - - ctx.strokeStyle = '#f00'; - ctx.beginPath(); - ctx.moveTo(0, -25); - ctx.arcTo(50, -25, 50, 50, 0); - ctx.stroke(); - - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - ctx.lineWidth = 50; - - ctx.strokeStyle = '#0f0'; - ctx.beginPath(); - ctx.moveTo(0, 25); - ctx.arcTo(100, 25, -100, 25, 0); - ctx.stroke(); - - ctx.strokeStyle = '#f00'; - ctx.beginPath(); - ctx.moveTo(100, 25); - ctx.arcTo(200, 25, 50, 25, 0); - ctx.stroke(); - - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + } + function test_scale(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.fillStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(0, 50); + ctx.translate(100, 0); + ctx.scale(0.1, 1); + ctx.arcTo(50, 50, 50, 0, 50); + ctx.lineTo(-1000, 0); + ctx.fill(); + + //FIXME + //comparePixel(ctx, 0,0, 0,255,0,255); + //comparePixel(ctx, 50,0, 0,255,0,255); + //comparePixel(ctx, 99,0, 0,255,0,255); + //comparePixel(ctx, 0,25, 0,255,0,255); + //comparePixel(ctx, 50,25, 0,255,0,255); + //comparePixel(ctx, 99,25, 0,255,0,255); + //comparePixel(ctx, 0,49, 0,255,0,255); + //comparePixel(ctx, 50,49, 0,255,0,255); + //comparePixel(ctx, 99,49, 0,255,0,255); + } + function test_shape(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + var tol = 1.5; // tolerance to avoid antialiasing artifacts + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 10; + ctx.beginPath(); + ctx.moveTo(10, 25); + ctx.arcTo(75, 25, 75, 60, 20); + ctx.stroke(); + + ctx.fillStyle = '#0f0'; + ctx.beginPath(); + ctx.rect(10, 20, 45, 10); + ctx.moveTo(80, 45); + ctx.arc(55, 45, 25+tol, 0, -Math.PI/2, true); + ctx.arc(55, 45, 15-tol, -Math.PI/2, 0, false); + ctx.fill(); + + comparePixel(ctx, 50,25, 0,255,0,255); + comparePixel(ctx, 55,19, 0,255,0,255); + comparePixel(ctx, 55,20, 0,255,0,255); + comparePixel(ctx, 55,21, 0,255,0,255); + comparePixel(ctx, 64,22, 0,255,0,255); + comparePixel(ctx, 65,21, 0,255,0,255); + comparePixel(ctx, 72,28, 0,255,0,255); + comparePixel(ctx, 73,27, 0,255,0,255); + comparePixel(ctx, 78,36, 0,255,0,255); + comparePixel(ctx, 79,35, 0,255,0,255); + comparePixel(ctx, 80,44, 0,255,0,255); + comparePixel(ctx, 80,45, 0,255,0,255); + comparePixel(ctx, 80,46, 0,255,0,255); + comparePixel(ctx, 65,45, 0,255,0,255); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.fillStyle = '#f00'; + ctx.beginPath(); + ctx.rect(10, 20, 45, 10); + ctx.moveTo(80, 45); + ctx.arc(55, 45, 25-tol, 0, -Math.PI/2, true); + ctx.arc(55, 45, 15+tol, -Math.PI/2, 0, false); + ctx.fill(); + + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 10; + ctx.beginPath(); + ctx.moveTo(10, 25); + ctx.arcTo(75, 25, 75, 60, 20); + ctx.stroke(); + + //comparePixel(ctx, 50,25, 0,255,0,255); + comparePixel(ctx, 55,19, 0,255,0,255); + comparePixel(ctx, 55,20, 0,255,0,255); + if (canvas.renderTarget === Canvas.Image) { + //FIXME:broken for Canvas.FramebufferObject + comparePixel(ctx, 55,21, 0,255,0,255); } + comparePixel(ctx, 64,22, 0,255,0,255); + comparePixel(ctx, 65,21, 0,255,0,255); + comparePixel(ctx, 72,28, 0,255,0,255); + comparePixel(ctx, 73,27, 0,255,0,255); + comparePixel(ctx, 78,36, 0,255,0,255); + comparePixel(ctx, 79,35, 0,255,0,255); + comparePixel(ctx, 80,44, 0,255,0,255); + comparePixel(ctx, 80,45, 0,255,0,255); + comparePixel(ctx, 80,46, 0,255,0,255); + ctx.reset(); + + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 50; + ctx.beginPath(); + ctx.moveTo(-100, -100); + ctx.arcTo(-100, 25, 200, 25, 10); + ctx.stroke(); + + comparePixel(ctx, 1,1, 0,255,0,255); + comparePixel(ctx, 1,48, 0,255,0,255); + comparePixel(ctx, 50,25, 0,255,0,255); + comparePixel(ctx, 98,1, 0,255,0,255); + comparePixel(ctx, 98,48, 0,255,0,255); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 50; + ctx.beginPath(); + ctx.moveTo(0, 25); + ctx.arcTo(200, 25, 200, 50, 10); + ctx.stroke(); + + //FIXME + //comparePixel(ctx, 1,1, 0,255,0,255); + //comparePixel(ctx, 1,48, 0,255,0,255); + //comparePixel(ctx, 50,25, 0,255,0,255); + //comparePixel(ctx, 98,1, 0,255,0,255); + //comparePixel(ctx, 98,48, 0,255,0,255); + } + + function test_transform(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.fillStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(0, 50); + ctx.translate(100, 0); + ctx.arcTo(50, 50, 50, 0, 50); + ctx.lineTo(-100, 0); + ctx.fill(); + + comparePixel(ctx, 0,0, 0,255,0,255); + comparePixel(ctx, 50,0, 0,255,0,255); + comparePixel(ctx, 99,0, 0,255,0,255); + comparePixel(ctx, 0,25, 0,255,0,255); + comparePixel(ctx, 50,25, 0,255,0,255); + comparePixel(ctx, 99,25, 0,255,0,255); + comparePixel(ctx, 0,49, 0,255,0,255); + comparePixel(ctx, 50,49, 0,255,0,255); + comparePixel(ctx, 99,49, 0,255,0,255); + } + function test_zero(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(0, 25); + ctx.arcTo(100, 25, 100, 100, 0); + ctx.stroke(); + + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(0, -25); + ctx.arcTo(50, -25, 50, 50, 0); + ctx.stroke(); + + comparePixel(ctx, 50,25, 0,255,0,255); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(0, 25); + ctx.arcTo(100, 25, -100, 25, 0); + ctx.stroke(); + + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(100, 25); + ctx.arcTo(200, 25, 50, 25, 0); + ctx.stroke(); + + comparePixel(ctx, 50,25, 0,255,0,255); } } diff --git a/tests/auto/quick/qquickcanvasitem/data/tst_canvas.qml b/tests/auto/quick/qquickcanvasitem/data/tst_canvas.qml index a70c798594..7c17499f68 100644 --- a/tests/auto/quick/qquickcanvasitem/data/tst_canvas.qml +++ b/tests/auto/quick/qquickcanvasitem/data/tst_canvas.qml @@ -1,281 +1,231 @@ import QtQuick 2.0 -import QtTest 1.0 - -Rectangle { - id:container - width:100 - height:100 - Component { - id:canvas - Canvas { - id:c - width:100;height:100 - onPaint: { - var context = getContext("2d"); - context.fillStyle = "red"; - context.fillRect(0, 0, 100, 100); - } - renderTarget:Canvas.Image - renderStrategy:Canvas.Threaded - property int paintCount:spyPaint.count - property int paintedCount:spyPainted.count - property int canvasSizeChangedCount:spyCanvasSizeChanged.count - property int tileSizeChangedCount:spyTileSizeChanged.count - property int renderStrategyChangedCount:spyRenderStrategyChanged.count - property int canvasWindowChangedCount:spyCanvasWindowChanged.count - property int renderTargetChangedCount:spyRenderTargetChanged.count - property int imageLoadedCount:spyImageLoaded.count - property int availableChangedCount:spyAvailableChanged.count - - SignalSpy {id: spyPaint;target:c;signalName: "paint"} - SignalSpy {id: spyPainted;target:c;signalName: "painted"} - SignalSpy {id: spyCanvasSizeChanged;target:c;signalName: "canvasSizeChanged"} - SignalSpy {id: spyTileSizeChanged;target:c;signalName: "tileSizeChanged"} - SignalSpy {id: spyRenderStrategyChanged;target:c;signalName: "renderStrategyChanged"} - SignalSpy {id: spyCanvasWindowChanged;target:c;signalName: "canvasWindowChanged"} - SignalSpy {id: spyRenderTargetChanged;target:c;signalName: "renderTargetChanged"} - SignalSpy {id: spyImageLoaded;target:c;signalName: "imageLoaded"} - SignalSpy {id: spyAvailableChanged;target:c;signalName: "availableChanged"} - } - } - - TestCase { - name: "Canvas"; when: windowShown - function test_canvasSize() { - var c = canvas.createObject(container); - verify(c); - wait(100); - verify(c.availableChangedCount, 1); - - //by default canvasSize is same with canvas' actual size - // when canvas size changes, canvasSize should be changed as well. - compare(c.canvasSize.width, c.width); - compare(c.canvasSize.height, c.height); - c.width = 20; - compare(c.canvasSize.width, 20); - compare(c.canvasSizeChangedCount, 1); - c.height = 5; - compare(c.canvasSizeChangedCount, 2); - compare(c.canvasSize.height, 5); - - //change canvasSize manually, then canvasSize detaches from canvas - //actual size. - c.canvasSize.width = 100; - compare(c.canvasSizeChangedCount, 3); - compare(c.canvasSize.width, 100); - compare(c.width, 20); - c.canvasSize.height = 50; - compare(c.canvasSizeChangedCount, 4); - compare(c.canvasSize.height, 50); - compare(c.height, 5); - - c.width = 10; - compare(c.canvasSizeChangedCount, 4); - compare(c.canvasSize.width, 100); - compare(c.canvasSize.height, 50); - - c.height = 10; - compare(c.canvasSizeChangedCount, 4); - compare(c.canvasSize.width, 100); - compare(c.canvasSize.height, 50); - c.destroy(); - } - function test_tileSize() { - var c = canvas.createObject(container); - verify(c); - wait(100); - verify(c.availableChangedCount, 1); - - compare(c.tileSize.width, c.width); - compare(c.tileSize.height, c.height); - c.width = 20; - compare(c.tileSize.width, 20); - compare(c.tileSizeChangedCount, 1); - c.height = 5; - compare(c.tileSizeChangedCount, 2); - compare(c.tileSize.height, 5); - - c.tileSize.width = 100; - compare(c.tileSizeChangedCount, 3); - compare(c.tileSize.width, 100); - compare(c.width, 20); - c.tileSize.height = 50; - compare(c.tileSizeChangedCount, 4); - compare(c.tileSize.height, 50); - compare(c.height, 5); - - c.width = 10; - compare(c.tileSizeChangedCount, 4); - compare(c.tileSize.width, 100); - compare(c.tileSize.height, 50); - - c.height = 10; - compare(c.tileSizeChangedCount, 4); - compare(c.tileSize.width, 100); - compare(c.tileSize.height, 50); - c.destroy(); - } +CanvasTestCase { + id:testCase + name: "canvas" + function init_data() { return testData("2d"); } + + function test_canvasSize(row) { + var c = createCanvasObject(row); + verify(c); + var ctx = c.getContext("2d"); + verify(ctx); + + tryCompare(c, "availableChangedCount", 1, 100); + //by default canvasSize is same with canvas' actual size + // when canvas size changes, canvasSize should be changed as well. + compare(c.canvasSize.width, c.width); + compare(c.canvasSize.height, c.height); + c.width = 20; + compare(c.canvasSize.width, 20); + compare(c.canvasSizeChangedCount, 1); + c.height = 5; + compare(c.canvasSizeChangedCount, 2); + compare(c.canvasSize.height, 5); + + //change canvasSize manually, then canvasSize detaches from canvas + //actual size. + c.canvasSize.width = 100; + compare(c.canvasSizeChangedCount, 3); + compare(c.canvasSize.width, 100); + compare(c.width, 20); + c.canvasSize.height = 50; + compare(c.canvasSizeChangedCount, 4); + compare(c.canvasSize.height, 50); + compare(c.height, 5); + + c.width = 10; + compare(c.canvasSizeChangedCount, 4); + compare(c.canvasSize.width, 100); + compare(c.canvasSize.height, 50); + + c.height = 10; + + compare(c.canvasSizeChangedCount, 4); + compare(c.canvasSize.width, 100); + compare(c.canvasSize.height, 50); + c.destroy(); + } + function test_tileSize(row) { + var c = createCanvasObject(row); + verify(c); + var ctx = c.getContext("2d"); + verify(ctx); + tryCompare(c, "availableChangedCount", 1, 100); + + compare(c.tileSize.width, c.width); + compare(c.tileSize.height, c.height); + c.width = 20; + compare(c.tileSize.width, 20); + compare(c.tileSizeChangedCount, 1); + c.height = 5; + compare(c.tileSizeChangedCount, 2); + compare(c.tileSize.height, 5); + + c.tileSize.width = 100; + compare(c.tileSizeChangedCount, 3); + compare(c.tileSize.width, 100); + compare(c.width, 20); + c.tileSize.height = 50; + compare(c.tileSizeChangedCount, 4); + compare(c.tileSize.height, 50); + compare(c.height, 5); + + c.width = 10; + compare(c.tileSizeChangedCount, 4); + compare(c.tileSize.width, 100); + compare(c.tileSize.height, 50); + + c.height = 10; + compare(c.tileSizeChangedCount, 4); + compare(c.tileSize.width, 100); + compare(c.tileSize.height, 50); + c.destroy(); + + } - function test_canvasWindow() { - var c = canvas.createObject(container); - verify(c); - wait(100); - verify(c.availableChangedCount, 1); - compare(c.canvasWindow.x, 0); - compare(c.canvasWindow.y, 0); - compare(c.canvasWindow.width, c.width); - compare(c.canvasWindow.height, c.height); - - c.width = 20; - compare(c.canvasWindow.width, 20); - compare(c.canvasWindowChangedCount, 1); - c.height = 5; - compare(c.canvasWindowChangedCount, 2); - compare(c.canvasWindow.height, 5); - - c.canvasWindow.x = 5; - c.canvasWindow.y = 6; - c.canvasWindow.width = 10; - c.canvasWindow.height =20; - compare(c.canvasWindowChangedCount, 6); - compare(c.canvasWindow.width, 10); - compare(c.canvasWindow.height, 20); - compare(c.canvasWindow.x, 5); - compare(c.canvasWindow.y, 6); - c.destroy(); - - } - function test_renderTargetAndStrategy() { - var c = canvas.createObject(container); - verify(c); - wait(100); - verify(c.availableChangedCount, 1); - - compare(c.renderTarget, Canvas.Image); - compare(c.renderStrategy, Canvas.Threaded); - c.destroy(); - - } - function test_save() { - var c = canvas.createObject(container); - verify(c); - wait(100); - verify(c.availableChangedCount, 1); - - c.renderTarget = Canvas.Image; - c.requestPaint(); - wait(100); - verify(c.save("c.png")); - c.loadImage("c.png"); - wait(200); - compare(c.imageLoadedCount, 1); - verify(c.isImageLoaded("c.png")); - verify(!c.isImageLoading("c.png")); - verify(!c.isImageError("c.png")); - c.destroy(); - - } - function test_toDataURL_data() { - return [{mimeType:"image/png"}, + function test_canvasWindow(row) { + var c = createCanvasObject(row); + verify(c); + var ctx = c.getContext("2d"); + verify(ctx); + + tryCompare(c, "availableChangedCount", 1, 100); + compare(c.canvasWindow.x, 0); + compare(c.canvasWindow.y, 0); + compare(c.canvasWindow.width, c.width); + compare(c.canvasWindow.height, c.height); + + c.width = 20; + compare(c.canvasWindow.width, 20); + compare(c.canvasWindowChangedCount, 1); + c.height = 5; + compare(c.canvasWindowChangedCount, 2); + compare(c.canvasWindow.height, 5); + + c.canvasWindow.x = 5; + c.canvasWindow.y = 6; + c.canvasWindow.width = 10; + c.canvasWindow.height =20; + compare(c.canvasWindowChangedCount, 6); + compare(c.canvasWindow.width, 10); + compare(c.canvasWindow.height, 20); + compare(c.canvasWindow.x, 5); + compare(c.canvasWindow.y, 6); + c.destroy(); + + } + + function test_save(row) { + var c = createCanvasObject(row); + verify(c); + var ctx = c.getContext("2d"); + + tryCompare(c, "availableChangedCount", 1, 100); + + c.requestPaint(); + verify(c.save("c.png")); + c.loadImage("c.png"); + wait(200); + verify(c.isImageLoaded("c.png")); + verify(!c.isImageLoading("c.png")); + verify(!c.isImageError("c.png")); + c.destroy(); + } + + function test_toDataURL(row) { + var c = createCanvasObject(row); + verify(c); + var ctx = c.getContext("2d"); + verify(ctx); + + tryCompare(c, "availableChangedCount", 1, 100); + + var imageTypes = [ + {mimeType:"image/png"}, {mimeType:"image/bmp"}, {mimeType:"image/jpeg"}, {mimeType:"image/x-portable-pixmap"}, //{mimeType:"image/tiff"}, QTBUG-23980 {mimeType:"image/xpm"}, - ]; - } - - function test_toDataURL(data) { - var c = canvas.createObject(container); - verify(c); - wait(100); - verify(c.availableChangedCount, 1); - - var ctx = c.getContext("2d"); + ]; + for (var i = 0; i < imageTypes.length; i++) { ctx.fillStyle = "red"; ctx.fillRect(0, 0, c.width, c.height); - wait(100); var dataUrl = c.toDataURL(); - verify(dataUrl != "data:,"); + verify(dataUrl !== "data:,"); dataUrl = c.toDataURL("image/invalid"); - verify(dataUrl == "data:,"); + verify(dataUrl === "data:,"); - dataUrl = c.toDataURL(data.mimeType); - verify(dataUrl != "data:,"); + dataUrl = c.toDataURL(imageTypes[i].mimeType); + verify(dataUrl !== "data:,"); ctx.save(); ctx.fillStyle = "blue"; ctx.fillRect(0, 0, c.width, c.height); ctx.restore(); - wait(100); - - var dataUrl2 = c.toDataURL(data.mimeType); - verify (dataUrl2 != "data:,"); - verify (dataUrl2 != dataUrl); - c.destroy(); - - } - function test_paint() { - var c = canvas.createObject(container); - verify(c); - wait(100); - verify(c.availableChangedCount, 1); - - c.renderTarget = Canvas.Image; - c.renderStrategy = Canvas.Immediate; - var ctx = c.getContext("2d"); - ctx.fillRect(0, 0, c.width, c.height); - c.toDataURL(); - wait(100); - - compare(c.paintedCount, 2); - compare(c.paintCount, 1); - c.destroy(); - - } - function test_loadImage() { - var c = canvas.createObject(container); - verify(c); - wait(100); - verify(c.availableChangedCount, 1); - - c.loadImage("red.png"); - wait(200); - compare(c.imageLoadedCount, 1); - verify(c.isImageLoaded("red.png")); - verify(!c.isImageLoading("red.png")); - verify(!c.isImageError("red.png")); - - c.unloadImage("red.png"); - verify(!c.isImageLoaded("red.png")); - verify(!c.isImageLoading("red.png")); - verify(!c.isImageError("red.png")); - c.destroy(); - - } - - function test_getContext() { - var c = canvas.createObject(container); - verify(c); - wait(100); - verify(c.availableChangedCount, 1); - - var ctx = c.getContext("2d"); - verify(ctx); - compare(ctx.canvas, c); - ctx = c.getContext('2d'); - verify(ctx); - compare(ctx.canvas, c); - ctx = c.getContext('2D'); - verify(ctx); - compare(ctx.canvas, c); - ignoreWarning(Qt.resolvedUrl("tst_canvas.qml") + ":10:9: QML Canvas: Canvas already initialized with a different context type"); - ctx = c.getContext('invalid'); - verify(!ctx); - c.destroy(); - - } - } + + var dataUrl2 = c.toDataURL(imageTypes[i].mimeType); + verify (dataUrl2 !== "data:,"); + verify (dataUrl2 !== dataUrl); + } + c.destroy(); + + } + function test_paint(row) { + var c = createCanvasObject(row); + verify(c); + var ctx = c.getContext("2d"); + tryCompare(c, "availableChangedCount", 1, 100); + + ctx.fillRect(0, 0, c.width, c.height); + c.toDataURL(); + tryCompare(c, "paintedCount", 2, 200); + tryCompare(c, "paintCount", 1, 200); + c.destroy(); + } + function test_loadImage(row) { + var c = createCanvasObject(row); + verify(c); + var ctx = c.getContext("2d"); + verify(ctx); + + tryCompare(c, "availableChangedCount", 1, 100); + + verify(!c.isImageLoaded("red.png")); + c.loadImage("red.png"); + wait(200); + verify(c.isImageLoaded("red.png")); + verify(!c.isImageLoading("red.png")); + verify(!c.isImageError("red.png")); + + c.unloadImage("red.png"); + verify(!c.isImageLoaded("red.png")); + verify(!c.isImageLoading("red.png")); + verify(!c.isImageError("red.png")); + c.destroy(); + + } + + function test_getContext(row) { + var c = createCanvasObject(row); + verify(c); + var ctx = c.getContext("2d"); + verify(ctx); + tryCompare(c, "availableChangedCount", 1, 100); + + compare(ctx.canvas, c); + ctx = c.getContext('2d'); + verify(ctx); + compare(ctx.canvas, c); + ctx = c.getContext('2D'); + verify(ctx); + compare(ctx.canvas, c); + ignoreWarning(Qt.resolvedUrl("CanvasComponent.qml") + ":6:9: QML Canvas: Canvas already initialized with a different context type"); + ctx = c.getContext('invalid'); + verify(!ctx); + c.destroy(); + + } } diff --git a/tests/auto/quick/qquickcanvasitem/data/tst_composite.qml b/tests/auto/quick/qquickcanvasitem/data/tst_composite.qml index 60c63ae04b..3e41efdcc4 100644 --- a/tests/auto/quick/qquickcanvasitem/data/tst_composite.qml +++ b/tests/auto/quick/qquickcanvasitem/data/tst_composite.qml @@ -1,383 +1,388 @@ import QtQuick 2.0 -import QtTest 1.0 -import "testhelper.js" as Helper -Canvas { - id:canvas; width:100;height:50; renderTarget:Canvas.Image; renderStrategy:Canvas.Threaded - TestCase { - name: "composite"; when: windowShown - function test_clearRect() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - ctx.globalCompositeOperation = 'destination-atop'; - ctx.clearRect(0, 0, 100, 50); - verify(Helper.comparePixel(ctx, 50,25, 0,0,0,0)); - } - - function test_clip_data() { - return [ {compsite:"copy"}, - {compsite:"destination-atop"}, - {compsite:"destination-in"}, - {compsite:"destination-out"}, - {compsite:"destination-over"}, - {compsite:"lighter"}, - {compsite:"source-atop"}, - {compsite:"source-in"}, - {compsite:"source-out"}, - {compsite:"source-over"}, - {compsite:"xor"} - ]; - } - function test_clip(data) { - var ctx = canvas.getContext('2d'); +CanvasTestCase { + id:testCase + name: "composite" + function init_data() { return testData("2d"); } + function test_clearRect(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'destination-atop'; + ctx.clearRect(0, 0, 100, 50); + comparePixel(ctx, 50,25, 0,0,0,0); + } + + function test_clip(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + var composites = [ {compsite:"copy"}, + {compsite:"destination-atop"}, + {compsite:"destination-in"}, + {compsite:"destination-out"}, + {compsite:"destination-over"}, + // {compsite:"lighter"}, //qt doesn't support lighter + {compsite:"source-atop"}, + {compsite:"source-in"}, + {compsite:"source-out"}, + {compsite:"source-over"}, + {compsite:"xor"} + ]; + for (var i=0; i 0; --i) - { - testCase.compare(ctx.lineWidth, i); //strange javascript error here - ctx.restore(); - } - - for (var i = 0; i < 16; ++i) - ctx.restore(); - ctx.lineWidth = 0.5; - ctx.restore(); - compare(ctx.lineWidth, 0.5); - - } - function test_strokeStyle() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - - // Test that restore() undoes any modifications - var old = ctx.strokeStyle; - ctx.save(); - ctx.strokeStyle = "#ff0000"; - ctx.restore(); - compare(ctx.strokeStyle, old); - - // Also test that save() doesn't modify the values - ctx.strokeStyle = "#ff0000"; - old = ctx.strokeStyle; - // we're not interested in failures caused by get(set(x)) != x (e.g. - // from rounding), so compare against 'old' instead of against "#ff0000" - ctx.save(); - compare(ctx.strokeStyle, old); - ctx.restore(); - +CanvasTestCase { + id:testCase + name: "state" + function init_data() { return testData("2d"); } + function test_bitmap(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.save(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.restore(); + comparePixel(ctx, 50,25, 0,255,0,255); + canvas.destroy() + } + function test_clip(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.save(); + ctx.rect(0, 0, 1, 1); + ctx.clip(); + ctx.restore(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + //comparePixel(ctx, 50,25, 0,255,0,255); + canvas.destroy() + } + function test_fillStyle(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + // Test that restore() undoes any modifications + var old = ctx.fillStyle; + ctx.save(); + ctx.fillStyle = "#ff0000"; + ctx.restore(); + compare(ctx.fillStyle, old); + + // Also test that save() doesn't modify the values + ctx.fillStyle = "#ff0000"; + old = ctx.fillStyle; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "#ff0000" + ctx.save(); + compare(ctx.fillStyle, old); + ctx.restore(); + canvas.destroy() + } + function test_font(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + // Test that restore() undoes any modifications + var old = ctx.font; + ctx.save(); + ctx.font = "25px serif"; + ctx.restore(); + compare(ctx.font, old); + + // Also test that save() doesn't modify the values + ctx.font = "25px serif"; + old = ctx.font; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "25px serif" + ctx.save(); + compare(ctx.font, old); + ctx.restore(); + canvas.destroy() + } + function test_globalAlpha(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + // Test that restore() undoes any modifications + var old = ctx.globalAlpha; + ctx.save(); + ctx.globalAlpha = 0.5; + ctx.restore(); + compare(ctx.globalAlpha, old); + + // Also test that save() doesn't modify the values + ctx.globalAlpha = 0.5; + old = ctx.globalAlpha; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 0.5 + ctx.save(); + compare(ctx.globalAlpha, old); + ctx.restore(); + canvas.destroy() + } + function test_globalCompositeOperation(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + // Test that restore() undoes any modifications + var old = ctx.globalCompositeOperation; + ctx.save(); + ctx.globalCompositeOperation = "copy"; + ctx.restore(); + compare(ctx.globalCompositeOperation, old); + + // Also test that save() doesn't modify the values + ctx.globalCompositeOperation = "copy"; + old = ctx.globalCompositeOperation; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "copy" + ctx.save(); + compare(ctx.globalCompositeOperation, old); + ctx.restore(); + canvas.destroy() + } + function test_lineCap(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + // Test that restore() undoes any modifications + var old = ctx.lineCap; + ctx.save(); + ctx.lineCap = "round"; + ctx.restore(); + compare(ctx.lineCap, old); + + // Also test that save() doesn't modify the values + ctx.lineCap = "round"; + old = ctx.lineCap; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "round" + ctx.save(); + compare(ctx.lineCap, old); + ctx.restore(); + canvas.destroy() + } + function test_lineJoin(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + // Test that restore() undoes any modifications + var old = ctx.lineJoin; + ctx.save(); + ctx.lineJoin = "round"; + ctx.restore(); + compare(ctx.lineJoin, old); + + // Also test that save() doesn't modify the values + ctx.lineJoin = "round"; + old = ctx.lineJoin; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "round" + ctx.save(); + compare(ctx.lineJoin, old); + ctx.restore(); + canvas.destroy() + } + function test_lineWidth(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + // Test that restore() undoes any modifications + var old = ctx.lineJoin; + ctx.save(); + ctx.lineJoin = "round"; + ctx.restore(); + compare(ctx.lineJoin, old, "ctx.lineJoin", "old"); + + // Also test that save() doesn't modify the values + ctx.lineJoin = "round"; + old = ctx.lineJoin; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "round" + ctx.save(); + compare(ctx.lineJoin, old); + ctx.restore(); + canvas.destroy() + } + function test_miterLimit(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + // Test that restore() undoes any modifications + var old = ctx.miterLimit; + ctx.save(); + ctx.miterLimit = 0.5; + ctx.restore(); + compare(ctx.miterLimit, old); + + // Also test that save() doesn't modify the values + ctx.miterLimit = 0.5; + old = ctx.miterLimit; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 0.5 + ctx.save(); + compare(ctx.miterLimit, old); + ctx.restore(); + canvas.destroy() + } + function test_path(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.save(); + ctx.rect(0, 0, 100, 50); + ctx.restore(); + ctx.fillStyle = '#0f0'; + ctx.fill(); + comparePixel(ctx, 50,25, 0,255,0,255); + canvas.destroy() + } + function test_shadow(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + // Test that restore() undoes any modifications + var old = ctx.shadowBlur; + ctx.save(); + ctx.shadowBlur = 5; + ctx.restore(); + compare(ctx.shadowBlur, old); + + // Also test that save() doesn't modify the values + ctx.shadowBlur = 5; + old = ctx.shadowBlur; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 5 + ctx.save(); + compare(ctx.shadowBlur, old); + ctx.restore(); + + // Test that restore() undoes any modifications + var old = ctx.shadowColor; + ctx.save(); + ctx.shadowColor = "#ff0000"; + ctx.restore(); + compare(ctx.shadowColor, old); + + // Also test that save() doesn't modify the values + ctx.shadowColor = "#ff0000"; + old = ctx.shadowColor; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "#ff0000" + ctx.save(); + compare(ctx.shadowColor, old); + ctx.restore(); + + // Test that restore() undoes any modifications + var old = ctx.shadowOffsetX; + ctx.save(); + ctx.shadowOffsetX = 5; + ctx.restore(); + compare(ctx.shadowOffsetX, old); + + // Also test that save() doesn't modify the values + ctx.shadowOffsetX = 5; + old = ctx.shadowOffsetX; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 5 + ctx.save(); + compare(ctx.shadowOffsetX, old); + ctx.restore(); + + // Test that restore() undoes any modifications + var old = ctx.shadowOffsetY; + ctx.save(); + ctx.shadowOffsetY = 5; + ctx.restore(); + compare(ctx.shadowOffsetY, old); + + // Also test that save() doesn't modify the values + ctx.shadowOffsetY = 5; + old = ctx.shadowOffsetY; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against 5 + ctx.save(); + compare(ctx.shadowOffsetY, old); + ctx.restore(); + canvas.destroy() + } + function test_stack(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.lineWidth = 1; + ctx.save(); + ctx.lineWidth = 2; + ctx.save(); + ctx.lineWidth = 3; + compare(ctx.lineWidth, 3); + ctx.restore(); + compare(ctx.lineWidth, 2); + ctx.restore(); + compare(ctx.lineWidth, 1); + + var limit = 512; + for (var i = 1; i < limit; ++i) + { + ctx.save(); + ctx.lineWidth = i; } - - function test_text() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - - // Test that restore() undoes any modifications - var old = ctx.textAlign; - ctx.save(); - ctx.textAlign = "center"; - ctx.restore(); - compare(ctx.textAlign, old); - - // Also test that save() doesn't modify the values - ctx.textAlign = "center"; - old = ctx.textAlign; - // we're not interested in failures caused by get(set(x)) != x (e.g. - // from rounding), so compare against 'old' instead of against "center" - ctx.save(); - compare(ctx.textAlign, old); + for (var i = limit-1; i > 0; --i) + { + testCase.compare(ctx.lineWidth, i); //strange javascript error here ctx.restore(); - - // Test that restore() undoes any modifications - var old = ctx.textBaseline; - ctx.save(); - ctx.textBaseline = "bottom"; - ctx.restore(); - compare(ctx.textBaseline, old); - - // Also test that save() doesn't modify the values - ctx.textBaseline = "bottom"; - old = ctx.textBaseline; - // we're not interested in failures caused by get(set(x)) != x (e.g. - // from rounding), so compare against 'old' instead of against "bottom" - ctx.save(); - compare(ctx.textBaseline, old); - ctx.restore(); - - } - function test_transform() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - - ctx.fillStyle = '#0f0'; - ctx.fillRect(0, 0, 100, 50); - ctx.save(); - ctx.translate(200, 0); + for (var i = 0; i < 16; ++i) ctx.restore(); - ctx.fillStyle = '#f00'; - ctx.fillRect(-200, 0, 100, 50); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - - - } + ctx.lineWidth = 0.5; + ctx.restore(); + compare(ctx.lineWidth, 0.5); + canvas.destroy() + } + function test_strokeStyle(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + // Test that restore() undoes any modifications + var old = ctx.strokeStyle; + ctx.save(); + ctx.strokeStyle = "#ff0000"; + ctx.restore(); + compare(ctx.strokeStyle, old); + + // Also test that save() doesn't modify the values + ctx.strokeStyle = "#ff0000"; + old = ctx.strokeStyle; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "#ff0000" + ctx.save(); + compare(ctx.strokeStyle, old); + ctx.restore(); + canvas.destroy() + } + function test_text(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + // Test that restore() undoes any modifications + var old = ctx.textAlign; + ctx.save(); + ctx.textAlign = "center"; + ctx.restore(); + compare(ctx.textAlign, old); + + // Also test that save() doesn't modify the values + ctx.textAlign = "center"; + old = ctx.textAlign; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "center" + ctx.save(); + compare(ctx.textAlign, old); + ctx.restore(); + + // Test that restore() undoes any modifications + var old = ctx.textBaseline; + ctx.save(); + ctx.textBaseline = "bottom"; + ctx.restore(); + compare(ctx.textBaseline, old); + + // Also test that save() doesn't modify the values + ctx.textBaseline = "bottom"; + old = ctx.textBaseline; + // we're not interested in failures caused by get(set(x)) != x (e.g. + // from rounding), so compare against 'old' instead of against "bottom" + ctx.save(); + compare(ctx.textBaseline, old); + ctx.restore(); + canvas.destroy() + } + function test_transform(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.save(); + ctx.translate(200, 0); + ctx.restore(); + ctx.fillStyle = '#f00'; + ctx.fillRect(-200, 0, 100, 50); + comparePixel(ctx, 50,25, 0,255,0,255); + canvas.destroy() } } diff --git a/tests/auto/quick/qquickcanvasitem/data/tst_strokeStyle.qml b/tests/auto/quick/qquickcanvasitem/data/tst_strokeStyle.qml index c81ef73b90..22803a19ce 100644 --- a/tests/auto/quick/qquickcanvasitem/data/tst_strokeStyle.qml +++ b/tests/auto/quick/qquickcanvasitem/data/tst_strokeStyle.qml @@ -1,49 +1,49 @@ import QtQuick 2.0 -import QtTest 1.0 -import "testhelper.js" as Helper -Canvas { - id:canvas; width:100;height:50; renderTarget:Canvas.Image; renderStrategy:Canvas.Threaded - smooth: false - TestCase { - name: "strokeStyle"; when: windowShown - function test_default() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - compare(ctx.strokeStyle, "#000000") - ctx.clearRect(0, 0, 1, 1); - compare(ctx.strokeStyle, "#000000") - } - function test_saverestore() { - var ctx = canvas.getContext('2d'); - var old = ctx.strokeStyle; - ctx.save(); - ctx.strokeStyle = "#ffaaff"; - ctx.restore(); - compare(ctx.strokeStyle, old); - - ctx.strokeStyle = "#ffcc88"; - old = ctx.strokeStyle; - ctx.save(); - compare(ctx.strokeStyle, old); - ctx.restore(); - } - function test_namedColor() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - ctx.strokeStyle = "red"; - ctx.strokeRect(0,0,1,1); - verify(Helper.comparePixel(ctx,0,0,255,0,0,255)); - - ctx.strokeStyle = "black"; - ctx.strokeRect(0,0,1,1); - verify(Helper.comparePixel(ctx,0,0,0,0,0,255)); +CanvasTestCase { + id:testCase + name: "strokeStyle" + function init_data() { return testData("2d"); } + function test_default(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + compare(ctx.strokeStyle, "#000000") + ctx.clearRect(0, 0, 1, 1); + compare(ctx.strokeStyle, "#000000") + canvas.destroy() + } + function test_saverestore(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + var old = ctx.strokeStyle; + ctx.save(); + ctx.strokeStyle = "#ffaaff"; + ctx.restore(); + compare(ctx.strokeStyle, old); - ctx.strokeStyle = "white"; - ctx.strokeRect(0,0,1,1); - verify(Helper.comparePixel(ctx,0,0,255,255,255,255)); - } + ctx.strokeStyle = "#ffcc88"; + old = ctx.strokeStyle; + ctx.save(); + compare(ctx.strokeStyle, old); + ctx.restore(); + canvas.destroy() + } + function test_namedColor(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.strokeStyle = "red"; + ctx.strokeRect(0,0,1,1); + comparePixel(ctx,0,0,255,0,0,255); + ctx.strokeStyle = "black"; + ctx.strokeRect(0,0,1,1); + comparePixel(ctx,0,0,0,0,0,255); + ctx.strokeStyle = "white"; + ctx.strokeRect(0,0,1,1); + comparePixel(ctx,0,0,255,255,255,255); + canvas.destroy() } } diff --git a/tests/auto/quick/qquickcanvasitem/data/tst_text.qml b/tests/auto/quick/qquickcanvasitem/data/tst_text.qml index 11618e95a9..bfc4067040 100644 --- a/tests/auto/quick/qquickcanvasitem/data/tst_text.qml +++ b/tests/auto/quick/qquickcanvasitem/data/tst_text.qml @@ -1,34 +1,44 @@ import QtQuick 2.0 -import QtTest 1.0 -import "testhelper.js" as Helper -Canvas { - id:canvas; width:100;height:50; renderTarget: Canvas.Image; renderStrategy:Canvas.Threaded - TestCase { - //TODO - name: "text"; when: windowShown - function test_baseLine() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - } - function test_align() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - } - function test_stroke() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - } - function test_fill() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - } - function test_font() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - } - function test_measure() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - } - } + +CanvasTestCase { + id:testCase + name: "text" + function init_data() { return testData("2d"); } + function test_baseLine(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + canvas.destroy() + } + function test_align(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + canvas.destroy() + } + function test_stroke(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + canvas.destroy() + } + function test_fill(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + canvas.destroy() + } + function test_font(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + canvas.destroy() + } + function test_measure(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + canvas.destroy() + } + } diff --git a/tests/auto/quick/qquickcanvasitem/data/tst_transform.qml b/tests/auto/quick/qquickcanvasitem/data/tst_transform.qml index b8505c6452..b2f5b51fa5 100644 --- a/tests/auto/quick/qquickcanvasitem/data/tst_transform.qml +++ b/tests/auto/quick/qquickcanvasitem/data/tst_transform.qml @@ -1,487 +1,492 @@ import QtQuick 2.0 -import QtTest 1.0 -import "testhelper.js" as Helper -Canvas { - id:canvas; width:100;height:50; renderTarget: Canvas.Image; renderStrategy:Canvas.Threaded - TestCase { - name: "transform"; when: windowShown - function test_order() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - - ctx.scale(2, 1); - ctx.rotate(Math.PI / 2); - ctx.fillStyle = '#0f0'; - ctx.fillRect(0, -50, 50, 50); - verify(Helper.comparePixel(ctx, 75,25, 0,255,0,255)); - } - function test_rotate() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - - ctx.rotate(Math.PI / 2); - ctx.fillStyle = '#0f0'; - ctx.fillRect(0, -100, 50, 100); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - - ctx.translate(100, 10); - ctx.rotate(Infinity); - ctx.rotate(-Infinity); - ctx.rotate(NaN); - - ctx.fillStyle = '#0f0'; - ctx.fillRect(-100, -10, 100, 50); - - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - - ctx.rotate(Math.PI); // should fail obviously if this is 3.1 degrees - ctx.fillStyle = '#0f0'; - ctx.fillRect(-100, -50, 100, 50); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - - ctx.rotate(Math.PI * (1 + 4096)); // == pi (mod 2*pi) - // We need about pi +/- 0.001 in order to get correct-looking results - // 32-bit floats can store pi*4097 with precision 2^-10, so that should - // be safe enough on reasonable implementations - ctx.fillStyle = '#0f0'; - ctx.fillRect(-100, -50, 100, 50); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 98,2, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 98,47, 0,255,0,255)); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - - ctx.rotate(-Math.PI * (1 + 4096)); - ctx.fillStyle = '#0f0'; - ctx.fillRect(-100, -50, 100, 50); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 98,2, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 98,47, 0,255,0,255)); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - - ctx.rotate(0); - ctx.fillStyle = '#0f0'; - ctx.fillRect(0, 0, 100, 50); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - - - } - function test_scale() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - - ctx.scale(2, 4); - ctx.fillStyle = '#0f0'; - ctx.fillRect(0, 0, 50, 12.5); - verify(Helper.comparePixel(ctx, 90,40, 0,255,0,255)); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - - ctx.scale(1e5, 1e5); - ctx.fillStyle = '#0f0'; - ctx.fillRect(0, 0, 1, 1); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - - ctx.scale(Math.sqrt(2), Math.sqrt(2)); - ctx.scale(Math.sqrt(2), Math.sqrt(2)); - ctx.fillStyle = '#0f0'; - ctx.fillRect(0, 0, 50, 25); - verify(Helper.comparePixel(ctx, 90,40, 0,255,0,255)); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - - ctx.save(); - ctx.scale(-1, 1); - ctx.fillStyle = '#0f0'; - ctx.fillRect(-50, 0, 50, 50); - ctx.restore(); - - ctx.save(); - ctx.scale(1, -1); - ctx.fillStyle = '#0f0'; - ctx.fillRect(50, -50, 50, 50); - ctx.restore(); - verify(Helper.comparePixel(ctx, 25,25, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 75,25, 0,255,0,255)); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - - ctx.translate(100, 10); - ctx.scale(Infinity, 0.1); - ctx.scale(-Infinity, 0.1); - ctx.scale(NaN, 0.1); - ctx.scale(0.1, Infinity); - ctx.scale(0.1, -Infinity); - ctx.scale(0.1, NaN); - ctx.scale(Infinity, Infinity); - - ctx.fillStyle = '#0f0'; - ctx.fillRect(-100, -10, 100, 50); - - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - ctx.reset(); - - ctx.fillStyle = '#0f0'; - ctx.fillRect(0, 0, 100, 50); - - ctx.save(); - ctx.translate(50, 0); - ctx.scale(0, 1); - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - ctx.restore(); - - ctx.save(); - ctx.translate(0, 25); - ctx.scale(1, 0); - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - ctx.restore(); - - // Firefox has a bug where it renders the canvas as empty and toDataURL throws an exception - canvas.toDataURL(); - - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - } - function test_setTransform() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - - ctx.setTransform(1/2,0, 0,1/2, 0,0); - ctx.setTransform(2,0, 0,2, 0,0); - ctx.fillStyle = '#0f0'; - ctx.fillRect(0, 0, 50, 25); - verify(Helper.comparePixel(ctx, 75,35, 0,255,0,255)); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - - ctx.translate(100, 10); - ctx.setTransform(Infinity, 0, 0, 0, 0, 0); - ctx.setTransform(-Infinity, 0, 0, 0, 0, 0); - ctx.setTransform(NaN, 0, 0, 0, 0, 0); - ctx.setTransform(0, Infinity, 0, 0, 0, 0); - ctx.setTransform(0, -Infinity, 0, 0, 0, 0); - ctx.setTransform(0, NaN, 0, 0, 0, 0); - ctx.setTransform(0, 0, Infinity, 0, 0, 0); - ctx.setTransform(0, 0, -Infinity, 0, 0, 0); - ctx.setTransform(0, 0, NaN, 0, 0, 0); - ctx.setTransform(0, 0, 0, Infinity, 0, 0); - ctx.setTransform(0, 0, 0, -Infinity, 0, 0); - ctx.setTransform(0, 0, 0, NaN, 0, 0); - ctx.setTransform(0, 0, 0, 0, Infinity, 0); - ctx.setTransform(0, 0, 0, 0, -Infinity, 0); - ctx.setTransform(0, 0, 0, 0, NaN, 0); - ctx.setTransform(0, 0, 0, 0, 0, Infinity); - ctx.setTransform(0, 0, 0, 0, 0, -Infinity); - ctx.setTransform(0, 0, 0, 0, 0, NaN); - ctx.setTransform(Infinity, Infinity, 0, 0, 0, 0); - ctx.setTransform(Infinity, Infinity, Infinity, 0, 0, 0); - ctx.setTransform(Infinity, Infinity, Infinity, Infinity, 0, 0); - ctx.setTransform(Infinity, Infinity, Infinity, Infinity, Infinity, 0); - ctx.setTransform(Infinity, Infinity, Infinity, Infinity, Infinity, Infinity); - ctx.setTransform(Infinity, Infinity, Infinity, Infinity, 0, Infinity); - ctx.setTransform(Infinity, Infinity, Infinity, 0, Infinity, 0); - ctx.setTransform(Infinity, Infinity, Infinity, 0, Infinity, Infinity); - ctx.setTransform(Infinity, Infinity, Infinity, 0, 0, Infinity); - ctx.setTransform(Infinity, Infinity, 0, Infinity, 0, 0); - ctx.setTransform(Infinity, Infinity, 0, Infinity, Infinity, 0); - ctx.setTransform(Infinity, Infinity, 0, Infinity, Infinity, Infinity); - ctx.setTransform(Infinity, Infinity, 0, Infinity, 0, Infinity); - ctx.setTransform(Infinity, Infinity, 0, 0, Infinity, 0); - ctx.setTransform(Infinity, Infinity, 0, 0, Infinity, Infinity); - ctx.setTransform(Infinity, Infinity, 0, 0, 0, Infinity); - ctx.setTransform(Infinity, 0, Infinity, 0, 0, 0); - ctx.setTransform(Infinity, 0, Infinity, Infinity, 0, 0); - ctx.setTransform(Infinity, 0, Infinity, Infinity, Infinity, 0); - ctx.setTransform(Infinity, 0, Infinity, Infinity, Infinity, Infinity); - ctx.setTransform(Infinity, 0, Infinity, Infinity, 0, Infinity); - ctx.setTransform(Infinity, 0, Infinity, 0, Infinity, 0); - ctx.setTransform(Infinity, 0, Infinity, 0, Infinity, Infinity); - ctx.setTransform(Infinity, 0, Infinity, 0, 0, Infinity); - ctx.setTransform(Infinity, 0, 0, Infinity, 0, 0); - ctx.setTransform(Infinity, 0, 0, Infinity, Infinity, 0); - ctx.setTransform(Infinity, 0, 0, Infinity, Infinity, Infinity); - ctx.setTransform(Infinity, 0, 0, Infinity, 0, Infinity); - ctx.setTransform(Infinity, 0, 0, 0, Infinity, 0); - ctx.setTransform(Infinity, 0, 0, 0, Infinity, Infinity); - ctx.setTransform(Infinity, 0, 0, 0, 0, Infinity); - ctx.setTransform(0, Infinity, Infinity, 0, 0, 0); - ctx.setTransform(0, Infinity, Infinity, Infinity, 0, 0); - ctx.setTransform(0, Infinity, Infinity, Infinity, Infinity, 0); - ctx.setTransform(0, Infinity, Infinity, Infinity, Infinity, Infinity); - ctx.setTransform(0, Infinity, Infinity, Infinity, 0, Infinity); - ctx.setTransform(0, Infinity, Infinity, 0, Infinity, 0); - ctx.setTransform(0, Infinity, Infinity, 0, Infinity, Infinity); - ctx.setTransform(0, Infinity, Infinity, 0, 0, Infinity); - ctx.setTransform(0, Infinity, 0, Infinity, 0, 0); - ctx.setTransform(0, Infinity, 0, Infinity, Infinity, 0); - ctx.setTransform(0, Infinity, 0, Infinity, Infinity, Infinity); - ctx.setTransform(0, Infinity, 0, Infinity, 0, Infinity); - ctx.setTransform(0, Infinity, 0, 0, Infinity, 0); - ctx.setTransform(0, Infinity, 0, 0, Infinity, Infinity); - ctx.setTransform(0, Infinity, 0, 0, 0, Infinity); - ctx.setTransform(0, 0, Infinity, Infinity, 0, 0); - ctx.setTransform(0, 0, Infinity, Infinity, Infinity, 0); - ctx.setTransform(0, 0, Infinity, Infinity, Infinity, Infinity); - ctx.setTransform(0, 0, Infinity, Infinity, 0, Infinity); - ctx.setTransform(0, 0, Infinity, 0, Infinity, 0); - ctx.setTransform(0, 0, Infinity, 0, Infinity, Infinity); - ctx.setTransform(0, 0, Infinity, 0, 0, Infinity); - ctx.setTransform(0, 0, 0, Infinity, Infinity, 0); - ctx.setTransform(0, 0, 0, Infinity, Infinity, Infinity); - ctx.setTransform(0, 0, 0, Infinity, 0, Infinity); - ctx.setTransform(0, 0, 0, 0, Infinity, Infinity); - - ctx.fillStyle = '#0f0'; - ctx.fillRect(-100, -10, 100, 50); - - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - ctx.reset(); - - // Create green with a red square ring inside it - ctx.fillStyle = '#0f0'; - ctx.fillRect(0, 0, 100, 50); - ctx.fillStyle = '#f00'; - ctx.fillRect(20, 10, 60, 30); - ctx.fillStyle = '#0f0'; - ctx.fillRect(40, 20, 20, 10); - - // Draw a skewed shape to fill that gap, to make sure it is aligned correctly - ctx.setTransform(1,4, 2,3, 5,6); - // Post-transform coordinates: - // [[20,10],[80,10],[80,40],[20,40],[20,10],[40,20],[40,30],[60,30],[60,20],[40,20],[20,10]]; - // Hence pre-transform coordinates: - var pts=[[-7.4,11.2],[-43.4,59.2],[-31.4,53.2],[4.6,5.2],[-7.4,11.2], - [-15.4,25.2],[-11.4,23.2],[-23.4,39.2],[-27.4,41.2],[-15.4,25.2], - [-7.4,11.2]]; - ctx.beginPath(); - ctx.moveTo(pts[0][0], pts[0][1]); - for (var i = 0; i < pts.length; ++i) - ctx.lineTo(pts[i][0], pts[i][1]); - ctx.fill(); - /* - //FIXME: - verify(Helper.comparePixel(ctx, 21,11, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 79,11, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 21,39, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 79,39, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 39,19, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 61,19, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 39,31, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 61,31, 0,255,0,255)); - */ - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - - ctx.transform(1,0, 0,1, 0,0); - ctx.fillStyle = '#0f0'; - ctx.fillRect(0, 0, 100, 50); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - - } - function test_transform() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - - ctx.transform(1,2, 3,4, 5,6); - ctx.transform(-2,1, 3/2,-1/2, 1,-2); - ctx.fillStyle = '#0f0'; - ctx.fillRect(0, 0, 100, 50); - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - - ctx.translate(100, 10); - ctx.transform(Infinity, 0, 0, 0, 0, 0); - ctx.transform(-Infinity, 0, 0, 0, 0, 0); - ctx.transform(NaN, 0, 0, 0, 0, 0); - ctx.transform(0, Infinity, 0, 0, 0, 0); - ctx.transform(0, -Infinity, 0, 0, 0, 0); - ctx.transform(0, NaN, 0, 0, 0, 0); - ctx.transform(0, 0, Infinity, 0, 0, 0); - ctx.transform(0, 0, -Infinity, 0, 0, 0); - ctx.transform(0, 0, NaN, 0, 0, 0); - ctx.transform(0, 0, 0, Infinity, 0, 0); - ctx.transform(0, 0, 0, -Infinity, 0, 0); - ctx.transform(0, 0, 0, NaN, 0, 0); - ctx.transform(0, 0, 0, 0, Infinity, 0); - ctx.transform(0, 0, 0, 0, -Infinity, 0); - ctx.transform(0, 0, 0, 0, NaN, 0); - ctx.transform(0, 0, 0, 0, 0, Infinity); - ctx.transform(0, 0, 0, 0, 0, -Infinity); - ctx.transform(0, 0, 0, 0, 0, NaN); - ctx.transform(Infinity, Infinity, 0, 0, 0, 0); - ctx.transform(Infinity, Infinity, Infinity, 0, 0, 0); - ctx.transform(Infinity, Infinity, Infinity, Infinity, 0, 0); - ctx.transform(Infinity, Infinity, Infinity, Infinity, Infinity, 0); - ctx.transform(Infinity, Infinity, Infinity, Infinity, Infinity, Infinity); - ctx.transform(Infinity, Infinity, Infinity, Infinity, 0, Infinity); - ctx.transform(Infinity, Infinity, Infinity, 0, Infinity, 0); - ctx.transform(Infinity, Infinity, Infinity, 0, Infinity, Infinity); - ctx.transform(Infinity, Infinity, Infinity, 0, 0, Infinity); - ctx.transform(Infinity, Infinity, 0, Infinity, 0, 0); - ctx.transform(Infinity, Infinity, 0, Infinity, Infinity, 0); - ctx.transform(Infinity, Infinity, 0, Infinity, Infinity, Infinity); - ctx.transform(Infinity, Infinity, 0, Infinity, 0, Infinity); - ctx.transform(Infinity, Infinity, 0, 0, Infinity, 0); - ctx.transform(Infinity, Infinity, 0, 0, Infinity, Infinity); - ctx.transform(Infinity, Infinity, 0, 0, 0, Infinity); - ctx.transform(Infinity, 0, Infinity, 0, 0, 0); - ctx.transform(Infinity, 0, Infinity, Infinity, 0, 0); - ctx.transform(Infinity, 0, Infinity, Infinity, Infinity, 0); - ctx.transform(Infinity, 0, Infinity, Infinity, Infinity, Infinity); - ctx.transform(Infinity, 0, Infinity, Infinity, 0, Infinity); - ctx.transform(Infinity, 0, Infinity, 0, Infinity, 0); - ctx.transform(Infinity, 0, Infinity, 0, Infinity, 0); - ctx.transform(Infinity, 0, Infinity, 0, Infinity, Infinity); - ctx.transform(Infinity, 0, Infinity, 0, 0, Infinity); - ctx.transform(Infinity, 0, 0, Infinity, 0, 0); - ctx.transform(Infinity, 0, 0, Infinity, Infinity, 0); - ctx.transform(Infinity, 0, 0, Infinity, Infinity, Infinity); - ctx.transform(Infinity, 0, 0, Infinity, 0, Infinity); - ctx.transform(Infinity, 0, 0, 0, Infinity, 0); - ctx.transform(Infinity, 0, 0, 0, Infinity, Infinity); - ctx.transform(Infinity, 0, 0, 0, 0, Infinity); - ctx.transform(0, Infinity, Infinity, 0, 0, 0); - ctx.transform(0, Infinity, Infinity, Infinity, 0, 0); - ctx.transform(0, Infinity, Infinity, Infinity, Infinity, 0); - ctx.transform(0, Infinity, Infinity, Infinity, Infinity, Infinity); - ctx.transform(0, Infinity, Infinity, Infinity, 0, Infinity); - ctx.transform(0, Infinity, Infinity, 0, Infinity, 0); - ctx.transform(0, Infinity, Infinity, 0, Infinity, Infinity); - ctx.transform(0, Infinity, Infinity, 0, 0, Infinity); - ctx.transform(0, Infinity, 0, Infinity, 0, 0); - ctx.transform(0, Infinity, 0, Infinity, Infinity, 0); - ctx.transform(0, Infinity, 0, Infinity, Infinity, Infinity); - ctx.transform(0, Infinity, 0, Infinity, 0, Infinity); - ctx.transform(0, Infinity, 0, 0, Infinity, 0); - ctx.transform(0, Infinity, 0, 0, Infinity, Infinity); - ctx.transform(0, Infinity, 0, 0, 0, Infinity); - ctx.transform(0, 0, Infinity, Infinity, 0, 0); - ctx.transform(0, 0, Infinity, Infinity, Infinity, 0); - ctx.transform(0, 0, Infinity, Infinity, Infinity, Infinity); - ctx.transform(0, 0, Infinity, Infinity, 0, Infinity); - ctx.transform(0, 0, Infinity, 0, Infinity, 0); - ctx.transform(0, 0, Infinity, 0, Infinity, Infinity); - ctx.transform(0, 0, Infinity, 0, 0, Infinity); - ctx.transform(0, 0, 0, Infinity, Infinity, 0); - ctx.transform(0, 0, 0, Infinity, Infinity, Infinity); - ctx.transform(0, 0, 0, Infinity, 0, Infinity); - ctx.transform(0, 0, 0, 0, Infinity, Infinity); - - ctx.fillStyle = '#0f0'; - ctx.fillRect(-100, -10, 100, 50); - - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - ctx.reset(); - - // Create green with a red square ring inside it - ctx.fillStyle = '#0f0'; - ctx.fillRect(0, 0, 100, 50); - ctx.fillStyle = '#f00'; - ctx.fillRect(20, 10, 60, 30); - ctx.fillStyle = '#0f0'; - ctx.fillRect(40, 20, 20, 10); - - // Draw a skewed shape to fill that gap, to make sure it is aligned correctly - ctx.transform(1,4, 2,3, 5,6); - // Post-transform coordinates: - // [[20,10],[80,10],[80,40],[20,40],[20,10],[40,20],[40,30],[60,30],[60,20],[40,20],[20,10]]; - // Hence pre-transform coordinates: - var pts=[[-7.4,11.2],[-43.4,59.2],[-31.4,53.2],[4.6,5.2],[-7.4,11.2], - [-15.4,25.2],[-11.4,23.2],[-23.4,39.2],[-27.4,41.2],[-15.4,25.2], - [-7.4,11.2]]; - ctx.beginPath(); - ctx.moveTo(pts[0][0], pts[0][1]); - for (var i = 0; i < pts.length; ++i) - ctx.lineTo(pts[i][0], pts[i][1]); - ctx.fill(); - /* - //FIXME: - verify(Helper.comparePixel(ctx, 21,11, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 79,11, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 21,39, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 79,39, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 39,19, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 61,19, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 39,31, 0,255,0,255)); - verify(Helper.comparePixel(ctx, 61,31, 0,255,0,255)); - */ - } - function test_translate() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - - ctx.translate(100, 50); - ctx.fillStyle = '#0f0'; - ctx.fillRect(-100, -50, 100, 50); - verify(Helper.comparePixel(ctx, 90,40, 0,255,0,255)); - ctx.reset(); - - ctx.fillStyle = '#f00'; - ctx.fillRect(0, 0, 100, 50); - - ctx.translate(100, 10); - ctx.translate(Infinity, 0.1); - ctx.translate(-Infinity, 0.1); - ctx.translate(NaN, 0.1); - ctx.translate(0.1, Infinity); - ctx.translate(0.1, -Infinity); - ctx.translate(0.1, NaN); - ctx.translate(Infinity, Infinity); - - ctx.fillStyle = '#0f0'; - ctx.fillRect(-100, -10, 100, 50); - - verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); - - - } + +CanvasTestCase { + id:testCase + name: "transform" + function init_data() { return testData("2d"); } + function test_order(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.scale(2, 1); + ctx.rotate(Math.PI / 2); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, -50, 50, 50); + comparePixel(ctx, 75,25, 0,255,0,255); + canvas.destroy() + } + function test_rotate(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.rotate(Math.PI / 2); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, -100, 50, 100); + comparePixel(ctx, 50,25, 0,255,0,255); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.translate(100, 10); + ctx.rotate(Infinity); + ctx.rotate(-Infinity); + ctx.rotate(NaN); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(-100, -10, 100, 50); + + comparePixel(ctx, 50,25, 0,255,0,255); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.rotate(Math.PI); // should fail obviously if this is 3.1 degrees + ctx.fillStyle = '#0f0'; + ctx.fillRect(-100, -50, 100, 50); + comparePixel(ctx, 50,25, 0,255,0,255); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.rotate(Math.PI * (1 + 4096)); // == pi (mod 2*pi) + // We need about pi +/- 0.001 in order to get correct-looking results + // 32-bit floats can store pi*4097 with precision 2^-10, so that should + // be safe enough on reasonable implementations + ctx.fillStyle = '#0f0'; + ctx.fillRect(-100, -50, 100, 50); + comparePixel(ctx, 50,25, 0,255,0,255); + comparePixel(ctx, 98,2, 0,255,0,255); + comparePixel(ctx, 98,47, 0,255,0,255); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.rotate(-Math.PI * (1 + 4096)); + ctx.fillStyle = '#0f0'; + ctx.fillRect(-100, -50, 100, 50); + comparePixel(ctx, 50,25, 0,255,0,255); + comparePixel(ctx, 98,2, 0,255,0,255); + comparePixel(ctx, 98,47, 0,255,0,255); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.rotate(0); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + comparePixel(ctx, 50,25, 0,255,0,255); + canvas.destroy() + } + function test_scale(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.scale(2, 4); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 50, 12.5); + comparePixel(ctx, 90,40, 0,255,0,255); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.scale(1e5, 1e5); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 1, 1); + comparePixel(ctx, 50,25, 0,255,0,255); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.scale(Math.sqrt(2), Math.sqrt(2)); + ctx.scale(Math.sqrt(2), Math.sqrt(2)); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 50, 25); + comparePixel(ctx, 90,40, 0,255,0,255); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.save(); + ctx.scale(-1, 1); + ctx.fillStyle = '#0f0'; + ctx.fillRect(-50, 0, 50, 50); + ctx.restore(); + + ctx.save(); + ctx.scale(1, -1); + ctx.fillStyle = '#0f0'; + ctx.fillRect(50, -50, 50, 50); + ctx.restore(); + comparePixel(ctx, 25,25, 0,255,0,255); + comparePixel(ctx, 75,25, 0,255,0,255); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.translate(100, 10); + ctx.scale(Infinity, 0.1); + ctx.scale(-Infinity, 0.1); + ctx.scale(NaN, 0.1); + ctx.scale(0.1, Infinity); + ctx.scale(0.1, -Infinity); + ctx.scale(0.1, NaN); + ctx.scale(Infinity, Infinity); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(-100, -10, 100, 50); + + comparePixel(ctx, 50,25, 0,255,0,255); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.save(); + ctx.translate(50, 0); + ctx.scale(0, 1); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.restore(); + + ctx.save(); + ctx.translate(0, 25); + ctx.scale(1, 0); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.restore(); + + // Firefox has a bug where it renders the canvas as empty and toDataURL throws an exception + canvas.toDataURL(); + + comparePixel(ctx, 50,25, 0,255,0,255); + canvas.destroy() } + function test_setTransform(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.setTransform(1/2,0, 0,1/2, 0,0); + ctx.setTransform(2,0, 0,2, 0,0); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 50, 25); + comparePixel(ctx, 75,35, 0,255,0,255); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.translate(100, 10); + ctx.setTransform(Infinity, 0, 0, 0, 0, 0); + ctx.setTransform(-Infinity, 0, 0, 0, 0, 0); + ctx.setTransform(NaN, 0, 0, 0, 0, 0); + ctx.setTransform(0, Infinity, 0, 0, 0, 0); + ctx.setTransform(0, -Infinity, 0, 0, 0, 0); + ctx.setTransform(0, NaN, 0, 0, 0, 0); + ctx.setTransform(0, 0, Infinity, 0, 0, 0); + ctx.setTransform(0, 0, -Infinity, 0, 0, 0); + ctx.setTransform(0, 0, NaN, 0, 0, 0); + ctx.setTransform(0, 0, 0, Infinity, 0, 0); + ctx.setTransform(0, 0, 0, -Infinity, 0, 0); + ctx.setTransform(0, 0, 0, NaN, 0, 0); + ctx.setTransform(0, 0, 0, 0, Infinity, 0); + ctx.setTransform(0, 0, 0, 0, -Infinity, 0); + ctx.setTransform(0, 0, 0, 0, NaN, 0); + ctx.setTransform(0, 0, 0, 0, 0, Infinity); + ctx.setTransform(0, 0, 0, 0, 0, -Infinity); + ctx.setTransform(0, 0, 0, 0, 0, NaN); + ctx.setTransform(Infinity, Infinity, 0, 0, 0, 0); + ctx.setTransform(Infinity, Infinity, Infinity, 0, 0, 0); + ctx.setTransform(Infinity, Infinity, Infinity, Infinity, 0, 0); + ctx.setTransform(Infinity, Infinity, Infinity, Infinity, Infinity, 0); + ctx.setTransform(Infinity, Infinity, Infinity, Infinity, Infinity, Infinity); + ctx.setTransform(Infinity, Infinity, Infinity, Infinity, 0, Infinity); + ctx.setTransform(Infinity, Infinity, Infinity, 0, Infinity, 0); + ctx.setTransform(Infinity, Infinity, Infinity, 0, Infinity, Infinity); + ctx.setTransform(Infinity, Infinity, Infinity, 0, 0, Infinity); + ctx.setTransform(Infinity, Infinity, 0, Infinity, 0, 0); + ctx.setTransform(Infinity, Infinity, 0, Infinity, Infinity, 0); + ctx.setTransform(Infinity, Infinity, 0, Infinity, Infinity, Infinity); + ctx.setTransform(Infinity, Infinity, 0, Infinity, 0, Infinity); + ctx.setTransform(Infinity, Infinity, 0, 0, Infinity, 0); + ctx.setTransform(Infinity, Infinity, 0, 0, Infinity, Infinity); + ctx.setTransform(Infinity, Infinity, 0, 0, 0, Infinity); + ctx.setTransform(Infinity, 0, Infinity, 0, 0, 0); + ctx.setTransform(Infinity, 0, Infinity, Infinity, 0, 0); + ctx.setTransform(Infinity, 0, Infinity, Infinity, Infinity, 0); + ctx.setTransform(Infinity, 0, Infinity, Infinity, Infinity, Infinity); + ctx.setTransform(Infinity, 0, Infinity, Infinity, 0, Infinity); + ctx.setTransform(Infinity, 0, Infinity, 0, Infinity, 0); + ctx.setTransform(Infinity, 0, Infinity, 0, Infinity, Infinity); + ctx.setTransform(Infinity, 0, Infinity, 0, 0, Infinity); + ctx.setTransform(Infinity, 0, 0, Infinity, 0, 0); + ctx.setTransform(Infinity, 0, 0, Infinity, Infinity, 0); + ctx.setTransform(Infinity, 0, 0, Infinity, Infinity, Infinity); + ctx.setTransform(Infinity, 0, 0, Infinity, 0, Infinity); + ctx.setTransform(Infinity, 0, 0, 0, Infinity, 0); + ctx.setTransform(Infinity, 0, 0, 0, Infinity, Infinity); + ctx.setTransform(Infinity, 0, 0, 0, 0, Infinity); + ctx.setTransform(0, Infinity, Infinity, 0, 0, 0); + ctx.setTransform(0, Infinity, Infinity, Infinity, 0, 0); + ctx.setTransform(0, Infinity, Infinity, Infinity, Infinity, 0); + ctx.setTransform(0, Infinity, Infinity, Infinity, Infinity, Infinity); + ctx.setTransform(0, Infinity, Infinity, Infinity, 0, Infinity); + ctx.setTransform(0, Infinity, Infinity, 0, Infinity, 0); + ctx.setTransform(0, Infinity, Infinity, 0, Infinity, Infinity); + ctx.setTransform(0, Infinity, Infinity, 0, 0, Infinity); + ctx.setTransform(0, Infinity, 0, Infinity, 0, 0); + ctx.setTransform(0, Infinity, 0, Infinity, Infinity, 0); + ctx.setTransform(0, Infinity, 0, Infinity, Infinity, Infinity); + ctx.setTransform(0, Infinity, 0, Infinity, 0, Infinity); + ctx.setTransform(0, Infinity, 0, 0, Infinity, 0); + ctx.setTransform(0, Infinity, 0, 0, Infinity, Infinity); + ctx.setTransform(0, Infinity, 0, 0, 0, Infinity); + ctx.setTransform(0, 0, Infinity, Infinity, 0, 0); + ctx.setTransform(0, 0, Infinity, Infinity, Infinity, 0); + ctx.setTransform(0, 0, Infinity, Infinity, Infinity, Infinity); + ctx.setTransform(0, 0, Infinity, Infinity, 0, Infinity); + ctx.setTransform(0, 0, Infinity, 0, Infinity, 0); + ctx.setTransform(0, 0, Infinity, 0, Infinity, Infinity); + ctx.setTransform(0, 0, Infinity, 0, 0, Infinity); + ctx.setTransform(0, 0, 0, Infinity, Infinity, 0); + ctx.setTransform(0, 0, 0, Infinity, Infinity, Infinity); + ctx.setTransform(0, 0, 0, Infinity, 0, Infinity); + ctx.setTransform(0, 0, 0, 0, Infinity, Infinity); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(-100, -10, 100, 50); + + comparePixel(ctx, 50,25, 0,255,0,255); + ctx.reset(); + + // Create green with a red square ring inside it + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.fillStyle = '#f00'; + ctx.fillRect(20, 10, 60, 30); + ctx.fillStyle = '#0f0'; + ctx.fillRect(40, 20, 20, 10); + + // Draw a skewed shape to fill that gap, to make sure it is aligned correctly + ctx.setTransform(1,4, 2,3, 5,6); + // Post-transform coordinates: + // [[20,10],[80,10],[80,40],[20,40],[20,10],[40,20],[40,30],[60,30],[60,20],[40,20],[20,10]]; + // Hence pre-transform coordinates: + var pts=[[-7.4,11.2],[-43.4,59.2],[-31.4,53.2],[4.6,5.2],[-7.4,11.2], + [-15.4,25.2],[-11.4,23.2],[-23.4,39.2],[-27.4,41.2],[-15.4,25.2], + [-7.4,11.2]]; + ctx.beginPath(); + ctx.moveTo(pts[0][0], pts[0][1]); + for (var i = 0; i < pts.length; ++i) + ctx.lineTo(pts[i][0], pts[i][1]); + ctx.fill(); + /* + //FIXME: + comparePixel(ctx, 21,11, 0,255,0,255); + comparePixel(ctx, 79,11, 0,255,0,255); + comparePixel(ctx, 21,39, 0,255,0,255); + comparePixel(ctx, 79,39, 0,255,0,255); + comparePixel(ctx, 39,19, 0,255,0,255); + comparePixel(ctx, 61,19, 0,255,0,255); + comparePixel(ctx, 39,31, 0,255,0,255); + comparePixel(ctx, 61,31, 0,255,0,255); + */ + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.transform(1,0, 0,1, 0,0); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + comparePixel(ctx, 50,25, 0,255,0,255); + canvas.destroy() + } + function test_transform(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.transform(1,2, 3,4, 5,6); + ctx.transform(-2,1, 3/2,-1/2, 1,-2); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + comparePixel(ctx, 50,25, 0,255,0,255); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.translate(100, 10); + ctx.transform(Infinity, 0, 0, 0, 0, 0); + ctx.transform(-Infinity, 0, 0, 0, 0, 0); + ctx.transform(NaN, 0, 0, 0, 0, 0); + ctx.transform(0, Infinity, 0, 0, 0, 0); + ctx.transform(0, -Infinity, 0, 0, 0, 0); + ctx.transform(0, NaN, 0, 0, 0, 0); + ctx.transform(0, 0, Infinity, 0, 0, 0); + ctx.transform(0, 0, -Infinity, 0, 0, 0); + ctx.transform(0, 0, NaN, 0, 0, 0); + ctx.transform(0, 0, 0, Infinity, 0, 0); + ctx.transform(0, 0, 0, -Infinity, 0, 0); + ctx.transform(0, 0, 0, NaN, 0, 0); + ctx.transform(0, 0, 0, 0, Infinity, 0); + ctx.transform(0, 0, 0, 0, -Infinity, 0); + ctx.transform(0, 0, 0, 0, NaN, 0); + ctx.transform(0, 0, 0, 0, 0, Infinity); + ctx.transform(0, 0, 0, 0, 0, -Infinity); + ctx.transform(0, 0, 0, 0, 0, NaN); + ctx.transform(Infinity, Infinity, 0, 0, 0, 0); + ctx.transform(Infinity, Infinity, Infinity, 0, 0, 0); + ctx.transform(Infinity, Infinity, Infinity, Infinity, 0, 0); + ctx.transform(Infinity, Infinity, Infinity, Infinity, Infinity, 0); + ctx.transform(Infinity, Infinity, Infinity, Infinity, Infinity, Infinity); + ctx.transform(Infinity, Infinity, Infinity, Infinity, 0, Infinity); + ctx.transform(Infinity, Infinity, Infinity, 0, Infinity, 0); + ctx.transform(Infinity, Infinity, Infinity, 0, Infinity, Infinity); + ctx.transform(Infinity, Infinity, Infinity, 0, 0, Infinity); + ctx.transform(Infinity, Infinity, 0, Infinity, 0, 0); + ctx.transform(Infinity, Infinity, 0, Infinity, Infinity, 0); + ctx.transform(Infinity, Infinity, 0, Infinity, Infinity, Infinity); + ctx.transform(Infinity, Infinity, 0, Infinity, 0, Infinity); + ctx.transform(Infinity, Infinity, 0, 0, Infinity, 0); + ctx.transform(Infinity, Infinity, 0, 0, Infinity, Infinity); + ctx.transform(Infinity, Infinity, 0, 0, 0, Infinity); + ctx.transform(Infinity, 0, Infinity, 0, 0, 0); + ctx.transform(Infinity, 0, Infinity, Infinity, 0, 0); + ctx.transform(Infinity, 0, Infinity, Infinity, Infinity, 0); + ctx.transform(Infinity, 0, Infinity, Infinity, Infinity, Infinity); + ctx.transform(Infinity, 0, Infinity, Infinity, 0, Infinity); + ctx.transform(Infinity, 0, Infinity, 0, Infinity, 0); + ctx.transform(Infinity, 0, Infinity, 0, Infinity, 0); + ctx.transform(Infinity, 0, Infinity, 0, Infinity, Infinity); + ctx.transform(Infinity, 0, Infinity, 0, 0, Infinity); + ctx.transform(Infinity, 0, 0, Infinity, 0, 0); + ctx.transform(Infinity, 0, 0, Infinity, Infinity, 0); + ctx.transform(Infinity, 0, 0, Infinity, Infinity, Infinity); + ctx.transform(Infinity, 0, 0, Infinity, 0, Infinity); + ctx.transform(Infinity, 0, 0, 0, Infinity, 0); + ctx.transform(Infinity, 0, 0, 0, Infinity, Infinity); + ctx.transform(Infinity, 0, 0, 0, 0, Infinity); + ctx.transform(0, Infinity, Infinity, 0, 0, 0); + ctx.transform(0, Infinity, Infinity, Infinity, 0, 0); + ctx.transform(0, Infinity, Infinity, Infinity, Infinity, 0); + ctx.transform(0, Infinity, Infinity, Infinity, Infinity, Infinity); + ctx.transform(0, Infinity, Infinity, Infinity, 0, Infinity); + ctx.transform(0, Infinity, Infinity, 0, Infinity, 0); + ctx.transform(0, Infinity, Infinity, 0, Infinity, Infinity); + ctx.transform(0, Infinity, Infinity, 0, 0, Infinity); + ctx.transform(0, Infinity, 0, Infinity, 0, 0); + ctx.transform(0, Infinity, 0, Infinity, Infinity, 0); + ctx.transform(0, Infinity, 0, Infinity, Infinity, Infinity); + ctx.transform(0, Infinity, 0, Infinity, 0, Infinity); + ctx.transform(0, Infinity, 0, 0, Infinity, 0); + ctx.transform(0, Infinity, 0, 0, Infinity, Infinity); + ctx.transform(0, Infinity, 0, 0, 0, Infinity); + ctx.transform(0, 0, Infinity, Infinity, 0, 0); + ctx.transform(0, 0, Infinity, Infinity, Infinity, 0); + ctx.transform(0, 0, Infinity, Infinity, Infinity, Infinity); + ctx.transform(0, 0, Infinity, Infinity, 0, Infinity); + ctx.transform(0, 0, Infinity, 0, Infinity, 0); + ctx.transform(0, 0, Infinity, 0, Infinity, Infinity); + ctx.transform(0, 0, Infinity, 0, 0, Infinity); + ctx.transform(0, 0, 0, Infinity, Infinity, 0); + ctx.transform(0, 0, 0, Infinity, Infinity, Infinity); + ctx.transform(0, 0, 0, Infinity, 0, Infinity); + ctx.transform(0, 0, 0, 0, Infinity, Infinity); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(-100, -10, 100, 50); + + comparePixel(ctx, 50,25, 0,255,0,255); + ctx.reset(); + + // Create green with a red square ring inside it + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.fillStyle = '#f00'; + ctx.fillRect(20, 10, 60, 30); + ctx.fillStyle = '#0f0'; + ctx.fillRect(40, 20, 20, 10); + + // Draw a skewed shape to fill that gap, to make sure it is aligned correctly + ctx.transform(1,4, 2,3, 5,6); + // Post-transform coordinates: + // [[20,10],[80,10],[80,40],[20,40],[20,10],[40,20],[40,30],[60,30],[60,20],[40,20],[20,10]]; + // Hence pre-transform coordinates: + var pts=[[-7.4,11.2],[-43.4,59.2],[-31.4,53.2],[4.6,5.2],[-7.4,11.2], + [-15.4,25.2],[-11.4,23.2],[-23.4,39.2],[-27.4,41.2],[-15.4,25.2], + [-7.4,11.2]]; + ctx.beginPath(); + ctx.moveTo(pts[0][0], pts[0][1]); + for (var i = 0; i < pts.length; ++i) + ctx.lineTo(pts[i][0], pts[i][1]); + ctx.fill(); + /* + //FIXME: + comparePixel(ctx, 21,11, 0,255,0,255); + comparePixel(ctx, 79,11, 0,255,0,255); + comparePixel(ctx, 21,39, 0,255,0,255); + comparePixel(ctx, 79,39, 0,255,0,255); + comparePixel(ctx, 39,19, 0,255,0,255); + comparePixel(ctx, 61,19, 0,255,0,255); + comparePixel(ctx, 39,31, 0,255,0,255); + comparePixel(ctx, 61,31, 0,255,0,255); + */ + canvas.destroy() + } + function test_translate(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.translate(100, 50); + ctx.fillStyle = '#0f0'; + ctx.fillRect(-100, -50, 100, 50); + comparePixel(ctx, 90,40, 0,255,0,255); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.translate(100, 10); + ctx.translate(Infinity, 0.1); + ctx.translate(-Infinity, 0.1); + ctx.translate(NaN, 0.1); + ctx.translate(0.1, Infinity); + ctx.translate(0.1, -Infinity); + ctx.translate(0.1, NaN); + ctx.translate(Infinity, Infinity); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(-100, -10, 100, 50); + + comparePixel(ctx, 50,25, 0,255,0,255); + canvas.destroy() + } } -- cgit v1.2.3