summaryrefslogtreecommitdiff
path: root/src/tests/eio/eio_model_test_monitor_add.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/tests/eio/eio_model_test_monitor_add.c61
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 @@
13 13
14#include <check.h> 14#include <check.h>
15 15
16#define EFL_MODEL_TEST_FILENAME_PATH "/tmp"
17
18Eina_Bool children_added = EINA_FALSE; 16Eina_Bool children_added = EINA_FALSE;
17Eina_Tmpstr* temp_filename = NULL;
18const char* tmpdir = NULL;
19 19
20static Eina_Bool 20static Eina_Bool
21_load_monitor_status_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info) 21_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
28 if (!(st->status & EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES)) 28 if (!(st->status & EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES))
29 return EINA_TRUE; 29 return EINA_TRUE;
30 30
31 eo_do(obj, efl_model_property_get("filename", &value_prop)); 31 eo_do(obj, efl_model_property_get("path", &value_prop));
32 fail_if(!value_prop, "ERROR: Cannot get property!\n"); 32 fail_if(!value_prop, "ERROR: Cannot get property!\n");
33 33
34 str = eina_value_to_string(value_prop); 34 str = eina_value_to_string(value_prop);
35 fail_if(!str, "ERROR: Cannot convert value to string!\n"); 35 fail_if(!str, "ERROR: Cannot convert value to string!\n");
36 fprintf(stderr, "new children filename %s\n", str); 36 fprintf(stderr, "new children filename %s\n", str);
37 if(strcmp(str, "test_file_monitor_add") == 0) 37 if(strcmp(str, temp_filename) == 0)
38 { 38 {
39 fprintf(stderr, "is child that we want\n"); 39 fprintf(stderr, "is child that we want\n");
40 eo_do(obj, eo_event_callback_del(EFL_MODEL_BASE_EVENT_LOAD_STATUS, _load_monitor_status_cb, data)); 40 eo_do(obj, eo_event_callback_del(EFL_MODEL_BASE_EVENT_LOAD_STATUS, _load_monitor_status_cb, data));
41 children_added = EINA_TRUE; 41 children_added = EINA_TRUE;
42 eo_do(parent, efl_model_child_del(obj)); 42 eo_do(parent, efl_model_child_del(obj));
43 ecore_main_loop_quit();
44 } 43 }
45 44
46 return EINA_FALSE; 45 return EINA_FALSE;
47} 46}
48 47
49static Eina_Bool 48static Eina_Bool
49_children_removed_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void* event_info EINA_UNUSED)
50{
51 if(children_added)
52 {
53 Efl_Model_Children_Event* evt = event_info;
54
55 Eina_Bool b;
56 eo_do(evt->child, b = efl_model_load_status_get() & EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES);
57 if(b)
58 {
59 const Eina_Value* value_prop = NULL;
60 const char* str = NULL;
61
62 eo_do(evt->child, efl_model_property_get("path", &value_prop));
63 fail_if(!value_prop, "ERROR: Cannot get property!\n");
64
65 str = eina_value_to_string(value_prop);
66 fail_if(!str, "ERROR: Cannot convert value to string!\n");
67 if(strcmp(str, temp_filename) == 0)
68 ecore_main_loop_quit();
69 }
70 }
71 return EINA_TRUE;
72}
73
74static Eina_Bool
50_children_added_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info) 75_children_added_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
51{ 76{
52 Efl_Model_Children_Event* evt = event_info; 77 Efl_Model_Children_Event* evt = event_info;
@@ -67,6 +92,7 @@ _children_count_cb(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *
67 Efl_Model_Load_Status status; 92 Efl_Model_Load_Status status;
68 Eo *child; 93 Eo *child;
69 unsigned int i = 0; 94 unsigned int i = 0;
95 int fd = 0;
70 96
71 fprintf(stderr, "Children count number=%d\n", *len); 97 fprintf(stderr, "Children count number=%d\n", *len);
72 98
@@ -78,7 +104,10 @@ _children_count_cb(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *
78 fprintf(stdout, "Got %d childs from Accessor. status=%d\n", i, status); 104 fprintf(stdout, "Got %d childs from Accessor. status=%d\n", i, status);
79 } 105 }
80 106
81 fclose(fopen(EFL_MODEL_TEST_FILENAME_PATH "/test_file_monitor_add", "w+")); 107 if((fd = eina_file_mkstemp("prefixXXXXXX.ext", &temp_filename)) > 0)
108 {
109 close(fd);
110 }
82 111
83 return EINA_TRUE; 112 return EINA_TRUE;
84} 113}
@@ -93,20 +122,30 @@ START_TEST(eio_model_test_test_monitor_add)
93 fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n"); 122 fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n");
94 fail_if(!eio_init(), "ERROR: Cannot init EIO!\n"); 123 fail_if(!eio_init(), "ERROR: Cannot init EIO!\n");
95 124
96 filemodel = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(EFL_MODEL_TEST_FILENAME_PATH)); 125#ifndef HAVE_EVIL
126#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
127 if (getuid() == geteuid())
128#endif
129 {
130 tmpdir = getenv("TMPDIR");
131 if (!tmpdir) tmpdir = getenv("XDG_RUNTIME_DIR");
132 }
133 if (!tmpdir) tmpdir = "/tmp";
134#else
135 tmpdir = (char *)evil_tmpdir_get();
136#endif /* ! HAVE_EVIL */
137
138 filemodel = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(tmpdir));
97 fail_if(!filemodel, "ERROR: Cannot init model!\n"); 139 fail_if(!filemodel, "ERROR: Cannot init model!\n");
98 140
99 eo_do(filemodel, eo_event_callback_add(EFL_MODEL_BASE_EVENT_CHILD_ADDED, _children_added_cb, NULL)); 141 eo_do(filemodel, eo_event_callback_add(EFL_MODEL_BASE_EVENT_CHILD_ADDED, _children_added_cb, NULL));
142 eo_do(filemodel, eo_event_callback_add(EFL_MODEL_BASE_EVENT_CHILD_REMOVED, _children_removed_cb, NULL));
100 eo_do(filemodel, eo_event_callback_add(EFL_MODEL_BASE_EVENT_CHILDREN_COUNT_CHANGED, _children_count_cb, NULL)); 143 eo_do(filemodel, eo_event_callback_add(EFL_MODEL_BASE_EVENT_CHILDREN_COUNT_CHANGED, _children_count_cb, NULL));
101 144
102 eo_do(filemodel, efl_model_load()); 145 eo_do(filemodel, efl_model_load());
103 146
104 ecore_main_loop_begin(); 147 ecore_main_loop_begin();
105 148
106 sleep(1); /**< EIO is asynchrounous so I must give some time for deletions to execute */
107
108 ecore_main_loop_iterate(); /**< Give time to unlink file */
109
110 eo_unref(filemodel); 149 eo_unref(filemodel);
111 150
112 eio_shutdown(); 151 eio_shutdown();