File: TestSuite.h

package info (click to toggle)
syslog-ng 3.8.1-10
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 47,320 kB
  • ctags: 43,937
  • sloc: ansic: 159,432; yacc: 25,059; sh: 13,574; makefile: 4,669; python: 3,468; java: 3,218; xml: 2,309; perl: 318; lex: 316; awk: 184
file content (193 lines) | stat: -rw-r--r-- 4,731 bytes parent folder | download
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
 * Copyright 2014 MongoDB, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#ifndef TEST_SUITE_H
#define TEST_SUITE_H


#include <stdio.h>


#ifdef __cplusplus
extern "C" {
#endif


#ifndef BINARY_DIR
# define BINARY_DIR "tests/binary"
#endif


#ifdef ASSERT
# undef ASSERT
#endif
#define ASSERT assert


#ifdef ASSERT_OR_PRINT
# undef ASSERT_OR_PRINT
#endif
#define ASSERT_OR_PRINT(_statement, _err) \
   do { \
      if (! (_statement)) { \
         fprintf(stderr, "FAIL:%s:%d  %s()\n  %s\n  %s\n\n", \
                         __FILE__, __LINE__, __FUNCTION__, \
                         #_statement, _err.message); \
         fflush(stderr); \
         abort(); \
      } \
   } while (0)


#ifdef ASSERT_CMPINT
# undef ASSERT_CMPINT
#endif
#define ASSERT_CMPINT(a, eq, b) \
   do { \
      if (!((a) eq (b))) { \
         fprintf(stderr, "FAIL\n\nAssert Failure: %d %s %d\n" \
                         "%s:%d  %s()\n", \
                         a, #eq, b, \
                         __FILE__, __LINE__, __FUNCTION__); \
         abort(); \
      } \
   } while (0)


#ifdef ASSERT_ALMOST_EQUAL
# undef ASSERT_ALMOST_EQUAL
#endif
#define ASSERT_ALMOST_EQUAL(a, b) \
   do { \
      /* evaluate once */ \
      int64_t _a = (a); \
      int64_t _b = (b); \
      if (!(_a > (_b * 4) / 5 && (_a < (_b * 6) / 5))) { \
         fprintf(stderr, "FAIL\n\nAssert Failure: %" PRId64 \
                         " not within 20%% of %" PRId64 "\n" \
                         "%s:%d  %s()\n", \
                         _a, _b, \
                         __FILE__, __LINE__, __FUNCTION__); \
         abort(); \
      } \
   } while (0)


#define ASSERT_CMPSTR(a, b) \
   do { \
      if (((a) != (b)) && !!strcmp((a), (b))) { \
         fprintf(stderr, "FAIL\n\nAssert Failure: \"%s\" != \"%s\"\n", \
                         a, b); \
         abort(); \
      } \
   } while (0)


#define ASSERT_CONTAINS(a, b) \
   do { \
      if (NULL == strstr ((a), (b))) { \
         fprintf(stderr, \
                 "FAIL\n\nAssert Failure: \"%s\" does not contain \"%s\"\n", \
                 a, b); \
         abort(); \
      } \
   } while (0)

#define ASSERT_STARTSWITH(a, b) \
   do { \
      if ((a) != strstr ((a), (b))) { \
         fprintf(stderr, \
                 "FAIL\n\nAssert Failure: \"%s\" does not start with \"%s\"\n", \
                 a, b); \
         abort(); \
      } \
   } while (0)

#define AWAIT(_condition) \
   do { \
      int64_t _start = bson_get_monotonic_time (); \
      while (! (_condition)) { \
         if (bson_get_monotonic_time() - _start > 1000 * 1000) { \
            fprintf (stderr, \
                     "%s:%d %s(): \"%s\" still false after 1 second\n", \
                     __FILE__, __LINE__, __FUNCTION__, #_condition); \
            abort (); \
         } \
      }  \
   } while (0)

#define MAX_TEST_NAME_LENGTH 500


typedef void (*TestFunc) (void);
typedef void (*TestFuncWC) (void*);
typedef void (*TestFuncDtor) (void*);
typedef struct _Test Test;
typedef struct _TestSuite TestSuite;


struct _Test
{
   Test *next;
   char *name;
   TestFuncWC func;
   TestFuncDtor dtor;
   void *ctx;
   int exit_code;
   unsigned seed;
   int (*check) (void);
};


struct _TestSuite
{
   char *prgname;
   char *name;
   char *testname;
   Test *tests;
   FILE *outfile;
   int flags;
};


void TestSuite_Init    (TestSuite *suite,
                        const char *name,
                        int argc,
                        char **argv);
void TestSuite_Add     (TestSuite *suite,
                        const char *name,
                        TestFunc func);
void TestSuite_AddWC   (TestSuite *suite,
                        const char *name,
                        TestFuncWC func,
                        TestFuncDtor dtor,
                        void *ctx);
void TestSuite_AddFull (TestSuite *suite,
                        const char *name,
                        TestFuncWC func,
                        TestFuncDtor dtor,
                        void *ctx,
                        int (*check) (void));
int  TestSuite_Run     (TestSuite *suite);
void TestSuite_Destroy (TestSuite *suite);

#ifdef __cplusplus
}
#endif


#endif /* TEST_SUITE_H */