1 2 #ifndef UPB_TEST_H_ 3 #define UPB_TEST_H_ 4 5 #include <stdio.h> 6 #include <stdlib.h> 7 #include <stdint.h> 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 int num_assertions = 0; 14 uint32_t testhash = 0; 15 16 #define PRINT_FAILURE(expr) \ 17 fprintf(stderr, "Assertion failed: %s:%d\n", __FILE__, __LINE__); \ 18 fprintf(stderr, "expr: %s\n", #expr); \ 19 if (testhash) { \ 20 fprintf(stderr, "assertion failed running test %x. " \ 21 "Run with the arg %x to run only this test.\n", \ 22 testhash, testhash); \ 23 } 24 25 #define ASSERT(expr) do { \ 26 ++num_assertions; \ 27 if (!(expr)) { \ 28 PRINT_FAILURE(expr) \ 29 abort(); \ 30 } \ 31 } while (0) 32 33 #define ASSERT_NOCOUNT(expr) do { \ 34 if (!(expr)) { \ 35 PRINT_FAILURE(expr) \ 36 abort(); \ 37 } \ 38 } while (0) 39 40 #define ASSERT_STATUS(expr, status) do { \ 41 ++num_assertions; \ 42 if (!(expr)) { \ 43 PRINT_FAILURE(expr) \ 44 fprintf(stderr, "failed status: %s\n", upb_status_errmsg(status)); \ 45 abort(); \ 46 } \ 47 } while (0) 48 49 #ifdef __cplusplus 50 } /* extern "C" */ 51 #endif 52 53 #endif /* UPB_DECODER_H_ */ 54