946
946
nih_error_init ();
948
948
TEST_FILENAME (dirname);
949
mkdir (dirname, 0755);
949
TEST_EQ (mkdir (dirname, 0755), 0);
951
TEST_FEATURE ("with watched file");
952
strcpy (filename, dirname);
953
strcat (filename, "/foo");
955
/* Create file first since we don't set a create handler on the
958
fd = fopen (filename, "w");
959
fprintf (fd, "bar\n");
970
watch = nih_watch_new (NULL, filename, FALSE, FALSE, NULL,
971
NULL, my_modify_handler,
972
my_delete_handler, &watch);
973
TEST_NE_P (watch, NULL);
975
/* Now, modify the existing file to trigger the modify handler. */
976
fd = fopen (filename, "a+");
977
fprintf (fd, "baz\n");
983
FD_ZERO (&exceptfds);
985
nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds);
986
select (nfds, &readfds, &writefds, &exceptfds, NULL);
987
nih_io_handle_fds (&readfds, &writefds, &exceptfds);
989
TEST_EQ_STR (watch->path, filename);
991
/* Ensure no regression to old behaviour (LP:#777097) */
992
TEST_NE (last_path[ strlen(last_path) - 1 ], '/');
994
TEST_EQ_STR (last_path, filename);
995
TEST_EQ (modify_called, 1);
1001
FD_ZERO (&writefds);
1002
FD_ZERO (&exceptfds);
1004
nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds);
1005
select (nfds, &readfds, &writefds, &exceptfds, NULL);
1006
nih_io_handle_fds (&readfds, &writefds, &exceptfds);
1008
TEST_EQ (delete_called, 1);
1011
nih_free (last_path);
951
1022
watch = nih_watch_new (NULL, dirname, TRUE, TRUE, my_filter,
952
1023
my_create_handler, my_modify_handler,
953
1024
my_delete_handler, &watch);
956
1025
/* Check that creating a file within the directory being watched
957
1026
* results in the create handler being called, and passed the full
958
1027
* path of the created file to it.