gfx/2d/unittest/TestCairo.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial