[PATCH 11/12] test: Use cairo_test_list_t for the main test list

Andrea Canciani <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
Instead of embedding the pointer in the test structure, consistently
use the cairo_test_list_t structure for test lists.

This cleans up the code as the reverse-list operation can be reused.

Moreover this makes the code clearer, because each test list is now
independent and has no way to know about other test lists.
---
 test/cairo-test-runner.c |   24 ++++++------------------
 test/cairo-test.h        |    3 +--
 2 files changed, 7 insertions(+), 20 deletions(-)

diff --git a/test/cairo-test-runner.c b/test/cairo-test-runner.c
index 6a1fc98..b0e598d 100644
--- a/test/cairo-test-runner.c
+++ b/test/cairo-test-runner.c
@@ -107,7 +107,7 @@ typedef enum {
     GT
 } cairo_test_compare_op_t;
 
-static cairo_test_t *tests;
+static cairo_test_list_t *tests;
 
 static void CAIRO_BOILERPLATE_PRINTF_FORMAT(2,3)
 _log (cairo_test_context_t *ctx,
@@ -125,18 +125,6 @@ _log (cairo_test_context_t *ctx,
     va_end (ap);
 }
 
-static void
-_tests_reverse (void)
-{
-    cairo_test_t *list, *next;
-
-    for (list = tests, tests = NULL; list != NULL; list = next) {
-	next = list->next;
-	list->next = tests;
-	tests = list;
-    }
-}
-
 static cairo_test_list_t *
 _list_prepend (cairo_test_list_t *head, const cairo_test_t *test)
 {
@@ -709,7 +697,7 @@ int
 main (int argc, char **argv)
 {
     cairo_test_runner_t runner;
-    cairo_test_t *test;
+    cairo_test_list_t *test_list;
     cairo_test_status_t *target_status;
     unsigned int n, m;
     char targets[4096];
@@ -723,7 +711,7 @@ main (int argc, char **argv)
 #endif
 
     _cairo_test_runner_register_tests ();
-    _tests_reverse ();
+    tests = _list_reverse (tests);
 
     memset (&runner, 0, sizeof (runner));
     runner.num_device_offsets = 1;
@@ -768,7 +756,8 @@ main (int argc, char **argv)
 				 runner.base.num_targets);
     }
 
-    for (test = tests; test != NULL; test = test->next) {
+    for (test_list = tests; test_list != NULL; test_list = test_list->next) {
+	const cairo_test_t *test = test_list->test;
 	cairo_test_context_t ctx;
 	cairo_test_status_t status;
 	cairo_bool_t failed = FALSE, xfailed = FALSE, error = FALSE, crashed = FALSE, skipped = TRUE;
@@ -1097,6 +1086,5 @@ main (int argc, char **argv)
 void
 cairo_test_register (cairo_test_t *test)
 {
-    test->next = tests;
-    tests = test;
+    tests = _list_prepend (tests, test);
 }
diff --git a/test/cairo-test.h b/test/cairo-test.h
index 5e342a4..d41cd29 100644
--- a/test/cairo-test.h
+++ b/test/cairo-test.h
@@ -153,7 +153,6 @@ typedef cairo_test_status_t
 (cairo_test_draw_function_t) (cairo_t *cr, int width, int height);
 
 struct _cairo_test {
-    struct _cairo_test *next;
     const char *name;
     const char *description;
     const char *keywords;
@@ -194,7 +193,7 @@ struct _cairo_test {
 void _register_##name (void); \
 void _register_##name (void) { \
     static cairo_test_t test = { \
-	NULL, #name, description, \
+	#name, description, \
 	keywords, requirements, \
 	width, height, \
 	preamble, draw \
-- 
1.7.5.4

--
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.