Tests for crypto; more tests for buffers
[tor.git] / src / common / test.h
blob8be3afd77e44db019b5d3c0d930b2624ac51e53f
1 /* Copyright 2001,2002 Roger Dingledine, Matej Pfajfar. */
2 /* See LICENSE for licensing information */
3 /* $Id$ */
5 #ifndef __TEST_H
6 #define __TEST_H
8 #include <string.h>
10 #define STMT_BEGIN do {
11 #define STMT_END } while (0)
13 #define test_fail() \
14 STMT_BEGIN \
15 printf("\nFile %s: line %d (%s): assertion failed.", \
16 __FILE__, \
17 __LINE__, \
18 __PRETTY_FUNCTION__); \
19 return; \
20 STMT_END
22 #define test_assert(expr) \
23 STMT_BEGIN \
24 if(expr) { printf("."); } else { \
25 printf("\nFile %s: line %d (%s): assertion failed: (%s)\n", \
26 __FILE__, \
27 __LINE__, \
28 __PRETTY_FUNCTION__, \
29 #expr); \
30 return; \
31 } STMT_END
33 #define test_eq(expr1, expr2) \
34 STMT_BEGIN if(expr1==expr2) { printf("."); } else { \
35 printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n"\
36 " (%ld != %ld)\n", \
37 __FILE__, \
38 __LINE__, \
39 __PRETTY_FUNCTION__, \
40 #expr1, #expr2, \
41 (long)expr1, (long)expr2); \
42 return; \
43 } STMT_END
45 #define test_neq(expr1, expr2) \
46 STMT_BEGIN if(expr1!=expr2) { printf("."); } else { \
47 printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n"\
48 " (%ld == %ld)\n", \
49 __FILE__, \
50 __LINE__, \
51 __PRETTY_FUNCTION__, \
52 #expr1, #expr2, \
53 (long)expr1, (long)expr2); \
54 return; \
55 } STMT_END
57 #define test_streq(expr1, expr2) \
58 STMT_BEGIN if(!strcmp(expr1,expr2)) { printf("."); } else { \
59 printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n"\
60 " (%s != %s)\n", \
61 __FILE__, \
62 __LINE__, \
63 __PRETTY_FUNCTION__, \
64 #expr1, #expr2, \
65 expr1, expr2); \
66 return; \
67 } STMT_END
69 #define test_strneq(expr1, expr2) \
70 STMT_BEGIN if(strcmp(expr1,expr2)) { printf("."); } else { \
71 printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n"\
72 " (%s == %s)\n", \
73 __FILE__, \
74 __LINE__, \
75 __PRETTY_FUNCTION__, \
76 #expr1, #expr2, \
77 expr1, expr2); \
78 return; \
79 } STMT_END
81 #define test_memeq(expr1, expr2, len) \
82 STMT_BEGIN if(!memcmp(expr1,expr2,len)) { printf("."); } else { \
83 printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n", \
84 __FILE__, \
85 __LINE__, \
86 __PRETTY_FUNCTION__, \
87 #expr1, #expr2); \
88 return; \
89 } STMT_END
91 #define test_memneq(expr1, expr2, len) \
92 STMT_BEGIN if(memcmp(expr1,expr2,len)) { printf("."); } else { \
93 printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n", \
94 __FILE__, \
95 __LINE__, \
96 __PRETTY_FUNCTION__, \
97 #expr1, #expr2); \
98 return; \
99 } STMT_END
101 #endif
104 Local Variables:
105 mode:c
106 indent-tabs-mode:nil
107 c-basic-offset:2
108 End: