test_helpers.h 878 B

123456789101112131415161718192021222324252627
  1. #ifndef _TEST_HELPERS
  2. #define _TEST_HELPERS
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <errno.h>
  6. // Throws an error on a well-defined error value.
  7. #define ERROR_IF(func, status, condition) { \
  8. if (status condition) { \
  9. fprintf(stderr, "%s:%d: ‘%s‘ returned an error in function ‘%s’: %s (%d)\n", \
  10. __FILE__, __LINE__, #func, __func__, strerror(errno), errno); \
  11. exit(EXIT_FAILURE); \
  12. }\
  13. }
  14. // Throws an error on an return value not defined by the standards.
  15. // Used for sanity checking the return values.
  16. #define UNEXP_IF(func, status, condition) { \
  17. if (status condition) { \
  18. fprintf(stderr, "%s:%d: ‘%s‘ returned a value not defined by the standards in function ‘%s’: %d\n", \
  19. __FILE__, __LINE__, #func, __func__, status); \
  20. exit(EXIT_FAILURE); \
  21. }\
  22. }
  23. #endif /* _TEST_HELPERS */