ucx/test.h

Fri, 12 Oct 2012 12:00:06 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 12 Oct 2012 12:00:06 +0200
changeset 70
6721482eaf8e
parent 69
fb59270b1de3
child 83
3b552d7a9610
permissions
-rw-r--r--

fixed memory leak in ucx_map_rehash

     1 /* 
     2  * File:   test.h
     3  * Author: Mike
     4  *
     5  * Created on 18. Februar 2012, 14:15
     6  *
     7  *
     8  *
     9  * Usage of this test framework:
    10  *
    11  * **** IN HEADER FILE: ****
    12  *
    13  * UCX_TEST_DECLARE(function_name)
    14  *
    15  * **** IN SOURCE FILE: ****
    16  *
    17  * UCX_TEST_IMPLEMENT(function_name) {
    18  *  <memory allocation and other stuff here>
    19  *  UCX_TEST_BEGIN
    20  *  <tests with UCX_TEST_ASSERT here>
    21  *  UCX_TEST_END
    22  *  <cleanup of memory here>
    23  * }
    24  *
    25  * PLEASE NOTE: if a test fails, a longjump is performed
    26  * back to the UCX_TEST_BEGIN macro!
    27  *
    28  * You may use multiple BEGIN-END blocks if you are aware of the
    29  * longjmp behaviour.
    30  *
    31  */
    33 #ifndef TEST_H
    34 #define	TEST_H
    36 #include "ucx.h"
    37 #include <stdio.h>
    38 #include <string.h>
    39 #include <setjmp.h>
    40 #include "list.h"
    42 #ifdef	__cplusplus
    43 extern "C" {
    44 #endif
    46 #ifndef __FUNCTION__
    47 #define __FUNCTION__ __func__
    48 #endif
    50 typedef struct {
    51     unsigned int success;
    52     unsigned int failure;
    53     UcxList *tests;
    54 } UcxTestSuite;
    56 typedef void(*UcxTest)(UcxTestSuite*,FILE*);
    58 UcxTestSuite* ucx_test_suite_new();
    59 void ucx_test_suite_free(UcxTestSuite*);
    61 void ucx_test_register(UcxTestSuite*, UcxTest);
    62 void ucx_test_run(UcxTestSuite*, FILE*);
    64 #define UCX_TEST_DECLARE(name) void name(UcxTestSuite*,FILE *)
    65 #define UCX_TEST_IMPLEMENT(name) void name(UcxTestSuite* _suite_,FILE *_output_)
    67 #define UCX_TEST_BEGIN fwrite("Running ", 1, 8, _output_);\
    68         fwrite(__FUNCTION__, 1, strlen(__FUNCTION__), _output_);\
    69         fwrite("... ", 1, 4, _output_);\
    70         jmp_buf _env_; \
    71         if (!setjmp(_env_)) {
    73 #define UCX_TEST_ASSERT(condition,message) if (!(condition)) { \
    74         fwrite(message".\n", 1, 2+strlen(message), _output_); \
    75         _suite_->failure++; \
    76         longjmp(_env_, 1);\
    77     }
    79 #define UCX_TEST_SUBROUTINE(name,data) void name(UcxTestSuite* _suite_,\
    80         FILE *_output_, jmp_buf _env_, void* data)
    81 #define UCX_TEST_CALL_SUBROUTINE(name,data) name(_suite_,_output_,_env_,data);
    83 #define UCX_TEST_END fwrite("success.\n", 1, 9, _output_); _suite_->success++;}
    85 #ifdef	__cplusplus
    86 }
    87 #endif
    89 #endif	/* TEST_H */

mercurial