Rename Qt Quick-specific classes to QQuick*
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / qquickcanvasitem / data / tst_arc.qml
1 import QtQuick 2.0
2 import QtTest 1.0
3 import "testhelper.js" as Helper
4
5 Canvas {
6    id:canvas; width:100;height:50; renderTarget: Canvas.Image
7    TestCase {
8        name: "arc"; when: windowShown
9        function test_angle_1() {
10            var ctx = canvas.getContext('2d');
11            ctx.reset();
12
13            ctx.fillStyle = '#0f0';
14            ctx.fillRect(0, 0, 100, 50);
15            ctx.fillStyle = '#f00';
16            ctx.beginPath();
17            ctx.moveTo(100, 0);
18            ctx.arc(100, 0, 150, Math.PI/2, -Math.PI, true);
19            ctx.fill();
20            verify(Helper.comparePixel(ctx,50,25, 0,255,0,255));
21         }
22        function test_angle_2() {
23            var ctx = canvas.getContext('2d');
24            ctx.reset();
25
26            ctx.fillStyle = '#0f0';
27            ctx.fillRect(0, 0, 100, 50);
28            ctx.fillStyle = '#f00';
29            ctx.beginPath();
30            ctx.moveTo(100, 0);
31            ctx.arc(100, 0, 150, -3*Math.PI/2, -Math.PI, true);
32            ctx.fill();
33            verify(Helper.comparePixel(ctx,50,25, 0,255,0,255));
34         }
35        function test_angle_3() {
36            var ctx = canvas.getContext('2d');
37            ctx.reset();
38            ctx.fillStyle = '#0f0';
39            ctx.fillRect(0, 0, 100, 50);
40            ctx.fillStyle = '#f00';
41            ctx.beginPath();
42            ctx.moveTo(100, 0);
43            ctx.arc(100, 0, 150, (512+1/2)*Math.PI, (1024-1)*Math.PI, true);
44            ctx.fill();
45            //verify(Helper.comparePixel(ctx,50,25, 0,255,0,255));
46         }
47        function test_angle_4() {
48            var ctx = canvas.getContext('2d');
49            ctx.reset();
50
51            ctx.fillStyle = '#f00';
52            ctx.fillRect(0, 0, 100, 50);
53            ctx.fillStyle = '#0f0';
54            ctx.beginPath();
55            ctx.moveTo(50, 25);
56            ctx.arc(50, 25, 60, (512+1/2)*Math.PI, (1024-1)*Math.PI, false);
57            ctx.fill();
58            verify(Helper.comparePixel(ctx,1,1, 0,255,0,255));
59            verify(Helper.comparePixel(ctx,98,1, 0,255,0,255));
60            verify(Helper.comparePixel(ctx,1,48, 0,255,0,255));
61            verify(Helper.comparePixel(ctx,98,48, 0,255,0,255));
62         }
63        function test_angle_5() {
64            var ctx = canvas.getContext('2d');
65            ctx.reset();
66
67            ctx.fillStyle = '#0f0';
68            ctx.fillRect(0, 0, 100, 50);
69            ctx.fillStyle = '#f00';
70            ctx.beginPath();
71            ctx.moveTo(100, 0);
72            ctx.arc(100, 0, 150, (1024-1)*Math.PI, (512+1/2)*Math.PI, false);
73            ctx.fill();
74            /*FIXME:
75            actual  :[255,0,0,255]
76            expected:[0,255,0,255] +/- 0
77            */
78            //verify(Helper.comparePixel(ctx,50,25, 0,255,0,255));
79         }
80
81        function test_angle_6() {
82            var ctx = canvas.getContext('2d');
83            ctx.reset();
84
85            ctx.fillStyle = '#f00';
86            ctx.fillRect(0, 0, 100, 50);
87            ctx.fillStyle = '#0f0';
88            ctx.beginPath();
89            ctx.moveTo(50, 25);
90            ctx.arc(50, 25, 60, (1024-1)*Math.PI, (512+1/2)*Math.PI, true);
91            ctx.fill();
92
93            verify(Helper.comparePixel(ctx,1,1, 0,255,0,255));
94            verify(Helper.comparePixel(ctx,98,1, 0,255,0,255));
95            verify(Helper.comparePixel(ctx,1,48, 0,255,0,255));
96            verify(Helper.comparePixel(ctx,98,48, 0,255,0,255));
97         }
98
99        function test_empty() {
100            var ctx = canvas.getContext('2d');
101            ctx.reset();
102
103            ctx.fillStyle = '#0f0';
104            ctx.fillRect(0, 0, 100, 50);
105            ctx.lineWidth = 50;
106            ctx.strokeStyle = '#f00';
107            ctx.beginPath();
108            ctx.arc(200, 25, 5, 0, 2*Math.PI, true);
109            ctx.stroke();
110            /*FIXME:
111            actual  :[255,0,0,255]
112            expected:[0,255,0,255] +/- 0
113            */
114            //verify(Helper.comparePixel(ctx,50,25, 0,255,0,255));
115         }
116        function test_nonempty() {
117            var ctx = canvas.getContext('2d');
118            ctx.reset();
119
120            ctx.fillStyle = '#f00';
121            ctx.fillRect(0, 0, 100, 50);
122            ctx.lineWidth = 50;
123            ctx.strokeStyle = '#0f0';
124            ctx.beginPath();
125            ctx.moveTo(0, 25);
126            ctx.arc(200, 25, 5, 0, 2*Math.PI, true);
127            ctx.stroke();
128            verify(Helper.comparePixel(ctx,50,25, 0,255,0,255));
129         }
130        function test_nonfinite() {
131            skip("FIXME");
132            var ctx = canvas.getContext('2d');
133            ctx.reset();
134
135            ctx.fillStyle = '#f00';
136            ctx.fillRect(0, 0, 100, 50);
137            ctx.moveTo(0, 0);
138            ctx.lineTo(100, 0);
139            ctx.arc(Infinity, 0, 50, 0, 2*Math.PI, true);
140            ctx.arc(-Infinity, 0, 50, 0, 2*Math.PI, true);
141            ctx.arc(NaN, 0, 50, 0, 2*Math.PI, true);
142            ctx.arc(0, Infinity, 50, 0, 2*Math.PI, true);
143            ctx.arc(0, -Infinity, 50, 0, 2*Math.PI, true);
144            ctx.arc(0, NaN, 50, 0, 2*Math.PI, true);
145            ctx.arc(0, 0, Infinity, 0, 2*Math.PI, true);
146            ctx.arc(0, 0, -Infinity, 0, 2*Math.PI, true);
147            ctx.arc(0, 0, NaN, 0, 2*Math.PI, true);
148            ctx.arc(0, 0, 50, Infinity, 2*Math.PI, true);
149            ctx.arc(0, 0, 50, -Infinity, 2*Math.PI, true);
150            ctx.arc(0, 0, 50, NaN, 2*Math.PI, true);
151            ctx.arc(0, 0, 50, 0, Infinity, true);
152            ctx.arc(0, 0, 50, 0, -Infinity, true);
153            ctx.arc(0, 0, 50, 0, NaN, true);
154            ctx.arc(Infinity, Infinity, 50, 0, 2*Math.PI, true);
155            ctx.arc(Infinity, Infinity, Infinity, 0, 2*Math.PI, true);
156            ctx.arc(Infinity, Infinity, Infinity, Infinity, 2*Math.PI, true);
157            ctx.arc(Infinity, Infinity, Infinity, Infinity, Infinity, true);
158            ctx.arc(Infinity, Infinity, Infinity, 0, Infinity, true);
159            ctx.arc(Infinity, Infinity, 50, Infinity, 2*Math.PI, true);
160            ctx.arc(Infinity, Infinity, 50, Infinity, Infinity, true);
161            ctx.arc(Infinity, Infinity, 50, 0, Infinity, true);
162            ctx.arc(Infinity, 0, Infinity, 0, 2*Math.PI, true);
163            ctx.arc(Infinity, 0, Infinity, Infinity, 2*Math.PI, true);
164            ctx.arc(Infinity, 0, Infinity, Infinity, Infinity, true);
165            ctx.arc(Infinity, 0, Infinity, 0, Infinity, true);
166            ctx.arc(Infinity, 0, 50, Infinity, 2*Math.PI, true);
167            ctx.arc(Infinity, 0, 50, Infinity, Infinity, true);
168            ctx.arc(Infinity, 0, 50, 0, Infinity, true);
169            ctx.arc(0, Infinity, Infinity, 0, 2*Math.PI, true);
170            ctx.arc(0, Infinity, Infinity, Infinity, 2*Math.PI, true);
171            ctx.arc(0, Infinity, Infinity, Infinity, Infinity, true);
172            ctx.arc(0, Infinity, Infinity, 0, Infinity, true);
173            ctx.arc(0, Infinity, 50, Infinity, 2*Math.PI, true);
174            ctx.arc(0, Infinity, 50, Infinity, Infinity, true);
175            ctx.arc(0, Infinity, 50, 0, Infinity, true);
176            ctx.arc(0, 0, Infinity, Infinity, 2*Math.PI, true);
177            ctx.arc(0, 0, Infinity, Infinity, Infinity, true);
178            ctx.arc(0, 0, Infinity, 0, Infinity, true);
179            ctx.arc(0, 0, 50, Infinity, Infinity, true);
180            ctx.lineTo(100, 50);
181            ctx.lineTo(0, 50);
182            ctx.fillStyle = '#0f0';
183            ctx.fill();
184            verify(Helper.comparePixel(ctx,50,25, 0,255,0,255));
185            verify(Helper.comparePixel(ctx,90,45, 0,255,0,255));
186        }
187        function test_end() {
188            var ctx = canvas.getContext('2d');
189            ctx.reset();
190
191            ctx.fillStyle = '#f00';
192            ctx.fillRect(0, 0, 100, 50);
193            ctx.lineWidth = 50;
194            ctx.strokeStyle = '#0f0';
195            ctx.beginPath();
196            ctx.moveTo(-100, 0);
197            ctx.arc(-100, 0, 25, -Math.PI/2, Math.PI/2, true);
198            ctx.lineTo(100, 25);
199            ctx.stroke();
200            verify(Helper.comparePixel(ctx,50,25, 0,255,0,255));
201         }
202        function test_negative() {
203            var ctx = canvas.getContext('2d');
204            ctx.reset();
205
206            try { var err = false;
207              ctx.arc(0, 0, -1, 0, 0, true);
208            } catch (e) {
209                if (e.code != DOMException.INDEX_SIZE_ERR)
210                    fail("expected exception of type INDEX_SIZE_ERR, got: "+e.message);
211                err = true;
212            } finally {
213                verify(err, "should throw exception of type INDEX_SIZE_ERR: ctx.arc(0, 0, -1, 0, 0, true)");
214            }
215
216        }
217
218        function test_scale_1() {
219            var ctx = canvas.getContext('2d');
220            ctx.reset();
221
222            ctx.fillStyle = '#f00';
223            ctx.fillRect(0, 0, 100, 50);
224            ctx.scale(2, 0.5);
225            ctx.fillStyle = '#0f0';
226            ctx.beginPath();
227            ctx.arc(25, 50, 56, 0, 2*Math.PI, false);
228            ctx.fill();
229            ctx.fillStyle = '#f00';
230            ctx.beginPath();
231            ctx.moveTo(-25, 50);
232            ctx.arc(-25, 50, 24, 0, 2*Math.PI, false);
233            ctx.moveTo(75, 50);
234            ctx.arc(75, 50, 24, 0, 2*Math.PI, false);
235            ctx.moveTo(25, -25);
236            ctx.arc(25, -25, 24, 0, 2*Math.PI, false);
237            ctx.moveTo(25, 125);
238            ctx.arc(25, 125, 24, 0, 2*Math.PI, false);
239            ctx.fill();
240
241            verify(Helper.comparePixel(ctx, 0,0, 0,255,0,255));
242            verify(Helper.comparePixel(ctx, 50,0, 0,255,0,255));
243            //verify(Helper.comparePixel(ctx, 99,0, 0,255,0,255));
244            verify(Helper.comparePixel(ctx, 0,25, 0,255,0,255));
245            verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
246            //verify(Helper.comparePixel(ctx, 99,25, 0,255,0,255));
247            //verify(Helper.comparePixel(ctx, 0,49, 0,255,0,255));
248            //verify(Helper.comparePixel(ctx, 50,49, 0,255,0,255));
249            //verify(Helper.comparePixel(ctx, 99,49, 0,255,0,255));
250        }
251
252        function test_scale_2() {
253            var ctx = canvas.getContext('2d');
254            ctx.reset();
255
256            ctx.fillStyle = '#f00';
257            ctx.fillRect(0, 0, 100, 50);
258            ctx.scale(100, 100);
259            ctx.strokeStyle = '#0f0';
260            ctx.lineWidth = 1.2;
261            ctx.beginPath();
262            ctx.arc(0, 0, 0.6, 0, Math.PI/2, false);
263            ctx.stroke();
264
265            verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255));
266            verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255));
267            verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255));
268            verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255));
269            verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
270            verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255));
271            verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255));
272            verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255));
273            //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255));
274        }
275
276        function test_selfintersect_1() {
277            var ctx = canvas.getContext('2d');
278            ctx.reset();
279
280            ctx.fillStyle = '#0f0';
281            ctx.fillRect(0, 0, 100, 50);
282            ctx.lineWidth = 200;
283            ctx.strokeStyle = '#f00';
284            ctx.beginPath();
285            ctx.arc(100, 50, 25, 0, -Math.PI/2, true);
286            ctx.stroke();
287            ctx.beginPath();
288            ctx.arc(0, 0, 25, 0, -Math.PI/2, true);
289            ctx.stroke();
290            //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255));
291            //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
292        }
293
294        function test_selfintersect_2() {
295            var ctx = canvas.getContext('2d');
296            ctx.reset();
297
298            ctx.fillStyle = '#f00';
299            ctx.fillRect(0, 0, 100, 50);
300            ctx.lineWidth = 180;
301            ctx.strokeStyle = '#0f0';
302            ctx.beginPath();
303            ctx.arc(-50, 50, 25, 0, -Math.PI/2, true);
304            ctx.stroke();
305            ctx.beginPath();
306            ctx.arc(100, 0, 25, 0, -Math.PI/2, true);
307            ctx.stroke();
308            verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
309            //verify(Helper.comparePixel(ctx, 90,10, 0,255,0,255));
310            //verify(Helper.comparePixel(ctx, 97,1, 0,255,0,255));
311            //verify(Helper.comparePixel(ctx, 97,2, 0,255,0,255));
312            //verify(Helper.comparePixel(ctx, 97,3, 0,255,0,255));
313            verify(Helper.comparePixel(ctx, 2,48, 0,255,0,255));
314        }
315
316        function test_shape_1() {
317            var ctx = canvas.getContext('2d');
318            ctx.reset();
319
320            ctx.fillStyle = '#0f0';
321            ctx.fillRect(0, 0, 100, 50);
322            ctx.lineWidth = 50;
323            ctx.strokeStyle = '#f00';
324            ctx.beginPath();
325            ctx.arc(50, 50, 50, 0, Math.PI, false);
326            ctx.stroke();
327            //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
328            //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255));
329            verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255));
330            verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255));
331            verify(Helper.comparePixel(ctx, 20,48, 0,255,0,255));
332            //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255));
333        }
334
335        function test_shape_2() {
336            var ctx = canvas.getContext('2d');
337            ctx.reset();
338
339            ctx.fillStyle = '#f00';
340            ctx.fillRect(0, 0, 100, 50);
341            ctx.lineWidth = 100;
342            ctx.strokeStyle = '#0f0';
343            ctx.beginPath();
344            ctx.arc(50, 50, 50, 0, Math.PI, true);
345            ctx.stroke();
346            verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
347            verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255));
348            verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255));
349            verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255));
350            verify(Helper.comparePixel(ctx, 20,48, 0,255,0,255));
351            verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255));
352        }
353        function test_shape_3() {
354            var ctx = canvas.getContext('2d');
355            ctx.reset();
356
357            ctx.fillStyle = '#0f0';
358            ctx.fillRect(0, 0, 100, 50);
359            ctx.lineWidth = 100;
360            ctx.strokeStyle = '#f00';
361            ctx.beginPath();
362            ctx.arc(0, 50, 50, 0, -Math.PI/2, false);
363            ctx.stroke();
364            //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
365            //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255));
366            verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255));
367            //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255));
368            //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255));
369        }
370
371        function test_shape_4() {
372            var ctx = canvas.getContext('2d');
373            ctx.reset();
374
375            ctx.fillStyle = '#f00';
376            ctx.fillRect(0, 0, 100, 50);
377            ctx.lineWidth = 150;
378            ctx.strokeStyle = '#0f0';
379            ctx.beginPath();
380            ctx.arc(-50, 50, 100, 0, -Math.PI/2, true);
381            ctx.stroke();
382            verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
383            verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255));
384            verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255));
385            verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255));
386            verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255));
387        }
388
389        function test_shape_5() {
390            var ctx = canvas.getContext('2d');
391            ctx.reset();
392
393            ctx.fillStyle = '#0f0';
394            ctx.fillRect(0, 0, 100, 50);
395            ctx.lineWidth = 200;
396            ctx.strokeStyle = '#f00';
397            ctx.beginPath();
398            ctx.arc(300, 0, 100, 0, 5*Math.PI, false);
399            ctx.stroke();
400            //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
401            //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255));
402            //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255));
403            //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255));
404            //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255));
405        }
406
407        function test_twopie() {
408            var ctx = canvas.getContext('2d');
409            ctx.reset();
410
411            ctx.fillStyle = '#0f0';
412            ctx.fillRect(0, 0, 100, 50);
413            ctx.strokeStyle = '#f00';
414            ctx.lineWidth = 100;
415            ctx.beginPath();
416            ctx.arc(50, 25, 50, 0, 2*Math.PI - 1e-4, true);
417            ctx.stroke();
418            //verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255));
419            ctx.reset();
420
421            ctx.fillStyle = '#f00';
422            ctx.fillRect(0, 0, 100, 50);
423            ctx.strokeStyle = '#0f0';
424            ctx.lineWidth = 100;
425            ctx.beginPath();
426            ctx.arc(50, 25, 50, 0, 2*Math.PI - 1e-4, false);
427            ctx.stroke();
428            verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255));
429            ctx.reset();
430
431            ctx.fillStyle = '#f00';
432            ctx.fillRect(0, 0, 100, 50);
433            ctx.strokeStyle = '#0f0';
434            ctx.lineWidth = 100;
435            ctx.beginPath();
436            ctx.arc(50, 25, 50, 0, 2*Math.PI + 1e-4, true);
437            ctx.stroke();
438            verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255));
439            ctx.reset();
440
441            ctx.fillStyle = '#f00';
442            ctx.fillRect(0, 0, 100, 50);
443            ctx.strokeStyle = '#0f0';
444            ctx.lineWidth = 100;
445            ctx.beginPath();
446            ctx.arc(50, 25, 50, 0, 2*Math.PI + 1e-4, false);
447            ctx.stroke();
448            verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255));
449        }
450
451        function test_zero() {
452            var ctx = canvas.getContext('2d');
453            ctx.reset();
454
455            ctx.fillStyle = '#0f0';
456            ctx.fillRect(0, 0, 100, 50);
457            ctx.strokeStyle = '#f00';
458            ctx.lineWidth = 100;
459            ctx.beginPath();
460            ctx.arc(50, 25, 50, 0, 0, true);
461            ctx.stroke();
462            //verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255));
463            ctx.reset();
464
465            ctx.fillStyle = '#0f0';
466            ctx.fillRect(0, 0, 100, 50);
467            ctx.strokeStyle = '#f00';
468            ctx.lineWidth = 100;
469            ctx.beginPath();
470            ctx.arc(50, 25, 50, 0, 0, false);
471            ctx.stroke();
472            //verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255));
473            ctx.reset();
474
475            ctx.fillStyle = '#f00'
476            ctx.fillRect(0, 0, 100, 50);
477            ctx.lineWidth = 50;
478            ctx.strokeStyle = '#0f0';
479            ctx.beginPath();
480            ctx.moveTo(0, 25);
481            ctx.arc(200, 25, 0, 0, Math.PI, true);
482            ctx.stroke();
483            verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
484
485        }
486    }
487 }