variadic test subroutines

Wed, 27 Feb 2013 09:41:17 +0100

author
Mike Becker <universe@uap-core.de>
date
Wed, 27 Feb 2013 09:41:17 +0100
changeset 88
18823857ce79
parent 87
bd444539cced
child 89
47f7fdbddb62

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
     1.1 --- a/test/main.c	Mon Feb 25 16:26:50 2013 +0100
     1.2 +++ b/test/main.c	Wed Feb 27 09:41:17 2013 +0100
     1.3 @@ -65,15 +65,23 @@
     1.4      UCX_TEST_END
     1.5  }
     1.6  
     1.7 -UCX_TEST_SUBROUTINE(testTestSuiteRoutineSuccess,field) {
     1.8 -    int* i = (int*) field;
     1.9 +UCX_TEST_SUBROUTINE(testTestSuiteRoutineRoutine, float f) {
    1.10 +    UCX_TEST_ASSERT(f == 3.14f, "calling routine in a routine fails");
    1.11 +}
    1.12 +
    1.13 +UCX_TEST_SUBROUTINE(testTestSuiteRoutine2Param, int i, float f) {
    1.14 +    UCX_TEST_ASSERT(i == 42, "two parameter routine fails");
    1.15 +    UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineRoutine, f);
    1.16 +}
    1.17 +
    1.18 +UCX_TEST_SUBROUTINE(testTestSuiteRoutineSuccess, int* i) {
    1.19      *i += 2;
    1.20      UCX_TEST_ASSERT(*i==4, "the test framework fails");
    1.21  }
    1.22  
    1.23 -UCX_TEST_SUBROUTINE(testTestSuiteRoutineFailure,field) {
    1.24 -    int* i = (int*) field;
    1.25 +UCX_TEST_SUBROUTINE(testTestSuiteRoutineFailure, int* i) {
    1.26      *i += 2;
    1.27 +    // Next test shall fail!
    1.28      UCX_TEST_ASSERT(*i==4, "the test framework works");
    1.29  }
    1.30  
    1.31 @@ -93,6 +101,12 @@
    1.32      UCX_TEST_END
    1.33  }
    1.34  
    1.35 +UCX_TEST_IMPLEMENT(testTestSuiteRoutineMultiparam) {
    1.36 +    UCX_TEST_BEGIN
    1.37 +    UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutine2Param, 42, 3.14f);
    1.38 +    UCX_TEST_END
    1.39 +}
    1.40 +
    1.41  int main(int argc, char **argv) {
    1.42      printf("UCX Tests\n---------\n");
    1.43  
    1.44 @@ -102,8 +116,9 @@
    1.45      ucx_test_register(suite, testTestSuiteNegative);
    1.46      ucx_test_register(suite, testTestSuiteRoutinePositive);
    1.47      ucx_test_register(suite, testTestSuiteRoutineNegative);
    1.48 +    ucx_test_register(suite, testTestSuiteRoutineMultiparam);
    1.49      ucx_test_run(suite, stdout);
    1.50 -    if (suite->failure == 2 && suite->success == 2) {
    1.51 +    if (suite->failure == 2 && suite->success == 3) {
    1.52          ucx_test_suite_free(suite);
    1.53  
    1.54          printf("\nLibrary function tests\n");
     2.1 --- a/test/map_tests.c	Mon Feb 25 16:26:50 2013 +0100
     2.2 +++ b/test/map_tests.c	Wed Feb 27 09:41:17 2013 +0100
     2.3 @@ -139,8 +139,7 @@
     2.4      ucx_map_free(map);
     2.5  }
     2.6  
     2.7 -UCX_TEST_SUBROUTINE(test_ucx_map_itersrt, mapptr) {
     2.8 -    UcxMap *map = (UcxMap*) mapptr;
     2.9 +UCX_TEST_SUBROUTINE(test_ucx_map_itersrt, UcxMap *map) {
    2.10      int v1 = 10;
    2.11      int v2 = 15;
    2.12      int v3 = 7;
     3.1 --- a/ucx/test.h	Mon Feb 25 16:26:50 2013 +0100
     3.2 +++ b/ucx/test.h	Wed Feb 27 09:41:17 2013 +0100
     3.3 @@ -82,9 +82,10 @@
     3.4          longjmp(_env_, 1);\
     3.5      }
     3.6  
     3.7 -#define UCX_TEST_SUBROUTINE(name,data) void name(UcxTestSuite* _suite_,\
     3.8 -        FILE *_output_, jmp_buf _env_, void* data)
     3.9 -#define UCX_TEST_CALL_SUBROUTINE(name,data) name(_suite_,_output_,_env_,data);
    3.10 +#define UCX_TEST_SUBROUTINE(name,...) void name(UcxTestSuite* _suite_,\
    3.11 +        FILE *_output_, jmp_buf _env_, __VA_ARGS__)
    3.12 +#define UCX_TEST_CALL_SUBROUTINE(name,...) \
    3.13 +        name(_suite_,_output_,_env_,__VA_ARGS__);
    3.14  
    3.15  #define UCX_TEST_END fwrite("success.\n", 1, 9, _output_); _suite_->success++;}
    3.16  

mercurial