summaryrefslogtreecommitdiff
path: root/test/trap-clip.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2008-08-11 21:12:45 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2008-08-13 21:54:59 +0100
commit436c0c8be28546813139f391a62303d4c1894fc3 (patch)
tree7134b42ba4af4da886f8bd7906f4d6a144d1a134 /test/trap-clip.c
parentc73b3e43e120065e40d8fc48c9bdbd88ebe8ab40 (diff)
[test] Preparatory work for running under memfault.
In order to run under memfault, the framework is first extended to handle running concurrent tests - i.e. multi-threading. (Not that this is a requirement for memfault, instead it shares a common goal of storing per-test data). To that end all the global data is moved into a per-test context and the targets are adjusted to avoid overlap on shared, global resources (such as output files and frame buffers). In order to preserve the simplicity of the standard draw routines, the context is not passed explicitly as a parameter to the routines, but is instead attached to the cairo_t via the user_data. For the masochist, to enable the tests to be run across multiple threads simply set the environment variable CAIRO_TEST_NUM_THREADS to the desired number. In the long run, we can hope the need for memfault (runtime testing of error paths) will be mitigated by static analysis. A promising candidate for this task would appear to be http://hal.cs.berkeley.edu/cil/.
Diffstat (limited to 'test/trap-clip.c')
-rw-r--r--test/trap-clip.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/test/trap-clip.c b/test/trap-clip.c
index 3712c9024..0decb7ba4 100644
--- a/test/trap-clip.c
+++ b/test/trap-clip.c
@@ -31,22 +31,22 @@
#define HEIGHT 16
#define PAD 2
-const char png_filename[] = "romedalen.png";
+static const char png_filename[] = "romedalen.png";
static void
-set_solid_pattern (cairo_t *cr, int x, int y)
+set_solid_pattern (const cairo_test_context_t *ctx, cairo_t *cr, int x, int y)
{
cairo_set_source_rgb (cr, 0, 0, 0.6);
}
static void
-set_translucent_pattern (cairo_t *cr, int x, int y)
+set_translucent_pattern (const cairo_test_context_t *ctx, cairo_t *cr, int x, int y)
{
cairo_set_source_rgba (cr, 0, 0, 0.6, 0.5);
}
static void
-set_gradient_pattern (cairo_t *cr, int x, int y)
+set_gradient_pattern (const cairo_test_context_t *ctx, cairo_t *cr, int x, int y)
{
cairo_pattern_t *pattern;
@@ -59,11 +59,11 @@ set_gradient_pattern (cairo_t *cr, int x, int y)
}
static void
-set_image_pattern (cairo_t *cr, int x, int y)
+set_image_pattern (const cairo_test_context_t *ctx, cairo_t *cr, int x, int y)
{
cairo_pattern_t *pattern;
- pattern = cairo_test_create_pattern_from_png (png_filename);
+ pattern = cairo_test_create_pattern_from_png (ctx, png_filename);
cairo_set_source (cr, pattern);
cairo_pattern_destroy (pattern);
}
@@ -140,20 +140,20 @@ clip_circle (cairo_t *cr, int x, int y)
cairo_new_path (cr);
}
-static void (*pattern_funcs[])(cairo_t *cr, int x, int y) = {
+static void (* const pattern_funcs[])(const cairo_test_context_t *ctx, cairo_t *cr, int x, int y) = {
set_solid_pattern,
set_translucent_pattern,
set_gradient_pattern,
set_image_pattern,
};
-static void (*draw_funcs[])(cairo_t *cr, int x, int y) = {
+static void (* const draw_funcs[])(cairo_t *cr, int x, int y) = {
draw_rect,
draw_rects,
draw_polygon,
};
-static void (*clip_funcs[])(cairo_t *cr, int x, int y) = {
+static void (* const clip_funcs[])(cairo_t *cr, int x, int y) = {
clip_none,
clip_rect,
clip_rects,
@@ -166,7 +166,7 @@ static void (*clip_funcs[])(cairo_t *cr, int x, int y) = {
static cairo_test_draw_function_t draw;
-cairo_test_t test = {
+static const cairo_test_t test = {
"trap-clip",
"Trapezoid clipping\n",
IMAGE_WIDTH, IMAGE_HEIGHT,
@@ -176,6 +176,7 @@ cairo_test_t test = {
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
+ const cairo_test_context_t *ctx = cairo_test_get_context (cr);
size_t i, j, k, x, y;
for (k = 0; k < ARRAY_SIZE (clip_funcs); k++) {
@@ -188,10 +189,10 @@ draw (cairo_t *cr, int width, int height)
cairo_move_to (cr, x, y);
clip_funcs[k] (cr, x, y);
- pattern_funcs[i] (cr, x, y);
+ pattern_funcs[i] (ctx, cr, x, y);
draw_funcs[j] (cr, x, y);
if (cairo_status (cr))
- cairo_test_log ("%d %d HERE!\n", (int)i, (int)j);
+ cairo_test_log (ctx, "%d %d HERE!\n", (int)i, (int)j);
cairo_restore (cr);
}
@@ -199,7 +200,7 @@ draw (cairo_t *cr, int width, int height)
}
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
- cairo_test_log ("%d %d .HERE!\n", (int)i, (int)j);
+ cairo_test_log (ctx, "%d %d .HERE!\n", (int)i, (int)j);
return CAIRO_TEST_SUCCESS;
}