]> git.notmuchmail.org Git - notmuch/blob - test/notmuch-test.h
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / test / notmuch-test.h
1 #ifndef _NOTMUCH_TEST_H
2 #define _NOTMUCH_TEST_H
3 #ifndef _GNU_SOURCE
4 #define _GNU_SOURCE
5 #endif
6
7 #include <assert.h>
8 #include <dlfcn.h>
9 #include <fcntl.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <sys/stat.h>
14 #include <sys/types.h>
15 #include <sys/wait.h>
16 #include <talloc.h>
17 #include <unistd.h>
18
19 #include <notmuch.h>
20
21 inline static void
22 expect0 (int line, notmuch_status_t ret)
23 {
24     if (ret) {
25         fprintf (stderr, "line %d: %d\n", line, ret);
26         exit (1);
27     }
28 }
29
30 #define EXPECT0(v)  expect0 (__LINE__, v);
31
32 inline static void *
33 dlsym_next (const char *symbol)
34 {
35     void *sym = dlsym (RTLD_NEXT, symbol);
36     char *str = dlerror ();
37
38     if (str != NULL) {
39         fprintf (stderr, "finding symbol '%s' failed: %s", symbol, str);
40         exit (77);
41     }
42     return sym;
43 }
44
45 #define WRAP_DLFUNC(_rtype, _func, _args)                               \
46     _rtype _func _args;                                                 \
47     _rtype _func _args {                                                \
48         static _rtype (*_func##_orig) _args = NULL;                         \
49         if (! _func##_orig ) *(void **) (&_func##_orig) = dlsym_next (#_func);
50 #endif