summaryrefslogtreecommitdiff
path: root/src/tests/eio
diff options
context:
space:
mode:
authorkabeer khan <kabeer.khan@samsung.com>2015-04-28 11:08:08 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-04-28 11:37:11 +0200
commitb869a4e02c949059af29dbc1c69216deb34c443d (patch)
tree3d976f0336baa585e087dd40494c5169f8ba496e /src/tests/eio
parenta9911f5fd81f8f9f04a9815b6ef4ce8de878c4ca (diff)
eio: add new tests for eio.
Summary: Signed-off-by: kabeer khan <kabeer.khan@samsung.com> Reviewers: cedric Reviewed By: cedric Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2414 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/tests/eio')
-rw-r--r--src/tests/eio/eio_test_file.c172
1 files changed, 156 insertions, 16 deletions
diff --git a/src/tests/eio/eio_test_file.c b/src/tests/eio/eio_test_file.c
index 786ba7b8c8..912c975c08 100644
--- a/src/tests/eio/eio_test_file.c
+++ b/src/tests/eio/eio_test_file.c
@@ -10,11 +10,24 @@
10 10
11#include <Eio.h> 11#include <Eio.h>
12#include <Ecore.h> 12#include <Ecore.h>
13#include <Ecore_File.h>
13 14
14#include "eio_suite.h" 15#include "eio_suite.h"
15 16
16static int default_rights = 0777; 17static unsigned int default_rights = 0755;
17static int test_count = 0; 18static int test_count = 0;
19static const char *good_dirs[] =
20 {
21 "eio_file_ls_simple_dir",
22 "b."
23 };
24static const char *files[] =
25 {
26 ".hidden_file",
27 "~$b@:-*$a!{}",
28 "$b$a",
29 "normal_file"
30 };
18 31
19static Eina_Bool 32static Eina_Bool
20_filter_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, const char *file) 33_filter_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, const char *file)
@@ -67,15 +80,26 @@ _direct_main_cb(void *data, Eio_File *handler EINA_UNUSED, const Eina_File_Direc
67} 80}
68 81
69static void 82static void
70_progress_cb(void *data, Eio_File *handler EINA_UNUSED, const Eio_Progress *info) 83_progress_cb(void *data, Eio_File *handler EINA_UNUSED, const Eio_Progress *info EINA_UNUSED)
71{ 84{
72 int *number_of_listed_files = (int *)data; 85 int *number_of_listed_files = (int *)data;
73 86
74 fprintf(stderr, "Processing file:%s\n", info->source);
75 (*number_of_listed_files)++; 87 (*number_of_listed_files)++;
76} 88}
77 89
78static void 90static void
91_stat_done_cb(void *data, Eio_File *handler EINA_UNUSED, const Eina_Stat *stat)
92{
93 unsigned int rights;
94 Eina_Bool *is_dir = (Eina_Bool *)data;
95 fail_if(eio_file_is_dir(stat) != *is_dir);
96 fail_if(eio_file_is_lnk(stat));
97 rights = stat->mode & (S_IRWXU | S_IRWXG | S_IRWXO);
98 fail_if(rights != default_rights);
99 ecore_main_loop_quit();
100}
101
102static void
79_done_cb(void *data, Eio_File *handler EINA_UNUSED) 103_done_cb(void *data, Eio_File *handler EINA_UNUSED)
80{ 104{
81 int *number_of_listed_files = (int *)data; 105 int *number_of_listed_files = (int *)data;
@@ -117,18 +141,6 @@ Eina_Tmpstr*
117create_test_dirs(Eina_Tmpstr *test_dirname) 141create_test_dirs(Eina_Tmpstr *test_dirname)
118{ 142{
119 int i, fd; 143 int i, fd;
120 const char *good_dirs[] =
121 {
122 "eio_file_ls_simple_dir",
123 "b."
124 };
125 const char *files[] =
126 {
127 ".hidden_file",
128 "~$b@:-*$a!{}",
129 "$b$a",
130 "normal_file"
131 };
132 int count = sizeof(good_dirs) / sizeof(const char *); 144 int count = sizeof(good_dirs) / sizeof(const char *);
133 fail_if(test_dirname == NULL); 145 fail_if(test_dirname == NULL);
134 146
@@ -162,6 +174,7 @@ create_test_dirs(Eina_Tmpstr *test_dirname)
162START_TEST(eio_file_test_ls) 174START_TEST(eio_file_test_ls)
163{ 175{
164 int number_of_listed_files = 0, ret; 176 int number_of_listed_files = 0, ret;
177 const char *new_dir = "new_dir";
165 178
166 ret = ecore_init(); 179 ret = ecore_init();
167 fail_if(ret < 1); 180 fail_if(ret < 1);
@@ -172,6 +185,8 @@ START_TEST(eio_file_test_ls)
172 185
173 Eina_Tmpstr *test_dirname = get_eio_test_file_tmp_dir(); 186 Eina_Tmpstr *test_dirname = get_eio_test_file_tmp_dir();
174 Eina_Tmpstr *nested_dirname = create_test_dirs(test_dirname); 187 Eina_Tmpstr *nested_dirname = create_test_dirs(test_dirname);
188 Eina_Tmpstr *nested_filename = get_full_path(test_dirname, files[3]);
189 Eina_Tmpstr *new_dirname = get_full_path(test_dirname, new_dir);
175 190
176 eio_file_ls(test_dirname, _filter_cb, _main_cb, _done_cb, _error_cb, 191 eio_file_ls(test_dirname, _filter_cb, _main_cb, _done_cb, _error_cb,
177 &number_of_listed_files); 192 &number_of_listed_files);
@@ -203,6 +218,14 @@ START_TEST(eio_file_test_ls)
203 fail_if(number_of_listed_files != 0); //check asynchronous 218 fail_if(number_of_listed_files != 0); //check asynchronous
204 ecore_main_loop_begin(); 219 ecore_main_loop_begin();
205 220
221 test_count = 1;
222 eio_file_unlink(nested_filename, _done_cb, _error_cb, &test_count);
223 ecore_main_loop_begin();
224
225 test_count = 1;
226 eio_file_mkdir(new_dirname, default_rights, _done_cb, _error_cb, &test_count);
227 ecore_main_loop_begin();
228
206 number_of_listed_files = 0; 229 number_of_listed_files = 0;
207 eio_dir_unlink(nested_dirname, _delete_filter_cb, _progress_cb, _done_cb, 230 eio_dir_unlink(nested_dirname, _delete_filter_cb, _progress_cb, _done_cb,
208 _error_cb, &number_of_listed_files); 231 _error_cb, &number_of_listed_files);
@@ -213,12 +236,128 @@ START_TEST(eio_file_test_ls)
213 number_of_listed_files = 0; 236 number_of_listed_files = 0;
214 eio_dir_unlink(test_dirname, _delete_filter_cb, _progress_cb, _done_cb, 237 eio_dir_unlink(test_dirname, _delete_filter_cb, _progress_cb, _done_cb,
215 _error_cb, &number_of_listed_files); 238 _error_cb, &number_of_listed_files);
216 test_count = 6; // 4 internal files + 1 dir + 1 test_dir 239 test_count = 6; // 3 internal files + 2 dir + 1 test_dir
240 fail_if(number_of_listed_files != 0); // check asynchronous
241 ecore_main_loop_begin();
242
243 eina_tmpstr_del(nested_dirname);
244 eina_tmpstr_del(test_dirname);
245 eina_tmpstr_del(nested_filename);
246 eina_tmpstr_del(new_dirname);
247 eina_shutdown();
248 eio_shutdown();
249 ecore_shutdown();
250}
251END_TEST
252
253START_TEST(eio_file_test_file)
254{
255 int number_of_listed_files = 0, ret;
256 Eina_Bool is_dir;
257 const char * new_file = "new_file";
258
259 ret = ecore_init();
260 fail_if(ret < 1);
261 ret = eio_init();
262 fail_if(ret < 1);
263 ret = eina_init();
264 fail_if(ret < 1);
265 ret = ecore_file_init();
266 fail_if(ret < 1);
267
268
269 Eina_Tmpstr *test_dirname = get_eio_test_file_tmp_dir();
270 Eina_Tmpstr *nested_dirname = create_test_dirs(test_dirname);
271 Eina_Tmpstr *nested_filename = get_full_path(test_dirname, files[3]);
272 Eina_Tmpstr *new_filename = get_full_path(nested_dirname, new_file);
273 Eina_Tmpstr *new_dirname = get_full_path(test_dirname, new_file);
274
275 is_dir = EINA_TRUE;
276 eio_file_direct_stat(nested_dirname, _stat_done_cb, _error_cb, &is_dir);
277 ecore_main_loop_begin();
278
279 test_count = 1;
280 default_rights = 0766;
281 eio_file_chmod(nested_filename, default_rights, _done_cb, _error_cb, &test_count);
282 ecore_main_loop_begin();
283
284 is_dir = EINA_FALSE;
285 eio_file_direct_stat(nested_filename, _stat_done_cb, _error_cb, &is_dir);
286 ecore_main_loop_begin();
287
288 test_count = 1;
289 eio_file_move(nested_filename, new_filename, _progress_cb, _done_cb,
290 _error_cb, &test_count);
291 ecore_main_loop_begin();
292
293 fail_if(ecore_file_exists(nested_filename));
294 eio_file_ls(nested_dirname, _filter_cb, _main_cb, _done_cb, _error_cb,
295 &number_of_listed_files);
296 test_count = 4;
297 fail_if(number_of_listed_files != 0); //check asynchronous
298 ecore_main_loop_begin();
299
300 number_of_listed_files = 0;
301 eio_file_ls(test_dirname, _filter_cb, _main_cb, _done_cb, _error_cb,
302 &number_of_listed_files);
303 test_count = 4; //2 dirs + 2 normal files
304 fail_if(number_of_listed_files != 0); //check asynchronous
305 ecore_main_loop_begin();
306
307 test_count = 1;
308 eio_file_copy(new_filename, nested_filename, _progress_cb, _done_cb,
309 _error_cb, &test_count);
310 ecore_main_loop_begin();
311
312 number_of_listed_files = 0;
313 eio_file_ls(nested_dirname, _filter_cb, _main_cb, _done_cb, _error_cb,
314 &number_of_listed_files);
315 test_count = 4; // 3 normal files + 1 new file
316 fail_if(number_of_listed_files != 0); //check asynchronous
317 ecore_main_loop_begin();
318
319 number_of_listed_files = 0;
320 eio_file_ls(test_dirname, _filter_cb, _main_cb, _done_cb, _error_cb,
321 &number_of_listed_files);
322 test_count = 5;
323 fail_if(number_of_listed_files != 0); //check asynchronous
324 ecore_main_loop_begin();
325
326 number_of_listed_files = 0;
327 eio_dir_move(nested_dirname, new_dirname, _direct_filter_cb, _progress_cb,
328 _done_cb, _error_cb, &number_of_listed_files);
329 test_count = 1;
330 fail_if(number_of_listed_files != 0); //check asynchronous
331 ecore_main_loop_begin();
332 fail_if(ecore_file_is_dir(nested_dirname));
333 fail_if(!ecore_file_is_dir(new_dirname));
334
335 number_of_listed_files = 0;
336 eio_dir_copy(new_dirname, nested_dirname, _direct_filter_cb, _progress_cb,
337 _done_cb, _error_cb, &number_of_listed_files);
338 test_count = 6;
339 fail_if(number_of_listed_files != 0); //check asynchronous
340 ecore_main_loop_begin();
341 fail_if(!ecore_file_is_dir(nested_dirname));
342 fail_if(!ecore_file_is_dir(new_dirname));
343
344 number_of_listed_files = 0;
345 eio_dir_unlink(nested_dirname, _delete_filter_cb, _progress_cb, _done_cb,
346 _error_cb, &number_of_listed_files);
347 test_count = 5; // 4 internal files + 1 nested_dir
217 fail_if(number_of_listed_files != 0); // check asynchronous 348 fail_if(number_of_listed_files != 0); // check asynchronous
218 ecore_main_loop_begin(); 349 ecore_main_loop_begin();
350 fail_if(ecore_file_is_dir(nested_dirname));
351
352 fail_if(!ecore_file_recursive_rm(test_dirname));
353 fail_if(ecore_file_is_dir(new_dirname));
219 354
220 eina_tmpstr_del(nested_dirname); 355 eina_tmpstr_del(nested_dirname);
221 eina_tmpstr_del(test_dirname); 356 eina_tmpstr_del(test_dirname);
357 eina_tmpstr_del(nested_filename);
358 eina_tmpstr_del(new_filename);
359 eina_tmpstr_del(new_dirname);
360 ecore_file_shutdown();
222 eina_shutdown(); 361 eina_shutdown();
223 eio_shutdown(); 362 eio_shutdown();
224 ecore_shutdown(); 363 ecore_shutdown();
@@ -229,5 +368,6 @@ void
229eio_test_file(TCase *tc) 368eio_test_file(TCase *tc)
230{ 369{
231 tcase_add_test(tc, eio_file_test_ls); 370 tcase_add_test(tc, eio_file_test_ls);
371 tcase_add_test(tc, eio_file_test_file);
232} 372}
233 373