test.h 610 B

123456789101112131415161718192021222324252627282930313233
  1. #ifndef __TEST_H__
  2. #define __TEST_H__
  3. #include "stdio.h"
  4. static int test_passed = 0;
  5. static int test_failed = 0;
  6. /* Terminate current test with error */
  7. #define fail() return __LINE__
  8. /* Successful end of the test case */
  9. #define done() return 0
  10. /* Check single condition */
  11. #define check(cond) do { if (!(cond)) fail(); } while (0)
  12. /* Test runner */
  13. static void test(int (*func)(void), const char *name)
  14. {
  15. int r = func();
  16. if (r == 0)
  17. {
  18. test_passed++;
  19. }
  20. else
  21. {
  22. test_failed++;
  23. printf("FAILED: %s (at line %d)\n", name, r);
  24. }
  25. }
  26. #endif /* __TEST_H__ */