summaryrefslogtreecommitdiff
path: root/src/tests/eio
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-04-05 15:19:59 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-04-05 16:23:38 +0200
commit7928609a2945d2aef038b1e97a6d800d864d6f1a (patch)
treea66dd4a9bc24ff2a33ebb6ed9b76cbe08bb08aa5 /src/tests/eio
parent2f5383333196004f9113952c864bf9848025a04b (diff)
efl: move emodel to be an efl interfaces.
Diffstat (limited to 'src/tests/eio')
-rw-r--r--src/tests/eio/eio_model_test_file.c232
-rw-r--r--src/tests/eio/eio_model_test_monitor_add.c125
-rw-r--r--src/tests/eio/eio_suite.c2
-rw-r--r--src/tests/eio/eio_suite.h2
4 files changed, 361 insertions, 0 deletions
diff --git a/src/tests/eio/eio_model_test_file.c b/src/tests/eio/eio_model_test_file.c
new file mode 100644
index 0000000000..af5269d033
--- /dev/null
+++ b/src/tests/eio/eio_model_test_file.c
@@ -0,0 +1,232 @@
1//Compile with:
2// gcc -o emodel_test_file emodel_test_file.c `pkg-config --cflags --libs emodel`
3#ifdef HAVE_CONFIG_H
4# include <config.h>
5#endif
6
7#include <Eo.h>
8#include <Eio.h>
9#include <Ecore.h>
10#include <Efl.h>
11#include <eio_model.h>
12#include <stdio.h>
13
14#include <check.h>
15
16#define EFL_MODEL_TEST_FILENAME_PATH "/tmp"
17#define EFL_MODEL_MAX_TEST_CHILDS 16
18
19/**
20 * The following test works however
21 * it is going to rename (move) the original directory to
22 * new one so '/tmp' as root dir doesn't work , you'll need to use
23 * '/tmp/some_other_dir' as root instead.
24 */
25//#define _RUN_LOCAL_TEST
26
27struct reqs_t {
28 /* property change */
29 int changed_is_dir;
30 int changed_is_lnk;
31 int changed_size;
32 int changed_mtime;
33
34 /* properties list */
35 int proplist_filename;
36 int proplist_path;
37 int proplist_mtime;
38 int proplist_is_dir;
39 int proplist_is_lnk;
40 int proplist_size;
41
42 /* misc tests for data or propeties */
43 int properties;
44 int children;
45 int child_add;
46 int child_del;
47};
48
49static struct reqs_t reqs;
50static Ecore_Event_Handler *handler;
51
52static Eina_Bool
53 exit_func(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev)
54 {
55 Ecore_Event_Signal_Exit *e;
56
57 e = (Ecore_Event_Signal_Exit *)ev;
58 if (e->interrupt) fprintf(stdout, "Exit: interrupt\n");
59 else if (e->quit) fprintf(stdout, "Exit: quit\n");
60 else if (e->terminate) fprintf(stdout, "Exit: terminate\n");
61 ecore_main_loop_quit();
62 return ECORE_CALLBACK_CANCEL;
63 }
64
65static Eina_Bool
66_load_status_cb(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
67{
68 Efl_Model_Load *st = event_info;
69 printf("Load CHANGE\n");
70
71 if (st->status & EFL_MODEL_LOAD_STATUS_LOADED_CHILDREN)
72 printf("Children is Loaded\n");
73
74 if (st->status & EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES)
75 printf("Properties is Loaded\n");
76
77 if ((st->status & EFL_MODEL_LOAD_STATUS_LOADED) == EFL_MODEL_LOAD_STATUS_LOADED)
78 {
79 Eina_Accessor *accessor;
80 const Eina_Value *value_prop;
81 Efl_Model_Load_Status status;
82 unsigned int total;
83 char *str;
84
85 printf("Model is Loaded\n");
86 eo_do(obj, status = efl_model_property_get("filename", &value_prop));
87 str = eina_value_to_string(value_prop);
88 printf("efl_model_loaded filename %s, status=%d\n", str, status);
89 free(str);
90
91 eo_do(obj, status = efl_model_property_get("size", &value_prop));
92 str = eina_value_to_string(value_prop);
93 printf("efl_model_loaded size %s, status=%d\n", str, status);
94 free(str);
95
96 eo_do(obj, status = efl_model_property_get("mtime", &value_prop));
97 str = eina_value_to_string(value_prop);
98 printf("efl_model_loaded mtime %s, status=%d\n", str, status);
99 free(str);
100
101 eo_do(obj, efl_model_children_count_get(&total));
102 printf("efl_model_test count %d\n", (int)total);
103
104 /**< get full list */
105 eo_do(obj, status = efl_model_children_slice_get(0 ,0 ,(Eina_Accessor **)&accessor));
106 eina_accessor_free(accessor);
107 eo_do(obj, status = efl_model_children_slice_get(5 ,5 ,(Eina_Accessor **)&accessor));
108 eina_accessor_free(accessor);
109 ecore_main_loop_quit();
110 }
111 return EINA_TRUE;
112}
113
114static Eina_Bool
115_properties_change_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
116{
117 const Efl_Model_Property_Event *evt = (Efl_Model_Property_Event *)event_info;
118 const char *prop;
119 Eina_Array_Iterator it;
120 unsigned int i;
121
122 EINA_ARRAY_ITER_NEXT(evt->changed_properties, i, prop, it)
123 {
124 if (!strcmp(prop, "is_dir"))
125 reqs.changed_is_dir = 1;
126 else if (!strcmp(prop, "is_lnk"))
127 reqs.changed_is_lnk = 1;
128 else if (!strcmp(prop, "size"))
129 reqs.changed_size = 1;
130 else if (!strcmp(prop, "mtime"))
131 reqs.changed_mtime = 1;
132 }
133
134 reqs.properties = 1;
135 return EINA_TRUE;
136}
137
138static Eina_Bool
139_children_count_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
140{
141 unsigned int *len = (unsigned int *)event_info;
142 unsigned int total;
143
144 fprintf(stdout, "Children count number=%d\n", *len);
145 reqs.children = *len;
146
147 eo_do(obj, efl_model_children_count_get(&total));
148 fprintf(stdout, "New total children count number=%d\n", *len);
149
150 return EINA_TRUE;
151}
152
153START_TEST(eio_model_test_test_file)
154{
155 Eo *filemodel = NULL;
156 const Eina_Value *value_prop;
157 Efl_Model_Load_Status status;
158#ifdef _RUN_LOCAL_TEST
159 Eina_Value nameset_value;
160#endif
161 Eina_Array *properties_list;
162 Eina_Array_Iterator iterator;
163 char *str;
164 unsigned int i;
165
166 memset(&reqs, -1, sizeof(struct reqs_t));
167
168 fail_if(!eina_init(), "ERROR: Cannot init Eina!\n");
169 fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n");
170 fail_if(!eio_init(), "ERROR: Cannot init EIO!\n");
171
172 filemodel = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(EFL_MODEL_TEST_FILENAME_PATH));
173 fail_if(!filemodel, "ERROR: Cannot init model!\n");
174
175 eo_do(filemodel, eo_event_callback_add(EFL_MODEL_BASE_EVENT_LOAD_STATUS, _load_status_cb, NULL));
176 eo_do(filemodel, eo_event_callback_add(EFL_MODEL_BASE_EVENT_PROPERTIES_CHANGED, _properties_change_cb, NULL));
177 eo_do(filemodel, eo_event_callback_add(EFL_MODEL_BASE_EVENT_CHILDREN_COUNT_CHANGED, _children_count_cb, NULL));
178
179 eo_do(filemodel, efl_model_load());
180
181 handler = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, exit_func, NULL);
182
183 eo_do(filemodel, status = efl_model_property_get("filename", &value_prop));
184 str = eina_value_to_string(value_prop);
185 printf("efl_model_test filename %s, load status %d\n", str, status);
186
187 free(str);
188
189 i = 0;
190 eo_do(filemodel, efl_model_properties_get(&properties_list));
191 EINA_ARRAY_ITER_NEXT(properties_list, i, str, iterator)
192 {
193 fprintf(stdout, "Returned property list %d: %s\n", i, str);
194 if(!strcmp(str, "filename"))
195 reqs.proplist_filename = 1;
196 else if(!strcmp(str, "path"))
197 reqs.proplist_path = 1;
198 else if(!strcmp(str, "mtime"))
199 reqs.proplist_mtime = 1;
200 else if(!strcmp(str, "is_dir"))
201 reqs.proplist_is_dir = 1;
202 else if(!strcmp(str, "is_lnk"))
203 reqs.proplist_is_lnk = 1;
204 else if(!strcmp(str, "size"))
205 reqs.proplist_size = 1;
206 }
207
208 ecore_main_loop_begin();
209
210#ifdef _RUN_LOCAL_TEST
211 eina_value_setup(&nameset_value, EINA_VALUE_TYPE_STRING);
212 eina_value_setup(&value_prop, EINA_VALUE_TYPE_STRING);
213 eina_value_set(&nameset_value, "/tmp/efl_model_test");
214 eo_do(filemodel, efl_model_property_set("path", &nameset_value));
215 eina_value_flush(&nameset_value);
216 eo_do(filemodel, status = efl_model_property_get("path", &value_prop));
217#endif
218
219 sleep(1); /**< EIO is asynchrounous so I must give some time for deletions to execute */
220 eo_unref(filemodel);
221 ecore_shutdown();
222 eina_shutdown();
223 eio_shutdown();
224}
225END_TEST
226
227void
228eio_model_test_file(TCase *tc)
229{
230 tcase_add_test(tc, eio_model_test_test_file);
231}
232
diff --git a/src/tests/eio/eio_model_test_monitor_add.c b/src/tests/eio/eio_model_test_monitor_add.c
new file mode 100644
index 0000000000..af95ae8f75
--- /dev/null
+++ b/src/tests/eio/eio_model_test_monitor_add.c
@@ -0,0 +1,125 @@
1//Compile with:
2// gcc -o emodel_test_file emodel_test_file.c `pkg-config --cflags --libs emodel`
3#ifdef HAVE_CONFIG_H
4# include <config.h>
5#endif
6
7#include <Eo.h>
8#include <Eio.h>
9#include <Ecore.h>
10#include <Efl.h>
11#include <eio_model.h>
12#include <stdio.h>
13
14#include <check.h>
15
16#define EFL_MODEL_TEST_FILENAME_PATH "/tmp"
17
18Eina_Bool children_added = EINA_FALSE;
19
20static Eina_Bool
21_load_monitor_status_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
22{
23 Efl_Model_Load* st = event_info;
24 Eo* parent = data;
25 const Eina_Value* value_prop = NULL;
26 const char* str = NULL;
27
28 if (!(st->status & EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES))
29 return EINA_TRUE;
30
31 eo_do(obj, efl_model_property_get("filename", &value_prop));
32 fail_if(!value_prop, "ERROR: Cannot get property!\n");
33
34 str = eina_value_to_string(value_prop);
35 fail_if(!str, "ERROR: Cannot convert value to string!\n");
36 fprintf(stderr, "new children filename %s\n", str);
37 if(strcmp(str, "test_file_monitor_add") == 0)
38 {
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));
41 children_added = EINA_TRUE;
42 eo_do(parent, efl_model_child_del(obj));
43 ecore_main_loop_quit();
44 }
45
46 return EINA_FALSE;
47}
48
49static Eina_Bool
50_children_added_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
51{
52 Efl_Model_Children_Event* evt = event_info;
53 if (evt == NULL)
54 return EINA_TRUE;
55
56 eo_do(evt->child, eo_event_callback_add(EFL_MODEL_BASE_EVENT_LOAD_STATUS, _load_monitor_status_cb, obj));
57 eo_do(evt->child, efl_model_load());
58
59 return EINA_TRUE;
60}
61
62static Eina_Bool
63_children_count_cb(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
64{
65 unsigned int *len = event_info;
66 Eina_Accessor *accessor;
67 Efl_Model_Load_Status status;
68 Eo *child;
69 unsigned int i = 0;
70
71 fprintf(stderr, "Children count number=%d\n", *len);
72
73 /**< get full list */
74 eo_do(obj, status = efl_model_children_slice_get(0 ,0 ,(Eina_Accessor **)&accessor));
75 if(accessor != NULL)
76 {
77 EINA_ACCESSOR_FOREACH(accessor, i, child) {}
78 fprintf(stdout, "Got %d childs from Accessor. status=%d\n", i, status);
79 }
80
81 fclose(fopen(EFL_MODEL_TEST_FILENAME_PATH "/test_file_monitor_add", "w+"));
82
83 return EINA_TRUE;
84}
85
86START_TEST(eio_model_test_test_monitor_add)
87{
88 Eo *filemodel = NULL;
89
90 fprintf(stderr, "efl_model_test_test_monitor_add\n");
91
92 fail_if(!eina_init(), "ERROR: Cannot init Eina!\n");
93 fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n");
94 fail_if(!eio_init(), "ERROR: Cannot init EIO!\n");
95
96 filemodel = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(EFL_MODEL_TEST_FILENAME_PATH));
97 fail_if(!filemodel, "ERROR: Cannot init model!\n");
98
99 eo_do(filemodel, eo_event_callback_add(EFL_MODEL_BASE_EVENT_CHILD_ADDED, _children_added_cb, NULL));
100 eo_do(filemodel, eo_event_callback_add(EFL_MODEL_BASE_EVENT_CHILDREN_COUNT_CHANGED, _children_count_cb, NULL));
101
102 eo_do(filemodel, efl_model_load());
103
104 ecore_main_loop_begin();
105
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);
111
112 eio_shutdown();
113 ecore_shutdown();
114 eina_shutdown();
115
116 fail_if(!children_added);
117}
118END_TEST
119
120void
121eio_model_test_monitor_add(TCase *tc)
122{
123 tcase_add_test(tc, eio_model_test_test_monitor_add);
124}
125
diff --git a/src/tests/eio/eio_suite.c b/src/tests/eio/eio_suite.c
index 08deb05803..ecc52247b3 100644
--- a/src/tests/eio/eio_suite.c
+++ b/src/tests/eio/eio_suite.c
@@ -19,6 +19,8 @@ struct _Eio_Test_Case
19 19
20static const Eio_Test_Case etc[] = { 20static const Eio_Test_Case etc[] = {
21 {"Eio_Monitor", eio_test_monitor}, 21 {"Eio_Monitor", eio_test_monitor},
22 {"Eio Model", eio_model_test_file},
23 {"Eio Model Monitor", eio_model_test_monitor_add},
22 {NULL, NULL} 24 {NULL, NULL}
23}; 25};
24 26
diff --git a/src/tests/eio/eio_suite.h b/src/tests/eio/eio_suite.h
index 2212f8eafb..d59a2ab6c0 100644
--- a/src/tests/eio/eio_suite.h
+++ b/src/tests/eio/eio_suite.h
@@ -4,5 +4,7 @@
4#include <check.h> 4#include <check.h>
5 5
6void eio_test_monitor(TCase *tc); 6void eio_test_monitor(TCase *tc);
7void eio_model_test_file(TCase *tc);
8void eio_model_test_monitor_add(TCase *tc);
7 9
8#endif /* _EIO_SUITE_H */ 10#endif /* _EIO_SUITE_H */