Refactor context2d thread logic
[profile/ivi/qtdeclarative.git] / tests / auto / quick / qquickcanvasitem / data / CanvasTestCase.qml
1 import QtQuick 2.0
2 import QtTest 1.0
3
4 TestCase {
5   id:testCase
6   when:windowShown
7   width:100
8   height:100
9   property Component component:CanvasComponent{}
10   function cleanupTestCase() {
11     wait(100) //wait for a short while to make sure no leaked textures
12   }
13   function testData(type) {
14     if (type === "2d")
15       return [
16              { tag:"image threaded", properties:{width:100, height:100, renderTarget:Canvas.Image, renderStrategy:Canvas.Threaded}},
17 //             { tag:"image cooperative", properties:{width:100, height:100, renderTarget:Canvas.Image, renderStrategy:Canvas.Cooperative}},
18              { tag:"image immediate", properties:{width:100, height:100, renderTarget:Canvas.Image, renderStrategy:Canvas.Immediate}},
19 //             { tag:"fbo cooperative", properties:{width:100, height:100, renderTarget:Canvas.FramebufferObject, renderStrategy:Canvas.Cooperative}},
20 //             { tag:"fbo immediate", properties:{width:100, height:100, renderTarget:Canvas.FramebufferObject, renderStrategy:Canvas.Immediate}},
21 //             { tag:"fbo threaded", properties:{width:100, height:100, renderTarget:Canvas.FramebufferObject, renderStrategy:Canvas.Threaded}}
22            ];
23      return [];
24   }
25
26   function createCanvasObject(data) {
27     return component.createObject(testCase, data.properties);
28   }
29
30   function comparePixel(ctx,x,y,r,g,b,a, d)
31   {
32     var c = ctx.getImageData(x,y,1,1).data;
33     if (d === undefined)
34       d = 0;
35     r = Math.round(r);
36     g = Math.round(g);
37     b = Math.round(b);
38     a = Math.round(a);
39
40     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;
41     if (notSame)
42       qtest_fail('Pixel compare fail:\nactual  :[' + c[0]+','+c[1]+','+c[2]+','+c[3] + ']\nexpected:['+r+','+g+','+b+','+a+'] +/- '+d, 1);
43   }
44
45 }