summaryrefslogtreecommitdiff
path: root/src/tests/eio
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-06-03 16:52:03 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-06-03 17:22:12 -0300
commit8fec0d5139a3ff30037ba159bb62ff2f733d96a8 (patch)
tree0316d756b8150e9ef40d76668e5084fdb06af29a /src/tests/eio
parent1dcccfdf8160ca6113d66c51c226302221b9a049 (diff)
eina: Remove unnecessary indirection to promises
Now when dealing with pointer types, we will not get pointer to pointer semantics in callbacks and eina_promise_owner_value_set for Eina_Promise. It will work as expected: Eina_Promise_Owner* promise = eina_promise_add(); void* p = malloc(sizeof(T)); eina_promise_owner_value_set(promise, p, &free);
Diffstat (limited to 'src/tests/eio')
-rw-r--r--src/tests/eio/eio_test_job.c43
1 files changed, 20 insertions, 23 deletions
diff --git a/src/tests/eio/eio_test_job.c b/src/tests/eio/eio_test_job.c
index 9ef8ced03c..7c9a007216 100644
--- a/src/tests/eio/eio_test_job.c
+++ b/src/tests/eio/eio_test_job.c
@@ -62,7 +62,7 @@ _main_cb(void *data, const char *file, Eina_Promise* promise EINA_UNUSED)
62} 62}
63 63
64static void 64static void
65_done_cb(void *data, Eio_File *handler EINA_UNUSED, Eina_Promise* promise EINA_UNUSED) 65_done_cb(void *data, void* value EINA_UNUSED, Eina_Promise* promise EINA_UNUSED)
66{ 66{
67 int *number_of_listed_files = (int *)data; 67 int *number_of_listed_files = (int *)data;
68 fail_if((*number_of_listed_files) != test_count); 68 fail_if((*number_of_listed_files) != test_count);
@@ -79,19 +79,20 @@ _error_cb(void *data EINA_UNUSED, Eina_Error error, Eina_Promise* promise EINA_U
79} 79}
80 80
81static void 81static void
82_open_done_cb(void *data, Eina_File **file, Eina_Promise* promise) 82_open_done_cb(void *data, void *file_value, Eina_Promise* promise EINA_UNUSED)
83{ 83{
84 Eina_Bool *opened = (Eina_Bool *)data; 84 Eina_Bool *opened = (Eina_Bool *)data;
85 *opened = EINA_TRUE; 85 *opened = EINA_TRUE;
86 eina_promise_release_value_ownership(promise); 86 Eina_File* file = eina_file_dup(file_value);
87 eina_file_close(*file); 87 eina_file_close(file);
88 ecore_main_loop_quit(); 88 ecore_main_loop_quit();
89} 89}
90 90
91static void 91static void
92_stat_done_cb(void *data, const Eina_Stat *stat, Eina_Promise* promise EINA_UNUSED) 92_stat_done_cb(void *data, void *value, Eina_Promise* promise EINA_UNUSED)
93{ 93{
94 Eina_Bool *is_dir = (Eina_Bool *)data; 94 Eina_Stat const* stat = value;
95 Eina_Bool *is_dir = data;
95 unsigned int rights; 96 unsigned int rights;
96 fail_if(eio_file_is_dir(stat) != *is_dir); 97 fail_if(eio_file_is_dir(stat) != *is_dir);
97 fail_if(eio_file_is_lnk(stat)); 98 fail_if(eio_file_is_lnk(stat));
@@ -119,10 +120,7 @@ _do_ls_test(Eio_Job_Test_Stat_Ls_Func ls_func,
119 promise = ls_func(job, test_dirname); 120 promise = ls_func(job, test_dirname);
120 test_count = expected_test_count; 121 test_count = expected_test_count;
121 eina_promise_progress_cb_add(promise, progress_cb, &main_files, NULL); 122 eina_promise_progress_cb_add(promise, progress_cb, &main_files, NULL);
122 eina_promise_then(promise, 123 eina_promise_then(promise, &_done_cb, &_error_cb, &main_files);
123 (Eina_Promise_Cb)&_done_cb,
124 (Eina_Promise_Error_Cb)&_error_cb,
125 &main_files);
126 124
127 ecore_main_loop_begin(); 125 ecore_main_loop_begin();
128 126
@@ -137,11 +135,11 @@ _do_direct_ls_test(Eio_Job_Test_Stat_Ls_Func ls_func,
137 const char *test_dirname) 135 const char *test_dirname)
138{ 136{
139 _do_ls_test(ls_func, 137 _do_ls_test(ls_func,
140 EIO_JOB_EVENT_FILTER_DIRECT, 138 EIO_JOB_EVENT_FILTER_DIRECT,
141 (Eo_Event_Cb)&_filter_direct_cb, 139 (Eo_Event_Cb)&_filter_direct_cb,
142 (Eina_Promise_Progress_Cb)&_main_direct_cb, 140 (Eina_Promise_Progress_Cb)&_main_direct_cb,
143 expected_test_count, 141 expected_test_count,
144 test_dirname); 142 test_dirname);
145} 143}
146 144
147START_TEST(eio_job_test_file_direct_stat) 145START_TEST(eio_job_test_file_direct_stat)
@@ -168,12 +166,12 @@ START_TEST(eio_job_test_file_direct_stat)
168 is_dir = EINA_TRUE; 166 is_dir = EINA_TRUE;
169 167
170 promise = eio_job_file_direct_stat(job, nested_dirname); 168 promise = eio_job_file_direct_stat(job, nested_dirname);
171 eina_promise_then(promise, (Eina_Promise_Cb)&_stat_done_cb, (Eina_Promise_Error_Cb)&_error_cb, &is_dir); 169 eina_promise_then(promise, &_stat_done_cb, &_error_cb, &is_dir);
172 ecore_main_loop_begin(); 170 ecore_main_loop_begin();
173 171
174 is_dir = EINA_FALSE; 172 is_dir = EINA_FALSE;
175 promise = eio_job_file_direct_stat(job, nested_filename); 173 promise = eio_job_file_direct_stat(job, nested_filename);
176 eina_promise_then(promise, (Eina_Promise_Cb)&_stat_done_cb, (Eina_Promise_Error_Cb)&_error_cb, &is_dir); 174 eina_promise_then(promise, &_stat_done_cb, &_error_cb, &is_dir);
177 ecore_main_loop_begin(); 175 ecore_main_loop_begin();
178 eo_unref(job); 176 eo_unref(job);
179 177
@@ -209,14 +207,12 @@ START_TEST(eio_job_test_ls_funcs)
209 207
210 // Start testing 208 // Start testing
211 209
212 fprintf(stderr, __FILE__ ":%d %s\n", __LINE__, __func__); fflush(stderr);
213 _do_ls_test(&eio_job_file_ls, 210 _do_ls_test(&eio_job_file_ls,
214 EIO_JOB_EVENT_FILTER_NAME, 211 EIO_JOB_EVENT_FILTER_NAME,
215 (Eo_Event_Cb)&_filter_cb, 212 (Eo_Event_Cb)&_filter_cb,
216 (Eina_Promise_Progress_Cb)&_main_cb, 213 (Eina_Promise_Progress_Cb)&_main_cb,
217 5, 214 5,
218 test_dirname); 215 test_dirname);
219 fprintf(stderr, __FILE__ ":%d %s\n", __LINE__, __func__); fflush(stderr);
220 216
221 _do_direct_ls_test(&eio_job_file_stat_ls, 5, test_dirname); 217 _do_direct_ls_test(&eio_job_file_stat_ls, 5, test_dirname);
222 218
@@ -246,12 +242,12 @@ START_TEST(eio_job_test_open)
246 242
247 ret = ecore_init(); 243 ret = ecore_init();
248 fail_if(ret < 1); 244 fail_if(ret < 1);
249 ret = eio_init();
250 fail_if(ret < 1);
251 ret = eina_init(); 245 ret = eina_init();
252 fail_if(ret < 1); 246 fail_if(ret < 1);
253 ret = ecore_file_init(); 247 ret = ecore_file_init();
254 fail_if(ret < 1); 248 fail_if(ret < 1);
249 ret = eio_init();
250 fail_if(ret < 1);
255 251
256 Eina_Tmpstr *test_dirname = get_eio_test_file_tmp_dir(); 252 Eina_Tmpstr *test_dirname = get_eio_test_file_tmp_dir();
257 Eina_Tmpstr *nested_dirname = create_test_dirs(test_dirname); 253 Eina_Tmpstr *nested_dirname = create_test_dirs(test_dirname);
@@ -262,7 +258,7 @@ START_TEST(eio_job_test_open)
262 Eina_Promise *promise = NULL; 258 Eina_Promise *promise = NULL;
263 259
264 promise = eio_job_file_open(job, nested_filename, EINA_FALSE); 260 promise = eio_job_file_open(job, nested_filename, EINA_FALSE);
265 eina_promise_then(promise, (Eina_Promise_Cb)&_open_done_cb, (Eina_Promise_Error_Cb)&_error_cb, &opened_file); 261 eina_promise_then(promise, &_open_done_cb, &_error_cb, &opened_file);
266 ecore_main_loop_begin(); 262 ecore_main_loop_begin();
267 eo_unref(job); 263 eo_unref(job);
268 fail_if(!opened_file); 264 fail_if(!opened_file);
@@ -272,10 +268,11 @@ START_TEST(eio_job_test_open)
272 268
273 eina_tmpstr_del(nested_dirname); 269 eina_tmpstr_del(nested_dirname);
274 eina_tmpstr_del(test_dirname); 270 eina_tmpstr_del(test_dirname);
271
272 eio_shutdown();
275 eina_tmpstr_del(nested_filename); 273 eina_tmpstr_del(nested_filename);
276 ecore_file_shutdown(); 274 ecore_file_shutdown();
277 eina_shutdown(); 275 eina_shutdown();
278 eio_shutdown();
279 ecore_shutdown(); 276 ecore_shutdown();
280} 277}
281END_TEST 278END_TEST