lwip_check.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #ifndef LWIP_HDR_LWIP_CHECK_H__
  2. #define LWIP_HDR_LWIP_CHECK_H__
  3. /* Common header file for lwIP unit tests using the check framework */
  4. #include <config.h>
  5. #include <check.h>
  6. #include <stdlib.h>
  7. #define FAIL_RET() do { fail(); return; } while(0)
  8. #define EXPECT(x) fail_unless(x)
  9. #define EXPECT_RET(x) do { fail_unless(x); if(!(x)) { return; }} while(0)
  10. #define EXPECT_RETX(x, y) do { fail_unless(x); if(!(x)) { return y; }} while(0)
  11. #define EXPECT_RETNULL(x) EXPECT_RETX(x, NULL)
  12. typedef struct {
  13. TFun func;
  14. const char *name;
  15. } testfunc;
  16. #define TESTFUNC(x) {(x), "" # x "" }
  17. /* Modified function from check.h, supplying function name */
  18. #define tcase_add_named_test(tc,tf) \
  19. _tcase_add_test((tc),(tf).func,(tf).name,0, 0, 0, 1)
  20. /** typedef for a function returning a test suite */
  21. typedef Suite* (suite_getter_fn)(void);
  22. /** Create a test suite */
  23. static Suite* create_suite(const char* name, testfunc *tests, size_t num_tests, SFun setup, SFun teardown)
  24. {
  25. size_t i;
  26. Suite *s = suite_create(name);
  27. for(i = 0; i < num_tests; i++) {
  28. TCase *tc_core = tcase_create(name);
  29. if ((setup != NULL) || (teardown != NULL)) {
  30. tcase_add_checked_fixture(tc_core, setup, teardown);
  31. }
  32. tcase_add_named_test(tc_core, tests[i]);
  33. suite_add_tcase(s, tc_core);
  34. }
  35. return s;
  36. }
  37. #endif /* LWIP_HDR_LWIP_CHECK_H__ */