aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickcanvasitem/data/tst_fillStyle.qml
blob: 58ea6d7f591d9efe7946cc030e80bfa4a1799ba3 (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
114
115
116
117
import QtQuick 2.0

CanvasTestCase {
   id:testCase
   name: "fillStyle"
   function init_data() { return testData("2d"); }
   function test_default(row) {
       var canvas = createCanvasObject(row);
       var ctx = canvas.getContext('2d');
       ctx.reset();
       verify(ctx.fillStyle, "#000000");
       ctx.clearRect(0, 0, 1, 1);
       compare(ctx.fillStyle, "#000000");
   }
   function test_get(row) {
       var canvas = createCanvasObject(row);
       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(row) {
       var canvas = createCanvasObject(row);
       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(row) {
       var canvas = createCanvasObject(row);
       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(row) {
       var canvas = createCanvasObject(row);
       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(row) {
       var canvas = createCanvasObject(row);
       var ctx = canvas.getContext('2d');
       ctx.reset();
       ctx.fillStyle = "red";
       ctx.fillRect(0,0,1,1);
       comparePixel(ctx,0,0,255,0,0,255);

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

       ctx.fillStyle = "white";
       ctx.fillRect(0,0,1,1);
       comparePixel(ctx,0,0,255,255,255,255);
   }
   function test_rgba(row) {
       var canvas = createCanvasObject(row);
       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);
       comparePixel(ctx, 0,0, 0,255,0,127);
   }

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