QML_RUNTIME_TESTING should be disabled by default.
[profile/ivi/qtdeclarative.git] / tests / auto / qtquick2 / qquickcanvasitem / data / tst_state.qml
1 import QtQuick 2.0
2 import QtTest 1.0
3 import "testhelper.js" as Helper
4 Canvas {
5    id:canvas; width:100;height:50; renderTarget: Canvas.Image
6    TestCase {
7        id:testCase
8        name: "state"; when: windowShown
9        function test_bitmap() {
10            var ctx = canvas.getContext('2d');
11            ctx.reset();
12            ctx.fillStyle = '#f00';
13            ctx.fillRect(0, 0, 100, 50);
14            ctx.save();
15            ctx.fillStyle = '#0f0';
16            ctx.fillRect(0, 0, 100, 50);
17            ctx.restore();
18            verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
19       }
20        function test_clip() {
21            var ctx = canvas.getContext('2d');
22            ctx.reset();
23
24            ctx.fillStyle = '#f00';
25            ctx.fillRect(0, 0, 100, 50);
26            ctx.save();
27            ctx.rect(0, 0, 1, 1);
28            ctx.clip();
29            ctx.restore();
30            ctx.fillStyle = '#0f0';
31            ctx.fillRect(0, 0, 100, 50);
32            //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
33
34        }
35        function test_fillStyle() {
36            var ctx = canvas.getContext('2d');
37            ctx.reset();
38            // Test that restore() undoes any modifications
39            var old = ctx.fillStyle;
40            ctx.save();
41            ctx.fillStyle = "#ff0000";
42            ctx.restore();
43            compare(ctx.fillStyle, old);
44
45            // Also test that save() doesn't modify the values
46            ctx.fillStyle = "#ff0000";
47            old = ctx.fillStyle;
48                // we're not interested in failures caused by get(set(x)) != x (e.g.
49                // from rounding), so compare against 'old' instead of against "#ff0000"
50            ctx.save();
51            compare(ctx.fillStyle, old);
52            ctx.restore();
53        }
54        function test_font() {
55            var ctx = canvas.getContext('2d');
56            ctx.reset();
57
58            // Test that restore() undoes any modifications
59            var old = ctx.font;
60            ctx.save();
61            ctx.font = "25px serif";
62            ctx.restore();
63            compare(ctx.font, old);
64
65            // Also test that save() doesn't modify the values
66            ctx.font = "25px serif";
67            old = ctx.font;
68                // we're not interested in failures caused by get(set(x)) != x (e.g.
69                // from rounding), so compare against 'old' instead of against "25px serif"
70            ctx.save();
71            compare(ctx.font, old);
72            ctx.restore();
73        }
74        function test_globalAlpha() {
75            var ctx = canvas.getContext('2d');
76            ctx.reset();
77
78            // Test that restore() undoes any modifications
79            var old = ctx.globalAlpha;
80            ctx.save();
81            ctx.globalAlpha = 0.5;
82            ctx.restore();
83            compare(ctx.globalAlpha, old);
84
85            // Also test that save() doesn't modify the values
86            ctx.globalAlpha = 0.5;
87            old = ctx.globalAlpha;
88                // we're not interested in failures caused by get(set(x)) != x (e.g.
89                // from rounding), so compare against 'old' instead of against 0.5
90            ctx.save();
91            compare(ctx.globalAlpha, old);
92            ctx.restore();
93         }
94        function test_globalCompositeOperation() {
95            var ctx = canvas.getContext('2d');
96            ctx.reset();
97
98            // Test that restore() undoes any modifications
99            var old = ctx.globalCompositeOperation;
100            ctx.save();
101            ctx.globalCompositeOperation = "copy";
102            ctx.restore();
103            compare(ctx.globalCompositeOperation, old);
104
105            // Also test that save() doesn't modify the values
106            ctx.globalCompositeOperation = "copy";
107            old = ctx.globalCompositeOperation;
108                // we're not interested in failures caused by get(set(x)) != x (e.g.
109                // from rounding), so compare against 'old' instead of against "copy"
110            ctx.save();
111            compare(ctx.globalCompositeOperation, old);
112            ctx.restore();
113        }
114        function test_lineCap() {
115            var ctx = canvas.getContext('2d');
116            ctx.reset();
117
118            // Test that restore() undoes any modifications
119            var old = ctx.lineCap;
120            ctx.save();
121            ctx.lineCap = "round";
122            ctx.restore();
123            compare(ctx.lineCap, old);
124
125            // Also test that save() doesn't modify the values
126            ctx.lineCap = "round";
127            old = ctx.lineCap;
128                // we're not interested in failures caused by get(set(x)) != x (e.g.
129                // from rounding), so compare against 'old' instead of against "round"
130            ctx.save();
131            compare(ctx.lineCap, old);
132            ctx.restore();
133        }
134        function test_lineJoin() {
135            var ctx = canvas.getContext('2d');
136            ctx.reset();
137
138            // Test that restore() undoes any modifications
139            var old = ctx.lineJoin;
140            ctx.save();
141            ctx.lineJoin = "round";
142            ctx.restore();
143            compare(ctx.lineJoin, old);
144
145            // Also test that save() doesn't modify the values
146            ctx.lineJoin = "round";
147            old = ctx.lineJoin;
148                // we're not interested in failures caused by get(set(x)) != x (e.g.
149                // from rounding), so compare against 'old' instead of against "round"
150            ctx.save();
151            compare(ctx.lineJoin, old);
152            ctx.restore();
153        }
154        function test_lineWidth() {
155            var ctx = canvas.getContext('2d');
156            ctx.reset();
157
158            // Test that restore() undoes any modifications
159            var old = ctx.lineJoin;
160            ctx.save();
161            ctx.lineJoin = "round";
162            ctx.restore();
163            compare(ctx.lineJoin, old, "ctx.lineJoin", "old");
164
165            // Also test that save() doesn't modify the values
166            ctx.lineJoin = "round";
167            old = ctx.lineJoin;
168                // we're not interested in failures caused by get(set(x)) != x (e.g.
169                // from rounding), so compare against 'old' instead of against "round"
170            ctx.save();
171            compare(ctx.lineJoin, old);
172            ctx.restore();
173        }
174        function test_miterLimit() {
175            var ctx = canvas.getContext('2d');
176            ctx.reset();
177
178            // Test that restore() undoes any modifications
179            var old = ctx.miterLimit;
180            ctx.save();
181            ctx.miterLimit = 0.5;
182            ctx.restore();
183            compare(ctx.miterLimit, old);
184
185            // Also test that save() doesn't modify the values
186            ctx.miterLimit = 0.5;
187            old = ctx.miterLimit;
188                // we're not interested in failures caused by get(set(x)) != x (e.g.
189                // from rounding), so compare against 'old' instead of against 0.5
190            ctx.save();
191            compare(ctx.miterLimit, old);
192            ctx.restore();
193        }
194        function test_path() {
195            var ctx = canvas.getContext('2d');
196            ctx.reset();
197
198            ctx.fillStyle = '#f00';
199            ctx.fillRect(0, 0, 100, 50);
200            ctx.save();
201            ctx.rect(0, 0, 100, 50);
202            ctx.restore();
203            ctx.fillStyle = '#0f0';
204            ctx.fill();
205            verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
206        }
207        function test_shadow() {
208            var ctx = canvas.getContext('2d');
209            ctx.reset();
210
211            // Test that restore() undoes any modifications
212            var old = ctx.shadowBlur;
213            ctx.save();
214            ctx.shadowBlur = 5;
215            ctx.restore();
216            compare(ctx.shadowBlur, old);
217
218            // Also test that save() doesn't modify the values
219            ctx.shadowBlur = 5;
220            old = ctx.shadowBlur;
221                // we're not interested in failures caused by get(set(x)) != x (e.g.
222                // from rounding), so compare against 'old' instead of against 5
223            ctx.save();
224            compare(ctx.shadowBlur, old);
225            ctx.restore();
226
227            // Test that restore() undoes any modifications
228            var old = ctx.shadowColor;
229            ctx.save();
230            ctx.shadowColor = "#ff0000";
231            ctx.restore();
232            compare(ctx.shadowColor, old);
233
234            // Also test that save() doesn't modify the values
235            ctx.shadowColor = "#ff0000";
236            old = ctx.shadowColor;
237                // we're not interested in failures caused by get(set(x)) != x (e.g.
238                // from rounding), so compare against 'old' instead of against "#ff0000"
239            ctx.save();
240            compare(ctx.shadowColor, old);
241            ctx.restore();
242
243            // Test that restore() undoes any modifications
244            var old = ctx.shadowOffsetX;
245            ctx.save();
246            ctx.shadowOffsetX = 5;
247            ctx.restore();
248            compare(ctx.shadowOffsetX, old);
249
250            // Also test that save() doesn't modify the values
251            ctx.shadowOffsetX = 5;
252            old = ctx.shadowOffsetX;
253                // we're not interested in failures caused by get(set(x)) != x (e.g.
254                // from rounding), so compare against 'old' instead of against 5
255            ctx.save();
256            compare(ctx.shadowOffsetX, old);
257            ctx.restore();
258
259            // Test that restore() undoes any modifications
260            var old = ctx.shadowOffsetY;
261            ctx.save();
262            ctx.shadowOffsetY = 5;
263            ctx.restore();
264            compare(ctx.shadowOffsetY, old);
265
266            // Also test that save() doesn't modify the values
267            ctx.shadowOffsetY = 5;
268            old = ctx.shadowOffsetY;
269                // we're not interested in failures caused by get(set(x)) != x (e.g.
270                // from rounding), so compare against 'old' instead of against 5
271            ctx.save();
272            compare(ctx.shadowOffsetY, old);
273            ctx.restore();
274
275        }
276        function test_stack() {
277            var ctx = canvas.getContext('2d');
278            ctx.reset();
279
280            ctx.lineWidth = 1;
281            ctx.save();
282            ctx.lineWidth = 2;
283            ctx.save();
284            ctx.lineWidth = 3;
285            compare(ctx.lineWidth, 3);
286            ctx.restore();
287            compare(ctx.lineWidth, 2);
288            ctx.restore();
289            compare(ctx.lineWidth, 1);
290
291            var limit = 512;
292            for (var i = 1; i < limit; ++i)
293            {
294                ctx.save();
295                ctx.lineWidth = i;
296            }
297            for (var i = limit-1; i > 0; --i)
298            {
299                testCase.compare(ctx.lineWidth, i); //strange javascript error here
300                ctx.restore();
301            }
302
303            for (var i = 0; i < 16; ++i)
304                ctx.restore();
305            ctx.lineWidth = 0.5;
306            ctx.restore();
307            compare(ctx.lineWidth, 0.5);
308
309        }
310        function test_strokeStyle() {
311            var ctx = canvas.getContext('2d');
312            ctx.reset();
313
314            // Test that restore() undoes any modifications
315            var old = ctx.strokeStyle;
316            ctx.save();
317            ctx.strokeStyle = "#ff0000";
318            ctx.restore();
319            compare(ctx.strokeStyle, old);
320
321            // Also test that save() doesn't modify the values
322            ctx.strokeStyle = "#ff0000";
323            old = ctx.strokeStyle;
324                // we're not interested in failures caused by get(set(x)) != x (e.g.
325                // from rounding), so compare against 'old' instead of against "#ff0000"
326            ctx.save();
327            compare(ctx.strokeStyle, old);
328            ctx.restore();
329
330
331        }
332
333        function test_text() {
334            var ctx = canvas.getContext('2d');
335            ctx.reset();
336
337            // Test that restore() undoes any modifications
338            var old = ctx.textAlign;
339            ctx.save();
340            ctx.textAlign = "center";
341            ctx.restore();
342            compare(ctx.textAlign, old);
343
344            // Also test that save() doesn't modify the values
345            ctx.textAlign = "center";
346            old = ctx.textAlign;
347                // we're not interested in failures caused by get(set(x)) != x (e.g.
348                // from rounding), so compare against 'old' instead of against "center"
349            ctx.save();
350            compare(ctx.textAlign, old);
351            ctx.restore();
352
353            // Test that restore() undoes any modifications
354            var old = ctx.textBaseline;
355            ctx.save();
356            ctx.textBaseline = "bottom";
357            ctx.restore();
358            compare(ctx.textBaseline, old);
359
360            // Also test that save() doesn't modify the values
361            ctx.textBaseline = "bottom";
362            old = ctx.textBaseline;
363                // we're not interested in failures caused by get(set(x)) != x (e.g.
364                // from rounding), so compare against 'old' instead of against "bottom"
365            ctx.save();
366            compare(ctx.textBaseline, old);
367            ctx.restore();
368
369
370        }
371
372        function test_transform() {
373            var ctx = canvas.getContext('2d');
374            ctx.reset();
375
376            ctx.fillStyle = '#0f0';
377            ctx.fillRect(0, 0, 100, 50);
378            ctx.save();
379            ctx.translate(200, 0);
380            ctx.restore();
381            ctx.fillStyle = '#f00';
382            ctx.fillRect(-200, 0, 100, 50);
383            verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
384
385
386        }
387
388
389    }
390 }