}
static void watch_functionality_basic_test() {
- assert(0);
+ /* see `man inotify` for explanation of alignment modifiers */
+ char buf[4096] __attribute__ ((aligned(__alignof__(struct inotify_event))));
+ const struct inotify_event *event;
+ int fd, watch_fd;
+ ssize_t len;
+ char *p;
+
+ fd = inotify_init();
+ assert(fd>=0);
+
+ watch_fd = inotify_add_watch(fd,TEST_DIRECTORY,WATCH_FLAGS);
+ assert(watch_fd>=0);
+
+ system("echo hello > " TEST_DIRECTORY "/notarealfile.txt"); // IN_CREATE + IN_MODIFY + IN_CLOSE_WRITE
+ system("echo hello2 >> " TEST_DIRECTORY "/notarealfile.txt"); // IN_MODIFY + IN_CLOSE_WRITE
+ system("mv " TEST_DIRECTORY "/notarealfile.txt " TEST_DIRECTORY "/notarealfile2.txt"); // IN_MOVED_TO
+ system("rm " TEST_DIRECTORY "/notarealfile2.txt"); // IN_DELETE
+
+ len = read(fd,buf,sizeof(buf));
+ assert(len==336);
+
+ p = buf;
+ event = (const struct inotify_event*) p;
+ assert(event->mask & IN_CREATE);
+ assert(strcmp(event->name,"notarealfile.txt")==0);
+
+ p += (sizeof(struct inotify_event)+event->len);
+ event = (const struct inotify_event*) p;
+ assert(event->mask & IN_MODIFY);
+ assert(strcmp(event->name,"notarealfile.txt")==0);
+
+ p += (sizeof(struct inotify_event)+event->len);
+ event = (const struct inotify_event*) p;
+ assert(event->mask & IN_CLOSE_WRITE);
+ assert(strcmp(event->name,"notarealfile.txt")==0);
+
+ p += (sizeof(struct inotify_event)+event->len);
+ event = (const struct inotify_event*) p;
+ assert(event->mask & IN_MODIFY);
+ assert(strcmp(event->name,"notarealfile.txt")==0);
+
+ p += (sizeof(struct inotify_event)+event->len);
+ event = (const struct inotify_event*) p;
+ assert(event->mask & IN_CLOSE_WRITE);
+ assert(strcmp(event->name,"notarealfile.txt")==0);
+
+ p += (sizeof(struct inotify_event)+event->len);
+ event = (const struct inotify_event*) p;
+ assert(event->mask & IN_MOVED_TO);
+ assert(strcmp(event->name,"notarealfile2.txt")==0);
+
+ p += (sizeof(struct inotify_event)+event->len);
+ event = (const struct inotify_event*) p;
+ assert(event->mask & IN_DELETE);
+ assert(strcmp(event->name,"notarealfile2.txt")==0);
+
+ assert((p+(sizeof(struct inotify_event)+event->len)-buf)==336);
+
+ close(fd);
+
+ reset_env();
}
static void watch_spawn_all_basic_test() {
close(fd);
torrent_free(p);
+
+ reset_env();
}