gfx/2d/unittest/TestCairo.cpp

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:a604fd882e2f
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
4
5 #include "cairo.h"
6
7 #include "gtest/gtest.h"
8
9 namespace mozilla {
10 namespace layers {
11
12 void TryCircle(double centerX, double centerY, double radius) {
13 printf("TestCairo:TryArcs centerY %f, radius %f\n",centerY,radius);
14
15 cairo_surface_t *surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,8,21);
16 ASSERT_TRUE(surf != nullptr);
17
18 cairo_t *cairo = cairo_create(surf);
19 ASSERT_TRUE(cairo != nullptr);
20
21 cairo_set_antialias(cairo, CAIRO_ANTIALIAS_NONE);
22 cairo_arc(cairo, 0.0, centerY, radius, 0.0, 6.2831853071795862);
23 cairo_fill_preserve(cairo);
24
25 cairo_surface_destroy(surf);
26 cairo_destroy(cairo);
27 }
28
29 TEST(Cairo, Simple) {
30 TryCircle(0.0, 0.0, 14.0);
31 TryCircle(0.0, 1.0, 22.4);
32 TryCircle(1.0, 0.0, 1422.4);
33 TryCircle(1.0, 1.0, 3422.4);
34 TryCircle(-10.0, 1.0, -2);
35 }
36
37 TEST(Cairo, Bug825721) {
38 // OK:
39 TryCircle(0.0, 0.0, 8761126469220696064.0);
40 TryCircle(0.0, 1.0, 8761126469220696064.0);
41
42 // OK:
43 TryCircle(1.0, 0.0, 5761126469220696064.0);
44
45 // This was the crash in 825721. Note that centerY has to be non-zero,
46 // and radius has to be not only large, but in particular range.
47 // 825721 has a band-aid fix, where the crash is inevitable, but does
48 // not fix the cause. The same code crashes in cairo standalone.
49 TryCircle(0.0, 1.0, 5761126469220696064.0);
50 }
51
52 }
53 }

mercurial