5
4
#include "event_operator.h"
7
/* TEST_ENSURE_CLEAN_ENV:
9
* Ensure the environment is as pristine as possible (to avoid follow-on
10
* errors caused by not freeing objects in a previous test, say)
12
#define TEST_ENSURE_CLEAN_ENV() \
14
setvbuf(stdout, NULL, _IONBF, 0); \
17
TEST_HASH_EMPTY (job_classes); \
21
TEST_LIST_EMPTY (conf_sources); \
24
if (nih_io_watches) { \
25
TEST_LIST_EMPTY (nih_io_watches); \
29
TEST_LIST_EMPTY (nih_timers); \
32
if (nih_child_watches) { \
33
TEST_LIST_EMPTY (nih_child_watches); \
37
TEST_LIST_EMPTY (events); \
43
* @force: if TRUE, force an update,
44
* @timeout: struct timeval pointer, or NULL if no timeout required.
46
* Request NIH look for a file event relating to any NihIo objects,
47
* with an optional timeout. Behaviour can be forced via @force.
49
#define _TEST_WATCH_UPDATE(force, timeout) \
53
fd_set readfds, writefds, exceptfds; \
56
FD_ZERO (&writefds); \
57
FD_ZERO (&exceptfds); \
59
nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds); \
61
ret = select (nfds, &readfds, &writefds, \
62
&exceptfds, timeout); \
64
if (force || ret > 0) \
65
nih_io_handle_fds (&readfds, &writefds, &exceptfds); \
71
* Request NIH look for a file event relating to any NihIo objects,
73
#define TEST_WATCH_UPDATE() \
74
_TEST_WATCH_UPDATE (0, NULL)
77
* TEST_WATCH_UPDATE_TIMEOUT:
78
* @timeout: struct timeval pointer.
80
* Request NIH look for a file event relating to any NihIo objects
81
* within time period @timeout.
83
#define TEST_WATCH_UPDATE_TIMEOUT(timeout) \
84
_TEST_WATCH_UPDATE (0, timeout)
87
* TEST_WATCH_UPDATE_TIMEOUT_SECS:
88
* @secs: seconds to wait before timeout.
90
* Request NIH look for a file event relating to any NihIo objects
91
* within @secs timeout.
93
#define TEST_WATCH_UPDATE_TIMEOUT_SECS(secs) \
98
_TEST_WATCH_UPDATE (0, &_t); \
102
* TEST_FORCE_WATCH_UPDATE:
104
* Force NIH to look for a file event relating to any NihIo objects.
106
#define TEST_FORCE_WATCH_UPDATE() \
107
_TEST_WATCH_UPDATE (1, NULL)
110
* TEST_FORCE_WATCH_UPDATE_TIMEOUT:
111
* @timeout: struct timeval pointer.
113
* Force NIH to look for a file event relating to any NihIo objects
114
* within time period @timeout.
116
#define TEST_FORCE_WATCH_UPDATE_TIMEOUT(timeout) \
117
_TEST_WATCH_UPDATE (1, timeout)
120
* TEST_FORCE_WATCH_UPDATE_TIMEOUT_SECS:
121
* @timeout: struct timeval pointer.
123
* Force NIH to look for a file event relating to any NihIo objects
124
* within time period @timeout.
126
#define TEST_FORCE_WATCH_UPDATE_TIMEOUT_SECS(secs) \
131
_TEST_WATCH_UPDATE (1, &_t); \
135
* ENSURE_DIRECTORY_EMPTY:
136
* @path: Full path to a directory.
138
* Ensure specified directory is empty.
140
#define ENSURE_DIRECTORY_EMPTY(path) \
143
struct dirent *file = NULL; \
146
dp = opendir (path); \
147
TEST_NE_P (dp, NULL); \
149
while((file = readdir (dp))) { \
150
if (!strcmp (".", file->d_name) || \
151
!strcmp ("..", file->d_name)) \
158
TEST_EQ (count, 0); \
166
* @name: name of string element.
168
* Compare string element @name in objects @a and @b.
170
* Returns: 0 if strings are identical
171
* (or both NULL), else 1.
173
#define obj_string_check(a, b, name) \
174
string_check ((a)->name, (b)->name)
181
* @name: name of numeric element.
183
* Compare numeric element @name in objects @a and @b.
185
* Returns: 0 if @a and @b are identical, else 1.
187
#define obj_num_check(a, b, name) \
191
* TEST_CMP_INT_ARRAYS:
194
* @sizea: size of @a,
195
* @sizeb: size of @b.
197
* Compare integer arrays @a and @b for equivalence.
199
* Returns: 0 if arrays are identical, else -1.
201
#define TEST_CMP_INT_ARRAYS(a, b, sizea, sizeb) \
204
if (sizea == sizeb) { \
208
if ((a)[__i] != (b)[__i]) { \
218
* TEST_CMP_STR_ARRAYS:
219
* @a: first string array,
220
* @b: second string array,
221
* @sizea: length of @a,
222
* @sizeb: length of @b.
224
* Compare string arrays @a and @b for equivalence.
226
* Returns: 0 if arrays are identical, else -1.
228
#define TEST_CMP_STR_ARRAYS(a, b, sizea, sizeb) \
230
if (sizea == sizeb) { \
231
for (size_t __i = 0; \
234
if (strcmp (a[__i], b[__i])) { \
244
* TEST_TWO_LISTS_FOREACH:
245
* @list1: entry in the first list to iterate,
246
* @list2: entry in the second list to iterate,
247
* @iter1: name of iterator variable for @list1,
248
* @iter2: name of iterator variable for @list2.
250
* Dual version of NIH_LIST_FOREACH() which iterates
251
* two lists in tandem.
253
#define TEST_TWO_LISTS_FOREACH(list1, list2, iter1, iter2) \
254
for (NihList *iter1 = (list1)->next, \
255
*iter2 = (list2)->next; \
256
iter1 != (list1) && iter2 != (list2); \
257
iter1 = iter1->next, \
261
* TEST_TWO_HASHES_FOREACH:
262
* @hash1: entry in the first hash to iterate,
263
* @hash2: entry in the second hash to iterate,
264
* @iter1: name of iterator variable for @hash1,
265
* @iter2: name of iterator variable for @hash2.
267
* Dual version of NIH_HASH_FOREACH() which iterates
268
* two hashes in tandem.
270
#define TEST_TWO_HASHES_FOREACH(hash1, hash2, iter1, iter2) \
271
for (size_t _##iter##_i = 0; _##iter##_i < (hash1)->size; \
273
TEST_TWO_LISTS_FOREACH (&(hash1)->bins[_##iter##_i], \
274
&(hash2)->bins[_##iter##_i], \
278
* TEST_TWO_TREES_FOREACH:
279
* @tree1: root of the first tree to iterate,
280
* @tree2: root of the second tree to iterate,
281
* @iter1: name of iterator variable for @tree1,
282
* @iter2: name of iterator variable for @tree2.
284
* Dual version of NIH_TREE_FOREACH() which walks
285
* two trees in tandem.
287
#define TEST_TWO_TREES_FOREACH(tree1, tree2, iter1, iter2) \
288
for (NihTree *iter1 = nih_tree_next (tree1, NULL), \
289
*iter2 = nih_tree_next (tree2, NULL); \
290
iter1 != NULL && iter2 != NULL; \
291
iter1 = nih_tree_next (tree1, iter1), \
292
iter2 = nih_tree_next (tree2, iter2))
299
* Determine size of specified array.
301
* Returns: array size.
303
#define TEST_ARRAY_SIZE(array) \
304
(sizeof (array) / sizeof (array[0]))
307
int string_check (const char *a, const char *b)
308
__attribute__ ((warn_unused_result));
310
11
int event_operator_diff (EventOperator *a, EventOperator *b)
311
12
__attribute__ ((warn_unused_result));
313
Session * session_from_chroot (const char *chroot)
14
Session *session_from_chroot (const char *chroot)
314
15
__attribute__ ((warn_unused_result));
17
void ensure_env_clean (void);
19
void clean_env (void);
316
21
#endif /* TEST_UTIL_H */