ucx/test.h

changeset 33
9c219a62070d
parent 27
22644e2572bc
child 69
fb59270b1de3
     1.1 --- a/ucx/test.h	Thu May 31 09:18:26 2012 +0200
     1.2 +++ b/ucx/test.h	Thu May 31 12:51:22 2012 +0200
     1.3 @@ -3,6 +3,31 @@
     1.4   * Author: Mike
     1.5   *
     1.6   * Created on 18. Februar 2012, 14:15
     1.7 + *
     1.8 + *
     1.9 + *
    1.10 + * Usage of this test framework:
    1.11 + *
    1.12 + * **** IN HEADER FILE: ****
    1.13 + *
    1.14 + * UCX_TEST_DECLARE(function_name)
    1.15 + *
    1.16 + * **** IN SOURCE FILE: ****
    1.17 + *
    1.18 + * UCX_TEST_IMPLEMENT(function_name) {
    1.19 + *  <memory allocation and other stuff here>
    1.20 + *  UCX_TEST_BEGIN
    1.21 + *  <tests with UCX_TEST_ASSERT here>
    1.22 + *  UCX_TEST_END
    1.23 + *  <cleanup of memory here>
    1.24 + * }
    1.25 + *
    1.26 + * PLEASE NOTE: if a test fails, a longjump is performed
    1.27 + * back to the UCX_TEST_BEGIN macro!
    1.28 + *
    1.29 + * You may use multiple BEGIN-END blocks if you are aware of the
    1.30 + * longjmp behaviour.
    1.31 + *
    1.32   */
    1.33  
    1.34  #ifndef TEST_H
    1.35 @@ -10,6 +35,7 @@
    1.36  
    1.37  #include <stdio.h>
    1.38  #include <string.h>
    1.39 +#include <setjmp.h>
    1.40  #include "list.h"
    1.41  
    1.42  #ifdef	__cplusplus
    1.43 @@ -31,16 +57,25 @@
    1.44  void ucx_test_run(UcxTestSuite*, FILE*);
    1.45  
    1.46  #define UCX_TEST_DECLARE(name) void name(UcxTestSuite*,FILE *);
    1.47 -#define UCX_TEST_BEGIN(name) void name(UcxTestSuite* _suite_,FILE *_output_) {\
    1.48 -    fwrite("Running "#name"... ", 1, 12+strlen(#name), _output_);
    1.49 +#define UCX_TEST_IMPLEMENT(name) void name(UcxTestSuite* _suite_,FILE *_output_)
    1.50 +
    1.51 +#define UCX_TEST_BEGIN fwrite("Running ", 1, 8, _output_);\
    1.52 +        fwrite(__func__, 1, strlen(__func__), _output_);\
    1.53 +        fwrite("... ", 1, 4, _output_);\
    1.54 +        jmp_buf _env_; \
    1.55 +        if (!setjmp(_env_)) {
    1.56  
    1.57  #define UCX_TEST_ASSERT(condition,message) if (!(condition)) { \
    1.58          fwrite(message".\n", 1, 2+strlen(message), _output_); \
    1.59          _suite_->failure++; \
    1.60 -        return;\
    1.61 +        longjmp(_env_, 1);\
    1.62      }
    1.63  
    1.64 -#define UCX_TEST_END } fwrite("success.\n", 1, 9, _output_); _suite_->success++;
    1.65 +#define UCX_TEST_SUBROUTINE(name,data) void name(UcxTestSuite* _suite_,\
    1.66 +        FILE *_output_, jmp_buf _env_, void* data)
    1.67 +#define UCX_TEST_CALL_SUBROUTINE(name,data) name(_suite_,_output_,_env_,data);
    1.68 +
    1.69 +#define UCX_TEST_END fwrite("success.\n", 1, 9, _output_); _suite_->success++;}
    1.70  
    1.71  #ifdef	__cplusplus
    1.72  }

mercurial