test/list_tests.c

changeset 33
9c219a62070d
parent 30
23bb65cbf7a4
child 35
fdabd1240b69
     1.1 --- a/test/list_tests.c	Thu May 31 09:18:26 2012 +0200
     1.2 +++ b/test/list_tests.c	Thu May 31 12:51:22 2012 +0200
     1.3 @@ -4,35 +4,34 @@
     1.4  
     1.5  #include "list_tests.h"
     1.6  
     1.7 -UCX_TEST_BEGIN(test_ucx_list_append) {
     1.8 +UCX_TEST_IMPLEMENT(test_ucx_list_append) {
     1.9      UcxList *list = ucx_list_append(NULL, "Hello");
    1.10 -    
    1.11 +    UCX_TEST_BEGIN
    1.12      UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed")
    1.13      
    1.14      list = ucx_list_append(list, " World!");
    1.15      
    1.16      UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed")
    1.17      UCX_TEST_ASSERT(list->next->next == NULL, "failed")
    1.18 -    
    1.19 +
    1.20 +    UCX_TEST_END
    1.21      ucx_list_free(list);
    1.22 -    
    1.23 -    UCX_TEST_END
    1.24  }
    1.25  
    1.26 -UCX_TEST_BEGIN(test_ucx_list_prepend) {
    1.27 +UCX_TEST_IMPLEMENT(test_ucx_list_prepend) {
    1.28      UcxList *list = ucx_list_prepend(NULL, " World!");
    1.29 +    UCX_TEST_BEGIN
    1.30      list = ucx_list_prepend(list, "Hello");
    1.31      
    1.32      UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed")
    1.33      UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed")
    1.34      UCX_TEST_ASSERT(list->next->next == NULL, "failed")
    1.35      
    1.36 +    UCX_TEST_END
    1.37      ucx_list_free(list);
    1.38 -    
    1.39 -    UCX_TEST_END
    1.40  }
    1.41  
    1.42 -UCX_TEST_BEGIN(test_ucx_list_equals) {
    1.43 +UCX_TEST_IMPLEMENT(test_ucx_list_equals) {
    1.44      UcxList *list = ucx_list_append(NULL, "Hello");
    1.45      list = ucx_list_append(list, " World!");
    1.46      UcxList *list2 = ucx_list_prepend(NULL, " World!");
    1.47 @@ -40,33 +39,37 @@
    1.48      UcxList *list3 = ucx_list_prepend(NULL, " Welt!");
    1.49      list3 = ucx_list_prepend(list3, "Hallo");
    1.50      
    1.51 +    UCX_TEST_BEGIN
    1.52      UCX_TEST_ASSERT(ucx_list_equals(list, list2, cmp_string, NULL), "failed")
    1.53      UCX_TEST_ASSERT(!ucx_list_equals(list, list3, cmp_string, NULL), "failed")
    1.54 +    UCX_TEST_END
    1.55      
    1.56      ucx_list_free(list3);
    1.57      ucx_list_free(list2);
    1.58      ucx_list_free(list);
    1.59 -    
    1.60 -    UCX_TEST_END
    1.61  }
    1.62  
    1.63 -UCX_TEST_BEGIN(test_ucx_list_concat) {
    1.64 +UCX_TEST_IMPLEMENT(test_ucx_list_concat) {
    1.65      UcxList *list = ucx_list_append(NULL, "Hello");
    1.66      UcxList *list2 = ucx_list_prepend(NULL, " World!");
    1.67      
    1.68      list = ucx_list_concat(list, list2);
    1.69 +    UCX_TEST_BEGIN
    1.70      
    1.71      UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed")
    1.72      UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed")
    1.73      UCX_TEST_ASSERT(list->next->next == NULL, "failed")
    1.74      
    1.75 +    UCX_TEST_END
    1.76 +    if (list->next == NULL) {
    1.77 +        ucx_list_free(list2);
    1.78 +    }
    1.79      ucx_list_free(list);
    1.80 -    
    1.81 -    UCX_TEST_END
    1.82  }
    1.83  
    1.84 -UCX_TEST_BEGIN(test_ucx_list_size) {
    1.85 +UCX_TEST_IMPLEMENT(test_ucx_list_size) {
    1.86      UcxList *list = ucx_list_append(NULL, "This ");
    1.87 +    UCX_TEST_BEGIN
    1.88      list = ucx_list_append(list, "list ");
    1.89      list = ucx_list_append(list, "has ");
    1.90      list = ucx_list_append(list, "size ");
    1.91 @@ -74,13 +77,13 @@
    1.92      
    1.93      UCX_TEST_ASSERT(ucx_list_size(list) == 5, "failed");
    1.94      
    1.95 +    UCX_TEST_END
    1.96      ucx_list_free(list);
    1.97 -    
    1.98 -    UCX_TEST_END
    1.99  }
   1.100  
   1.101 -UCX_TEST_BEGIN(test_ucx_list_last) {
   1.102 +UCX_TEST_IMPLEMENT(test_ucx_list_last) {
   1.103      UcxList *list = ucx_list_append(NULL, "Find ");
   1.104 +    UCX_TEST_BEGIN
   1.105      list = ucx_list_append(list, "the ");
   1.106      list = ucx_list_append(list, "last!");
   1.107      
   1.108 @@ -88,13 +91,14 @@
   1.109      
   1.110      UCX_TEST_ASSERT(strncmp(last, "last!", 5) == 0, "failed");
   1.111      
   1.112 +    UCX_TEST_END
   1.113      ucx_list_free(list);
   1.114      
   1.115 -    UCX_TEST_END
   1.116  }
   1.117  
   1.118 -UCX_TEST_BEGIN(test_ucx_list_get) {
   1.119 +UCX_TEST_IMPLEMENT(test_ucx_list_get) {
   1.120      UcxList *list = ucx_list_append(NULL, "Find ");
   1.121 +    UCX_TEST_BEGIN
   1.122      list = ucx_list_append(list, "the ");
   1.123      list = ucx_list_append(list, "mid!");
   1.124      
   1.125 @@ -102,13 +106,13 @@
   1.126      
   1.127      UCX_TEST_ASSERT(strncmp(mid, "the ", 4) == 0, "failed");
   1.128      
   1.129 +    UCX_TEST_END
   1.130      ucx_list_free(list);
   1.131 -    
   1.132 -    UCX_TEST_END
   1.133  }
   1.134  
   1.135 -UCX_TEST_BEGIN(test_ucx_list_remove) {
   1.136 +UCX_TEST_IMPLEMENT(test_ucx_list_remove) {
   1.137      UcxList *list = ucx_list_append(NULL, "Hello");
   1.138 +    UCX_TEST_BEGIN
   1.139      list = ucx_list_append(list, " fucking");
   1.140      list = ucx_list_append(list, " World!");
   1.141      
   1.142 @@ -117,13 +121,12 @@
   1.143      UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed")
   1.144      UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed")
   1.145      UCX_TEST_ASSERT(list->next->next == NULL, "failed")
   1.146 +    UCX_TEST_END
   1.147      
   1.148      ucx_list_free(list);
   1.149 -    
   1.150 -    UCX_TEST_END
   1.151  }
   1.152  
   1.153 -UCX_TEST_BEGIN(test_ucx_list_clone) {
   1.154 +UCX_TEST_IMPLEMENT(test_ucx_list_clone) {
   1.155     
   1.156      char *hello = (char*)malloc(6);
   1.157      char *world = (char*)malloc(8);
   1.158 @@ -135,11 +138,13 @@
   1.159      list = ucx_list_append(list, world);
   1.160      
   1.161      UcxList *copy = ucx_list_clone(list, copy_string, NULL);
   1.162 +    UCX_TEST_BEGIN
   1.163  
   1.164      UCX_TEST_ASSERT(ucx_list_equals(list, copy, cmp_string, NULL), "failed")
   1.165      UCX_TEST_ASSERT(hello != copy->data, "first element is no copy")
   1.166      UCX_TEST_ASSERT(world != copy->next->data, "second element is no copy")
   1.167 -            
   1.168 +
   1.169 +    UCX_TEST_END
   1.170      free(copy->next->data);
   1.171      free(copy->data);
   1.172  
   1.173 @@ -147,6 +152,4 @@
   1.174      free(hello);
   1.175      ucx_list_free(list);
   1.176      ucx_list_free(copy);
   1.177 -    
   1.178 -    UCX_TEST_END
   1.179  }

mercurial