Angband
unit-test.h
Go to the documentation of this file.
1 /* unit-test.h */
2 
3 #ifndef UNIT_TEST_H
4 #define UNIT_TEST_H
5 
6 #include "unit-test-types.h"
7 #include "z-util.h"
8 
9 #define TEST
10 
11 extern int verbose;
12 
13 extern int showpass(void);
14 extern int showfail(void);
15 
16 /* Forward declaration, since suite_names may be at the end of the test
17  * file.
18  */
19 const char *suite_name;
20 
21 #define NOSETUP int setup_tests(void **data) { return 0; }
22 #define NOTEARDOWN int teardown_tests(void *data) { return 0; }
23 
24 #define ok return showpass();
25 
26 #define eq(x,y) \
27  if ((x) != (y)) { \
28  if (verbose) { \
29  showfail(); \
30  printf(" %s:%d: requirement '%s' == '%s' failed\n", suite_name, \
31  __LINE__, #x, #y); \
32  printf(" %s: 0x%016lld\n", #x, (long long)x); \
33  printf(" %s: 0x%016lld\n", #y, (long long)y); \
34  } \
35  return 1; \
36  }
37 
38 #define noteq(x,y) \
39  if ((x) == (y)) { \
40  if (verbose) { \
41  showfail(); \
42  printf(" %s:%d: requirement '%s' != '%s' failed\n", suite_name, \
43  __LINE__, #x, #y); \
44  printf(" %s: 0x%016lld\n", #x, (long long)x); \
45  printf(" %s: 0x%016lld\n", #y, (long long)y); \
46  } \
47  return 1; \
48  }
49 
50 #define require(x) \
51  do { \
52  if (!(x)) { \
53  if (verbose) \
54  showfail(); \
55  printf(" %s:%d: requirement '%s' failed\n", \
56  suite_name, __LINE__, #x); \
57  return 1; \
58  } \
59  } while (0)
60 
61 #if __WORDSIZE == 64
62 #define ptreq(x,y) \
63  if ((x) != (y)) { \
64  if (verbose) { \
65  showfail(); \
66  printf(" %s:%d: requirement '%s' == '%s' failed\n", suite_name, \
67  __LINE__, #x, #y); \
68  printf(" %s: 0x%016llx\n", #x, (unsigned long long)(x)); \
69  printf(" %s: 0x%016llx\n", #y, (unsigned long long)(y)); \
70  } \
71  return 1; \
72  }
73 
74 #else
75 #define ptreq(x,y) \
76  if ((x) != (y)) { \
77  if (verbose) { \
78  showfail(); \
79  printf(" %s:%d: requirement '%s' == '%s' failed\n", suite_name, \
80  __LINE__, #x, #y); \
81  printf(" %s: 0x%08lx\n", #x, (unsigned long)(x)); \
82  printf(" %s: 0x%08lx\n", #y, (unsigned long)(y)); \
83  } \
84  return 1; \
85  }
86 
87 #endif
88 
89 #endif /* !UNIT_TEST_H */