[test] Export a function to check whether a target is enabled.

Allow individuals tests to check whether a test target is enabled -
useful for those tests that circumvent cairo_test() and perform
feature testing.
This commit is contained in:
Chris Wilson 2008-01-10 13:04:52 +00:00
parent 436c0c8be2
commit f85a4aec1f
12 changed files with 133 additions and 63 deletions

View file

@ -1031,3 +1031,22 @@ cairo_test_paint_checkered (cairo_t *cr)
return status;
}
cairo_bool_t
cairo_test_is_target_enabled (const cairo_test_context_t *ctx, const char *target)
{
size_t i;
for (i = 0; i < ctx->num_targets; i++) {
const cairo_boilerplate_target_t *t = ctx->targets_to_test[i];
if (strcmp (t->name, target) == 0) {
/* XXX ask the target whether is it possible to run?
* e.g. the xlib backend could check whether it is able to connect
* to the Display.
*/
return TRUE;
}
}
return FALSE;
}

View file

@ -176,6 +176,10 @@ cairo_test_paint_checkered (cairo_t *cr);
#define CAIRO_TEST_DOUBLE_EQUALS(a,b) (fabs((a)-(b)) < 0.00001)
cairo_bool_t
cairo_test_is_target_enabled (const cairo_test_context_t *ctx,
const char *target);
CAIRO_END_DECLS
#endif

View file

@ -243,36 +243,42 @@ main (void)
cairo_test_init (&ctx, test_name);
#if CAIRO_HAS_PS_SURFACE
test_status = test_surface (&ctx, "ps", "create-for-stream.ps",
cairo_ps_surface_create,
cairo_ps_surface_create_for_stream);
cairo_test_log (&ctx, "TEST: %s TARGET: %s RESULT: %s\n",
test_name, "ps",
test_status ? "FAIL" : "PASS");
if (status == CAIRO_TEST_SUCCESS)
status = test_status;
if (cairo_test_is_target_enabled (&ctx, "ps")) {
test_status = test_surface (&ctx, "ps", "create-for-stream.ps",
cairo_ps_surface_create,
cairo_ps_surface_create_for_stream);
cairo_test_log (&ctx, "TEST: %s TARGET: %s RESULT: %s\n",
test_name, "ps",
test_status ? "FAIL" : "PASS");
if (status == CAIRO_TEST_SUCCESS)
status = test_status;
}
#endif
#if CAIRO_HAS_PDF_SURFACE
test_status = test_surface (&ctx, "pdf", "create-for-stream.pdf",
cairo_pdf_surface_create,
cairo_pdf_surface_create_for_stream);
cairo_test_log (&ctx, "TEST: %s TARGET: %s RESULT: %s\n",
test_name, "pdf",
test_status ? "FAIL" : "PASS");
if (status == CAIRO_TEST_SUCCESS)
status = test_status;
if (cairo_test_is_target_enabled (&ctx, "pdf")) {
test_status = test_surface (&ctx, "pdf", "create-for-stream.pdf",
cairo_pdf_surface_create,
cairo_pdf_surface_create_for_stream);
cairo_test_log (&ctx, "TEST: %s TARGET: %s RESULT: %s\n",
test_name, "pdf",
test_status ? "FAIL" : "PASS");
if (status == CAIRO_TEST_SUCCESS)
status = test_status;
}
#endif
#if CAIRO_HAS_SVG_SURFACE
test_status = test_surface (&ctx, "svg", "create-for-stream.svg",
cairo_svg_surface_create,
cairo_svg_surface_create_for_stream);
cairo_test_log (&ctx, "TEST: %s TARGET: %s RESULT: %s\n",
test_name, "svg",
test_status ? "FAIL" : "PASS");
if (status == CAIRO_TEST_SUCCESS)
status = test_status;
if (cairo_test_is_target_enabled (&ctx, "svg")) {
test_status = test_surface (&ctx, "svg", "create-for-stream.svg",
cairo_svg_surface_create,
cairo_svg_surface_create_for_stream);
cairo_test_log (&ctx, "TEST: %s TARGET: %s RESULT: %s\n",
test_name, "svg",
test_status ? "FAIL" : "PASS");
if (status == CAIRO_TEST_SUCCESS)
status = test_status;
}
#endif
cairo_test_fini (&ctx);

View file

