summaryrefslogtreecommitdiff
path: root/src/tests/eio
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2018-04-09 11:52:02 -0700
committerCedric BAIL <cedric@osg.samsung.com>2018-05-01 10:39:01 -0700
commit5b4d64ac13073a2c16fa3d75a009a2d30e449a7b (patch)
treebc802b035836f2d6ef0a6f1107b748fbaff0f0d0 /src/tests/eio
parent702bcd7de9049776ebf97492775ffe6e35c7caf4 (diff)
eio: migrate tests to use new Efl.Model API.
Diffstat (limited to 'src/tests/eio')
-rw-r--r--src/tests/eio/eio_model_test_file.c155
-rw-r--r--src/tests/eio/eio_model_test_monitor_add.c118
-rw-r--r--src/tests/eio/eio_test_manager.c73
3 files changed, 194 insertions, 152 deletions
diff --git a/src/tests/eio/eio_model_test_file.c b/src/tests/eio/eio_model_test_file.c
index 253ef8f0a0..812cc84cee 100644
--- a/src/tests/eio/eio_model_test_file.c
+++ b/src/tests/eio/eio_model_test_file.c
@@ -43,68 +43,110 @@ static struct reqs_t reqs;
43static Ecore_Event_Handler *handler; 43static Ecore_Event_Handler *handler;
44 44
45static Eina_Bool 45static Eina_Bool
46 exit_func(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev) 46exit_func(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev)
47 { 47{
48 Ecore_Event_Signal_Exit *e; 48 Ecore_Event_Signal_Exit *e;
49 49
50 e = (Ecore_Event_Signal_Exit *)ev; 50 e = (Ecore_Event_Signal_Exit *)ev;
51 if (e->interrupt) fprintf(stdout, "Exit: interrupt\n"); 51 if (e->interrupt) fprintf(stdout, "Exit: interrupt\n");
52 else if (e->quit) fprintf(stdout, "Exit: quit\n"); 52 else if (e->quit) fprintf(stdout, "Exit: quit\n");
53 else if (e->terminate) fprintf(stdout, "Exit: terminate\n"); 53 else if (e->terminate) fprintf(stdout, "Exit: terminate\n");
54 ecore_main_loop_quit(); 54 ecore_main_loop_quit();
55 return ECORE_CALLBACK_CANCEL; 55 return ECORE_CALLBACK_CANCEL;
56 } 56}
57 57
58static void 58static Eina_Value
59promise_then_count(void *data EINA_UNUSED, Efl_Event const *event) 59promise_then_accessor(void *data EINA_UNUSED,
60 const Eina_Value v,
61 const Eina_Future *dead_future EINA_UNUSED)
60{ 62{
61 int *total = ((Efl_Future_Event_Success*)event->info)->value; 63 Eo *child = NULL;
62 ck_assert_ptr_ne(total, NULL); 64 unsigned int i, len;
63 printf("efl_model_loaded count %d\n", *total); fflush(stdout); 65
66 fail_if(eina_value_type_get(&v) != EINA_VALUE_TYPE_ARRAY);
67
68 EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
69 ;
70
64 ecore_main_loop_quit(); 71 ecore_main_loop_quit();
72
73 return EINA_VALUE_EMPTY;
65} 74}
66 75
67static void 76static Eina_Value
68promise_then_accessor(void *data EINA_UNUSED, Efl_Event const* event) 77listing(void *data,
78 const Eina_Value v EINA_UNUSED,
79 const Eina_Future *dead_future EINA_UNUSED)
69{ 80{
70 Eina_Accessor *accessor = ((Efl_Future_Event_Success*)event->info)->value; 81 Eina_Future *future;
71 ck_assert_ptr_ne(accessor, NULL); 82 Efl_Model *filemodel = data;
72 printf("efl_model_loaded accessor %p\n", accessor); fflush(stdout);
73 83
74 Eo* child; 84 future = efl_model_children_slice_get(filemodel, 0, efl_model_children_count_get(filemodel));
75 int i = 0; 85 future = eina_future_then(future, &promise_then_accessor, NULL);
76 EINA_ACCESSOR_FOREACH(accessor, i, child)
77 {
78 printf("efl_model_loaded child: %d pointer %p\n", i, child);
79 }
80 86
81 ecore_main_loop_quit(); 87 return eina_future_as_value(future);
88}
89
90static Eina_Future *listingf = NULL;
91
92static Eina_Value
93clearup(void *data EINA_UNUSED,
94 const Eina_Value v,
95 const Eina_Future *dead_future EINA_UNUSED)
96{
97 listingf = NULL;
98
99 return v;
82} 100}
83 101
84static void 102static void
85promise_then_value(void *user EINA_UNUSED, Efl_Event const* event) 103setup_waiter(Efl_Model *model)
86{ 104{
87 Eina_Value* value = ((Efl_Future_Event_Success*)event->info)->value; 105 Efl_Loop *loop = efl_provider_find(model, EFL_LOOP_CLASS);
88 ck_assert_ptr_ne(value, NULL);
89 char *str = eina_value_to_string(value);
90 106
91 ck_assert_ptr_ne(str, NULL); 107 if (listingf) return ;
92 printf("efl_model_loaded property: %s\n", str); 108 listingf = efl_loop_job(loop);
93 free(str); 109 listingf = eina_future_then(listingf, listing, model);
110 listingf = eina_future_then(listingf, clearup, NULL);
111}
94 112
95 ecore_main_loop_quit(); 113static void
114_property_changed(void *data EINA_UNUSED, const Efl_Event *event)
115{
116 // Wait and check is_dir
117 Efl_Model_Property_Event *ev = event->info;
118 Efl_Model *filemodel = event->object;
119 const char *property;
120 Eina_Array_Iterator iterator;
121 unsigned int i;
122
123 EINA_ARRAY_ITER_NEXT(ev->changed_properties, i, property, iterator)
124 if (!strcmp(property, "is_dir"))
125 {
126 if (efl_model_children_count_get(filemodel) > 0)
127 setup_waiter(filemodel);
128 }
96} 129}
97 130
98static void 131static void
99error_promise_then(void* data EINA_UNUSED, Efl_Event const* event EINA_UNUSED) 132_child_added(void *data EINA_UNUSED, const Efl_Event *event)
100{ 133{
101 ck_abort_msg(0, "Error Promise cb"); 134 // Wait for a child being added to setup a job to list the directory
102 ecore_main_loop_quit(); 135 Efl_Model *filemodel = event->object;
136
137 if (efl_model_children_count_get(filemodel) > 0)
138 setup_waiter(filemodel);
103} 139}
104 140
141EFL_CALLBACKS_ARRAY_DEFINE(model,
142 { EFL_MODEL_EVENT_PROPERTIES_CHANGED, _property_changed },
143 { EFL_MODEL_EVENT_CHILD_ADDED, _child_added })
144
105EFL_START_TEST(eio_model_test_test_file) 145EFL_START_TEST(eio_model_test_test_file)
106{ 146{
107 Eo *filemodel = NULL; 147 Eo *filemodel = NULL;
148 Eina_Value *result;
149 char *str;
108 150
109 memset(&reqs, 0, sizeof(struct reqs_t)); 151 memset(&reqs, 0, sizeof(struct reqs_t));
110 152
@@ -113,34 +155,32 @@ EFL_START_TEST(eio_model_test_test_file)
113 fail_if(!efl_object_init(), "ERROR: Cannot init EO!\n"); 155 fail_if(!efl_object_init(), "ERROR: Cannot init EO!\n");
114 fail_if(!eio_init(), "ERROR: Cannot init EIO!\n"); 156 fail_if(!eio_init(), "ERROR: Cannot init EIO!\n");
115 157
116 filemodel = efl_add(EIO_MODEL_CLASS, efl_main_loop_get(), eio_model_path_set(efl_added, EFL_MODEL_TEST_FILENAME_PATH)); 158 filemodel = efl_add(EIO_MODEL_CLASS, efl_main_loop_get(),
159 eio_model_path_set(efl_added, EFL_MODEL_TEST_FILENAME_PATH));
117 fail_if(!filemodel, "ERROR: Cannot init model!\n"); 160 fail_if(!filemodel, "ERROR: Cannot init model!\n");
118 161
119 handler = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, exit_func, NULL); 162 handler = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, exit_func, NULL);
120 163
121 Efl_Future *future; 164 result = efl_model_property_get(filemodel, "filename");
165 fail_if(!result);
166 str = eina_value_to_string(result);
167 fail_if(!str);
168 free(str);
169 eina_value_free(result);
122 170
123 future = efl_model_property_get(filemodel, "filename"); 171 result = efl_model_property_get(filemodel, "size");
124 efl_future_then(future, &promise_then_value, &error_promise_then, NULL, NULL); 172 fail_if(!result);
125 ecore_main_loop_begin(); 173 eina_value_free(result);
126
127 future = efl_model_property_get(filemodel, "size");
128 efl_future_then(future, &promise_then_value, &error_promise_then, NULL, NULL);
129 ecore_main_loop_begin();
130 174
131 future = efl_model_property_get(filemodel, "mtime"); 175 result = efl_model_property_get(filemodel, "mtime");
132 efl_future_then(future, &promise_then_value, &error_promise_then, NULL, NULL); 176 fail_if(!result);
133 ecore_main_loop_begin(); 177 eina_value_free(result);
134 178
135 future = efl_model_children_slice_get(filemodel, 0, 0); 179 efl_event_callback_array_add(filemodel, model(), NULL);
136 efl_future_then(future, &promise_then_accessor, &error_promise_then, NULL, NULL);
137 ecore_main_loop_begin();
138 180
139 future = efl_model_children_count_get(filemodel);
140 efl_future_then(future, &promise_then_count, &error_promise_then, NULL, NULL);
141 ecore_main_loop_begin(); 181 ecore_main_loop_begin();
142 182
143 efl_unref(filemodel); 183 efl_del(filemodel);
144 184
145 eio_shutdown(); 185 eio_shutdown();
146 ecore_shutdown(); 186 ecore_shutdown();
@@ -153,4 +193,3 @@ eio_model_test_file(TCase *tc)
153{ 193{
154 tcase_add_test(tc, eio_model_test_test_file); 194 tcase_add_test(tc, eio_model_test_test_file);
155} 195}
156
diff --git a/src/tests/eio/eio_model_test_monitor_add.c b/src/tests/eio/eio_model_test_monitor_add.c
index fe3cdc2ba1..bdb6b0781a 100644
--- a/src/tests/eio/eio_model_test_monitor_add.c
+++ b/src/tests/eio/eio_model_test_monitor_add.c
@@ -16,94 +16,88 @@ Eina_Tmpstr* temp_filename = NULL;
16const char* tmpdir = NULL; 16const char* tmpdir = NULL;
17Eina_Bool children_deleted = EINA_FALSE; 17Eina_Bool children_deleted = EINA_FALSE;
18 18
19struct _pair
20{
21 Eo *parent, *child;
22};
23
24void _children_removed_get_value_cb(void* data EINA_UNUSED, Efl_Event const* event)
25{
26 Efl_Future_Event_Success* info = event->info;
27 Eina_Value* value = info->value;
28 char* filename = eina_value_to_string(value);
29 if(temp_filename && strcmp(filename, temp_filename) == 0)
30 ecore_main_loop_quit();
31 free(filename);
32
33 ecore_main_loop_quit();
34}
35
36static void 19static void
37_children_removed_cb(void *data EINA_UNUSED, const Efl_Event* event) 20_children_removed_cb(void *data EINA_UNUSED, const Efl_Event* event)
38{ 21{
39 if(children_deleted) 22 Efl_Model_Children_Event* evt = event->info;
40 { 23 Eina_Value *path;
41 Efl_Model_Children_Event* evt = event->info; 24 char *str;
42 Efl_Future* future;
43 25
44 future = efl_model_property_get(evt->child, "path"); 26 fail_if(evt->child == NULL);
27 path = efl_model_property_get(evt->child, "path");
28 fail_if(path == NULL);
29 str = eina_value_to_string(path);
30 fail_if(str == NULL);
45 31
46 efl_future_then(future, _children_removed_get_value_cb, NULL, NULL, NULL); 32 if (temp_filename && strcmp(str, temp_filename) == 0)
47 } 33 ecore_main_loop_quit();
48}
49 34
50struct _added_get_value_data 35 free(str);
51{ 36 eina_value_free(path);
52 Eo *object, *child; 37}
53};
54typedef struct _added_get_value_data added_get_value_data;
55 38
56void _children_added_get_value_cb(void* d, Efl_Event const* event) 39static Eina_Value
40_children_get(void *data,
41 const Eina_Value v,
42 const Eina_Future *dead_future EINA_UNUSED)
57{ 43{
58 Efl_Future_Event_Success* info = event->info; 44 Efl_Model *filemodel = data;
59 Eina_Value* value = info->value; 45 Eo *child = NULL;
60 added_get_value_data* data = d; 46 unsigned int i, len;
61 47
62 char* filename = eina_value_to_string(value); 48 fail_if(eina_value_type_get(&v) != EINA_VALUE_TYPE_ARRAY);
63 49
64 if(temp_filename && strcmp(temp_filename, filename) == 0) 50 EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
65 { 51 {
66 children_deleted = EINA_TRUE; 52 Eina_Value *path;
67 efl_model_child_del(data->object, data->child); 53 char *str;
54
55 path = efl_model_property_get(child, "path");
56 fail_if(path == NULL);
57 str = eina_value_to_string(path);
58 fail_if(str == NULL);
59
60 if (strcmp(temp_filename, str) == 0)
61 {
62 children_deleted = EINA_TRUE;
63 efl_model_child_del(filemodel, child);
64 }
65 free(str);
66 eina_value_free(path);
68 } 67 }
69 free(filename); 68
69 return v;
70} 70}
71 71
72static void 72static void
73_children_added_cb(void *d EINA_UNUSED, const Efl_Event* event) 73_children_added_cb(void *d EINA_UNUSED, const Efl_Event* event)
74{ 74{
75 Efl_Model_Children_Event* evt = event->info; 75 Efl_Model_Children_Event* evt = event->info;
76 Efl_Future* future; 76 Eina_Future *future;
77 77
78 future = efl_model_property_get(evt->child, "path"); 78 future = efl_model_children_slice_get(event->object, evt->index, 1);
79 79 eina_future_then(future, _children_get, event->object);
80 added_get_value_data* data = malloc(sizeof(added_get_value_data));
81 data->object = event->object;
82 data->child = evt->child;
83 efl_future_then(future, _children_added_get_value_cb, NULL, NULL, data);
84} 80}
85 81
86static void 82static Eina_Value
87_create_file(void *data EINA_UNUSED, Efl_Event const* event EINA_UNUSED) 83_create_file(void *data EINA_UNUSED,
84 const Eina_Value v,
85 const Eina_Future *dead_future EINA_UNUSED)
88{ 86{
89 int fd; 87 int fd;
88
90 if((fd = eina_file_mkstemp("prefixXXXXXX.ext", &temp_filename)) > 0) 89 if((fd = eina_file_mkstemp("prefixXXXXXX.ext", &temp_filename)) > 0)
91 { 90 {
92 close(fd); 91 close(fd);
93 } 92 }
94}
95
96 93
97static void 94 return v;
98_create_file_error(void *data EINA_UNUSED, Efl_Event const* event EINA_UNUSED)
99{
100 ck_abort_msg(0, "Error Promise cb called in Create file");
101 ecore_main_loop_quit();
102} 95}
103 96
104EFL_START_TEST(eio_model_test_test_monitor_add) 97EFL_START_TEST(eio_model_test_test_monitor_add)
105{ 98{
106 Eo *filemodel = NULL; 99 Eo *filemodel = NULL;
100 Eina_Future* future;
107 101
108 fail_if(!eina_init(), "ERROR: Cannot init Eina!\n"); 102 fail_if(!eina_init(), "ERROR: Cannot init Eina!\n");
109 fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n"); 103 fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n");
@@ -112,20 +106,21 @@ EFL_START_TEST(eio_model_test_test_monitor_add)
112 106
113 tmpdir = eina_environment_tmp_get(); 107 tmpdir = eina_environment_tmp_get();
114 108
115 filemodel = efl_add(EIO_MODEL_CLASS, efl_main_loop_get(), eio_model_path_set(efl_added, tmpdir)); 109 filemodel = efl_add(EIO_MODEL_CLASS,
110 efl_main_loop_get(),
111 eio_model_path_set(efl_added, tmpdir));
116 fail_if(!filemodel, "ERROR: Cannot init model!\n"); 112 fail_if(!filemodel, "ERROR: Cannot init model!\n");
117 113
118 efl_event_callback_add(filemodel, EFL_MODEL_EVENT_CHILD_ADDED, &_children_added_cb, filemodel); 114 efl_event_callback_add(filemodel, EFL_MODEL_EVENT_CHILD_ADDED, &_children_added_cb, filemodel);
119 efl_event_callback_add(filemodel, EFL_MODEL_EVENT_CHILD_REMOVED, &_children_removed_cb, NULL); 115 efl_event_callback_add(filemodel, EFL_MODEL_EVENT_CHILD_REMOVED, &_children_removed_cb, NULL);
120 116
121 Efl_Future* future; 117 future = efl_model_children_slice_get(filemodel, 0, efl_model_children_count_get(filemodel));
122 future = efl_model_children_slice_get(filemodel, 0, 0);
123 118
124 efl_future_then(future, &_create_file, &_create_file_error, NULL, NULL); 119 eina_future_then(future, &_create_file, NULL);
125 120
126 ecore_main_loop_begin(); 121 ecore_main_loop_begin();
127 122
128 efl_unref(filemodel); 123 efl_del(filemodel);
129 124
130 eio_shutdown(); 125 eio_shutdown();
131 ecore_shutdown(); 126 ecore_shutdown();
@@ -140,4 +135,3 @@ eio_model_test_monitor_add(TCase *tc)
140{ 135{
141 tcase_add_test(tc, eio_model_test_test_monitor_add); 136 tcase_add_test(tc, eio_model_test_test_monitor_add);
142} 137}
143
diff --git a/src/tests/eio/eio_test_manager.c b/src/tests/eio/eio_test_manager.c
index a9d5ecc020..3f82af51cf 100644
--- a/src/tests/eio/eio_test_manager.c
+++ b/src/tests/eio/eio_test_manager.c
@@ -19,26 +19,19 @@ static Eina_Bool direct = EINA_FALSE;
19#define DONE_CALLED 0xdeadbeef 19#define DONE_CALLED 0xdeadbeef
20 20
21static void 21static void
22_access_cb(void *data, Eina_Accessor *access) 22_access_cb(void *data, Eina_Array *paths)
23{ 23{
24 uint64_t *number_of_listed_files = data; 24 uint64_t *number_of_listed_files = data;
25 Eina_Stringshare *s;
26 unsigned int count;
27 25
28 EINA_ACCESSOR_FOREACH(access, count, s) 26 *number_of_listed_files += eina_array_count(paths);
29 {
30 (*number_of_listed_files)++;
31 }
32} 27}
33 28
34static void 29static void
35_progress_cb(void *data, const Efl_Event *ev) 30_progress_cb(void *data, Eina_Array *entries)
36{ 31{
37 Efl_Future_Event_Progress *p = ev->info;
38 const Eina_Array *batch = p->progress;
39 uint64_t *number_of_listed_files = data; 32 uint64_t *number_of_listed_files = data;
40 33
41 (*number_of_listed_files) += eina_array_count(batch); 34 (*number_of_listed_files) += eina_array_count(entries);
42} 35}
43 36
44static Eina_Value 37static Eina_Value
@@ -71,27 +64,42 @@ _future_cb(void *data,
71 return file; 64 return file;
72} 65}
73 66
74static void 67static Eina_Value
75_done_cb(void *data, const Efl_Event *ev) 68_done_cb(void *data,
69 const Eina_Value file,
70 const Eina_Future *dead EINA_UNUSED)
76{ 71{
77 Efl_Future_Event_Success *success = ev->info;
78 uint64_t *files_count = success->value;
79 uint64_t *number_of_listed_files = data; 72 uint64_t *number_of_listed_files = data;
80 73
81 fail_if((*number_of_listed_files) != test_count); 74 if (eina_value_type_get(&file) == EINA_VALUE_TYPE_ERROR)
82 fail_if(*files_count != test_count); 75 {
83 *number_of_listed_files = DONE_CALLED; 76 Eina_Error err = 0;
84 ecore_main_loop_quit(); 77 const char *msg;
85}
86 78
87static void 79 eina_value_error_get(&file, &err);
88_error_cb(void *data EINA_UNUSED, const Efl_Event *ev) 80 msg = eina_error_msg_get(err);
89{ 81
90 Efl_Future_Event_Failure *failure = ev->info; 82 EINA_LOG_ERR("error: %s", msg);
91 const char *msg = eina_error_msg_get(failure->error); 83 abort();
84 }
85 else
86 {
87 Eina_Value convert = EINA_VALUE_EMPTY;
88 uint64_t files_count = 0;
89
90 eina_value_setup(&convert, EINA_VALUE_TYPE_ULONG);
91 eina_value_convert(&file, &convert);
92 eina_value_ulong_get(&convert, &files_count);
93
94 fail_if((*number_of_listed_files) != test_count);
95 fail_if(files_count != test_count);
96
97 *number_of_listed_files = DONE_CALLED;
98 }
92 99
93 EINA_LOG_ERR("error: %s", msg);
94 ecore_main_loop_quit(); 100 ecore_main_loop_quit();
101
102 return file;
95} 103}
96 104
97static Eina_Value 105static Eina_Value
@@ -152,29 +160,30 @@ _stat_done_cb(void *data,
152} 160}
153 161
154static void 162static void
155_test_ls(Efl_Future *(*func)(Eo *obj, const char *path, Eina_Bool recursive), 163_test_ls(Eina_Future *(*func)(Eo *obj, const char *path, Eina_Bool recursive,
164 void *info_data, EflIoDirectInfo info, Eina_Free_Cb info_free_cb),
156 uint64_t expected_test_count, 165 uint64_t expected_test_count,
157 const char* test_dirname) 166 const char* test_dirname)
158{ 167{
159 Efl_Io_Manager *job = efl_add(EFL_IO_MANAGER_CLASS, efl_main_loop_get()); 168 Efl_Io_Manager *job = efl_add(EFL_IO_MANAGER_CLASS, efl_main_loop_get());
160 Efl_Future *f = NULL; 169 Eina_Future *f = NULL;
161 uint64_t main_files = 0; 170 uint64_t main_files = 0;
162 171
163 fail_if(!job); 172 fail_if(!job);
164 173
165 f = func(job, test_dirname, EINA_FALSE); 174 f = func(job, test_dirname, EINA_FALSE, &main_files, _progress_cb, NULL);
166 fail_if(!f); 175 fail_if(!f);
167 test_count = expected_test_count; 176 test_count = expected_test_count;
168 efl_future_then(f, &_done_cb, &_error_cb, &_progress_cb, &main_files); 177 eina_future_then(f, &_done_cb, &main_files);
169 178
170 ecore_main_loop_begin(); 179 ecore_main_loop_begin();
171 180
172 fail_if(main_files != DONE_CALLED); 181 fail_if(main_files != DONE_CALLED);
173 main_files = 0; 182 main_files = 0;
174 183
175 f = func(job, test_dirname, EINA_TRUE); 184 f = func(job, test_dirname, EINA_TRUE, &main_files, _progress_cb, NULL);
176 test_count = expected_test_count + 4; 185 test_count = expected_test_count + 4;
177 efl_future_then(f, &_done_cb, &_error_cb, &_progress_cb, &main_files); 186 eina_future_then(f, &_done_cb, &main_files);
178 187
179 ecore_main_loop_begin(); 188 ecore_main_loop_begin();
180 189