Wed, 27 Feb 2013 09:41:17 +0100
variadic test subroutines
test/main.c | file | annotate | diff | comparison | revisions | |
test/map_tests.c | file | annotate | diff | comparison | revisions | |
ucx/test.h | file | annotate | diff | comparison | revisions |
--- a/test/main.c Mon Feb 25 16:26:50 2013 +0100 +++ b/test/main.c Wed Feb 27 09:41:17 2013 +0100 @@ -65,15 +65,23 @@ UCX_TEST_END } -UCX_TEST_SUBROUTINE(testTestSuiteRoutineSuccess,field) { - int* i = (int*) field; +UCX_TEST_SUBROUTINE(testTestSuiteRoutineRoutine, float f) { + UCX_TEST_ASSERT(f == 3.14f, "calling routine in a routine fails"); +} + +UCX_TEST_SUBROUTINE(testTestSuiteRoutine2Param, int i, float f) { + UCX_TEST_ASSERT(i == 42, "two parameter routine fails"); + UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineRoutine, f); +} + +UCX_TEST_SUBROUTINE(testTestSuiteRoutineSuccess, int* i) { *i += 2; UCX_TEST_ASSERT(*i==4, "the test framework fails"); } -UCX_TEST_SUBROUTINE(testTestSuiteRoutineFailure,field) { - int* i = (int*) field; +UCX_TEST_SUBROUTINE(testTestSuiteRoutineFailure, int* i) { *i += 2; + // Next test shall fail! UCX_TEST_ASSERT(*i==4, "the test framework works"); } @@ -93,6 +101,12 @@ UCX_TEST_END } +UCX_TEST_IMPLEMENT(testTestSuiteRoutineMultiparam) { + UCX_TEST_BEGIN + UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutine2Param, 42, 3.14f); + UCX_TEST_END +} + int main(int argc, char **argv) { printf("UCX Tests\n---------\n"); @@ -102,8 +116,9 @@ ucx_test_register(suite, testTestSuiteNegative); ucx_test_register(suite, testTestSuiteRoutinePositive); ucx_test_register(suite, testTestSuiteRoutineNegative); + ucx_test_register(suite, testTestSuiteRoutineMultiparam); ucx_test_run(suite, stdout); - if (suite->failure == 2 && suite->success == 2) { + if (suite->failure == 2 && suite->success == 3) { ucx_test_suite_free(suite); printf("\nLibrary function tests\n");
--- a/test/map_tests.c Mon Feb 25 16:26:50 2013 +0100 +++ b/test/map_tests.c Wed Feb 27 09:41:17 2013 +0100 @@ -139,8 +139,7 @@ ucx_map_free(map); } -UCX_TEST_SUBROUTINE(test_ucx_map_itersrt, mapptr) { - UcxMap *map = (UcxMap*) mapptr; +UCX_TEST_SUBROUTINE(test_ucx_map_itersrt, UcxMap *map) { int v1 = 10; int v2 = 15; int v3 = 7;
--- a/ucx/test.h Mon Feb 25 16:26:50 2013 +0100 +++ b/ucx/test.h Wed Feb 27 09:41:17 2013 +0100 @@ -82,9 +82,10 @@ longjmp(_env_, 1);\ } -#define UCX_TEST_SUBROUTINE(name,data) void name(UcxTestSuite* _suite_,\ - FILE *_output_, jmp_buf _env_, void* data) -#define UCX_TEST_CALL_SUBROUTINE(name,data) name(_suite_,_output_,_env_,data); +#define UCX_TEST_SUBROUTINE(name,...) void name(UcxTestSuite* _suite_,\ + FILE *_output_, jmp_buf _env_, __VA_ARGS__) +#define UCX_TEST_CALL_SUBROUTINE(name,...) \ + name(_suite_,_output_,_env_,__VA_ARGS__); #define UCX_TEST_END fwrite("success.\n", 1, 9, _output_); _suite_->success++;}