Fri, 09 Aug 2013 11:32:10 +0200
documented test.h and removed duplicated implement/declare macros for UCX_TEST
--- a/test/buffer_tests.c Fri Aug 09 10:24:02 2013 +0200 +++ b/test/buffer_tests.c Fri Aug 09 11:32:10 2013 +0200 @@ -28,7 +28,7 @@ #include "buffer_tests.h" -UCX_TEST_IMPLEMENT(test_ucx_buffer_seektell) { +UCX_TEST(test_ucx_buffer_seektell) { UcxBuffer *b = ucx_buffer_new(NULL, 32, UCX_BUFFER_DEFAULT); b->size = 16; // less than capacity int r; @@ -67,7 +67,7 @@ ucx_buffer_free(b); } -UCX_TEST_IMPLEMENT(test_ucx_buffer_putc) { +UCX_TEST(test_ucx_buffer_putc) { char *buffer = (char*) malloc(16); memset(buffer, 32, 16); @@ -107,7 +107,7 @@ free(buffer); } -UCX_TEST_IMPLEMENT(test_ucx_buffer_putc_ax) { +UCX_TEST(test_ucx_buffer_putc_ax) { UcxBuffer *b = ucx_buffer_new(NULL, 2, UCX_BUFFER_AUTOEXTEND); UCX_TEST_BEGIN @@ -131,7 +131,7 @@ } -UCX_TEST_IMPLEMENT(test_ucx_buffer_getc) { +UCX_TEST(test_ucx_buffer_getc) { char *buffer = (char*) malloc(16); memset(buffer, 32, 8); for (int i = 8; i < 16 ; i++) { @@ -161,7 +161,7 @@ free(buffer); } -UCX_TEST_IMPLEMENT(test_ucx_buffer_write) { +UCX_TEST(test_ucx_buffer_write) { char *buffer = (char*) malloc(16); memset(buffer, 32, 8); for (int i = 8; i < 16 ; i++) { @@ -203,7 +203,7 @@ free(buffer); } -UCX_TEST_IMPLEMENT(test_ucx_buffer_write_ax) { +UCX_TEST(test_ucx_buffer_write_ax) { char *buffer = (char*) malloc(16); UcxBuffer *b = ucx_buffer_new(buffer, 16, @@ -227,7 +227,7 @@ ucx_buffer_free(b); } -UCX_TEST_IMPLEMENT(test_ucx_buffer_read) { +UCX_TEST(test_ucx_buffer_read) { UcxBuffer *b = ucx_buffer_new(NULL, 8, UCX_BUFFER_AUTOFREE); char buf[32]; @@ -264,7 +264,7 @@ } -UCX_TEST_IMPLEMENT(test_ucx_buffer_extract) { +UCX_TEST(test_ucx_buffer_extract) { char *buffer = (char*) malloc(16); strcpy(buffer, "this is a test!"); @@ -292,7 +292,7 @@ ucx_buffer_free(src); } -UCX_TEST_IMPLEMENT(test_ucx_buffer_generic_copy) { +UCX_TEST(test_ucx_buffer_generic_copy) { UcxBuffer *b1 = ucx_buffer_new(NULL, 64, UCX_BUFFER_DEFAULT); UcxBuffer *b2 = ucx_buffer_new(NULL, 2, UCX_BUFFER_AUTOEXTEND);
--- a/test/buffer_tests.h Fri Aug 09 10:24:02 2013 +0200 +++ b/test/buffer_tests.h Fri Aug 09 11:32:10 2013 +0200 @@ -38,15 +38,15 @@ /* assume open and close to be correct */ -UCX_TEST_DECLARE(test_ucx_buffer_seektell); -UCX_TEST_DECLARE(test_ucx_buffer_putc); -UCX_TEST_DECLARE(test_ucx_buffer_putc_ax); -UCX_TEST_DECLARE(test_ucx_buffer_getc); -UCX_TEST_DECLARE(test_ucx_buffer_write); -UCX_TEST_DECLARE(test_ucx_buffer_write_ax); -UCX_TEST_DECLARE(test_ucx_buffer_read); -UCX_TEST_DECLARE(test_ucx_buffer_extract); -UCX_TEST_DECLARE(test_ucx_buffer_generic_copy); +UCX_TEST(test_ucx_buffer_seektell); +UCX_TEST(test_ucx_buffer_putc); +UCX_TEST(test_ucx_buffer_putc_ax); +UCX_TEST(test_ucx_buffer_getc); +UCX_TEST(test_ucx_buffer_write); +UCX_TEST(test_ucx_buffer_write_ax); +UCX_TEST(test_ucx_buffer_read); +UCX_TEST(test_ucx_buffer_extract); +UCX_TEST(test_ucx_buffer_generic_copy); #ifdef __cplusplus }
--- a/test/list_tests.c Fri Aug 09 10:24:02 2013 +0200 +++ b/test/list_tests.c Fri Aug 09 11:32:10 2013 +0200 @@ -29,7 +29,7 @@ #include "list_tests.h" #include "ucx/utils.h" -UCX_TEST_IMPLEMENT(test_ucx_list_append) { +UCX_TEST(test_ucx_list_append) { UcxList *list = ucx_list_append(NULL, (void*)"Hello"); UCX_TEST_BEGIN @@ -46,7 +46,7 @@ ucx_list_free(list); } -UCX_TEST_IMPLEMENT(test_ucx_list_prepend) { +UCX_TEST(test_ucx_list_prepend) { UcxList *list = ucx_list_prepend(NULL, (void*)" World!"); UCX_TEST_BEGIN @@ -62,7 +62,7 @@ ucx_list_free(list); } -UCX_TEST_IMPLEMENT(test_ucx_list_equals) { +UCX_TEST(test_ucx_list_equals) { UcxList *list = ucx_list_append(NULL, (void*)"Hello"); list = ucx_list_append(list, (void*)" World!"); UcxList *list2 = ucx_list_prepend(NULL, (void*)" World!"); @@ -80,7 +80,7 @@ ucx_list_free(list); } -UCX_TEST_IMPLEMENT(test_ucx_list_concat) { +UCX_TEST(test_ucx_list_concat) { UcxList *list = ucx_list_append(NULL, (void*)"Hello"); UcxList *list2 = ucx_list_prepend(NULL, (void*)" World!"); UCX_TEST_BEGIN @@ -97,7 +97,7 @@ ucx_list_free(list); } -UCX_TEST_IMPLEMENT(test_ucx_list_size) { +UCX_TEST(test_ucx_list_size) { UcxList *list = ucx_list_append(NULL, (void*)"This "); list = ucx_list_append(list, (void*)"list "); list = ucx_list_append(list, (void*)"has "); @@ -112,7 +112,7 @@ ucx_list_free(list); } -UCX_TEST_IMPLEMENT(test_ucx_list_first) { +UCX_TEST(test_ucx_list_first) { UcxList *list = ucx_list_append(NULL, (void*)"Find "); list = ucx_list_append(list, (void*)"the "); list = ucx_list_append(list, (void*)"first!"); @@ -127,7 +127,7 @@ ucx_list_free(list); } -UCX_TEST_IMPLEMENT(test_ucx_list_last) { +UCX_TEST(test_ucx_list_last) { UcxList *list = ucx_list_append(NULL, (void*)"Find "); list = ucx_list_append(list, (void*)"the "); list = ucx_list_append(list, (void*)"last!"); @@ -142,7 +142,7 @@ ucx_list_free(list); } -UCX_TEST_IMPLEMENT(test_ucx_list_get) { +UCX_TEST(test_ucx_list_get) { UcxList *list = ucx_list_append(NULL, (void*)"Find "); list = ucx_list_append(list, (void*)"the "); list = ucx_list_append(list, (void*)"mid!"); @@ -157,7 +157,7 @@ ucx_list_free(list); } -UCX_TEST_IMPLEMENT(test_ucx_list_indexof) { +UCX_TEST(test_ucx_list_indexof) { UcxList *list = ucx_list_append(NULL, (void*)"Find "); list = ucx_list_append(list, (void*)"the "); list = ucx_list_append(list, (void*)"mid!"); @@ -177,7 +177,7 @@ ucx_list_free(list); } -UCX_TEST_IMPLEMENT(test_ucx_list_find) { +UCX_TEST(test_ucx_list_find) { UcxList *l = ucx_list_append(NULL, (void*)"find "); l = ucx_list_append(l, (void*)"some "); l = ucx_list_append(l, (void*)"string!"); @@ -193,7 +193,7 @@ ucx_list_free(l); } -UCX_TEST_IMPLEMENT(test_ucx_list_contains) { +UCX_TEST(test_ucx_list_contains) { UcxList *l = ucx_list_append(NULL, (void*)"Contains "); l = ucx_list_append(l, (void*)"a "); l = ucx_list_append(l, (void*)"string!"); @@ -209,7 +209,7 @@ ucx_list_free(l); } -UCX_TEST_IMPLEMENT(test_ucx_list_remove) { +UCX_TEST(test_ucx_list_remove) { UcxList *list = ucx_list_append(NULL, (void*)"Hello"); list = ucx_list_append(list, (void*)" fucking"); list = ucx_list_append(list, (void*)" World!"); @@ -228,7 +228,7 @@ ucx_list_free(list); } -UCX_TEST_IMPLEMENT(test_ucx_list_clone) { +UCX_TEST(test_ucx_list_clone) { char *hello = (char*)malloc(6); char *world = (char*)malloc(8); @@ -256,7 +256,7 @@ ucx_list_free(copy); } -UCX_TEST_IMPLEMENT(test_ucx_list_sort) { +UCX_TEST(test_ucx_list_sort) { UcxList *list = ucx_list_append(NULL, (void*)"this"); list = ucx_list_append(list, (void*)"is"); list = ucx_list_append(list, (void*)"a");
--- a/test/list_tests.h Fri Aug 09 10:24:02 2013 +0200 +++ b/test/list_tests.h Fri Aug 09 11:32:10 2013 +0200 @@ -43,20 +43,20 @@ * ucx_list_free */ -UCX_TEST_DECLARE(test_ucx_list_append); -UCX_TEST_DECLARE(test_ucx_list_prepend); -UCX_TEST_DECLARE(test_ucx_list_equals); -UCX_TEST_DECLARE(test_ucx_list_concat); -UCX_TEST_DECLARE(test_ucx_list_size); -UCX_TEST_DECLARE(test_ucx_list_first); -UCX_TEST_DECLARE(test_ucx_list_last); -UCX_TEST_DECLARE(test_ucx_list_get); -UCX_TEST_DECLARE(test_ucx_list_indexof); -UCX_TEST_DECLARE(test_ucx_list_find); -UCX_TEST_DECLARE(test_ucx_list_contains); -UCX_TEST_DECLARE(test_ucx_list_remove); -UCX_TEST_DECLARE(test_ucx_list_clone); -UCX_TEST_DECLARE(test_ucx_list_sort); +UCX_TEST(test_ucx_list_append); +UCX_TEST(test_ucx_list_prepend); +UCX_TEST(test_ucx_list_equals); +UCX_TEST(test_ucx_list_concat); +UCX_TEST(test_ucx_list_size); +UCX_TEST(test_ucx_list_first); +UCX_TEST(test_ucx_list_last); +UCX_TEST(test_ucx_list_get); +UCX_TEST(test_ucx_list_indexof); +UCX_TEST(test_ucx_list_find); +UCX_TEST(test_ucx_list_contains); +UCX_TEST(test_ucx_list_remove); +UCX_TEST(test_ucx_list_clone); +UCX_TEST(test_ucx_list_sort); #ifdef __cplusplus }
--- a/test/logging_tests.c Fri Aug 09 10:24:02 2013 +0200 +++ b/test/logging_tests.c Fri Aug 09 11:32:10 2013 +0200 @@ -28,7 +28,7 @@ #include "logging_tests.h" -UCX_TEST_IMPLEMENT(test_ucx_logger_log) { +UCX_TEST(test_ucx_logger_log) { char buffer[100]; FILE *stream = tmpfile();
--- a/test/logging_tests.h Fri Aug 09 10:24:02 2013 +0200 +++ b/test/logging_tests.h Fri Aug 09 11:32:10 2013 +0200 @@ -36,7 +36,7 @@ extern "C" { #endif -UCX_TEST_DECLARE(test_ucx_logger_log); +UCX_TEST(test_ucx_logger_log); #ifdef __cplusplus }
--- a/test/main.c Fri Aug 09 10:24:02 2013 +0200 +++ b/test/main.c Fri Aug 09 11:32:10 2013 +0200 @@ -41,13 +41,13 @@ #include "prop_tests.h" #include "buffer_tests.h" -UCX_EXTERN UCX_TEST_IMPLEMENT(testTestSuitePositive) { +UCX_EXTERN UCX_TEST(testTestSuitePositive) { UCX_TEST_BEGIN UCX_TEST_ASSERT(2*2 == 4, "the test framework fails"); UCX_TEST_END } -UCX_EXTERN UCX_TEST_IMPLEMENT(testTestSuiteNegative) { +UCX_EXTERN UCX_TEST(testTestSuiteNegative) { UCX_TEST_BEGIN UCX_TEST_ASSERT(2*(-2) == 4, "the test framework works"); UCX_TEST_END @@ -73,7 +73,7 @@ UCX_TEST_ASSERT(*i==4, "the test framework works"); } -UCX_EXTERN UCX_TEST_IMPLEMENT(testTestSuiteRoutinePositive) { +UCX_EXTERN UCX_TEST(testTestSuiteRoutinePositive) { int i = 2; UCX_TEST_BEGIN UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineSuccess, &i); @@ -81,7 +81,7 @@ UCX_TEST_END } -UCX_EXTERN UCX_TEST_IMPLEMENT(testTestSuiteRoutineNegative) { +UCX_EXTERN UCX_TEST(testTestSuiteRoutineNegative) { int i = 0; UCX_TEST_BEGIN UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineFailure, &i); @@ -89,7 +89,7 @@ UCX_TEST_END } -UCX_EXTERN UCX_TEST_IMPLEMENT(testTestSuiteRoutineMultiparam) { +UCX_EXTERN UCX_TEST(testTestSuiteRoutineMultiparam) { UCX_TEST_BEGIN UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutine2Param, 42, 3.14f); UCX_TEST_END
--- a/test/map_tests.c Fri Aug 09 10:24:02 2013 +0200 +++ b/test/map_tests.c Fri Aug 09 11:32:10 2013 +0200 @@ -28,7 +28,7 @@ #include "map_tests.h" -UCX_TEST_IMPLEMENT(test_ucx_map_new) { +UCX_TEST(test_ucx_map_new) { UcxMap *map = ucx_map_new(16); UCX_TEST_BEGIN UCX_TEST_ASSERT(map->size == 16, "wrong size"); @@ -38,7 +38,7 @@ ucx_map_free(map); } -UCX_TEST_IMPLEMENT(test_ucx_key) { +UCX_TEST(test_ucx_key) { UcxKey key = ucx_key((void*)"This is a text.", 15); UCX_TEST_BEGIN UCX_TEST_ASSERT(strncmp((const char*)key.data, "This is a text.", 15) == 0, @@ -49,7 +49,7 @@ UCX_TEST_END } -UCX_TEST_IMPLEMENT(test_ucx_map_put) { +UCX_TEST(test_ucx_map_put) { UcxMap *map = ucx_map_new(4); @@ -94,7 +94,7 @@ ucx_map_free(map); } -UCX_TEST_IMPLEMENT(test_ucx_map_get) { +UCX_TEST(test_ucx_map_get) { UcxMap *map = ucx_map_new(4); int td[5]; @@ -125,7 +125,7 @@ ucx_map_free(map); } -UCX_TEST_IMPLEMENT(test_ucx_map_remove) { +UCX_TEST(test_ucx_map_remove) { UcxMap *map = ucx_map_new(4); int td[5]; @@ -188,7 +188,7 @@ UCX_TEST_ASSERT(check == v1+v2+v3+v4, "test1: wrong result"); } -UCX_TEST_IMPLEMENT(test_ucx_map_iterator) { +UCX_TEST(test_ucx_map_iterator) { UcxMap *map = ucx_map_new(16); UCX_TEST_BEGIN UCX_TEST_CALL_SUBROUTINE(test_ucx_map_itersrt, map) @@ -196,7 +196,7 @@ ucx_map_free(map); } -UCX_TEST_IMPLEMENT(test_ucx_map_iterator_chain) { +UCX_TEST(test_ucx_map_iterator_chain) { UcxMap *map = ucx_map_new(1); UCX_TEST_BEGIN UCX_TEST_CALL_SUBROUTINE(test_ucx_map_itersrt, map) @@ -204,7 +204,7 @@ ucx_map_free(map); } -UCX_TEST_IMPLEMENT(test_ucx_map_clone) { +UCX_TEST(test_ucx_map_clone) { UcxMap *map = ucx_map_new(4); ucx_map_cstr_put(map, "key1", (void*)"value1"); @@ -241,7 +241,7 @@ ucx_map_free(clone); } -UCX_TEST_IMPLEMENT(test_ucx_map_rehash) { +UCX_TEST(test_ucx_map_rehash) { UcxMap *map = ucx_map_new(4); char keys[10][5];
--- a/test/map_tests.h Fri Aug 09 10:24:02 2013 +0200 +++ b/test/map_tests.h Fri Aug 09 11:32:10 2013 +0200 @@ -36,15 +36,15 @@ extern "C" { #endif -UCX_TEST_DECLARE(test_ucx_map_new); -UCX_TEST_DECLARE(test_ucx_key); -UCX_TEST_DECLARE(test_ucx_map_put); -UCX_TEST_DECLARE(test_ucx_map_get); -UCX_TEST_DECLARE(test_ucx_map_remove); -UCX_TEST_DECLARE(test_ucx_map_iterator); -UCX_TEST_DECLARE(test_ucx_map_iterator_chain); -UCX_TEST_DECLARE(test_ucx_map_clone); -UCX_TEST_DECLARE(test_ucx_map_rehash); +UCX_TEST(test_ucx_map_new); +UCX_TEST(test_ucx_key); +UCX_TEST(test_ucx_map_put); +UCX_TEST(test_ucx_map_get); +UCX_TEST(test_ucx_map_remove); +UCX_TEST(test_ucx_map_iterator); +UCX_TEST(test_ucx_map_iterator_chain); +UCX_TEST(test_ucx_map_clone); +UCX_TEST(test_ucx_map_rehash); #ifdef __cplusplus
--- a/test/mpool_tests.c Fri Aug 09 10:24:02 2013 +0200 +++ b/test/mpool_tests.c Fri Aug 09 11:32:10 2013 +0200 @@ -30,7 +30,7 @@ #include "mpool_tests.h" -UCX_TEST_IMPLEMENT(test_ucx_mempool_new) { +UCX_TEST(test_ucx_mempool_new) { UcxMempool *pool = ucx_mempool_new(16); UCX_TEST_BEGIN UCX_TEST_ASSERT(pool->size == 16, "wrong size"); @@ -40,7 +40,7 @@ ucx_mempool_destroy(pool); } -UCX_TEST_IMPLEMENT(test_ucx_mempool_malloc) { +UCX_TEST(test_ucx_mempool_malloc) { UcxMempool *pool = ucx_mempool_new(1); UCX_TEST_BEGIN @@ -59,7 +59,7 @@ ucx_mempool_destroy(pool); } -UCX_TEST_IMPLEMENT(test_ucx_mempool_malloc_with_chcap) { +UCX_TEST(test_ucx_mempool_malloc_with_chcap) { UcxMempool *pool = ucx_mempool_new(1); UCX_TEST_BEGIN @@ -79,7 +79,7 @@ ucx_mempool_destroy(pool); } -UCX_TEST_IMPLEMENT(test_ucx_mempool_calloc) { +UCX_TEST(test_ucx_mempool_calloc) { UcxMempool *pool = ucx_mempool_new(1); UCX_TEST_BEGIN @@ -93,7 +93,7 @@ ucx_mempool_destroy(pool); } -UCX_TEST_IMPLEMENT(test_ucx_mempool_free) { +UCX_TEST(test_ucx_mempool_free) { UcxMempool *pool = ucx_mempool_new(16); void *mem1; void *mem2; @@ -128,7 +128,7 @@ *cb = 42; } -UCX_TEST_IMPLEMENT(test_ucx_mempool_set_destr) { +UCX_TEST(test_ucx_mempool_set_destr) { intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); UCX_TEST_BEGIN @@ -157,7 +157,7 @@ } -UCX_TEST_IMPLEMENT(test_ucx_mempool_reg_destr) { +UCX_TEST(test_ucx_mempool_reg_destr) { intptr_t *test = (intptr_t*) calloc(2, sizeof(intptr_t)); intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); @@ -184,7 +184,7 @@ if (cb != NULL) free(cb); } -UCX_TEST_IMPLEMENT(test_ucx_mempool_realloc) { +UCX_TEST(test_ucx_mempool_realloc) { intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); UCX_TEST_BEGIN
--- a/test/mpool_tests.h Fri Aug 09 10:24:02 2013 +0200 +++ b/test/mpool_tests.h Fri Aug 09 11:32:10 2013 +0200 @@ -36,14 +36,14 @@ extern "C" { #endif -UCX_TEST_DECLARE(test_ucx_mempool_new); -UCX_TEST_DECLARE(test_ucx_mempool_malloc); -UCX_TEST_DECLARE(test_ucx_mempool_malloc_with_chcap); -UCX_TEST_DECLARE(test_ucx_mempool_calloc); -UCX_TEST_DECLARE(test_ucx_mempool_free); -UCX_TEST_DECLARE(test_ucx_mempool_set_destr); -UCX_TEST_DECLARE(test_ucx_mempool_reg_destr); -UCX_TEST_DECLARE(test_ucx_mempool_realloc); +UCX_TEST(test_ucx_mempool_new); +UCX_TEST(test_ucx_mempool_malloc); +UCX_TEST(test_ucx_mempool_malloc_with_chcap); +UCX_TEST(test_ucx_mempool_calloc); +UCX_TEST(test_ucx_mempool_free); +UCX_TEST(test_ucx_mempool_set_destr); +UCX_TEST(test_ucx_mempool_reg_destr); +UCX_TEST(test_ucx_mempool_realloc); #ifdef __cplusplus }
--- a/test/prop_tests.c Fri Aug 09 10:24:02 2013 +0200 +++ b/test/prop_tests.c Fri Aug 09 11:32:10 2013 +0200 @@ -28,7 +28,7 @@ #include "prop_tests.h" -UCX_TEST_IMPLEMENT(test_ucx_properties_new) { +UCX_TEST(test_ucx_properties_new) { UcxProperties *parser = ucx_properties_new(); UCX_TEST_BEGIN @@ -42,7 +42,7 @@ ucx_properties_free(parser); } -UCX_TEST_IMPLEMENT(test_ucx_properties_next) { +UCX_TEST(test_ucx_properties_next) { const char *tests[] = { "name = value\n", "name=value\n", @@ -113,7 +113,7 @@ UCX_TEST_END } -UCX_TEST_IMPLEMENT(test_ucx_properties_next_multi) { +UCX_TEST(test_ucx_properties_next_multi) { const char *names[] = { "a", "b", @@ -176,7 +176,7 @@ ucx_properties_free(parser); } -UCX_TEST_IMPLEMENT(test_ucx_properties_next_part) { +UCX_TEST(test_ucx_properties_next_part) { UcxProperties *parser = ucx_properties_new(); const char *str; int r; @@ -286,7 +286,7 @@ ucx_properties_free(parser); } -UCX_TEST_IMPLEMENT(test_ucx_properties_next_long) { +UCX_TEST(test_ucx_properties_next_long) { UcxProperties *parser = ucx_properties_new(); int r; size_t name_len = 512; @@ -362,7 +362,7 @@ ucx_properties_free(parser); } -UCX_TEST_IMPLEMENT(test_ucx_properties2map) { +UCX_TEST(test_ucx_properties2map) { UcxMap *map = ucx_map_new(16); UcxProperties *parser = ucx_properties_new(); @@ -417,7 +417,7 @@ ucx_properties_free(parser); } -UCX_TEST_IMPLEMENT(test_ucx_properties_load) { +UCX_TEST(test_ucx_properties_load) { UCX_TEST_BEGIN FILE *f = tmpfile(); UCX_TEST_ASSERT(f, "test file cannot be opened, test aborted"); @@ -480,7 +480,7 @@ UCX_TEST_END } -UCX_TEST_IMPLEMENT(test_ucx_properties_store) { +UCX_TEST(test_ucx_properties_store) { UcxMap *map1 = ucx_map_new(16); ucx_map_cstr_put(map1, "key1", "value1"); ucx_map_cstr_put(map1, "key2", "value2");
--- a/test/prop_tests.h Fri Aug 09 10:24:02 2013 +0200 +++ b/test/prop_tests.h Fri Aug 09 11:32:10 2013 +0200 @@ -36,14 +36,14 @@ extern "C" { #endif -UCX_TEST_DECLARE(test_ucx_properties_new); -UCX_TEST_DECLARE(test_ucx_properties_next); -UCX_TEST_DECLARE(test_ucx_properties_next_multi); -UCX_TEST_DECLARE(test_ucx_properties_next_part); -UCX_TEST_DECLARE(test_ucx_properties_next_long); -UCX_TEST_DECLARE(test_ucx_properties2map); -UCX_TEST_DECLARE(test_ucx_properties_load); -UCX_TEST_DECLARE(test_ucx_properties_store); +UCX_TEST(test_ucx_properties_new); +UCX_TEST(test_ucx_properties_next); +UCX_TEST(test_ucx_properties_next_multi); +UCX_TEST(test_ucx_properties_next_part); +UCX_TEST(test_ucx_properties_next_long); +UCX_TEST(test_ucx_properties2map); +UCX_TEST(test_ucx_properties_load); +UCX_TEST(test_ucx_properties_store); #ifdef __cplusplus }
--- a/test/string_tests.c Fri Aug 09 10:24:02 2013 +0200 +++ b/test/string_tests.c Fri Aug 09 11:32:10 2013 +0200 @@ -28,7 +28,7 @@ #include "string_tests.h" -UCX_TEST_IMPLEMENT(test_sstr) { +UCX_TEST(test_sstr) { sstr_t s1 = sstr((char*)"1234"); sstr_t s2 = sstrn((char*)"ab", 2); @@ -40,7 +40,7 @@ UCX_TEST_END } -UCX_TEST_IMPLEMENT(test_sstr_len_cat) { +UCX_TEST(test_sstr_len_cat) { sstr_t s1 = ST("1234"); sstr_t s2 = ST(".:.:."); sstr_t s3 = ST("X"); @@ -69,7 +69,7 @@ free(cat.ptr); } -UCX_TEST_IMPLEMENT(test_sstrsplit) { +UCX_TEST(test_sstrsplit) { const char *original = "this,is,a,csv,string"; sstr_t test = ST("this,is,a,csv,string"); /* use copy of original here */ @@ -193,7 +193,7 @@ UCX_TEST_END } -UCX_TEST_IMPLEMENT(test_sstrtrim) { +UCX_TEST(test_sstrtrim) { sstr_t t1 = sstrtrim(sstr((char*)" ein test ")); sstr_t t2 = sstrtrim(sstr((char*)"abc")); sstr_t t3 = sstrtrim(sstr((char*)" 123"));
--- a/test/string_tests.h Fri Aug 09 10:24:02 2013 +0200 +++ b/test/string_tests.h Fri Aug 09 11:32:10 2013 +0200 @@ -36,10 +36,10 @@ extern "C" { #endif -UCX_TEST_DECLARE(test_sstr); -UCX_TEST_DECLARE(test_sstr_len_cat); -UCX_TEST_DECLARE(test_sstrsplit); -UCX_TEST_DECLARE(test_sstrtrim); +UCX_TEST(test_sstr); +UCX_TEST(test_sstr_len_cat); +UCX_TEST(test_sstrsplit); +UCX_TEST(test_sstrtrim); #ifdef __cplusplus }
--- a/ucx/test.c Fri Aug 09 10:24:02 2013 +0200 +++ b/ucx/test.c Fri Aug 09 11:32:10 2013 +0200 @@ -28,6 +28,12 @@ #include "test.h" + +struct UcxTestList{ + UcxTest test; + UcxTestList *next; +}; + UcxTestSuite* ucx_test_suite_new() { UcxTestSuite* suite = (UcxTestSuite*) malloc(sizeof(UcxTestSuite)); if (suite != NULL) { @@ -35,6 +41,7 @@ suite->failure = 0; suite->tests = NULL; } + return suite; }
--- a/ucx/test.h Fri Aug 09 10:24:02 2013 +0200 +++ b/ucx/test.h Fri Aug 09 11:32:10 2013 +0200 @@ -26,27 +26,45 @@ * POSSIBILITY OF SUCH DAMAGE. */ -/* - * +/** + * @file: test.h + * + * UCX Test Framework. + * * Usage of this test framework: * * **** IN HEADER FILE: **** * - * UCX_TEST_DECLARE(function_name) + * <pre> + * UCX_TEST(function_name) + * UCX_TEST_SUBROUTINE(subroutine_name, paramlist) // optional + * </pre> * * **** IN SOURCE FILE: **** + * <pre> + * UCX_TEST_SUBROUTINE(subroutine_name, paramlist) { + * // tests with UCX_TEST_ASSERT() + * } + * + * UCX_TEST(function_name) { + * // memory allocation and other stuff here + * #UCX_TEST_BEGIN + * // tests with UCX_TEST_ASSERT() and/or + * // calls with UCX_TEST_CALL_SUBROUTINE() here + * #UCX_TEST_END + * // cleanup of memory here + * } + * </pre> * - * UCX_TEST_IMPLEMENT(function_name) { - * <memory allocation and other stuff here> - * UCX_TEST_BEGIN - * <tests with UCX_TEST_ASSERT here> - * UCX_TEST_END - * <cleanup of memory here> - * } + * <b>Note:</b> if a test fails, a longjump is performed + * back to the #UCX_TEST_BEGIN macro! + * + * <b>Attention:</b> Do not call own functions within a test, that use + * UCX_TEST_ASSERT() macros and are not defined by using UCX_TEST_SUBROUTINE(). + * * - * PLEASE NOTE: if a test fails, a longjump is performed - * back to the UCX_TEST_BEGIN macro! - * + * @author Mike Becker + * @author Olaf Wintermann * */ @@ -63,50 +81,136 @@ #endif #ifndef __FUNCTION__ +/** + * Alias for the __func__ preprocessor macro. + * Some compilers use __func__ and others use __FUNC__. We use __FUNC__ so we + * define it for those compilers which use __func__. + */ #define __FUNCTION__ __func__ #endif +/** Type for the internal list of test cases. */ typedef struct UcxTestList UcxTestList; +/** Type for the UcxTestSuite. */ typedef struct UcxTestSuite UcxTestSuite; +/** Pointer to a test function. */ typedef void(*UcxTest)(UcxTestSuite*,FILE*); - -struct UcxTestList{ - UcxTest test; - UcxTestList *next; -}; +/** + * A test suite containing multiple test cases. + */ struct UcxTestSuite { + /** The number of successful tests after the suite has been run. */ unsigned int success; + /** The number of failed tests after the suite has been run. */ unsigned int failure; + /** + * Internal list of test cases. + * Use ucx_test_register() to add tests to this list. + */ UcxTestList *tests; }; +/** + * Creates a new test suite. + * @return a new test suite + */ UcxTestSuite* ucx_test_suite_new(); -void ucx_test_suite_free(UcxTestSuite*); +/** + * Destroys a test suite. + * @param the test suite to destroy + */ +void ucx_test_suite_free(UcxTestSuite* suite); -int ucx_test_register(UcxTestSuite*, UcxTest); -void ucx_test_run(UcxTestSuite*, FILE*); +/** + * Registers a test function with the specified test suite. + * + * @param suite the suite, the test function shall be added to + * @param test the test function to register + * @return EXIT_SUCCESS on success or EXIT_FAILURE on failure + */ +int ucx_test_register(UcxTestSuite* suite, UcxTest test); +/** + * Runs a test suite and writes the test log to the specified stream. + * @param suite the test suite to run + * @param outstream the stream the log shall be written to + */ +void ucx_test_run(UcxTestSuite* suite, FILE* outstream); -#define UCX_TEST_DECLARE(name) void name(UcxTestSuite*,FILE *) -#define UCX_TEST_IMPLEMENT(name) void name(UcxTestSuite* _suite_,FILE *_output_) +/** + * Macro for a #UcxTest function header. + * + * Use this macro to declare and/or define an #UcxTest function. + * + * @param name the name of the test function + */ +#define UCX_TEST(name) void name(UcxTestSuite* _suite_,FILE *_output_) +/** + * Marks the begin of a test. + * <b>Note:</b> Any UCX_TEST_ASSERT() calls must be performed <b>after</b> + * #UCX_TEST_BEGIN. + * + * @see #UCX_TEST_END + */ #define UCX_TEST_BEGIN fwrite("Running ", 1, 8, _output_);\ fwrite(__FUNCTION__, 1, strlen(__FUNCTION__), _output_);\ fwrite("... ", 1, 4, _output_);\ jmp_buf _env_; \ if (!setjmp(_env_)) { +/** + * Checks a test assertion. + * If the assertion is correct, the test carries on. If the assertion is not + * correct, the specified message (terminated by a dot and a line break) is + * written to the test suites output stream. + * @param condition the condition to check + * @param message the message that shall be printed out on failure + */ #define UCX_TEST_ASSERT(condition,message) if (!(condition)) { \ fwrite(message".\n", 1, 2+strlen(message), _output_); \ _suite_->failure++; \ longjmp(_env_, 1);\ } +/** + * Macro for a test subroutine function header. + * + * Use this to declare and/or define an subroutine that can be called by using + * UCX_TEST_CALL_SUBROUTINE(). + * + * @param name the name of the subroutine + * @param ... the parameter list + * + * @see UCX_TEST_CALL_SUBROUTINE() + */ #define UCX_TEST_SUBROUTINE(name,...) void name(UcxTestSuite* _suite_,\ FILE *_output_, jmp_buf _env_, __VA_ARGS__) + +/** + * Macro for calling a test subroutine. + * + * Subroutines declared with UCX_TEST_SUBROUTINE() can be called by using this + * macro. + * + * <b>Note:</b> You may <b>only</b> call subroutines within a #UCX_TEST_BEGIN- + * #UCX_TEST_END-block. + * + * @param name the name of the subroutine + * @param ... the argument list + * + * @see UCX_TEST_SUBROUTINE() + */ #define UCX_TEST_CALL_SUBROUTINE(name,...) \ name(_suite_,_output_,_env_,__VA_ARGS__); +/** + * Marks the end of a test. + * <b>Note:</b> Any UCX_TEST_ASSERT() calls must be performed <b>before</b> + * #UCX_TEST_END. + * + * @see #UCX_TEST_BEGIN + */ #define UCX_TEST_END fwrite("success.\n", 1, 9, _output_); _suite_->success++;} #ifdef __cplusplus