Wed, 27 Feb 2013 14:04:45 +0100
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 |
1.1 --- a/test/main.c Wed Feb 27 13:53:28 2013 +0100 1.2 +++ b/test/main.c Wed Feb 27 14:04:45 2013 +0100 1.3 @@ -111,6 +111,12 @@ 1.4 1.5 printf("\nLibrary function tests\n"); 1.6 suite = ucx_test_suite_new(); 1.7 + /* sstring Tests */ 1.8 + ucx_test_register(suite, test_sstr); 1.9 + ucx_test_register(suite, test_sstr_len_cat); 1.10 + ucx_test_register(suite, test_sstrsplit); 1.11 + ucx_test_register(suite, test_sstrtrim); 1.12 + 1.13 /* UcxLogger Tests */ 1.14 ucx_test_register(suite, test_ucx_logger_log); 1.15 1.16 @@ -162,11 +168,6 @@ 1.17 ucx_test_register(suite, test_ucx_map_store_load_with_mempool); 1.18 ucx_test_register(suite, test_ucx_map_clone); 1.19 ucx_test_register(suite, test_ucx_map_rehash); 1.20 - 1.21 - /* sstring Tests */ 1.22 - ucx_test_register(suite, test_sstr); 1.23 - ucx_test_register(suite, test_sstr_len_cat); 1.24 - ucx_test_register(suite, test_sstrsplit); 1.25 1.26 /* UcxMemstream Tests */ 1.27 ucx_test_register(suite, test_ucx_buffer_seektell);
2.1 --- a/test/string_tests.c Wed Feb 27 13:53:28 2013 +0100 2.2 +++ b/test/string_tests.c Wed Feb 27 14:04:45 2013 +0100 2.3 @@ -174,3 +174,10 @@ 2.4 2.5 UCX_TEST_END 2.6 } 2.7 + 2.8 +UCX_TEST_IMPLEMENT(test_sstrtrim) { 2.9 + sstr_t test = sstrtrim(sstr(" ein test ")); 2.10 + UCX_TEST_BEGIN 2.11 + UCX_TEST_ASSERT(strncmp(test.ptr, "ein test", test.length) == 0, "failed"); 2.12 + UCX_TEST_END 2.13 +}
3.1 --- a/test/string_tests.h Wed Feb 27 13:53:28 2013 +0100 3.2 +++ b/test/string_tests.h Wed Feb 27 14:04:45 2013 +0100 3.3 @@ -15,6 +15,7 @@ 3.4 UCX_TEST_DECLARE(test_sstr); 3.5 UCX_TEST_DECLARE(test_sstr_len_cat); 3.6 UCX_TEST_DECLARE(test_sstrsplit); 3.7 +UCX_TEST_DECLARE(test_sstrtrim); 3.8 3.9 #ifdef __cplusplus 3.10 }
4.1 --- a/ucx/string.c Wed Feb 27 13:53:28 2013 +0100 4.2 +++ b/ucx/string.c Wed Feb 27 14:04:45 2013 +0100 4.3 @@ -176,7 +176,7 @@ 4.4 4.5 sstr_t sstrtrim(sstr_t string) { 4.6 sstr_t newstr = string; 4.7 - int i; 4.8 + size_t i; 4.9 for(i=0;i<string.length;i++) { 4.10 char c = string.ptr[i]; 4.11 if(c > 32) {
5.1 --- a/ucx/test.c Wed Feb 27 13:53:28 2013 +0100 5.2 +++ b/ucx/test.c Wed Feb 27 14:04:45 2013 +0100 5.3 @@ -29,11 +29,16 @@ 5.4 5.5 int ucx_test_register(UcxTestSuite* suite, UcxTest test) { 5.6 if (suite->tests) { 5.7 - UcxTestList *list = (UcxTestList*) malloc(sizeof(UcxTestList)); 5.8 - if (list) { 5.9 - list->test = test; 5.10 - list->next = suite->tests; 5.11 - suite->tests = list; 5.12 + UcxTestList *newelem = (UcxTestList*) malloc(sizeof(UcxTestList)); 5.13 + if (newelem) { 5.14 + newelem->test = test; 5.15 + newelem->next = NULL; 5.16 + 5.17 + UcxTestList *last = suite->tests; 5.18 + while (last->next) { 5.19 + last = last->next; 5.20 + } 5.21 + last->next = newelem; 5.22 5.23 return EXIT_SUCCESS; 5.24 } else {