diff options
Diffstat (limited to 'src/tests/eio/eio_test_sentry.c')
-rw-r--r-- | src/tests/eio/eio_test_sentry.c | 241 |
1 files changed, 95 insertions, 146 deletions
diff --git a/src/tests/eio/eio_test_sentry.c b/src/tests/eio/eio_test_sentry.c index fb07e842f1..d4e687ec73 100644 --- a/src/tests/eio/eio_test_sentry.c +++ b/src/tests/eio/eio_test_sentry.c @@ -2,6 +2,8 @@ # include <config.h> #endif +#define EIO_SENTRY_BETA + #include <stdio.h> #include <unistd.h> #include <string.h> @@ -14,8 +16,8 @@ /////////////////timeout function -#define TEST_TIMEOUT_SEC 10 -#define TEST_OPERATION_DELAY 0.5 +#define TEST_TIMEOUT_SEC 0.5 +#define TEST_OPERATION_DELAY 0.05 static Ecore_Timer *test_timeout_timer; @@ -107,13 +109,14 @@ static Eina_Bool _modify_attrib_file(void *data) static void _check_event_path(void *data, const Efl_Event *event) { Eio_Sentry_Event *event_info = event->info; + /* ignore directory creation events */ + if (ecore_file_is_dir(event_info->trigger)) return; ck_assert_str_eq((const char*)data, event_info->trigger); } static Eina_Tmpstr *_common_init() { Eina_Tmpstr *dirname; - fail_if(eio_init() != 1); ecore_file_init(); //test timeout @@ -127,39 +130,34 @@ static void _common_shutdown(Eina_Tmpstr *dirname) { _delete_directory((void*)dirname); ecore_file_shutdown(); - fail_if(eio_shutdown() != 0); eina_tmpstr_del(dirname); + _cancel_timeout(); } /////// tests monitoring a directory -START_TEST(eio_test_sentry_add_and_remove) +EFL_START_TEST(eio_test_sentry_add_and_remove) { Eina_Tmpstr *dirname = _common_init(); Eina_Stringshare *filename; Eo *sentry; - filename = eina_stringshare_printf("%s/eio_test_sentry_directory_file_created_notify", dirname); + filename = eina_stringshare_printf("%s/eio_test_sentry_add_and_remove", dirname); _create_directory((void*)filename); - //sleep to avoid catching event generated by above manipulations - usleep(500000); - //monitor directory - sentry = efl_add(EIO_SENTRY_CLASS, NULL); + sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL); fail_if(!eio_sentry_add(sentry, filename)); - usleep(500000); - - eio_sentry_del(sentry, filename); + eio_sentry_remove(sentry, filename); efl_unref(sentry); _common_shutdown(dirname); } -END_TEST +EFL_END_TEST -START_TEST(eio_test_sentry_add_remove_add) +EFL_START_TEST(eio_test_sentry_add_remove_add) { Eina_Tmpstr *dirname = _common_init(); Eina_Stringshare *filename; @@ -168,26 +166,21 @@ START_TEST(eio_test_sentry_add_remove_add) filename = eina_stringshare_printf("%s/eio_test_sentry_add_remove_add", dirname); _create_directory((void*)filename); - //sleep to avoid catching event generated by above manipulations - usleep(500000); - //monitor directory - sentry = efl_add(EIO_SENTRY_CLASS, NULL); + sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL); fail_if(!eio_sentry_add(sentry, filename)); - eio_sentry_del(sentry, filename); - - usleep(500000); + eio_sentry_remove(sentry, filename); fail_if(!eio_sentry_add(sentry, filename)); - eio_sentry_del(sentry, filename); + eio_sentry_remove(sentry, filename); efl_unref(sentry); _common_shutdown(dirname); } -END_TEST +EFL_END_TEST -START_TEST(eio_test_sentry_add_add_remove_remove) +EFL_START_TEST(eio_test_sentry_add_add_remove_remove) { Eina_Tmpstr *dirname = _common_init(); Eina_Stringshare *filename1; @@ -199,23 +192,20 @@ START_TEST(eio_test_sentry_add_add_remove_remove) _create_directory((void*)filename1); _create_directory((void*)filename2); - //sleep to avoid catching event generated by above manipulations - usleep(500000); - - sentry = efl_add(EIO_SENTRY_CLASS, NULL); + sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL); //monitor directory fail_if(!eio_sentry_add(sentry, filename1)); fail_if(!eio_sentry_add(sentry, filename2)); - usleep(500000); - eio_sentry_del(sentry, filename1); - eio_sentry_del(sentry, filename2); + + eio_sentry_remove(sentry, filename1); + eio_sentry_remove(sentry, filename2); efl_unref(sentry); _common_shutdown(dirname); } -END_TEST +EFL_END_TEST static void _target_notified_cb(void *data, const Efl_Event *event) { @@ -225,17 +215,14 @@ static void _target_notified_cb(void *data, const Efl_Event *event) } -START_TEST(eio_test_sentry_directory_file_created_notify) +EFL_START_TEST(eio_test_sentry_directory_file_created_notify) { Eina_Tmpstr *dirname = _common_init(); Eina_Stringshare *filename; Eo* sentry; filename = eina_stringshare_printf("%s/eio_test_sentry_directory_file_created_notify", dirname); - sentry = efl_add(EIO_SENTRY_CLASS, NULL); - - //sleep to avoid catching event generated by above manipulations - usleep(500000); + sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL); //monitor directory fail_if(!eio_sentry_add(sentry, dirname)); @@ -249,9 +236,9 @@ START_TEST(eio_test_sentry_directory_file_created_notify) _common_shutdown(dirname); } -END_TEST +EFL_END_TEST -START_TEST(eio_test_sentry_directory_file_deleted_notify) +EFL_START_TEST(eio_test_sentry_directory_file_deleted_notify) { Eina_Tmpstr *dirname = _common_init(); Eina_Stringshare *filename; @@ -259,10 +246,7 @@ START_TEST(eio_test_sentry_directory_file_deleted_notify) filename = eina_stringshare_printf("%s/eio_test_sentry_directory_file_deleted_notify", dirname); _create_file((void*)filename); - sentry = efl_add(EIO_SENTRY_CLASS, NULL); - - //sleep to avoid catching event generated by above manipulations - usleep(500000); + sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL); //monitor directory fail_if(!eio_sentry_add(sentry, dirname)); @@ -276,9 +260,9 @@ START_TEST(eio_test_sentry_directory_file_deleted_notify) _common_shutdown(dirname); } -END_TEST +EFL_END_TEST -START_TEST(eio_test_sentry_directory_file_modified_notify) +EFL_START_TEST(eio_test_sentry_directory_file_modified_notify) { Eina_Tmpstr *dirname = _common_init(); Eina_Stringshare *filename; @@ -286,10 +270,7 @@ START_TEST(eio_test_sentry_directory_file_modified_notify) filename = eina_stringshare_printf("%s/eio_test_sentry_directory_file_modified_notify", dirname); _create_file((void*)filename); - sentry = efl_add(EIO_SENTRY_CLASS, NULL); - - //sleep to avoid catching event generated by above manipulations - usleep(500000); + sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL); //monitor directory fail_if(!eio_sentry_add(sentry, dirname)); @@ -304,9 +285,9 @@ START_TEST(eio_test_sentry_directory_file_modified_notify) //cleanup _common_shutdown(dirname); } -END_TEST +EFL_END_TEST -START_TEST(eio_test_sentry_directory_file_closed_notify) +EFL_START_TEST(eio_test_sentry_directory_file_closed_notify) { Eina_Tmpstr *dirname = _common_init(); Eina_Stringshare *filename; @@ -314,35 +295,34 @@ START_TEST(eio_test_sentry_directory_file_closed_notify) filename = eina_stringshare_printf("%s/eio_test_sentry_directory_file_closed_notify", dirname); _create_file((void*)filename); - sentry = efl_add(EIO_SENTRY_CLASS, NULL); - - //sleep to avoid catching event generated by above manipulations - usleep(500000); + sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL); //monitor directory fail_if(!eio_sentry_add(sentry, dirname)); - 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); + 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); - ecore_main_loop_begin(); + ecore_main_loop_begin(); + } efl_unref(sentry); _common_shutdown(dirname); } -END_TEST +EFL_END_TEST -START_TEST(eio_test_sentry_directory_directory_created_notify) +EFL_START_TEST(eio_test_sentry_directory_directory_created_notify) { Eina_Tmpstr *dirname = _common_init(); Eina_Stringshare *filename; Eo *sentry; filename = eina_stringshare_printf("%s/eio_test_sentry_directory_directory_created_notify", dirname); - sentry = efl_add(EIO_SENTRY_CLASS, NULL); - - //sleep to avoid catching event generated by above manipulations - usleep(500000); + sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL); //monitor directory fail_if(!eio_sentry_add(sentry, dirname)); @@ -356,9 +336,9 @@ START_TEST(eio_test_sentry_directory_directory_created_notify) _common_shutdown(dirname); } -END_TEST +EFL_END_TEST -START_TEST(eio_test_sentry_directory_directory_deleted_notify) +EFL_START_TEST(eio_test_sentry_directory_directory_deleted_notify) { Eina_Tmpstr *dirname = _common_init(); Eina_Stringshare *filename; @@ -366,10 +346,7 @@ START_TEST(eio_test_sentry_directory_directory_deleted_notify) filename = eina_stringshare_printf("%s/eio_test_sentry_directory_directory_deleted_notify", dirname); _create_directory((void*)filename); - sentry = efl_add(EIO_SENTRY_CLASS, NULL); - - //sleep to avoid catching event generated by above manipulations - usleep(500000); + sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL); //monitor directory fail_if(!eio_sentry_add(sentry, dirname)); @@ -383,9 +360,9 @@ START_TEST(eio_test_sentry_directory_directory_deleted_notify) _common_shutdown(dirname); } -END_TEST +EFL_END_TEST -START_TEST(eio_test_sentry_directory_directory_modified_notify) +EFL_START_TEST(eio_test_sentry_directory_directory_modified_notify) { Eina_Tmpstr *dirname = _common_init(); Eina_Stringshare *filename; @@ -393,10 +370,7 @@ START_TEST(eio_test_sentry_directory_directory_modified_notify) filename = eina_stringshare_printf("%s/eio_test_sentry_directory_directory_modified_notify", dirname); _create_directory((void*)filename); - sentry = efl_add(EIO_SENTRY_CLASS, NULL); - - //sleep to avoid catching event generated by above manipulations - usleep(500000); + sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL); //monitor directory fail_if(!eio_sentry_add(sentry, dirname)); @@ -410,15 +384,12 @@ START_TEST(eio_test_sentry_directory_directory_modified_notify) _common_shutdown(dirname); } -END_TEST +EFL_END_TEST -START_TEST(eio_test_sentry_directory_directory_self_deleted_notify) +EFL_START_TEST(eio_test_sentry_directory_directory_self_deleted_notify) { Eina_Tmpstr *dirname = _common_init(); - Eo *sentry = efl_add(EIO_SENTRY_CLASS, NULL); - - //sleep to avoid catching event generated by above manipulations - usleep(500000); + Eo *sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL); //monitor directory fail_if(!eio_sentry_add(sentry, dirname)); @@ -432,11 +403,11 @@ START_TEST(eio_test_sentry_directory_directory_self_deleted_notify) _common_shutdown(dirname); } -END_TEST +EFL_END_TEST // //////// test monitoring a single file -START_TEST(eio_test_sentry_file_file_modified_notify) +EFL_START_TEST(eio_test_sentry_file_file_modified_notify) { Eina_Tmpstr *dirname = _common_init(); Eina_Stringshare *filename; @@ -444,10 +415,7 @@ START_TEST(eio_test_sentry_file_file_modified_notify) filename = eina_stringshare_printf("%s/filecreated", dirname); _create_file((void*)filename); - sentry = efl_add(EIO_SENTRY_CLASS, NULL); - - //sleep to avoid catching event generated by above manipulations - usleep(500000); + sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL); //monitor file fail_if(!eio_sentry_add(sentry, filename)); @@ -462,9 +430,9 @@ START_TEST(eio_test_sentry_file_file_modified_notify) //cleanup _common_shutdown(dirname); } -END_TEST +EFL_END_TEST -START_TEST(eio_test_sentry_file_file_attrib_modified_notify) +EFL_START_TEST(eio_test_sentry_file_file_attrib_modified_notify) { Eina_Tmpstr *dirname = _common_init(); Eina_Stringshare *filename; @@ -472,10 +440,7 @@ START_TEST(eio_test_sentry_file_file_attrib_modified_notify) filename = eina_stringshare_printf("%s/eio_test_sentry_file_file_attrib_modified_notify", dirname); _create_file((void*)filename); - sentry = efl_add(EIO_SENTRY_CLASS, NULL); - - //sleep to avoid catching event generated by above manipulations - usleep(500000); + sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL); //monitor file fail_if(!eio_sentry_add(sentry, filename)); @@ -489,10 +454,10 @@ START_TEST(eio_test_sentry_file_file_attrib_modified_notify) _common_shutdown(dirname); } -END_TEST +EFL_END_TEST -START_TEST(eio_test_sentry_file_file_closed_notify) +EFL_START_TEST(eio_test_sentry_file_file_closed_notify) { Eina_Tmpstr *dirname = _common_init(); Eina_Stringshare *filename; @@ -500,25 +465,27 @@ START_TEST(eio_test_sentry_file_file_closed_notify) filename = eina_stringshare_printf("%s/eio_test_sentry_file_file_closed_notify", dirname); _create_file((void*)filename); - sentry = efl_add(EIO_SENTRY_CLASS, NULL); - - //sleep to avoid catching event generated by above manipulations - usleep(500000); + sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL); //monitor file fail_if(!eio_sentry_add(sentry, dirname)); - 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); + 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); - ecore_main_loop_begin(); + ecore_main_loop_begin(); + } efl_unref(sentry); _common_shutdown(dirname); } -END_TEST +EFL_END_TEST -START_TEST(eio_test_sentry_file_file_self_deleted_notify) +EFL_START_TEST(eio_test_sentry_file_file_self_deleted_notify) { Eina_Tmpstr *dirname = _common_init(); Eina_Stringshare *filename; @@ -526,10 +493,7 @@ START_TEST(eio_test_sentry_file_file_self_deleted_notify) filename = eina_stringshare_printf("%s/eio_test_sentry_file_file_self_deleted_notify", dirname); _create_file((void*)filename); - sentry = efl_add(EIO_SENTRY_CLASS, NULL); - - //sleep to avoid catching event generated by above manipulations - usleep(500000); + sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL); //monitor file fail_if(!eio_sentry_add(sentry, filename)); @@ -543,9 +507,9 @@ START_TEST(eio_test_sentry_file_file_self_deleted_notify) _common_shutdown(dirname); } -END_TEST +EFL_END_TEST -START_TEST(eio_test_sentry_two_monitors_one_event) +EFL_START_TEST(eio_test_sentry_two_monitors_one_event) { Eina_Tmpstr *dirname = _common_init(); Eina_Tmpstr *dirname2; @@ -555,10 +519,7 @@ START_TEST(eio_test_sentry_two_monitors_one_event) eina_file_mkdtemp("checkFileCreationXXXXXX", &dirname2); filename = eina_stringshare_printf("%s/eio_test_sentry_two_monitors_one_event", dirname); - sentry = efl_add(EIO_SENTRY_CLASS, NULL); - - //sleep to avoid catching event generated by above manipulations - usleep(500000); + sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL); //monitor directory fail_if(!eio_sentry_add(sentry, dirname)); @@ -574,10 +535,10 @@ START_TEST(eio_test_sentry_two_monitors_one_event) _delete_directory((void*)dirname2); _common_shutdown(dirname); } -END_TEST +EFL_END_TEST -START_TEST(eio_test_sentry_two_monitors_one_removed_one_event) +EFL_START_TEST(eio_test_sentry_two_monitors_one_removed_one_event) { Eina_Tmpstr *dirname = _common_init(); Eina_Tmpstr *dirname2; @@ -587,15 +548,12 @@ START_TEST(eio_test_sentry_two_monitors_one_removed_one_event) eina_file_mkdtemp("checkFileCreationXXXXXX", &dirname2); filename = eina_stringshare_printf("%s/eio_test_sentry_two_monitors_one_removed", dirname); - sentry = efl_add(EIO_SENTRY_CLASS, NULL); - - //sleep to avoid catching event generated by above manipulations - usleep(500000); + sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL); //monitor directory fail_if(!eio_sentry_add(sentry, dirname2)); fail_if(!eio_sentry_add(sentry, dirname)); - eio_sentry_del(sentry, dirname2); + eio_sentry_remove(sentry, dirname2); efl_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_CREATED, (Efl_Event_Cb)_target_notified_cb, filename); ecore_timer_add(TEST_OPERATION_DELAY, _create_file, filename); @@ -607,14 +565,14 @@ START_TEST(eio_test_sentry_two_monitors_one_removed_one_event) _delete_directory((void*)dirname2); _common_shutdown(dirname); } -END_TEST +EFL_END_TEST static void _unexpected_event_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED) { ck_abort_msg("unexpected event"); } -START_TEST(eio_test_sentry_two_monitors_one_removed_no_event) +EFL_START_TEST(eio_test_sentry_two_monitors_one_removed_no_event) { Eina_Tmpstr *dirname = _common_init(); Eina_Tmpstr *dirname2; @@ -624,19 +582,16 @@ START_TEST(eio_test_sentry_two_monitors_one_removed_no_event) eina_file_mkdtemp("checkFileCreationXXXXXX", &dirname2); filename = eina_stringshare_printf("%s/eio_test_sentry_two_monitors_one_removed", dirname); - sentry = efl_add(EIO_SENTRY_CLASS, NULL); - - //sleep to avoid catching event generated by above manipulations - usleep(500000); + sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL); //monitor directory fail_if(!eio_sentry_add(sentry, dirname)); fail_if(!eio_sentry_add(sentry, dirname2)); - eio_sentry_del(sentry, dirname); + eio_sentry_remove(sentry, dirname); efl_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_CREATED, (Efl_Event_Cb)_unexpected_event_cb, filename); ecore_timer_add(TEST_OPERATION_DELAY, _create_file, filename); - ecore_timer_add(TEST_TIMEOUT_SEC - 1, _test_timeout_expected, NULL); + ecore_timer_add(0.2, _test_timeout_expected, NULL); ecore_main_loop_begin(); @@ -645,9 +600,9 @@ START_TEST(eio_test_sentry_two_monitors_one_removed_no_event) _delete_directory((void*)dirname2); _common_shutdown(dirname); } -END_TEST +EFL_END_TEST -START_TEST(eio_test_sentry_two_files_in_same_directory) +EFL_START_TEST(eio_test_sentry_two_files_in_same_directory) { Eina_Tmpstr *dirname = _common_init(); Eina_Stringshare *filename; @@ -658,10 +613,7 @@ START_TEST(eio_test_sentry_two_files_in_same_directory) filename2 = eina_stringshare_printf("%s/eio_test_sentry_two_files_in_same_directory_2", dirname); _create_file((void*)filename); _create_file((void*)filename2); - sentry = efl_add(EIO_SENTRY_CLASS, NULL); - - //sleep to avoid catching event generated by above manipulations - usleep(500000); + sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL); //monitor file fail_if(!eio_sentry_add(sentry,filename)); @@ -677,10 +629,10 @@ START_TEST(eio_test_sentry_two_files_in_same_directory) //cleanup _common_shutdown(dirname); } -END_TEST +EFL_END_TEST -START_TEST(eio_test_sentry_two_files_in_same_directory_one_removed) +EFL_START_TEST(eio_test_sentry_two_files_in_same_directory_one_removed) { Eina_Tmpstr *dirname = _common_init(); Eina_Stringshare *filename; @@ -691,20 +643,17 @@ START_TEST(eio_test_sentry_two_files_in_same_directory_one_removed) 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); - sentry = efl_add(EIO_SENTRY_CLASS, NULL); - - //sleep to avoid catching event generated by above manipulations - usleep(500000); + sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL); //monitor file fail_if(!eio_sentry_add(sentry,filename)); fail_if(!eio_sentry_add(sentry,filename2)); - eio_sentry_del(sentry, filename); + eio_sentry_remove(sentry, filename); efl_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_MODIFIED, (Efl_Event_Cb)_unexpected_event_cb, filename); ecore_timer_add(TEST_OPERATION_DELAY, _modify_file, filename); - ecore_timer_add(TEST_TIMEOUT_SEC - 1, _test_timeout_expected, NULL); + ecore_timer_add(0.2, _test_timeout_expected, NULL); ecore_main_loop_begin(); @@ -713,7 +662,7 @@ START_TEST(eio_test_sentry_two_files_in_same_directory_one_removed) //cleanup _common_shutdown(dirname); } -END_TEST +EFL_END_TEST void eio_test_sentry(TCase *tc) |