test/main.c

changeset 26
59f147baea31
parent 21
d599fefc7620
child 27
22644e2572bc
--- a/test/main.c	Thu Feb 09 10:40:19 2012 +0100
+++ b/test/main.c	Sat Feb 18 15:50:43 2012 +0100
@@ -29,30 +29,55 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "ucx/test.h"
+
 #include "list_tests.h"
 #include "mpool_tests.h"
 #include "map_tests.h"
 
+UCX_TEST_BEGIN(testTestSuitePositive) {
+    UCX_TEST_ASSERT(2*2 == 4, "the test framework fails")
+    UCX_TEST_END
+}
+
+UCX_TEST_BEGIN(testTestSuiteNegative) {
+    UCX_TEST_ASSERT(2*(-2) == 4, "the test framework works")
+    UCX_TEST_END
+}
+
 int main(int argc, char **argv) {
     printf("UCX Tests\n---------\n");
 
-    printf("\nUcxDlist Tests\n");
-    if(dlist_tests()) {
-        fprintf(stderr, "dlist_tests failed\n");
-    }
+    printf("\nUcxTestSuite Tests\n");
+    UcxTestSuite* suite = ucx_test_suite_new();
+    ucx_test_register(suite, testTestSuitePositive);
+    ucx_test_register(suite, testTestSuiteNegative);
+    ucx_test_run(suite, stdout);
+    if (suite->failure == 1 && suite->success == 1) {
+        ucx_test_suite_free(suite);
+    
+        /* TODO: replace these tests with "real" tests */
+        printf("\nUcxDlist Tests\n");
+        if(dlist_tests()) {
+            fprintf(stderr, "dlist_tests failed\n");
+        }
 
-    printf("\nUcxList Tests\n   Assumed to be correct\n");
+        printf("\nUcxList Tests\n   Assumed to be correct\n");
 
-    printf("\nUcxMemPool Tests\n");
-    if(mpool_tests()) {
-        fprintf(stderr, "mpool_tests failed\n");
-    }
+        printf("\nUcxMemPool Tests\n");
+        if(mpool_tests()) {
+            fprintf(stderr, "mpool_tests failed\n");
+        }
 
-    printf("\nUcxMap Tests\n");
-    if(map_tests()) {
-        fprintf(stderr, "map_tests failed\n");
+        printf("\nUcxMap Tests\n");
+        if(map_tests()) {
+            fprintf(stderr, "map_tests failed\n");
+        }
+        
+        return EXIT_SUCCESS;
+    } else {
+        ucx_test_suite_free(suite);
+        return EXIT_FAILURE;
     }
-    
-    return EXIT_SUCCESS; 
 }
 

mercurial