2016-04-12 12:00:23 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2018-06-26 15:22:11 -07:00
|
|
|
#define EIO_SENTRY_BETA
|
|
|
|
|
2016-04-12 12:00:23 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <Ecore.h>
|
|
|
|
#include <Ecore_File.h>
|
|
|
|
#include <Eio.h>
|
|
|
|
|
|
|
|
#include "eio_suite.h"
|
|
|
|
|
|
|
|
/////////////////timeout function
|
|
|
|
|
2018-07-17 14:17:12 -07:00
|
|
|
#define TEST_TIMEOUT_SEC 1
|
2018-06-26 15:15:53 -07:00
|
|
|
#define TEST_OPERATION_DELAY 0.05
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
static Ecore_Timer *test_timeout_timer;
|
|
|
|
|
|
|
|
static Eina_Bool _test_timeout_cb(void *data EINA_UNUSED)
|
|
|
|
{
|
|
|
|
ck_abort_msg("test timeout");
|
|
|
|
ecore_main_loop_quit();
|
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _cancel_timeout()
|
|
|
|
{
|
|
|
|
if (test_timeout_timer != NULL)
|
|
|
|
{
|
|
|
|
ecore_timer_del (test_timeout_timer);
|
|
|
|
test_timeout_timer = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool _test_timeout_expected(void *data EINA_UNUSED)
|
|
|
|
{
|
|
|
|
if (test_timeout_timer != NULL)
|
|
|
|
{
|
|
|
|
_cancel_timeout();
|
|
|
|
}
|
|
|
|
ecore_main_loop_quit();
|
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////// file and directory operations
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char *src;
|
|
|
|
const char *dst;
|
|
|
|
} RenameOperation;
|
|
|
|
|
|
|
|
static Eina_Bool _delete_directory(void *data)
|
|
|
|
{
|
|
|
|
const char *dirname = (const char*)data;
|
|
|
|
if (ecore_file_is_dir(dirname))
|
|
|
|
{
|
|
|
|
ecore_file_recursive_rm(dirname);
|
|
|
|
}
|
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool _create_directory(void *data)
|
|
|
|
{
|
|
|
|
const char *dirname = (const char*)data;
|
|
|
|
ecore_file_mkpath(dirname);
|
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Eina_Bool _create_file(void *data)
|
|
|
|
{
|
|
|
|
FILE *fd = fopen((const char*)data, "wb+");
|
|
|
|
ck_assert_ptr_ne(fd, NULL);
|
|
|
|
fprintf(fd, "test test");
|
|
|
|
fclose(fd);
|
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool _delete_file(void *data)
|
|
|
|
{
|
|
|
|
Eina_Bool file_removed = ecore_file_remove((const char*)data);
|
|
|
|
ck_assert(file_removed);
|
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool _modify_file(void *data)
|
|
|
|
{
|
|
|
|
FILE *fd = fopen((const char*)data, "ab");
|
|
|
|
ck_assert_ptr_ne(fd, NULL);
|
|
|
|
fprintf(fd, "appened");
|
|
|
|
fclose(fd);
|
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool _modify_attrib_file(void *data)
|
|
|
|
{
|
|
|
|
int ret = chmod((const char*)data, 0666);
|
|
|
|
ck_assert_int_eq(ret, 0);
|
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/////// helper functions
|
|
|
|
|
2016-08-30 05:34:10 -07:00
|
|
|
static void _check_event_path(void *data, const Efl_Event *event)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
Eio_Sentry_Event *event_info = event->info;
|
2018-05-04 03:31:18 -07:00
|
|
|
/* ignore directory creation events */
|
|
|
|
if (ecore_file_is_dir(event_info->trigger)) return;
|
2016-04-12 12:00:23 -07:00
|
|
|
ck_assert_str_eq((const char*)data, event_info->trigger);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Tmpstr *_common_init()
|
|
|
|
{
|
|
|
|
Eina_Tmpstr *dirname;
|
|
|
|
ecore_file_init();
|
|
|
|
|
|
|
|
//test timeout
|
|
|
|
test_timeout_timer = ecore_timer_add(TEST_TIMEOUT_SEC, _test_timeout_cb, NULL);
|
|
|
|
|
|
|
|
eina_file_mkdtemp("checkFileCreationXXXXXX", &dirname);
|
|
|
|
return dirname;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _common_shutdown(Eina_Tmpstr *dirname)
|
|
|
|
{
|
|
|
|
_delete_directory((void*)dirname);
|
|
|
|
ecore_file_shutdown();
|
|
|
|
eina_tmpstr_del(dirname);
|
2018-06-26 15:17:24 -07:00
|
|
|
_cancel_timeout();
|
2016-04-12 12:00:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/////// tests monitoring a directory
|
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eio_test_sentry_add_and_remove)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
Eina_Tmpstr *dirname = _common_init();
|
|
|
|
Eina_Stringshare *filename;
|
|
|
|
Eo *sentry;
|
|
|
|
|
2018-04-23 06:50:51 -07:00
|
|
|
filename = eina_stringshare_printf("%s/eio_test_sentry_add_and_remove", dirname);
|
2016-04-12 12:00:23 -07:00
|
|
|
_create_directory((void*)filename);
|
|
|
|
|
|
|
|
//monitor directory
|
2018-04-11 10:38:21 -07:00
|
|
|
sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
fail_if(!eio_sentry_add(sentry, filename));
|
|
|
|
|
2018-02-14 18:14:52 -08:00
|
|
|
eio_sentry_remove(sentry, filename);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_unref(sentry);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
_common_shutdown(dirname);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eio_test_sentry_add_remove_add)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
Eina_Tmpstr *dirname = _common_init();
|
|
|
|
Eina_Stringshare *filename;
|
|
|
|
Eo* sentry;
|
|
|
|
|
|
|
|
filename = eina_stringshare_printf("%s/eio_test_sentry_add_remove_add", dirname);
|
|
|
|
_create_directory((void*)filename);
|
|
|
|
|
|
|
|
//monitor directory
|
2018-04-11 10:38:21 -07:00
|
|
|
sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
fail_if(!eio_sentry_add(sentry, filename));
|
2018-02-14 18:14:52 -08:00
|
|
|
eio_sentry_remove(sentry, filename);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
fail_if(!eio_sentry_add(sentry, filename));
|
2018-02-14 18:14:52 -08:00
|
|
|
eio_sentry_remove(sentry, filename);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_unref(sentry);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
_common_shutdown(dirname);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eio_test_sentry_add_add_remove_remove)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
Eina_Tmpstr *dirname = _common_init();
|
|
|
|
Eina_Stringshare *filename1;
|
|
|
|
Eina_Stringshare *filename2;
|
|
|
|
Eo *sentry;
|
|
|
|
|
|
|
|
filename1 = eina_stringshare_printf("%s/eio_test_sentry_add_add_remove_remove", dirname);
|
|
|
|
filename2 = eina_stringshare_printf("%s/eio_test_sentry_add_add_remove_remove", dirname);
|
|
|
|
_create_directory((void*)filename1);
|
|
|
|
_create_directory((void*)filename2);
|
|
|
|
|
2018-04-11 10:38:21 -07:00
|
|
|
sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//monitor directory
|
|
|
|
fail_if(!eio_sentry_add(sentry, filename1));
|
|
|
|
fail_if(!eio_sentry_add(sentry, filename2));
|
2018-05-04 03:31:18 -07:00
|
|
|
|
2018-02-14 18:14:52 -08:00
|
|
|
eio_sentry_remove(sentry, filename1);
|
|
|
|
eio_sentry_remove(sentry, filename2);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_unref(sentry);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
_common_shutdown(dirname);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2016-08-30 05:34:10 -07:00
|
|
|
static void _target_notified_cb(void *data, const Efl_Event *event)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
2016-06-20 07:31:31 -07:00
|
|
|
_check_event_path(data, event);
|
|
|
|
_cancel_timeout();
|
|
|
|
ecore_main_loop_quit();
|
2016-04-12 12:00:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eio_test_sentry_directory_file_created_notify)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
Eina_Tmpstr *dirname = _common_init();
|
|
|
|
Eina_Stringshare *filename;
|
|
|
|
Eo* sentry;
|
|
|
|
|
|
|
|
filename = eina_stringshare_printf("%s/eio_test_sentry_directory_file_created_notify", dirname);
|
2018-04-11 10:38:21 -07:00
|
|
|
sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//monitor directory
|
|
|
|
fail_if(!eio_sentry_add(sentry, dirname));
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_CREATED, (Efl_Event_Cb)_target_notified_cb, filename);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
ecore_timer_add(TEST_OPERATION_DELAY, _create_file, filename);
|
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_unref(sentry);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
_common_shutdown(dirname);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eio_test_sentry_directory_file_deleted_notify)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
Eina_Tmpstr *dirname = _common_init();
|
|
|
|
Eina_Stringshare *filename;
|
|
|
|
Eo *sentry;
|
|
|
|
|
|
|
|
filename = eina_stringshare_printf("%s/eio_test_sentry_directory_file_deleted_notify", dirname);
|
|
|
|
_create_file((void*)filename);
|
2018-04-11 10:38:21 -07:00
|
|
|
sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//monitor directory
|
|
|
|
fail_if(!eio_sentry_add(sentry, dirname));
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_DELETED, (Efl_Event_Cb)_target_notified_cb, filename);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
ecore_timer_add(TEST_OPERATION_DELAY, _delete_file, filename);
|
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_unref(sentry);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
_common_shutdown(dirname);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eio_test_sentry_directory_file_modified_notify)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
Eina_Tmpstr *dirname = _common_init();
|
|
|
|
Eina_Stringshare *filename;
|
|
|
|
Eo *sentry;
|
|
|
|
|
|
|
|
filename = eina_stringshare_printf("%s/eio_test_sentry_directory_file_modified_notify", dirname);
|
|
|
|
_create_file((void*)filename);
|
2018-04-11 10:38:21 -07:00
|
|
|
sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//monitor directory
|
|
|
|
fail_if(!eio_sentry_add(sentry, dirname));
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_MODIFIED, (Efl_Event_Cb)_target_notified_cb, filename);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
ecore_timer_add(TEST_OPERATION_DELAY, _modify_file, filename);
|
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_unref(sentry);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//cleanup
|
|
|
|
_common_shutdown(dirname);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eio_test_sentry_directory_file_closed_notify)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
Eina_Tmpstr *dirname = _common_init();
|
|
|
|
Eina_Stringshare *filename;
|
|
|
|
Eo *sentry;
|
|
|
|
|
|
|
|
filename = eina_stringshare_printf("%s/eio_test_sentry_directory_file_closed_notify", dirname);
|
|
|
|
_create_file((void*)filename);
|
2018-04-11 10:38:21 -07:00
|
|
|
sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//monitor directory
|
|
|
|
fail_if(!eio_sentry_add(sentry, dirname));
|
2018-06-26 15:22:11 -07:00
|
|
|
if (eio_sentry_fallback_check(sentry, dirname))
|
|
|
|
printf("skipping %s: using fallback monitoring\n", "eio_test_sentry_directory_file_closed_notify");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
efl_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_CLOSED, (Efl_Event_Cb)_target_notified_cb, filename);
|
|
|
|
ecore_timer_add(TEST_OPERATION_DELAY, _modify_file, filename);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2018-06-26 15:22:11 -07:00
|
|
|
ecore_main_loop_begin();
|
|
|
|
}
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_unref(sentry);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
_common_shutdown(dirname);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eio_test_sentry_directory_directory_created_notify)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
Eina_Tmpstr *dirname = _common_init();
|
|
|
|
Eina_Stringshare *filename;
|
|
|
|
Eo *sentry;
|
|
|
|
|
|
|
|
filename = eina_stringshare_printf("%s/eio_test_sentry_directory_directory_created_notify", dirname);
|
2018-04-11 10:38:21 -07:00
|
|
|
sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//monitor directory
|
|
|
|
fail_if(!eio_sentry_add(sentry, dirname));
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_event_callback_add(sentry, EIO_SENTRY_EVENT_DIRECTORY_CREATED, (Efl_Event_Cb)_target_notified_cb, filename);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
ecore_timer_add(TEST_OPERATION_DELAY, _create_directory, filename);
|
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_unref(sentry);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
_common_shutdown(dirname);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eio_test_sentry_directory_directory_deleted_notify)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
Eina_Tmpstr *dirname = _common_init();
|
|
|
|
Eina_Stringshare *filename;
|
|
|
|
Eo *sentry;
|
|
|
|
|
|
|
|
filename = eina_stringshare_printf("%s/eio_test_sentry_directory_directory_deleted_notify", dirname);
|
|
|
|
_create_directory((void*)filename);
|
2018-04-11 10:38:21 -07:00
|
|
|
sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//monitor directory
|
|
|
|
fail_if(!eio_sentry_add(sentry, dirname));
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_event_callback_add(sentry, EIO_SENTRY_EVENT_DIRECTORY_DELETED, (Efl_Event_Cb)_target_notified_cb, filename);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
ecore_timer_add(TEST_OPERATION_DELAY, _delete_directory, filename);
|
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_unref(sentry);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
_common_shutdown(dirname);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eio_test_sentry_directory_directory_modified_notify)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
Eina_Tmpstr *dirname = _common_init();
|
|
|
|
Eina_Stringshare *filename;
|
|
|
|
Eo *sentry;
|
|
|
|
|
|
|
|
filename = eina_stringshare_printf("%s/eio_test_sentry_directory_directory_modified_notify", dirname);
|
|
|
|
_create_directory((void*)filename);
|
2018-04-11 10:38:21 -07:00
|
|
|
sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//monitor directory
|
|
|
|
fail_if(!eio_sentry_add(sentry, dirname));
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_event_callback_add(sentry, EIO_SENTRY_EVENT_DIRECTORY_MODIFIED, (Efl_Event_Cb)_target_notified_cb, filename);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
ecore_timer_add(TEST_OPERATION_DELAY, _modify_attrib_file, filename);
|
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_unref(sentry);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
_common_shutdown(dirname);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eio_test_sentry_directory_directory_self_deleted_notify)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
Eina_Tmpstr *dirname = _common_init();
|
2018-04-11 10:38:21 -07:00
|
|
|
Eo *sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//monitor directory
|
|
|
|
fail_if(!eio_sentry_add(sentry, dirname));
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_event_callback_add(sentry, EIO_SENTRY_EVENT_SELF_DELETED, (Efl_Event_Cb)_target_notified_cb, dirname);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
ecore_timer_add(TEST_OPERATION_DELAY, _delete_directory, dirname);
|
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_unref(sentry);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
_common_shutdown(dirname);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
// //////// test monitoring a single file
|
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eio_test_sentry_file_file_modified_notify)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
Eina_Tmpstr *dirname = _common_init();
|
|
|
|
Eina_Stringshare *filename;
|
|
|
|
Eo *sentry;
|
|
|
|
|
|
|
|
filename = eina_stringshare_printf("%s/filecreated", dirname);
|
|
|
|
_create_file((void*)filename);
|
2018-04-11 10:38:21 -07:00
|
|
|
sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//monitor file
|
|
|
|
fail_if(!eio_sentry_add(sentry, filename));
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_MODIFIED, (Efl_Event_Cb)_target_notified_cb, filename);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
ecore_timer_add(TEST_OPERATION_DELAY, _modify_file, filename);
|
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_unref(sentry);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//cleanup
|
|
|
|
_common_shutdown(dirname);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eio_test_sentry_file_file_attrib_modified_notify)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
Eina_Tmpstr *dirname = _common_init();
|
|
|
|
Eina_Stringshare *filename;
|
|
|
|
Eo *sentry;
|
|
|
|
|
|
|
|
filename = eina_stringshare_printf("%s/eio_test_sentry_file_file_attrib_modified_notify", dirname);
|
|
|
|
_create_file((void*)filename);
|
2018-04-11 10:38:21 -07:00
|
|
|
sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//monitor file
|
|
|
|
fail_if(!eio_sentry_add(sentry, filename));
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_MODIFIED, (Efl_Event_Cb)_target_notified_cb, filename);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
ecore_timer_add(TEST_OPERATION_DELAY, _modify_attrib_file, filename);
|
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_unref(sentry);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
_common_shutdown(dirname);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eio_test_sentry_file_file_closed_notify)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
Eina_Tmpstr *dirname = _common_init();
|
|
|
|
Eina_Stringshare *filename;
|
|
|
|
Eo* sentry;
|
|
|
|
|
|
|
|
filename = eina_stringshare_printf("%s/eio_test_sentry_file_file_closed_notify", dirname);
|
|
|
|
_create_file((void*)filename);
|
2018-04-11 10:38:21 -07:00
|
|
|
sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//monitor file
|
|
|
|
fail_if(!eio_sentry_add(sentry, dirname));
|
2018-06-26 15:22:11 -07:00
|
|
|
if (eio_sentry_fallback_check(sentry, dirname))
|
|
|
|
printf("skipping %s: using fallback monitoring\n", "eio_test_sentry_file_file_closed_notify");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
efl_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_CLOSED, (Efl_Event_Cb)_target_notified_cb, filename);
|
|
|
|
ecore_timer_add(TEST_OPERATION_DELAY, _modify_file, filename);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2018-06-26 15:22:11 -07:00
|
|
|
ecore_main_loop_begin();
|
|
|
|
}
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_unref(sentry);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
_common_shutdown(dirname);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eio_test_sentry_file_file_self_deleted_notify)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
Eina_Tmpstr *dirname = _common_init();
|
|
|
|
Eina_Stringshare *filename;
|
|
|
|
Eo* sentry;
|
|
|
|
|
|
|
|
filename = eina_stringshare_printf("%s/eio_test_sentry_file_file_self_deleted_notify", dirname);
|
|
|
|
_create_file((void*)filename);
|
2018-04-11 10:38:21 -07:00
|
|
|
sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//monitor file
|
|
|
|
fail_if(!eio_sentry_add(sentry, filename));
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_event_callback_add(sentry, EIO_SENTRY_EVENT_SELF_DELETED, (Efl_Event_Cb)_target_notified_cb, filename);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
ecore_timer_add(TEST_OPERATION_DELAY, _delete_file, filename);
|
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_unref(sentry);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
_common_shutdown(dirname);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eio_test_sentry_two_monitors_one_event)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
Eina_Tmpstr *dirname = _common_init();
|
|
|
|
Eina_Tmpstr *dirname2;
|
|
|
|
Eo *sentry;
|
|
|
|
|
|
|
|
Eina_Stringshare *filename;
|
|
|
|
|
|
|
|
eina_file_mkdtemp("checkFileCreationXXXXXX", &dirname2);
|
|
|
|
filename = eina_stringshare_printf("%s/eio_test_sentry_two_monitors_one_event", dirname);
|
2018-04-11 10:38:21 -07:00
|
|
|
sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//monitor directory
|
|
|
|
fail_if(!eio_sentry_add(sentry, dirname));
|
|
|
|
fail_if(!eio_sentry_add(sentry, dirname2));
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_CREATED, (Efl_Event_Cb)_target_notified_cb, filename);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
ecore_timer_add(TEST_OPERATION_DELAY, _create_file, filename);
|
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_unref(sentry);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
_delete_directory((void*)dirname2);
|
|
|
|
_common_shutdown(dirname);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eio_test_sentry_two_monitors_one_removed_one_event)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
Eina_Tmpstr *dirname = _common_init();
|
|
|
|
Eina_Tmpstr *dirname2;
|
|
|
|
Eo *sentry;
|
|
|
|
|
|
|
|
Eina_Stringshare *filename;
|
|
|
|
|
|
|
|
eina_file_mkdtemp("checkFileCreationXXXXXX", &dirname2);
|
|
|
|
filename = eina_stringshare_printf("%s/eio_test_sentry_two_monitors_one_removed", dirname);
|
2018-04-11 10:38:21 -07:00
|
|
|
sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//monitor directory
|
|
|
|
fail_if(!eio_sentry_add(sentry, dirname2));
|
|
|
|
fail_if(!eio_sentry_add(sentry, dirname));
|
2018-02-14 18:14:52 -08:00
|
|
|
eio_sentry_remove(sentry, dirname2);
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_CREATED, (Efl_Event_Cb)_target_notified_cb, filename);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
ecore_timer_add(TEST_OPERATION_DELAY, _create_file, filename);
|
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_unref(sentry);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
_delete_directory((void*)dirname2);
|
|
|
|
_common_shutdown(dirname);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2016-08-30 05:34:10 -07:00
|
|
|
static void _unexpected_event_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
ck_abort_msg("unexpected event");
|
|
|
|
}
|
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eio_test_sentry_two_monitors_one_removed_no_event)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
Eina_Tmpstr *dirname = _common_init();
|
|
|
|
Eina_Tmpstr *dirname2;
|
|
|
|
Eo *sentry;
|
|
|
|
|
|
|
|
Eina_Stringshare *filename;
|
|
|
|
|
|
|
|
eina_file_mkdtemp("checkFileCreationXXXXXX", &dirname2);
|
|
|
|
filename = eina_stringshare_printf("%s/eio_test_sentry_two_monitors_one_removed", dirname);
|
2018-04-11 10:38:21 -07:00
|
|
|
sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//monitor directory
|
|
|
|
fail_if(!eio_sentry_add(sentry, dirname));
|
|
|
|
fail_if(!eio_sentry_add(sentry, dirname2));
|
2018-02-14 18:14:52 -08:00
|
|
|
eio_sentry_remove(sentry, dirname);
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_CREATED, (Efl_Event_Cb)_unexpected_event_cb, filename);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
ecore_timer_add(TEST_OPERATION_DELAY, _create_file, filename);
|
2018-05-04 03:31:18 -07:00
|
|
|
ecore_timer_add(0.2, _test_timeout_expected, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_unref(sentry);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
_delete_directory((void*)dirname2);
|
|
|
|
_common_shutdown(dirname);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eio_test_sentry_two_files_in_same_directory)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
Eina_Tmpstr *dirname = _common_init();
|
|
|
|
Eina_Stringshare *filename;
|
|
|
|
Eina_Stringshare *filename2;
|
|
|
|
Eo *sentry;
|
|
|
|
|
|
|
|
filename = eina_stringshare_printf("%s/eio_test_sentry_two_files_in_same_directory_1", dirname);
|
|
|
|
filename2 = eina_stringshare_printf("%s/eio_test_sentry_two_files_in_same_directory_2", dirname);
|
|
|
|
_create_file((void*)filename);
|
|
|
|
_create_file((void*)filename2);
|
2018-04-11 10:38:21 -07:00
|
|
|
sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//monitor file
|
|
|
|
fail_if(!eio_sentry_add(sentry,filename));
|
|
|
|
fail_if(!eio_sentry_add(sentry,filename2));
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_MODIFIED, (Efl_Event_Cb)_target_notified_cb, filename);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
ecore_timer_add(TEST_OPERATION_DELAY, _modify_file, filename);
|
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_unref(sentry);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//cleanup
|
|
|
|
_common_shutdown(dirname);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eio_test_sentry_two_files_in_same_directory_one_removed)
|
2016-04-12 12:00:23 -07:00
|
|
|
{
|
|
|
|
Eina_Tmpstr *dirname = _common_init();
|
|
|
|
Eina_Stringshare *filename;
|
|
|
|
Eina_Stringshare *filename2;
|
|
|
|
Eo *sentry;
|
|
|
|
|
|
|
|
filename = eina_stringshare_printf("%s/eio_test_sentry_two_files_in_same_directory_one_removed_1", dirname);
|
|
|
|
filename2 = eina_stringshare_printf("%s/eio_test_sentry_two_files_in_same_directory_one_removed_2", dirname);
|
|
|
|
_create_file((void*)filename);
|
|
|
|
_create_file((void*)filename2);
|
2018-04-11 10:38:21 -07:00
|
|
|
sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//monitor file
|
|
|
|
fail_if(!eio_sentry_add(sentry,filename));
|
|
|
|
fail_if(!eio_sentry_add(sentry,filename2));
|
2018-02-14 18:14:52 -08:00
|
|
|
eio_sentry_remove(sentry, filename);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_MODIFIED, (Efl_Event_Cb)_unexpected_event_cb, filename);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
ecore_timer_add(TEST_OPERATION_DELAY, _modify_file, filename);
|
2018-05-04 03:31:18 -07:00
|
|
|
ecore_timer_add(0.2, _test_timeout_expected, NULL);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_unref(sentry);
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
//cleanup
|
|
|
|
_common_shutdown(dirname);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2016-04-12 12:00:23 -07:00
|
|
|
|
|
|
|
|
|
|
|
void eio_test_sentry(TCase *tc)
|
|
|
|
{
|
|
|
|
tcase_add_test(tc, eio_test_sentry_add_and_remove);
|
|
|
|
tcase_add_test(tc, eio_test_sentry_add_remove_add);
|
|
|
|
tcase_add_test(tc, eio_test_sentry_add_add_remove_remove);
|
|
|
|
|
|
|
|
tcase_add_test(tc, eio_test_sentry_directory_file_created_notify);
|
|
|
|
tcase_add_test(tc, eio_test_sentry_directory_file_deleted_notify);
|
|
|
|
tcase_add_test(tc, eio_test_sentry_directory_file_modified_notify);
|
2019-06-20 04:50:35 -07:00
|
|
|
#if !defined(__MACH__)
|
2016-04-12 12:00:23 -07:00
|
|
|
tcase_add_test(tc, eio_test_sentry_directory_file_closed_notify);
|
|
|
|
#endif
|
|
|
|
tcase_add_test(tc, eio_test_sentry_directory_directory_created_notify);
|
|
|
|
tcase_add_test(tc, eio_test_sentry_directory_directory_deleted_notify);
|
|
|
|
tcase_add_test(tc, eio_test_sentry_directory_directory_modified_notify);
|
|
|
|
#ifndef __MACH__
|
|
|
|
tcase_add_test(tc, eio_test_sentry_directory_directory_self_deleted_notify);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
tcase_add_test(tc, eio_test_sentry_file_file_modified_notify);
|
|
|
|
tcase_add_test(tc, eio_test_sentry_file_file_attrib_modified_notify);
|
2019-06-20 04:50:35 -07:00
|
|
|
#if !defined(__MACH__)
|
2016-04-12 12:00:23 -07:00
|
|
|
tcase_add_test(tc, eio_test_sentry_file_file_closed_notify);
|
|
|
|
#endif
|
|
|
|
#ifndef __MACH__
|
|
|
|
tcase_add_test(tc, eio_test_sentry_file_file_self_deleted_notify);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
tcase_add_test(tc, eio_test_sentry_two_monitors_one_event);
|
|
|
|
tcase_add_test(tc, eio_test_sentry_two_monitors_one_removed_one_event);
|
|
|
|
tcase_add_test(tc, eio_test_sentry_two_monitors_one_removed_no_event);
|
|
|
|
tcase_add_test(tc, eio_test_sentry_two_files_in_same_directory);
|
|
|
|
tcase_add_test(tc, eio_test_sentry_two_files_in_same_directory_one_removed);
|
|
|
|
}
|