Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/2d/unittest/TestCairo.cpp
Line
Count
Source (jump to first uncovered line)
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
0
void TryCircle(double centerX, double centerY, double radius) {
13
0
  printf("TestCairo:TryArcs centerY %f, radius %f\n",centerY,radius);
14
0
15
0
  cairo_surface_t *surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,8,21);
16
0
  ASSERT_TRUE(surf != nullptr);
17
0
18
0
  cairo_t *cairo = cairo_create(surf);
19
0
  ASSERT_TRUE(cairo != nullptr);
20
0
21
0
  cairo_set_antialias(cairo, CAIRO_ANTIALIAS_NONE);
22
0
  cairo_arc(cairo, 0.0, centerY, radius, 0.0, 6.2831853071795862);
23
0
  cairo_fill_preserve(cairo);
24
0
25
0
  cairo_surface_destroy(surf);
26
0
  cairo_destroy(cairo);
27
0
}
28
29
0
TEST(Cairo, Simple) {
30
0
  TryCircle(0.0, 0.0, 14.0);
31
0
  TryCircle(0.0, 1.0, 22.4);
32
0
  TryCircle(1.0, 0.0, 1422.4);
33
0
  TryCircle(1.0, 1.0, 3422.4);
34
0
  TryCircle(-10.0, 1.0, -2);
35
0
}
36
37
0
TEST(Cairo, Bug825721) {
38
0
  // OK:
39
0
  TryCircle(0.0, 0.0, 8761126469220696064.0);
40
0
  TryCircle(0.0, 1.0, 8761126469220696064.0);
41
0
42
0
  // OK:
43
0
  TryCircle(1.0, 0.0, 5761126469220696064.0);
44
0
45
0
  // This was the crash in 825721.  Note that centerY has to be non-zero,
46
0
  // and radius has to be not only large, but in particular range.
47
0
  // 825721 has a band-aid fix, where the crash is inevitable, but does
48
0
  // not fix the cause.  The same code crashes in cairo standalone.
49
0
  TryCircle(0.0, 1.0, 5761126469220696064.0);
50
0
}
51
52
0
TEST(Cairo, Bug1063486) {
53
0
54
0
  double x1, y1, x2, y2;
55
0
  const double epsilon = .01;
56
0
57
0
  cairo_surface_t *surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1);
58
0
  ASSERT_TRUE(surf != nullptr);
59
0
60
0
  cairo_t *cairo = cairo_create(surf);
61
0
  ASSERT_TRUE(cairo != nullptr);
62
0
63
0
  printf("Path 1\n");
64
0
  cairo_move_to(cairo, -20, -10);
65
0
  cairo_line_to(cairo, 20, -10);
66
0
  cairo_line_to(cairo, 20, 10);
67
0
  cairo_curve_to(cairo, 10,10, -10,10, -20,10);
68
0
  cairo_curve_to(cairo, -30,10, -30,-10, -20,-10);
69
0
70
0
  cairo_path_extents(cairo, &x1, &y1, &x2, &y2);
71
0
72
0
  ASSERT_LT(std::abs(-27.5 - x1), epsilon); // the failing coordinate
73
0
  ASSERT_LT(std::abs(-10 - y1), epsilon);
74
0
  ASSERT_LT(std::abs(20 - x2), epsilon);
75
0
  ASSERT_LT(std::abs(10 - y2), epsilon);
76
0
77
0
  printf("Path 2\n");
78
0
  cairo_new_path(cairo);
79
0
  cairo_move_to(cairo, 10, 30);
80
0
  cairo_line_to(cairo, 90, 30);
81
0
  cairo_curve_to(cairo, 30,30, 30,30, 10,30);
82
0
  cairo_curve_to(cairo, 0,30, 0,0, 30,5);
83
0
84
0
  cairo_path_extents(cairo, &x1, &y1, &x2, &y2);
85
0
86
0
  ASSERT_LT(std::abs(4.019531 - x1), epsilon); // the failing coordinate
87
0
  ASSERT_LT(std::abs(4.437500 - y1), epsilon);
88
0
  ASSERT_LT(std::abs(90. - x2), epsilon);
89
0
  ASSERT_LT(std::abs(30. - y2), epsilon);
90
0
91
0
  cairo_surface_destroy(surf);
92
0
  cairo_destroy(cairo);
93
0
}
94
95
} // namespace layers
96
} // namespace mozilla