# HG changeset patch # User Mike Becker # Date 1361954477 -3600 # Node ID 18823857ce7922dfd5055e9c94293452a17a9a59 # Parent bd444539ccede1086397de466dbabfafaefdbae2 variadic test subroutines diff -r bd444539cced -r 18823857ce79 test/main.c --- 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"); diff -r bd444539cced -r 18823857ce79 test/map_tests.c --- 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; diff -r bd444539cced -r 18823857ce79 ucx/test.h --- 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++;}