diff options
author | Ulf Lilleengen <lulf@pvv.ntnu.no> | 2009-07-18 12:21:39 +0200 |
---|---|---|
committer | Ulf Lilleengen <lulf@pvv.ntnu.no> | 2009-07-18 12:21:39 +0200 |
commit | dfb0c1845a8937dbb1e669c16a2ed36547a8a00f (patch) | |
tree | 9940240b4fc91d15701d6d8532c8150ef629268c /pnotify/pnotify-0.2/test.c | |
parent | fe92bb6fa8c7ccd15d9506f65c54e78de25881f7 (diff) |
- Remove pnotify library again as the API is a bit messy and handles things in a
different way than musicfs requires.
Diffstat (limited to 'pnotify/pnotify-0.2/test.c')
-rw-r--r-- | pnotify/pnotify-0.2/test.c | 130 |
1 files changed, 0 insertions, 130 deletions
diff --git a/pnotify/pnotify-0.2/test.c b/pnotify/pnotify-0.2/test.c deleted file mode 100644 index bab8500..0000000 --- a/pnotify/pnotify-0.2/test.c +++ /dev/null @@ -1,130 +0,0 @@ -#include <err.h> -#include <signal.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <unistd.h> - -#include "pnotify.h" - -/* Compare a pnotify_event against an expected set of values */ -int -event_cmp(struct pnotify_event *ev, int wd, int mask, const char *name) -{ - int i = (ev->wd == wd) && - (ev->mask == mask) && - (strcmp(ev->name, name) == 0); - if (!i) { - printf(" *ERROR * mismatch: expecting '%d:%d:%s' but got '%d:%d:%s'\n", - wd, mask, name, - ev->wd, ev->mask, ev->name); - } - return i; -} - -#define test(x) printf(" * " #x ": %s\n", ((x) >= 0) ? "passed" : "failed") - -int -main(int argc, char **argv) -{ - struct pnotify_event evt; - struct pnotify_cb ctl; - int wd; - - /* Create a test directory */ - (void) system("rm -rf .check"); - if (system("mkdir .check") < 0) - err(1, "mkdir failed"); - if (system("mkdir .check/dir") < 0) - err(1, "mkdir failed"); - - /* Initialize the control structure */ - test(pnotify_init(&ctl)); - - /* Watch for events in the test directory */ - test((wd = pnotify_add_watch(&ctl, ".check", PN_ALL_EVENTS))); - - /* Create a new file */ - test (system("touch .check/foo")); - - /* Read the event */ - test (pnotify_get_event(&evt, &ctl)); - if (!event_cmp(&evt, 1, PN_CREATE, "foo")) - err(1, "unexpected event value"); - - /* Create a new file #2 */ - test (system("touch .check/bar")); - - /* Read the event */ - test (pnotify_get_event(&evt, &ctl)); - if (!event_cmp(&evt, 1, PN_CREATE, "bar")) - err(1, "unexpected event value"); - - /* Delete the new file */ - test (system("rm .check/foo")); - - /* Read the delete event */ - test (pnotify_get_event(&evt, &ctl)); - if (!event_cmp(&evt, 1, PN_DELETE, "foo")) - err(1, "unexpected event value"); - - /* Modify file #2 */ - test (system("echo hi >> .check/bar")); - - /* Read the modify event */ - test (pnotify_get_event(&evt, &ctl)); - if (!event_cmp(&evt, 1, PN_MODIFY, "bar")) - err(1, "unexpected event value"); - - /* Remove the watch */ - test (pnotify_rm_watch(&ctl, wd)); - - /* Destroy the control structure */ - test (pnotify_free(&ctl)); - -#if DEADWOOD - if ((fd = inotify_init()) < 0) - err(1, "%s", "inotify_init()"); - - if ((wd = inotify_add_watch(fd, ".check", IN_ALL_EVENTS)) <= 0) - err(1, "%s - %d", "inotify_add_watch()", wd); - - if ((wd = inotify_rm_watch(fd, wd)) < 0) - err(1, "%s", "inotify_rm_watch()"); - - if ((wd = inotify_rm_watch(fd, 666)) == 0) - err(1, "%s", "inotify_rm_watch() - false positive"); - - /* Add it back so we can monitor events */ - if ((wd = inotify_add_watch(fd, ".check", IN_ALL_EVENTS)) <= 0) - err(1, "%s - %d", "inotify_add_watch()", wd); - - printf("touching foo\n"); - if (system("touch .check/foo") < 0) - err(1, "touch failed"); - get_event(fd, &evt, &name, sizeof(name)); - -#if TODO - if ((wd = inotify_add_watch(fd, ".check/foo", IN_ALL_EVENTS)) <= 0) - err(1, "%s - %d", "inotify_add_watch()", wd); - - printf("touching bar\n"); - if (system("touch .check/bar") < 0) - err(1, "touch failed"); - - printf("unlinking foo\n"); - if (system("rm .check/foo") < 0) - err(1, "rm failed"); - - printf("unlinking bar\n"); - if (system("rm .check/bar") < 0) - err(1, "rm failed"); - -#endif -#endif - - printf("all tests passed.\n"); - exit(EXIT_SUCCESS); -} |