diff options
author | Felipe Magno de Almeida <felipe@expertisesolutions.com.br> | 2015-04-09 22:46:24 -0300 |
---|---|---|
committer | Felipe Magno de Almeida <felipe@expertisesolutions.com.br> | 2015-04-09 22:47:17 -0300 |
commit | d02f99ee21f6920102ea23da5ecc438290c22752 (patch) | |
tree | 16d89bd36a200d6375a4b39026f6380040070410 /src/tests/eio/eio_model_test_monitor_add.c | |
parent | 668fcab941a3f5eb8d580d575a74cd3c5c3b78d6 (diff) | |
download | efl-d02f99ee21f6920102ea23da5ecc438290c22752.tar.gz |
eio-model: Fix Eio model races in tests
Removed sleep and implemented a deterministic way to test if the test has really finished.
Diffstat (limited to 'src/tests/eio/eio_model_test_monitor_add.c')
-rw-r--r-- | src/tests/eio/eio_model_test_monitor_add.c | 61 |
1 files changed, 50 insertions, 11 deletions
diff --git a/src/tests/eio/eio_model_test_monitor_add.c b/src/tests/eio/eio_model_test_monitor_add.c index af95ae8f75..11d9e172a3 100644 --- a/src/tests/eio/eio_model_test_monitor_add.c +++ b/src/tests/eio/eio_model_test_monitor_add.c @@ -13,9 +13,9 @@ #include <check.h> -#define EFL_MODEL_TEST_FILENAME_PATH "/tmp" - Eina_Bool children_added = EINA_FALSE; +Eina_Tmpstr* temp_filename = NULL; +const char* tmpdir = NULL; static Eina_Bool _load_monitor_status_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info) @@ -28,25 +28,50 @@ _load_monitor_status_cb(void *data, Eo *obj, const Eo_Event_Description *desc EI if (!(st->status & EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES)) return EINA_TRUE; - eo_do(obj, efl_model_property_get("filename", &value_prop)); + eo_do(obj, efl_model_property_get("path", &value_prop)); fail_if(!value_prop, "ERROR: Cannot get property!\n"); str = eina_value_to_string(value_prop); fail_if(!str, "ERROR: Cannot convert value to string!\n"); fprintf(stderr, "new children filename %s\n", str); - if(strcmp(str, "test_file_monitor_add") == 0) + if(strcmp(str, temp_filename) == 0) { fprintf(stderr, "is child that we want\n"); eo_do(obj, eo_event_callback_del(EFL_MODEL_BASE_EVENT_LOAD_STATUS, _load_monitor_status_cb, data)); children_added = EINA_TRUE; eo_do(parent, efl_model_child_del(obj)); - ecore_main_loop_quit(); } return EINA_FALSE; } static Eina_Bool +_children_removed_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void* event_info EINA_UNUSED) +{ + if(children_added) + { + Efl_Model_Children_Event* evt = event_info; + + Eina_Bool b; + eo_do(evt->child, b = efl_model_load_status_get() & EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES); + if(b) + { + const Eina_Value* value_prop = NULL; + const char* str = NULL; + + eo_do(evt->child, efl_model_property_get("path", &value_prop)); + fail_if(!value_prop, "ERROR: Cannot get property!\n"); + + str = eina_value_to_string(value_prop); + fail_if(!str, "ERROR: Cannot convert value to string!\n"); + if(strcmp(str, temp_filename) == 0) + ecore_main_loop_quit(); + } + } + return EINA_TRUE; +} + +static Eina_Bool _children_added_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info) { Efl_Model_Children_Event* evt = event_info; @@ -67,6 +92,7 @@ _children_count_cb(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description * Efl_Model_Load_Status status; Eo *child; unsigned int i = 0; + int fd = 0; fprintf(stderr, "Children count number=%d\n", *len); @@ -78,7 +104,10 @@ _children_count_cb(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description * fprintf(stdout, "Got %d childs from Accessor. status=%d\n", i, status); } - fclose(fopen(EFL_MODEL_TEST_FILENAME_PATH "/test_file_monitor_add", "w+")); + if((fd = eina_file_mkstemp("prefixXXXXXX.ext", &temp_filename)) > 0) + { + close(fd); + } return EINA_TRUE; } @@ -93,20 +122,30 @@ START_TEST(eio_model_test_test_monitor_add) fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n"); fail_if(!eio_init(), "ERROR: Cannot init EIO!\n"); - filemodel = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(EFL_MODEL_TEST_FILENAME_PATH)); +#ifndef HAVE_EVIL +#if defined(HAVE_GETUID) && defined(HAVE_GETEUID) + if (getuid() == geteuid()) +#endif + { + tmpdir = getenv("TMPDIR"); + if (!tmpdir) tmpdir = getenv("XDG_RUNTIME_DIR"); + } + if (!tmpdir) tmpdir = "/tmp"; +#else + tmpdir = (char *)evil_tmpdir_get(); +#endif /* ! HAVE_EVIL */ + + filemodel = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(tmpdir)); fail_if(!filemodel, "ERROR: Cannot init model!\n"); eo_do(filemodel, eo_event_callback_add(EFL_MODEL_BASE_EVENT_CHILD_ADDED, _children_added_cb, NULL)); + eo_do(filemodel, eo_event_callback_add(EFL_MODEL_BASE_EVENT_CHILD_REMOVED, _children_removed_cb, NULL)); eo_do(filemodel, eo_event_callback_add(EFL_MODEL_BASE_EVENT_CHILDREN_COUNT_CHANGED, _children_count_cb, NULL)); eo_do(filemodel, efl_model_load()); ecore_main_loop_begin(); - sleep(1); /**< EIO is asynchrounous so I must give some time for deletions to execute */ - - ecore_main_loop_iterate(); /**< Give time to unlink file */ - eo_unref(filemodel); eio_shutdown(); |