fixed execution order of tests + added test for sstrtrim

Wed, 27 Feb 2013 14:04:45 +0100

author
Mike Becker <universe@uap-core.de>
date
Wed, 27 Feb 2013 14:04:45 +0100
changeset 97
499e1b465d77
parent 96
fbbff331beba
child 98
0a752853f792

fixed execution order of tests + added test for sstrtrim

test/main.c file | annotate | diff | comparison | revisions
test/string_tests.c file | annotate | diff | comparison | revisions
test/string_tests.h file | annotate | diff | comparison | revisions
ucx/string.c file | annotate | diff | comparison | revisions
ucx/test.c file | annotate | diff | comparison | revisions
--- a/test/main.c	Wed Feb 27 13:53:28 2013 +0100
+++ b/test/main.c	Wed Feb 27 14:04:45 2013 +0100
@@ -111,6 +111,12 @@
 
         printf("\nLibrary function tests\n");
         suite = ucx_test_suite_new();
+        /* sstring Tests */
+        ucx_test_register(suite, test_sstr);
+        ucx_test_register(suite, test_sstr_len_cat);
+        ucx_test_register(suite, test_sstrsplit);
+        ucx_test_register(suite, test_sstrtrim);
+        
         /* UcxLogger Tests */
         ucx_test_register(suite, test_ucx_logger_log);
 
@@ -162,11 +168,6 @@
         ucx_test_register(suite, test_ucx_map_store_load_with_mempool);
         ucx_test_register(suite, test_ucx_map_clone);
         ucx_test_register(suite, test_ucx_map_rehash);
-        
-        /* sstring Tests */
-        ucx_test_register(suite, test_sstr);
-        ucx_test_register(suite, test_sstr_len_cat);
-        ucx_test_register(suite, test_sstrsplit);
 
         /* UcxMemstream Tests */
         ucx_test_register(suite, test_ucx_buffer_seektell);
--- a/test/string_tests.c	Wed Feb 27 13:53:28 2013 +0100
+++ b/test/string_tests.c	Wed Feb 27 14:04:45 2013 +0100
@@ -174,3 +174,10 @@
 
     UCX_TEST_END
 }
+
+UCX_TEST_IMPLEMENT(test_sstrtrim) {
+    sstr_t test = sstrtrim(sstr("  ein test   "));
+    UCX_TEST_BEGIN
+    UCX_TEST_ASSERT(strncmp(test.ptr, "ein test", test.length) == 0, "failed");
+    UCX_TEST_END
+}
--- a/test/string_tests.h	Wed Feb 27 13:53:28 2013 +0100
+++ b/test/string_tests.h	Wed Feb 27 14:04:45 2013 +0100
@@ -15,6 +15,7 @@
 UCX_TEST_DECLARE(test_sstr);
 UCX_TEST_DECLARE(test_sstr_len_cat);
 UCX_TEST_DECLARE(test_sstrsplit);
+UCX_TEST_DECLARE(test_sstrtrim);
 
 #ifdef	__cplusplus
 }
--- a/ucx/string.c	Wed Feb 27 13:53:28 2013 +0100
+++ b/ucx/string.c	Wed Feb 27 14:04:45 2013 +0100
@@ -176,7 +176,7 @@
 
 sstr_t sstrtrim(sstr_t string) {
     sstr_t newstr = string;
-    int i;
+    size_t i;
     for(i=0;i<string.length;i++) {
         char c = string.ptr[i];
         if(c > 32) {
--- a/ucx/test.c	Wed Feb 27 13:53:28 2013 +0100
+++ b/ucx/test.c	Wed Feb 27 14:04:45 2013 +0100
@@ -29,11 +29,16 @@
 
 int ucx_test_register(UcxTestSuite* suite, UcxTest test) {
     if (suite->tests) {
-        UcxTestList *list = (UcxTestList*) malloc(sizeof(UcxTestList));
-        if (list) {
-            list->test = test;
-            list->next = suite->tests;
-            suite->tests = list;
+        UcxTestList *newelem = (UcxTestList*) malloc(sizeof(UcxTestList));
+        if (newelem) {
+            newelem->test = test;
+            newelem->next = NULL;
+            
+            UcxTestList *last = suite->tests;
+            while (last->next) {
+                last = last->next;
+            }
+            last->next = newelem;
             
             return EXIT_SUCCESS;
         } else {

mercurial