4aae317a7adaaf2298c240e394c906b9689a6840
[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              //TODO: Enable the followings later
18              //{ tag:"image cooperative", properties:{width:100, height:100, renderTarget:Canvas.Image, renderStrategy:Canvas.Cooperative}},
19              //{ tag:"image immediate", properties:{width:100, height:100, renderTarget:Canvas.Image, renderStrategy:Canvas.Immediate}},
20              //{ tag:"fbo cooperative", properties:{width:100, height:100, renderTarget:Canvas.FramebufferObject, renderStrategy:Canvas.Cooperative}},
21              //{ tag:"fbo immediate", properties:{width:100, height:100, renderTarget:Canvas.FramebufferObject, renderStrategy:Canvas.Immediate}},
22              //{ tag:"fbo threaded", properties:{width:100, height:100, renderTarget:Canvas.FramebufferObject, renderStrategy:Canvas.Threaded}}
23            ];
24      return [];
25   }
26
27   function createCanvasObject(data) {
28     return component.createObject(testCase, data.properties);
29   }
30
31   function comparePixel(ctx,x,y,r,g,b,a, d)
32   {
33     var c = ctx.getImageData(x,y,1,1).data;
34     if (d === undefined)
35       d = 0;
36     r = Math.round(r);
37     g = Math.round(g);
38     b = Math.round(b);
39     a = Math.round(a);
40
41     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;
42     if (notSame)
43       qtest_fail('Pixel compare fail:\nactual  :[' + c[0]+','+c[1]+','+c[2]+','+c[3] + ']\nexpected:['+r+','+g+','+b+','+a+'] +/- '+d, 1);
44   }
45
46 }