@ -89,7 +89,6 @@ int
main (void)
{
cairo_test_context_t ctx;
cairo_surface_t *surface = NULL;
cairo_t *cr;
cairo_status_t status;
cairo_test_status_t ret = CAIRO_TEST_SUCCESS;
@ -102,27 +101,37 @@ main (void)
cairo_test_init (&ctx, "fallback-resolution");
for (backend=0; backend < NUM_BACKENDS; backend++) {
cairo_surface_t *surface = NULL;
/* Create backend-specific surface and force image fallbacks. */
switch (backend) {
case PDF:
surface = cairo_pdf_surface_create (backend_filename[backend],
SIZE, SIZE);
cairo_boilerplate_pdf_surface_force_fallbacks (surface);
if (cairo_test_is_target_enabled (&ctx, "pdf")) {
surface = cairo_pdf_surface_create (backend_filename[backend],
SIZE, SIZE);
cairo_boilerplate_pdf_surface_force_fallbacks (surface);
}
break;
case PS:
surface = cairo_ps_surface_create (backend_filename[backend],
SIZE, SIZE);
cairo_boilerplate_ps_surface_force_fallbacks (surface);
if (cairo_test_is_target_enabled (&ctx, "ps")) {
surface = cairo_ps_surface_create (backend_filename[backend],
SIZE, SIZE);
cairo_boilerplate_ps_surface_force_fallbacks (surface);
}
break;
case SVG:
surface = cairo_svg_surface_create (backend_filename[backend],
SIZE, SIZE);
cairo_boilerplate_svg_surface_force_fallbacks (surface);
cairo_svg_surface_restrict_to_version (surface, CAIRO_SVG_VERSION_1_2);
if (cairo_test_is_target_enabled (&ctx, "svg")) {
surface = cairo_svg_surface_create (backend_filename[backend],
SIZE, SIZE);
cairo_boilerplate_svg_surface_force_fallbacks (surface);
cairo_svg_surface_restrict_to_version (surface, CAIRO_SVG_VERSION_1_2);
}
break;
}
if (surface == NULL)
continue;
cr = cairo_create (surface);
cairo_set_tolerance (cr, 3.0);

View file

@ -42,6 +42,10 @@ main (void)
int screen;
cairo_test_init (&ctx, "get-xrender-format");
if (! cairo_test_is_target_enabled (&ctx, "xlib")) {
cairo_test_fini (&ctx);
return CAIRO_TEST_UNTESTED;
}
dpy = XOpenDisplay (NULL);
if (! dpy) {

View file

@ -139,41 +139,45 @@ main (void)
cairo_test_init (&ctx, "multi-page");
#if CAIRO_HAS_PS_SURFACE
filename = "multi-page.ps";
if (cairo_test_is_target_enabled (&ctx, "ps")) {
filename = "multi-page.ps";
surface = cairo_ps_surface_create (filename,
WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
status = cairo_surface_status (surface);
if (status) {
cairo_test_log (&ctx, "Failed to create ps surface for file %s: %s\n",
filename, cairo_status_to_string (status));
result = CAIRO_TEST_FAILURE;
surface = cairo_ps_surface_create (filename,
WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
status = cairo_surface_status (surface);
if (status) {
cairo_test_log (&ctx, "Failed to create ps surface for file %s: %s\n",
filename, cairo_status_to_string (status));
result = CAIRO_TEST_FAILURE;
}
draw_some_pages (surface);
cairo_surface_destroy (surface);
printf ("multi-page: Please check %s to ensure it looks happy.\n", filename);
}
draw_some_pages (surface);
cairo_surface_destroy (surface);
printf ("multi-page: Please check %s to ensure it looks happy.\n", filename);
#endif
#if CAIRO_HAS_PDF_SURFACE
filename = "multi-page.pdf";
if (cairo_test_is_target_enabled (&ctx, "pdf")) {
filename = "multi-page.pdf";
surface = cairo_pdf_surface_create (filename,
WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
status = cairo_surface_status (surface);
if (status) {
cairo_test_log (&ctx, "Failed to create pdf surface for file %s: %s\n",
filename, cairo_status_to_string (status));
result = CAIRO_TEST_FAILURE;
surface = cairo_pdf_surface_create (filename,
WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
status = cairo_surface_status (surface);
if (status) {
cairo_test_log (&ctx, "Failed to create pdf surface for file %s: %s\n",
filename, cairo_status_to_string (status));
result = CAIRO_TEST_FAILURE;
}
draw_some_pages (surface);
cairo_surface_destroy (surface);
printf ("multi-page: Please check %s to ensure it looks happy.\n", filename);
}
draw_some_pages (surface);
cairo_surface_destroy (surface);
printf ("multi-page: Please check %s to ensure it looks happy.\n", filename);
#endif
cairo_test_fini (&ctx);

View file

@ -94,6 +94,10 @@ main (void)
size_t i;
cairo_test_init (&ctx, "pdf-features");
if (! cairo_test_is_target_enabled (&ctx, "pdf")) {
cairo_test_fini (&ctx);
return CAIRO_TEST_UNTESTED;
}
filename = "pdf-features.pdf";

View file

@ -98,6 +98,10 @@ main (void)
char dsc[255];
cairo_test_init (&ctx, "ps-features");
if (! cairo_test_is_target_enabled (&ctx, "ps")) {
cairo_test_fini (&ctx);
return CAIRO_TEST_UNTESTED;
}
filename = "ps-features.ps";

View file

@ -112,6 +112,10 @@ main (void)
cairo_surface_t *surface;
cairo_test_init (&ctx, "svg-clip");
if (! cairo_test_is_target_enabled (&ctx, "svg")) {
cairo_test_fini (&ctx);
return CAIRO_TEST_UNTESTED;
}
surface = cairo_svg_surface_create (filename,
WIDTH_IN_POINTS, HEIGHT_IN_POINTS);

View file

@ -95,6 +95,10 @@ main (void)
cairo_surface_t *surface;
cairo_test_init (&ctx, "svg-surface");
if (! cairo_test_is_target_enabled (&ctx, "svg")) {
cairo_test_fini (&ctx);
return CAIRO_TEST_UNTESTED;
}
surface = cairo_svg_surface_create (filename,
WIDTH_IN_POINTS, HEIGHT_IN_POINTS);

View file

@ -213,6 +213,10 @@ main (void)
cairo_test_status_t result = CAIRO_TEST_SUCCESS;
cairo_test_init (&ctx, "xlib-expose-event");
if (! cairo_test_is_target_enabled (&ctx, "xlib")) {
cairo_test_fini (&ctx);
return CAIRO_TEST_UNTESTED;
}
dpy = XOpenDisplay (NULL);
if (dpy == NULL) {

View file

@ -303,6 +303,10 @@ main (void)
int stride;
cairo_test_init (&ctx, "xlib-surface");
if (! cairo_test_is_target_enabled (&ctx, "xlib")) {
cairo_test_fini (&ctx);
return CAIRO_TEST_UNTESTED;
}
dpy = XOpenDisplay (NULL);
if (!dpy) {