#ifndef UCX_TEST_H
#define UCX_TEST_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <setjmp.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __FUNCTION__
#define __FUNCTION__ __func__
#endif
typedef struct UcxTestSuite UcxTestSuite;
typedef void(*UcxTest)(UcxTestSuite*,FILE*);
typedef struct UcxTestList UcxTestList;
struct UcxTestList {
UcxTest test;
UcxTestList *next;
};
struct UcxTestSuite {
unsigned int success;
unsigned int failure;
UcxTestList *tests;
};
UcxTestSuite* ucx_test_suite_new();
void ucx_test_suite_free(UcxTestSuite* suite);
int ucx_test_register(UcxTestSuite* suite, UcxTest test);
void ucx_test_run(UcxTestSuite* suite, FILE* outstream);
#define UCX_TEST(name) void name(UcxTestSuite* _suite_,FILE *_output_)
#define UCX_TEST_BEGIN fwrite("Running ", 1, 8, _output_);\
fwrite(__FUNCTION__, 1, strlen(__FUNCTION__), _output_);\
fwrite("... ", 1, 4, _output_);\
jmp_buf _env_; \
if (!setjmp(_env_)) {
#define UCX_TEST_ASSERT(condition,message) if (!(condition)) { \
fwrite(".\n"message, 1, 2+strlen(message), _output_); \
_suite_->failure++; \
longjmp(_env_, 1);\
}
#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++;}
#ifdef __cplusplus
}
#endif
#endif