test/main.c

changeset 27
22644e2572bc
parent 26
59f147baea31
child 28
1666cbeb1db8
     1.1 --- a/test/main.c	Sat Feb 18 15:50:43 2012 +0100
     1.2 +++ b/test/main.c	Sat Feb 18 18:36:30 2012 +0100
     1.3 @@ -31,10 +31,26 @@
     1.4  
     1.5  #include "ucx/test.h"
     1.6  
     1.7 +#include "main.h"
     1.8 +
     1.9  #include "list_tests.h"
    1.10 +#include "dlist_tests.h"
    1.11 +
    1.12  #include "mpool_tests.h"
    1.13  #include "map_tests.h"
    1.14  
    1.15 +int cmp_string(void* o1, void* o2, void* data) {
    1.16 +    return strcmp((char*)o1, (char*)o2);
    1.17 +}
    1.18 +
    1.19 +void* copy_string(void* e, void* data) {
    1.20 +    char *str = (char*) e;
    1.21 +    size_t n = 1+strlen(str);
    1.22 +    char *cpy = (char*) malloc(n);
    1.23 +    memcpy(cpy, str, n);
    1.24 +    return cpy;
    1.25 +}
    1.26 +
    1.27  UCX_TEST_BEGIN(testTestSuitePositive) {
    1.28      UCX_TEST_ASSERT(2*2 == 4, "the test framework fails")
    1.29      UCX_TEST_END
    1.30 @@ -48,22 +64,39 @@
    1.31  int main(int argc, char **argv) {
    1.32      printf("UCX Tests\n---------\n");
    1.33  
    1.34 -    printf("\nUcxTestSuite Tests\n");
    1.35 +    printf("\nUcxTestSuite Tests (1 failure is intended!)\n");
    1.36      UcxTestSuite* suite = ucx_test_suite_new();
    1.37      ucx_test_register(suite, testTestSuitePositive);
    1.38      ucx_test_register(suite, testTestSuiteNegative);
    1.39      ucx_test_run(suite, stdout);
    1.40      if (suite->failure == 1 && suite->success == 1) {
    1.41          ucx_test_suite_free(suite);
    1.42 -    
    1.43 +
    1.44 +        suite = ucx_test_suite_new();
    1.45 +        /* UcxList Tests */
    1.46 +        ucx_test_register(suite, test_ucx_list_append);
    1.47 +        ucx_test_register(suite, test_ucx_list_prepend);
    1.48 +        ucx_test_register(suite, test_ucx_list_equals);
    1.49 +        ucx_test_register(suite, test_ucx_list_concat);
    1.50 +        ucx_test_register(suite, test_ucx_list_size);
    1.51 +        ucx_test_register(suite, test_ucx_list_last);
    1.52 +        ucx_test_register(suite, test_ucx_list_get);
    1.53 +        ucx_test_register(suite, test_ucx_list_remove);
    1.54 +        ucx_test_register(suite, test_ucx_list_clone);
    1.55 +        
    1.56 +        /* UcxDlist Tests */
    1.57 +        ucx_test_register(suite, test_ucx_dlist_append);
    1.58 +        ucx_test_register(suite, test_ucx_dlist_prepend);
    1.59 +        ucx_test_register(suite, test_ucx_dlist_equals);
    1.60 +        ucx_test_register(suite, test_ucx_dlist_concat);
    1.61 +        ucx_test_register(suite, test_ucx_dlist_size);
    1.62 +        ucx_test_register(suite, test_ucx_dlist_first);
    1.63 +        ucx_test_register(suite, test_ucx_dlist_last);
    1.64 +        ucx_test_register(suite, test_ucx_dlist_get);
    1.65 +        ucx_test_register(suite, test_ucx_dlist_remove);
    1.66 +        ucx_test_register(suite, test_ucx_dlist_clone);
    1.67 +
    1.68          /* TODO: replace these tests with "real" tests */
    1.69 -        printf("\nUcxDlist Tests\n");
    1.70 -        if(dlist_tests()) {
    1.71 -            fprintf(stderr, "dlist_tests failed\n");
    1.72 -        }
    1.73 -
    1.74 -        printf("\nUcxList Tests\n   Assumed to be correct\n");
    1.75 -
    1.76          printf("\nUcxMemPool Tests\n");
    1.77          if(mpool_tests()) {
    1.78              fprintf(stderr, "mpool_tests failed\n");
    1.79 @@ -74,6 +107,9 @@
    1.80              fprintf(stderr, "map_tests failed\n");
    1.81          }
    1.82          
    1.83 +        ucx_test_run(suite, stdout);
    1.84 +        ucx_test_suite_free(suite);
    1.85 +        
    1.86          return EXIT_SUCCESS;
    1.87      } else {
    1.88          ucx_test_suite_free(suite);

mercurial