initial load of upstream version 1.06.32
[xmlrpc-c] / src / test / test.h
1 #include <stdlib.h>
2 #include <stdio.h>
3
4 #include "xmlrpc-c/util.h"
5
6 extern int total_tests;
7 extern int total_failures;
8
9
10 /* This is a good place to set a breakpoint. */
11 static __inline__ void
12 test_failure(const char * const file,
13              unsigned int const line,
14              const char * const label,
15              const char * const statement) {
16
17     ++total_failures;
18     printf("\n%s:%u: test failure: %s (%s)\n", file, line, label, statement);
19     abort();
20 }
21
22
23
24 #define TEST(statement) \
25 do { \
26     ++total_tests; \
27     if ((statement)) { \
28         printf("."); \
29     } else { \
30         test_failure(__FILE__, __LINE__, "expected", #statement); \
31     } \
32    } while (0)
33
34 #define TEST_NO_FAULT(env) \
35     do { \
36         ++total_tests; \
37         if (!(env)->fault_occurred) { \
38             printf("."); \
39         } else { \
40             test_failure(__FILE__, __LINE__, "fault occurred", \
41             (env)->fault_string); \
42         } \
43        } while (0)
44
45 static inline void
46 test_fault(xmlrpc_env * const envP,
47            int          const expectedCode,
48            const char * const fileName,
49            unsigned int const lineNumber) {
50
51     ++total_tests;
52     if (!envP->fault_occurred)
53         test_failure(fileName, lineNumber, "no fault occurred", "");
54     else if (envP->fault_code != expectedCode)
55         test_failure(fileName, lineNumber, "wrong fault occurred",
56                      envP->fault_string);
57     else
58         printf(".");
59
60     xmlrpc_env_clean(envP);
61     xmlrpc_env_init(envP);
62 }
63
64
65 #define TEST_FAULT(envP, code) \
66     do { test_fault(envP, code, __FILE__, __LINE__); } while(0)
67
68 ;
69
70 #define TEST_ERROR(reason) \
71 do { \
72     printf("Unable to test at %s/%u.  %s", __FILE__, __LINE__, reason); \
73     abort(); \
74    } while (0)
75