summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.sources3
-rw-r--r--test/bug-277.c94
-rw-r--r--test/coverage.c122
-rw-r--r--test/meson.build3
-rw-r--r--test/reference/coverage-column-triangles.ref.pngbin208 -> 886 bytes
-rw-r--r--test/reference/coverage-column-triangles.xfail.pngbin7632 -> 560 bytes
-rw-r--r--test/reference/coverage-column-triangles.xlib.xfail.pngbin12745 -> 1364 bytes
7 files changed, 160 insertions, 62 deletions
diff --git a/test/Makefile.sources b/test/Makefile.sources
index ab41aac5f..6a5b57575 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -24,8 +24,9 @@ test_sources = \
bug-spline.c \
big-trap.c \
bilevel-image.c \
- bug-40410.c \
+ bug-277.c \
bug-361.c \
+ bug-40410.c \
bug-431.c \
bug-448.c \
bug-535.c \
diff --git a/test/bug-277.c b/test/bug-277.c
new file mode 100644
index 000000000..f4de539a4
--- /dev/null
+++ b/test/bug-277.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright © 2022 Uli Schlachter
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author: Uli Schlachter <psychon@znc.in>
+ */
+
+#include "cairo-test.h"
+#include "cairo-script.h"
+
+struct write_data {
+ cairo_bool_t finished;
+ cairo_test_status_t test_status;
+};
+
+static cairo_surface_t*
+create_recording_surface ()
+{
+ /* Create a non-empty recording surface with arbitrary content */
+ cairo_surface_t *surf = cairo_recording_surface_create (CAIRO_CONTENT_COLOR, NULL);
+ cairo_t *cr = cairo_create (surf);
+
+ cairo_move_to (cr, 0, 0);
+ cairo_line_to (cr, 10, 0);
+ cairo_stroke (cr);
+
+ cairo_destroy (cr);
+ return surf;
+}
+
+static cairo_status_t
+write_func(void *closure, const unsigned char* bytes, unsigned int length)
+{
+ struct write_data *data = closure;
+ (void) bytes; (void) length;
+
+ if (data->finished)
+ data->test_status = CAIRO_TEST_ERROR;
+
+ return CAIRO_STATUS_SUCCESS;
+}
+
+static cairo_test_status_t
+preamble (cairo_test_context_t *ctx)
+{
+ struct write_data write_data = { FALSE, CAIRO_TEST_SUCCESS };
+ cairo_device_t *script_device = cairo_script_create_for_stream (write_func, &write_data);
+ cairo_surface_t *recording = create_recording_surface ();
+ cairo_surface_t *script;
+ cairo_t *cr;
+
+ /* Draw the recording surface to a script surface */
+ script = cairo_script_surface_create (script_device, CAIRO_CONTENT_COLOR, 5, 5);
+ cr = cairo_test_create (script, ctx);
+ cairo_set_source_surface (cr, recording, 0, 0);
+ cairo_paint (cr);
+ cairo_destroy (cr);
+ cairo_surface_destroy (script);
+
+ /* Finish the script device; no further writing allowed afterwards */
+ cairo_device_finish (script_device);
+ write_data.finished = TRUE;
+ cairo_device_destroy (script_device);
+
+ cairo_surface_destroy (recording);
+
+ return write_data.test_status;
+}
+
+CAIRO_TEST (bug_277,
+ "Regression test: Script surface emitting test after finish()",
+ NULL, /* keywords */
+ NULL, /* requirements */
+ 0, 0,
+ preamble, NULL)
diff --git a/test/coverage.c b/test/coverage.c
index 86216df31..0749fa22a 100644
--- a/test/coverage.c
+++ b/test/coverage.c
@@ -50,9 +50,9 @@ hars_petruska_f54_1_random (void)
}
static double
-random_offset (int range, int precise)
+random_offset (int range, int precise, int width)
{
- double x = hars_petruska_f54_1_random() / (double) UINT32_MAX * range / WIDTH;
+ double x = hars_petruska_f54_1_random() / (double) UINT32_MAX * range / width;
if (precise)
x = floor (x * PRECISION) / PRECISION;
return x;
@@ -69,9 +69,9 @@ rectangles (cairo_t *cr, int width, int height)
cairo_paint (cr);
#if GENERATE_REFERENCE
- for (x = 0; x < WIDTH; x++) {
- cairo_set_source_rgba (cr, 1, 1, 1, x * x * 1.0 / (WIDTH * WIDTH));
- cairo_rectangle (cr, x, 0, 1, HEIGHT);
+ for (x = 0; x < width; x++) {
+ cairo_set_source_rgba (cr, 1, 1, 1, x * x * 1.0 / (width * width));
+ cairo_rectangle (cr, x, 0, 1, height);
cairo_fill (cr);
}
#else
@@ -84,11 +84,11 @@ rectangles (cairo_t *cr, int width, int height)
case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
}
- for (x = 0; x < WIDTH; x++) {
- for (y = 0; y < HEIGHT; y++) {
- double dx = random_offset (WIDTH - x, TRUE);
- double dy = random_offset (WIDTH - x, TRUE);
- cairo_rectangle (cr, x + dx, y + dy, x / (double) WIDTH, x / (double) WIDTH);
+ for (x = 0; x < width; x++) {
+ for (y = 0; y < height; y++) {
+ double dx = random_offset (width - x, TRUE, width);
+ double dy = random_offset (width - x, TRUE, width);
+ cairo_rectangle (cr, x + dx, y + dy, x / (double) width, x / (double) width);
}
}
cairo_fill (cr);
@@ -102,15 +102,16 @@ static cairo_test_status_t
rhombus (cairo_t *cr, int width, int height)
{
int x, y;
+ int internal_size = width / 2;
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
cairo_paint (cr);
#if GENERATE_REFERENCE
- for (y = 0; y < WIDTH; y++) {
- for (x = 0; x < WIDTH; x++) {
+ for (y = 0; y < internal_size; y++) {
+ for (x = 0; x < internal_size; x++) {
cairo_set_source_rgba (cr, 1, 1, 1,
- x * y / (2. * WIDTH * WIDTH));
+ x * y / (2. * internal_size * internal_size));
cairo_rectangle (cr, 2*x, 2*y, 2, 2);
cairo_fill (cr);
}
@@ -119,10 +120,10 @@ rhombus (cairo_t *cr, int width, int height)
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
cairo_set_source_rgb (cr, 1, 1, 1);
- for (y = 0; y < WIDTH; y++) {
- double yf = y / (double) WIDTH;
- for (x = 0; x < WIDTH; x++) {
- double xf = x / (double) WIDTH;
+ for (y = 0; y < internal_size; y++) {
+ double yf = y / (double) internal_size;
+ for (x = 0; x < internal_size; x++) {
+ double xf = x / (double) internal_size;
cairo_move_to (cr,
2*x + 1 - xf,
@@ -157,9 +158,9 @@ intersecting_quads (cairo_t *cr, int width, int height)
cairo_paint (cr);
#if GENERATE_REFERENCE
- for (x = 0; x < WIDTH; x++) {
- cairo_set_source_rgba (cr, 1, 1, 1, x * x * 0.5 / (WIDTH * WIDTH));
- cairo_rectangle (cr, x, 0, 1, HEIGHT);
+ for (x = 0; x < width; x++) {
+ cairo_set_source_rgba (cr, 1, 1, 1, x * x * 0.5 / (width * width));
+ cairo_rectangle (cr, x, 0, 1, height);
cairo_fill (cr);
}
#else
@@ -172,11 +173,11 @@ intersecting_quads (cairo_t *cr, int width, int height)
case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
}
- for (x = 0; x < WIDTH; x++) {
- double step = x / (double) WIDTH;
- for (y = 0; y < HEIGHT; y++) {
- double dx = random_offset (WIDTH - x, TRUE);
- double dy = random_offset (WIDTH - x, TRUE);
+ for (x = 0; x < width; x++) {
+ double step = x / (double) width;
+ for (y = 0; y < height; y++) {
+ double dx = random_offset (width - x, TRUE, width);
+ double dy = random_offset (width - x, TRUE, width);
cairo_move_to (cr, x + dx, y + dy);
cairo_rel_line_to (cr, step, step);
cairo_rel_line_to (cr, 0, -step);
@@ -202,9 +203,9 @@ intersecting_triangles (cairo_t *cr, int width, int height)
cairo_paint (cr);
#if GENERATE_REFERENCE
- for (x = 0; x < WIDTH; x++) {
- cairo_set_source_rgba (cr, 1, 1, 1, x * x * 0.75 / (WIDTH * WIDTH));
- cairo_rectangle (cr, x, 0, 1, HEIGHT);
+ for (x = 0; x < width; x++) {
+ cairo_set_source_rgba (cr, 1, 1, 1, x * x * 0.75 / (width * width));
+ cairo_rectangle (cr, x, 0, 1, height);
cairo_fill (cr);
}
#else
@@ -217,11 +218,11 @@ intersecting_triangles (cairo_t *cr, int width, int height)
case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
}
- for (x = 0; x < WIDTH; x++) {
- double step = x / (double) WIDTH;
- for (y = 0; y < HEIGHT; y++) {
- double dx = random_offset (WIDTH - x, TRUE);
- double dy = random_offset (WIDTH - x, TRUE);
+ for (x = 0; x < width; x++) {
+ double step = x / (double) width;
+ for (y = 0; y < height; y++) {
+ double dx = random_offset (width - x, TRUE, width);
+ double dy = random_offset (width - x, TRUE, width);
/* left */
cairo_move_to (cr, x + dx, y + dy);
@@ -254,9 +255,9 @@ triangles (cairo_t *cr, int width, int height)
cairo_paint (cr);
#if GENERATE_REFERENCE
- for (x = 0; x < WIDTH; x++) {
- cairo_set_source_rgba (cr, 1, 1, 1, x * x * 0.5 / (WIDTH * WIDTH));
- cairo_rectangle (cr, x, 0, 1, HEIGHT);
+ for (x = 0; x < width; x++) {
+ cairo_set_source_rgba (cr, 1, 1, 1, x * x * 0.5 / (width * width));
+ cairo_rectangle (cr, x, 0, 1, height);
cairo_fill (cr);
}
#else
@@ -269,13 +270,13 @@ triangles (cairo_t *cr, int width, int height)
case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
}
- for (x = 0; x < WIDTH; x++) {
- for (y = 0; y < HEIGHT; y++) {
- double dx = random_offset (WIDTH - x, TRUE);
- double dy = random_offset (WIDTH - x, TRUE);
+ for (x = 0; x < width; x++) {
+ for (y = 0; y < height; y++) {
+ double dx = random_offset (width - x, TRUE, width);
+ double dy = random_offset (width - x, TRUE, width);
cairo_move_to (cr, x + dx, y + dy);
- cairo_rel_line_to (cr, x / (double) WIDTH, 0);
- cairo_rel_line_to (cr, 0, x / (double) WIDTH);
+ cairo_rel_line_to (cr, x / (double) width, 0);
+ cairo_rel_line_to (cr, 0, x / (double) width);
cairo_close_path (cr);
}
}
@@ -344,9 +345,9 @@ column_triangles (cairo_t *cr, int width, int height)
cairo_paint (cr);
#if GENERATE_REFERENCE
- for (x = 0; x < WIDTH; x++) {
- cairo_set_source_rgba (cr, 1, 1, 1, x * 0.5 / WIDTH);
- cairo_rectangle (cr, x, 0, 1, HEIGHT);
+ for (x = 0; x < width; x++) {
+ cairo_set_source_rgba (cr, 1, 1, 1, x * 0.5 / width);
+ cairo_rectangle (cr, x, 0, 1, height);
cairo_fill (cr);
}
#else
@@ -359,11 +360,11 @@ column_triangles (cairo_t *cr, int width, int height)
case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
}
- for (x = 0; x < WIDTH; x++) {
- double step = x / (double) (2 * WIDTH);
- for (y = 0; y < HEIGHT; y++) {
+ for (x = 0; x < width; x++) {
+ double step = x / (double) (2 * width);
+ for (y = 0; y < height; y++) {
for (i = 0; i < PRECISION; i++) {
- double dy = random_offset (WIDTH - x, FALSE);
+ double dy = random_offset (width - x, FALSE, width);
/*
* We want to test some sharing of edges to further
@@ -375,7 +376,7 @@ column_triangles (cairo_t *cr, int width, int height)
* s --- . ---
* t | |\ |
* e | | \ |
- * p --- .... | 2 * step = x / WIDTH
+ * p --- .... | 2 * step = x / width
* \ | |
* \| |
* . ---
@@ -383,8 +384,8 @@ column_triangles (cairo_t *cr, int width, int height)
* 1 / PRECISION
*
* Each column contains two triangles of width one quantum and
- * total height of (x / WIDTH), thus the total area covered by all
- * columns in each pixel is .5 * (x / WIDTH).
+ * total height of (x / width), thus the total area covered by all
+ * columns in each pixel is .5 * (x / width).
*/
cairo_move_to (cr, x + i / (double) PRECISION, y + dy);
@@ -413,9 +414,9 @@ row_triangles (cairo_t *cr, int width, int height)
cairo_paint (cr);
#if GENERATE_REFERENCE
- for (x = 0; x < WIDTH; x++) {
- cairo_set_source_rgba (cr, 1, 1, 1, x * 0.5 / WIDTH);
- cairo_rectangle (cr, x, 0, 1, HEIGHT);
+ for (x = 0; x < width; x++) {
+ cairo_set_source_rgba (cr, 1, 1, 1, x * 0.5 / width);
+ cairo_rectangle (cr, x, 0, 1, height);
cairo_fill (cr);
}
#else
@@ -428,11 +429,11 @@ row_triangles (cairo_t *cr, int width, int height)
case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
}
- for (x = 0; x < WIDTH; x++) {
- double step = x / (double) (2 * WIDTH);
- for (y = 0; y < HEIGHT; y++) {
+ for (x = 0; x < width; x++) {
+ double step = x / (double) (2 * width);
+ for (y = 0; y < height; y++) {
for (i = 0; i < PRECISION; i++) {
- double dx = random_offset (WIDTH - x, FALSE);
+ double dx = random_offset (width - x, FALSE, width);
/* See column_triangles() for a transposed description
* of this geometry.
@@ -490,7 +491,8 @@ CAIRO_TEST (coverage_column_triangles,
"Check the fidelity of the rasterisation.",
NULL, /* keywords */
"target=raster", /* requirements */
- WIDTH, HEIGHT,
+ /* Smaller height since this test does not vary by y-coordinate */
+ WIDTH, 4,
NULL, column_triangles)
CAIRO_TEST (coverage_triangles,
"Check the fidelity of the rasterisation.",
diff --git a/test/meson.build b/test/meson.build
index 4638dcca6..74e059b39 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -24,8 +24,9 @@ test_sources = [
'bug-spline.c',
'big-trap.c',
'bilevel-image.c',
- 'bug-40410.c',
+ 'bug-277.c',
'bug-361.c',
+ 'bug-40410.c',
'bug-431.c',
'bug-448.c',
'bug-535.c',
diff --git a/test/reference/coverage-column-triangles.ref.png b/test/reference/coverage-column-triangles.ref.png
index aa61031b7..24ccc9f2a 100644
--- a/test/reference/coverage-column-triangles.ref.png
+++ b/test/reference/coverage-column-triangles.ref.png
Binary files differ
diff --git a/test/reference/coverage-column-triangles.xfail.png b/test/reference/coverage-column-triangles.xfail.png
index 566b41544..9af5253c5 100644
--- a/test/reference/coverage-column-triangles.xfail.png
+++ b/test/reference/coverage-column-triangles.xfail.png
Binary files differ
diff --git a/test/reference/coverage-column-triangles.xlib.xfail.png b/test/reference/coverage-column-triangles.xlib.xfail.png
index f433b7a84..18e4af2da 100644
--- a/test/reference/coverage-column-triangles.xlib.xfail.png
+++ b/test/reference/coverage-column-triangles.xlib.xfail.png
Binary files differ