aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qquickcanvasitem/data/tst_fillStyle.qml
blob: 8f5a78cec0b5a4c1b8eb05db9165cf43c1984735 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import QtQuick 2.0
import QtTest 1.0
import "testhelper.js" as Helper

Canvas {
   id:canvas; width:1;height:1;renderTarget:Canvas.Image
   TestCase {
       name: "fillStyle"; when: windowShown
       function test_default() {
           var ctx = canvas.getContext('2d');
           ctx.reset();
           verify(ctx.fillStyle, "#000000");
           ctx.clearRect(0, 0, 1, 1);
           compare(ctx.fillStyle, "#000000");
       }
       function test_get() {
           var ctx = canvas.getContext('2d');
           ctx.reset();
           ctx.fillStyle = '#fa0';
           compare(ctx.fillStyle, '#ffaa00');
           ctx.fillStyle = Qt.rgba(0,0,0,0);
           compare(ctx.fillStyle, 'rgba(0, 0, 0, 0.0)');
       }
       function test_hex() {
           var ctx = canvas.getContext('2d');
           ctx.reset();
           ctx.fillStyle = '#f00';
           compare(ctx.fillStyle, '#ff0000');
           ctx.fillStyle = "#0f0";
           compare(ctx.fillStyle, '#00ff00');
           ctx.fillStyle = "#0fF";
           compare(ctx.fillStyle, '#00ffff');
           ctx.fillStyle = "#0aCCfb";
           compare(ctx.fillStyle, '#0accfb');

       }
       function test_invalid() {
           var ctx = canvas.getContext('2d');
           ctx.reset();
           ctx.fillStyle = '#fa0';
           compare(ctx.fillStyle, '#ffaa00');
           ctx.fillStyle = "invalid";
           compare(ctx.fillStyle, '#ffaa00');
           ctx.fillStyle = "rgb (1, 2, 3)";
           compare(ctx.fillStyle, '#ffaa00');
           ctx.fillStyle = '#fa0';

           ctx.fillStyle = "rgba(3, 1, 2)";
           compare(ctx.fillStyle, '#ffaa00');
           ctx.fillStyle = "rgb((3,4,1)";
           compare(ctx.fillStyle, '#ffaa00');
           ctx.fillStyle = "rgb(1, 3, 4, 0.5)";
           compare(ctx.fillStyle, '#ffaa00');
           ctx.fillStyle = "hsl(2, 3, 4, 0.8)";
           compare(ctx.fillStyle, '#ffaa00');
           ctx.fillStyle = "hsl(2, 3, 4";
           compare(ctx.fillStyle, '#ffaa00');
       }
       function test_saverestore() {
           var ctx = canvas.getContext('2d');
           var old = ctx.fillStyle;
           ctx.save();
           ctx.fillStyle = "#ffaaff";
           ctx.restore();
           compare(ctx.fillStyle, old);

           ctx.fillStyle = "#ffcc88";
           old = ctx.fillStyle;
           ctx.save();
           compare(ctx.fillStyle, old);
           ctx.restore();
       }
       function test_namedColor() {
           var ctx = canvas.getContext('2d');
           ctx.reset();
           ctx.fillStyle = "red";
           ctx.fillRect(0,0,1,1);
           verify(Helper.comparePixel(ctx,0,0,255,0,0,255));

           ctx.fillStyle = "black";
           ctx.fillRect(0,0,1,1);
           verify(Helper.comparePixel(ctx,0,0,0,0,0,255));

           ctx.fillStyle = "white";
           ctx.fillRect(0,0,1,1);
           verify(Helper.comparePixel(ctx,0,0,255,255,255,255));
       }
       function test_rgba() {
           var ctx = canvas.getContext('2d');
           ctx.reset();
           ctx.fillStyle = "rgb(-100, 300, 255)";
           compare(ctx.fillStyle, "#00ffff");
           ctx.fillStyle = "rgba(-100, 300, 255, 0.0)";
           compare(ctx.fillStyle, "rgba(0, 255, 255, 0.0)");
           ctx.fillStyle = "rgb(-10%, 110%, 50%)";
           compare(ctx.fillStyle, "#00ff80");

           ctx.clearRect(0, 0, 1, 1);
           ctx.fillStyle = 'rgba(0%, 100%, 0%, 0.499)';
           ctx.fillRect(0, 0, 1, 1);
           verify(Helper.comparePixel(ctx, 0,0, 0,255,0,127));
       }

       function test_hsla() {
           var ctx = canvas.getContext('2d');
           ctx.reset();
           ctx.fillStyle = "hsla(120, 100%, 50%, 0.499)";
           ctx.fillRect(0, 0, 1, 1);
           verify(Helper.comparePixel(ctx,0,0,0,255,0,127));
       }

   }
}