ucx/test.h

changeset 26
59f147baea31
child 27
22644e2572bc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ucx/test.h	Sat Feb 18 15:50:43 2012 +0100
     1.3 @@ -0,0 +1,49 @@
     1.4 +/* 
     1.5 + * File:   test.h
     1.6 + * Author: Mike
     1.7 + *
     1.8 + * Created on 18. Februar 2012, 14:15
     1.9 + */
    1.10 +
    1.11 +#ifndef TEST_H
    1.12 +#define	TEST_H
    1.13 +
    1.14 +#include <stdio.h>
    1.15 +#include <string.h>
    1.16 +#include "list.h"
    1.17 +
    1.18 +#ifdef	__cplusplus
    1.19 +extern "C" {
    1.20 +#endif
    1.21 +
    1.22 +typedef struct {
    1.23 +    unsigned int success;
    1.24 +    unsigned int failure;
    1.25 +    UcxList *tests;
    1.26 +} UcxTestSuite;
    1.27 +
    1.28 +typedef void(*UcxTest)(UcxTestSuite*,FILE*);
    1.29 +
    1.30 +UcxTestSuite* ucx_test_suite_new();
    1.31 +void ucx_test_suite_free(UcxTestSuite*);
    1.32 +
    1.33 +void ucx_test_register(UcxTestSuite*, UcxTest);
    1.34 +void ucx_test_run(UcxTestSuite*, FILE*);
    1.35 +
    1.36 +#define UCX_TEST_BEGIN(name) void name(UcxTestSuite* _suite_,FILE *_output_) {\
    1.37 +    fwrite("Running "#name"... ", 1, 12+strlen(#name), _output_);
    1.38 +
    1.39 +#define UCX_TEST_ASSERT(condition,message) if (!(condition)) { \
    1.40 +        fwrite(message".\n", 1, 2+strlen(message), _output_); \
    1.41 +        _suite_->failure++; \
    1.42 +        return;\
    1.43 +    }
    1.44 +
    1.45 +#define UCX_TEST_END } fwrite("success.\n", 1, 9, _output_); _suite_->success++;
    1.46 +
    1.47 +#ifdef	__cplusplus
    1.48 +}
    1.49 +#endif
    1.50 +
    1.51 +#endif	/* TEST_H */
    1.52 +

mercurial