| 1 |
/* |
| 2 |
* Test Directory Watch |
| 3 |
*/ |
| 4 |
|
| 5 |
#undef NDEBUG |
| 6 |
#include <c-stdaux.h> |
| 7 |
#include <stdlib.h> |
| 8 |
#include "util/dirwatch.h" |
| 9 |
|
| 10 |
static void test_basic(void) { |
| 11 |
int r, fd; |
| 12 |
|
| 13 |
/* test cleanup helper */ |
| 14 |
{ |
| 15 |
_c_cleanup_(dirwatch_freep) _c_unused_ Dirwatch *dw1 = NULL, *dw2 = NULL; |
| 16 |
|
| 17 |
/* prevent 'unused variable' warning */ |
| 18 |
dw1 = NULL; |
| 19 |
|
| 20 |
r = dirwatch_new(&dw2); |
| 21 |
c_assert(!r); |
| 22 |
} |
| 23 |
|
| 24 |
/* test no-op dispatcher */ |
| 25 |
{ |
| 26 |
_c_cleanup_(dirwatch_freep) Dirwatch *dw = NULL; |
| 27 |
|
| 28 |
r = dirwatch_new(&dw); |
| 29 |
c_assert(!r); |
| 30 |
|
| 31 |
fd = dirwatch_get_fd(dw); |
| 32 |
c_assert(fd >= 0); |
| 33 |
|
| 34 |
r = dirwatch_dispatch(dw); |
| 35 |
c_assert(!r); |
| 36 |
|
| 37 |
r = dirwatch_add(dw, "."); |
| 38 |
c_assert(!r); |
| 39 |
|
| 40 |
r = dirwatch_dispatch(dw); |
| 41 |
c_assert(!r); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
int main(int argc, char **argv) { |
| 46 |
test_basic(); |
| 47 |
return 0; |
| 48 |
} |