diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2008-08-11 21:12:45 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2008-08-13 21:54:59 +0100 |
commit | 436c0c8be28546813139f391a62303d4c1894fc3 (patch) | |
tree | 7134b42ba4af4da886f8bd7906f4d6a144d1a134 /test/copy-path.c | |
parent | c73b3e43e120065e40d8fc48c9bdbd88ebe8ab40 (diff) | |
download | cairo-436c0c8be28546813139f391a62303d4c1894fc3.tar.gz |
[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/copy-path.c')
-rw-r--r-- | test/copy-path.c | 81 |
1 files changed, 60 insertions, 21 deletions
diff --git a/test/copy-path.c b/test/copy-path.c index 362bb34d3..dfc671dce 100644 --- a/test/copy-path.c +++ b/test/copy-path.c @@ -28,7 +28,7 @@ static cairo_test_draw_function_t draw; -cairo_test_t test = { +static const cairo_test_t test = { "copy-path", "Tests calls to path_data functions: cairo_copy_path, cairo_copy_path_flat, and cairo_append_path", 45, 53, @@ -96,6 +96,7 @@ make_path (cairo_t *cr) static cairo_test_status_t draw (cairo_t *cr, int width, int height) { + const cairo_test_context_t *ctx = cairo_test_get_context (cr); cairo_path_t *path; cairo_t *cr_error; @@ -105,7 +106,8 @@ draw (cairo_t *cr, int width, int height) path = cairo_copy_path (cr_error); if (path->status == CAIRO_STATUS_SUCCESS || path->status != cairo_status (cr_error)) { - cairo_test_log ("Error: cairo_copy_path returned status of %s rather than propagating %s\n", + cairo_test_log (ctx, + "Error: cairo_copy_path returned status of %s rather than propagating %s\n", cairo_status_to_string (path->status), cairo_status_to_string (cairo_status (cr_error))); cairo_path_destroy (path); @@ -116,7 +118,8 @@ draw (cairo_t *cr, int width, int height) path = cairo_copy_path_flat (cr_error); if (path->status == CAIRO_STATUS_SUCCESS || path->status != cairo_status (cr_error)) { - cairo_test_log ("Error: cairo_copy_path_flat returned status of %s rather than propagating %s\n", + cairo_test_log (ctx, + "Error: cairo_copy_path_flat returned status of %s rather than propagating %s\n", cairo_status_to_string (path->status), cairo_status_to_string (cairo_status (cr_error))); cairo_path_destroy (path); @@ -125,18 +128,20 @@ draw (cairo_t *cr, int width, int height) cairo_path_destroy (path); cairo_destroy (cr_error); - + /* first check that we can copy an empty path */ cairo_new_path (cr); path = cairo_copy_path (cr); if (path->status != CAIRO_STATUS_SUCCESS) { - cairo_test_log ("Error: cairo_copy_path returned status of %s\n", + cairo_test_log (ctx, + "Error: cairo_copy_path returned status of %s\n", cairo_status_to_string (path->status)); cairo_path_destroy (path); return CAIRO_TEST_FAILURE; } if (path->num_data != 0) { - cairo_test_log ("Error: cairo_copy_path did not copy an empty path, returned path contains %d elements\n", + cairo_test_log (ctx, + "Error: cairo_copy_path did not copy an empty path, returned path contains %d elements\n", path->num_data); cairo_path_destroy (path); return CAIRO_TEST_FAILURE; @@ -144,7 +149,8 @@ draw (cairo_t *cr, int width, int height) cairo_append_path (cr, path); cairo_path_destroy (path); if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) { - cairo_test_log ("Error: cairo_append_path failed with a copy of an empty path, returned status of %s\n", + cairo_test_log (ctx, + "Error: cairo_append_path failed with a copy of an empty path, returned status of %s\n", cairo_status_to_string (cairo_status (cr))); return CAIRO_TEST_FAILURE; } @@ -197,51 +203,75 @@ draw (cairo_t *cr, int width, int height) int main (void) { + cairo_test_context_t ctx; cairo_t *cr; cairo_path_data_t data; cairo_path_t path; cairo_surface_t *surface; + cairo_status_t status; + + cairo_test_init (&ctx, "copy-path"); surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1); /* Test a few error cases for cairo_append_path_data */ cr = cairo_create (surface); cairo_append_path (cr, NULL); - if (cairo_status (cr) != CAIRO_STATUS_NULL_POINTER) - return 1; + status = cairo_status (cr); cairo_destroy (cr); + if (status != CAIRO_STATUS_NULL_POINTER) { + cairo_surface_destroy (surface); + cairo_test_fini (&ctx); + return CAIRO_TEST_FAILURE; + } cr = cairo_create (surface); path.status = -1; cairo_append_path (cr, &path); - if (cairo_status (cr) != CAIRO_STATUS_INVALID_STATUS) - return 1; + status = cairo_status (cr); cairo_destroy (cr); + if (status != CAIRO_STATUS_INVALID_STATUS) { + cairo_surface_destroy (surface); + cairo_test_fini (&ctx); + return CAIRO_TEST_FAILURE; + } cr = cairo_create (surface); path.status = CAIRO_STATUS_NO_MEMORY; cairo_append_path (cr, &path); - if (cairo_status (cr) != CAIRO_STATUS_NO_MEMORY) - return 1; + status = cairo_status (cr); cairo_destroy (cr); + if (status != CAIRO_STATUS_NO_MEMORY) { + cairo_surface_destroy (surface); + cairo_test_fini (&ctx); + return CAIRO_TEST_FAILURE; + } cr = cairo_create (surface); path.data = NULL; path.num_data = 0; path.status = CAIRO_STATUS_SUCCESS; cairo_append_path (cr, &path); - if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) - return 1; + status = cairo_status (cr); cairo_destroy (cr); + if (status != CAIRO_STATUS_SUCCESS) { + cairo_surface_destroy (surface); + cairo_test_fini (&ctx); + return CAIRO_TEST_FAILURE; + } cr = cairo_create (surface); path.data = NULL; path.num_data = 1; path.status = CAIRO_STATUS_SUCCESS; cairo_append_path (cr, &path); - if (cairo_status (cr) != CAIRO_STATUS_NULL_POINTER) - return 1; + status = cairo_status (cr); cairo_destroy (cr); + if (status != CAIRO_STATUS_NULL_POINTER) { + cairo_surface_destroy (surface); + cairo_test_fini (&ctx); + return CAIRO_TEST_FAILURE; + } cr = cairo_create (surface); /* Intentionally insert bogus header.length value (otherwise would be 2) */ @@ -250,19 +280,28 @@ main (void) path.data = &data; path.num_data = 1; cairo_append_path (cr, &path); - if (cairo_status (cr) != CAIRO_STATUS_INVALID_PATH_DATA) - return 1; + status = cairo_status (cr); cairo_destroy (cr); + if (status != CAIRO_STATUS_INVALID_PATH_DATA) { + cairo_surface_destroy (surface); + cairo_test_fini (&ctx); + return CAIRO_TEST_FAILURE; + } /* And test the degnerate case */ cr = cairo_create (surface); path.num_data = 0; cairo_append_path (cr, &path); - if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) - return 1; + status = cairo_status (cr); cairo_destroy (cr); + if (status != CAIRO_STATUS_SUCCESS) { + cairo_surface_destroy (surface); + cairo_test_fini (&ctx); + return CAIRO_TEST_FAILURE; + } cairo_surface_destroy (surface); + cairo_test_fini (&ctx); return cairo_test (&test); } |