summaryrefslogtreecommitdiff
path: root/tests/upb_test.h
blob: d4b06883c3ecfe84a83928181c2199ca8f6a9261 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

#ifndef UPB_TEST_H_
#define UPB_TEST_H_

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

int num_assertions = 0;
uint32_t testhash = 0;

#define PRINT_FAILURE(expr) \
  fprintf(stderr, "Assertion failed: %s:%d\n", __FILE__, __LINE__); \
  fprintf(stderr, "expr: %s\n", #expr); \
  if (testhash) { \
    fprintf(stderr, "assertion failed running test %x.  " \
                    "Run with the arg %x to run only this test.\n", \
                    testhash, testhash); \
  }

#define ASSERT(expr) do { \
  ++num_assertions; \
  if (!(expr)) { \
    PRINT_FAILURE(expr) \
    abort(); \
  } \
} while (0)

#define ASSERT_NOCOUNT(expr) do { \
  if (!(expr)) { \
    PRINT_FAILURE(expr) \
    abort(); \
  } \
} while (0)

#define ASSERT_STATUS(expr, status) do { \
  ++num_assertions; \
  if (!(expr)) { \
    PRINT_FAILURE(expr) \
    fprintf(stderr, "failed status: %s\n", upb_status_errmsg(status)); \
    abort(); \
  } \
} while (0)

#ifdef __cplusplus
}  /* extern "C" */
#endif

#endif  /* UPB_DECODER_H_ */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback