2014-05-19 19:46:18 +00:00
|
|
|
#ifndef LWIP_HDR_LWIP_CHECK_H__
|
|
|
|
#define LWIP_HDR_LWIP_CHECK_H__
|
2009-11-27 08:03:53 +00:00
|
|
|
|
|
|
|
/* Common header file for lwIP unit tests using the check framework */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <check.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#define FAIL_RET() do { fail(); return; } while(0)
|
|
|
|
#define EXPECT(x) fail_unless(x)
|
|
|
|
#define EXPECT_RET(x) do { fail_unless(x); if(!(x)) { return; }} while(0)
|
|
|
|
#define EXPECT_RETX(x, y) do { fail_unless(x); if(!(x)) { return y; }} while(0)
|
|
|
|
#define EXPECT_RETNULL(x) EXPECT_RETX(x, NULL)
|
|
|
|
|
2014-02-12 20:52:21 +00:00
|
|
|
typedef struct {
|
|
|
|
TFun func;
|
|
|
|
const char *name;
|
|
|
|
} testfunc;
|
|
|
|
|
|
|
|
#define TESTFUNC(x) {(x), "" # x "" }
|
|
|
|
|
|
|
|
/* Modified function from check.h, supplying function name */
|
|
|
|
#define tcase_add_named_test(tc,tf) \
|
|
|
|
_tcase_add_test((tc),(tf).func,(tf).name,0, 0, 0, 1)
|
|
|
|
|
2009-11-27 08:03:53 +00:00
|
|
|
/** typedef for a function returning a test suite */
|
|
|
|
typedef Suite* (suite_getter_fn)(void);
|
|
|
|
|
|
|
|
/** Create a test suite */
|
2014-02-12 20:52:21 +00:00
|
|
|
static Suite* create_suite(const char* name, testfunc *tests, size_t num_tests, SFun setup, SFun teardown)
|
2009-11-27 08:03:53 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
Suite *s = suite_create(name);
|
|
|
|
|
|
|
|
for(i = 0; i < num_tests; i++) {
|
2014-02-12 20:52:21 +00:00
|
|
|
TCase *tc_core = tcase_create(name);
|
2009-11-27 08:03:53 +00:00
|
|
|
if ((setup != NULL) || (teardown != NULL)) {
|
|
|
|
tcase_add_checked_fixture(tc_core, setup, teardown);
|
|
|
|
}
|
2014-02-12 20:52:21 +00:00
|
|
|
tcase_add_named_test(tc_core, tests[i]);
|
2009-11-27 08:03:53 +00:00
|
|
|
suite_add_tcase(s, tc_core);
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2014-05-19 19:46:18 +00:00
|
|
|
#endif /* LWIP_HDR_LWIP_CHECK_H__ */
|