Fix test fails related to QTBUG-22237
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / qquickcanvasitem / data / tst_fillStyle.qml
1 import QtQuick 2.0
2 import QtTest 1.0
3 import "testhelper.js" as Helper
4
5 Canvas {
6    id:canvas; width:1;height:1;renderTarget:Canvas.Image
7    TestCase {
8        name: "fillStyle"; when: windowShown
9        function test_default() {
10            var ctx = canvas.getContext('2d');
11            ctx.reset();
12            verify(ctx.fillStyle, "#000000");
13            ctx.clearRect(0, 0, 1, 1);
14            compare(ctx.fillStyle, "#000000");
15        }
16        function test_get() {
17            var ctx = canvas.getContext('2d');
18            ctx.reset();
19            ctx.fillStyle = '#fa0';
20            compare(ctx.fillStyle, '#ffaa00');
21            ctx.fillStyle = Qt.rgba(0,0,0,0);
22            compare(ctx.fillStyle, 'rgba(0, 0, 0, 0.0)');
23        }
24        function test_hex() {
25            var ctx = canvas.getContext('2d');
26            ctx.reset();
27            ctx.fillStyle = '#f00';
28            compare(ctx.fillStyle, '#ff0000');
29            ctx.fillStyle = "#0f0";
30            compare(ctx.fillStyle, '#00ff00');
31            ctx.fillStyle = "#0fF";
32            compare(ctx.fillStyle, '#00ffff');
33            ctx.fillStyle = "#0aCCfb";
34            compare(ctx.fillStyle, '#0accfb');
35
36        }
37        function test_invalid() {
38            var ctx = canvas.getContext('2d');
39            ctx.reset();
40            ctx.fillStyle = '#fa0';
41            compare(ctx.fillStyle, '#ffaa00');
42            ctx.fillStyle = "invalid";
43            compare(ctx.fillStyle, '#ffaa00');
44            ctx.fillStyle = "rgb (1, 2, 3)";
45            compare(ctx.fillStyle, '#ffaa00');
46            ctx.fillStyle = '#fa0';
47
48            ctx.fillStyle = "rgba(3, 1, 2)";
49            compare(ctx.fillStyle, '#ffaa00');
50            ctx.fillStyle = "rgb((3,4,1)";
51            compare(ctx.fillStyle, '#ffaa00');
52            ctx.fillStyle = "rgb(1, 3, 4, 0.5)";
53            compare(ctx.fillStyle, '#ffaa00');
54            ctx.fillStyle = "hsl(2, 3, 4, 0.8)";
55            compare(ctx.fillStyle, '#ffaa00');
56            ctx.fillStyle = "hsl(2, 3, 4";
57            compare(ctx.fillStyle, '#ffaa00');
58        }
59        function test_saverestore() {
60            var ctx = canvas.getContext('2d');
61            var old = ctx.fillStyle;
62            ctx.save();
63            ctx.fillStyle = "#ffaaff";
64            ctx.restore();
65            compare(ctx.fillStyle, old);
66
67            ctx.fillStyle = "#ffcc88";
68            old = ctx.fillStyle;
69            ctx.save();
70            compare(ctx.fillStyle, old);
71            ctx.restore();
72        }
73        function test_namedColor() {
74            var ctx = canvas.getContext('2d');
75            ctx.reset();
76            ctx.fillStyle = "red";
77            ctx.fillRect(0,0,1,1);
78            verify(Helper.comparePixel(ctx,0,0,255,0,0,255));
79
80            ctx.fillStyle = "black";
81            ctx.fillRect(0,0,1,1);
82            verify(Helper.comparePixel(ctx,0,0,0,0,0,255));
83
84            ctx.fillStyle = "white";
85            ctx.fillRect(0,0,1,1);
86            verify(Helper.comparePixel(ctx,0,0,255,255,255,255));
87        }
88        function test_rgba() {
89            var ctx = canvas.getContext('2d');
90            ctx.reset();
91            ctx.fillStyle = "rgb(-100, 300, 255)";
92            compare(ctx.fillStyle, "#00ffff");
93            ctx.fillStyle = "rgba(-100, 300, 255, 0.0)";
94            compare(ctx.fillStyle, "rgba(0, 255, 255, 0.0)");
95            ctx.fillStyle = "rgb(-10%, 110%, 50%)";
96            compare(ctx.fillStyle, "#00ff80");
97
98            ctx.clearRect(0, 0, 1, 1);
99            ctx.fillStyle = 'rgba(0%, 100%, 0%, 0.499)';
100            ctx.fillRect(0, 0, 1, 1);
101            verify(Helper.comparePixel(ctx, 0,0, 0,255,0,127));
102        }
103
104        function test_hsla() {
105            var ctx = canvas.getContext('2d');
106            ctx.reset();
107            ctx.fillStyle = "hsla(120, 100%, 50%, 0.499)";
108            ctx.fillRect(0, 0, 1, 1);
109            verify(Helper.comparePixel(ctx,0,0,0,255,0,127));
110        }
111
112    }
113 }