summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiep Ha <thiepha@gmail.com>2015-04-28 11:19:15 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-04-28 11:37:11 +0200
commit5c4eea6fffd4aef3d98f713e4f1de9242d0e1a02 (patch)
tree81b9afc6ea8b0f629ede2508602d57bb32d3a894
parente8525256e716e06d44a3ae1902cec618c5729772 (diff)
ecore_file: add more tests for ecore_file.
Summary: This patch adds more tests for ecore_file. It helps examine unchecked cases. Reviewers: Hermet, cedric Reviewed By: cedric Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2430 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
-rw-r--r--src/tests/ecore/ecore_test_ecore_file.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/tests/ecore/ecore_test_ecore_file.c b/src/tests/ecore/ecore_test_ecore_file.c
index c7acd9f094..d36131dcf3 100644
--- a/src/tests/ecore/ecore_test_ecore_file.c
+++ b/src/tests/ecore/ecore_test_ecore_file.c
@@ -127,7 +127,9 @@ END_TEST
127START_TEST(ecore_test_ecore_file_operations) 127START_TEST(ecore_test_ecore_file_operations)
128{ 128{
129 const char* dirs[] = {"b", "b/c", "b/c/d", "d", 0}; 129 const char* dirs[] = {"b", "b/c", "b/c/d", "d", 0};
130 char *dirs2[] = {"a2", "b2", "c2", 0};
130 const char *src_dir, *src_file, *dest_file; 131 const char *src_dir, *src_file, *dest_file;
132 const char *not_exist_file;
131 const char *tmpdir = NULL; 133 const char *tmpdir = NULL;
132 char *dup_dir, *path; 134 char *dup_dir, *path;
133 char *random_text = "This is random test String"; 135 char *random_text = "This is random test String";
@@ -137,6 +139,7 @@ START_TEST(ecore_test_ecore_file_operations)
137 char dir[MAXSIZE] = {'\0'}; 139 char dir[MAXSIZE] = {'\0'};
138 unsigned int ret; 140 unsigned int ret;
139 int fd; 141 int fd;
142 int i;
140 Eina_Bool res; 143 Eina_Bool res;
141 Eina_List *list, *l; 144 Eina_List *list, *l;
142 145
@@ -295,6 +298,92 @@ START_TEST(ecore_test_ecore_file_operations)
295 ret = setenv("PATH", src_dir, 1); 298 ret = setenv("PATH", src_dir, 1);
296 fail_if(ret != 0); 299 fail_if(ret != 0);
297 300
301 src_dir = get_tmp_dir();
302 fail_if(!src_dir);
303 strcpy(dir, src_dir);
304 strcat(dir, "/");
305 strcat(dir, dirs[0]);
306 fail_if(ecore_file_mkdir(dir) != EINA_TRUE);
307
308 fail_if(ecore_file_mkdirs(NULL) != -1);
309 for (i = 0; i < 3; i++)
310 {
311 char tmp[PATH_MAX];
312 strcpy(tmp, src_dir);
313 strcat(tmp, "/");
314 strcat(tmp, dirs2[i]);
315 dirs2[i] = strdup(tmp);
316 }
317 fail_if(ecore_file_mkdirs((const char **)dirs2) != 3);
318 for (i = 0; i < 3; i++)
319 free(dirs2[i]);
320
321 fail_if(ecore_file_mksubdirs(src_dir, NULL) != -1);
322 fail_if(ecore_file_mksubdirs(NULL, dirs) != -1);
323 fail_if(ecore_file_mksubdirs("", dirs) != -1);
324 fail_if(ecore_file_mksubdirs(src_file, dirs) != 0);
325
326 src_dir = get_tmp_dir();
327 fail_if(!src_dir);
328 fail_if(ecore_file_rmdir(src_dir) != EINA_TRUE);
329 fail_if(ecore_file_dir_is_empty(src_dir) != -1);
330 fail_if(ecore_file_ls(src_dir) != NULL);
331
332 not_exist_file = get_tmp_file();
333 fail_if(!not_exist_file);
334 fail_if(ecore_file_remove(not_exist_file) != EINA_TRUE);
335 fail_if(ecore_file_exists(not_exist_file) != EINA_FALSE);
336 fail_if(ecore_file_mod_time(not_exist_file) != 0);
337 fail_if(ecore_file_size(not_exist_file) != 0);
338
339 ck_assert_str_eq(ecore_file_realpath(NULL), "");
340 ck_assert_str_eq(ecore_file_realpath(not_exist_file), "");
341
342 src_file = get_tmp_file();
343 fail_if(!src_file);
344 fail_if(ecore_file_remove(src_file) != EINA_TRUE);
345 fd = open(src_file, O_RDWR|O_CREAT, 0400);
346 fail_if(fd < 0);
347 fail_if(close(fd) != 0);
348 fail_if(ecore_file_can_read(src_file) != EINA_TRUE);
349 fail_if(ecore_file_can_write(src_file) != EINA_FALSE);
350 fail_if(ecore_file_can_exec(src_file) != EINA_FALSE);
351 fail_if(ecore_file_cp(src_file, src_file) != EINA_FALSE);
352
353 src_file = get_tmp_file();
354 fail_if(!src_file);
355 fail_if(ecore_file_remove(src_file) != EINA_TRUE);
356 fd = open(src_file, O_RDWR|O_CREAT, 0200);
357 fail_if(fd < 0);
358 fail_if(close(fd) != 0);
359 fail_if(ecore_file_can_read(src_file) != EINA_FALSE);
360 fail_if(ecore_file_can_write(src_file) != EINA_TRUE);
361 fail_if(ecore_file_can_exec(src_file) != EINA_FALSE);
362
363 src_file = get_tmp_file();
364 fail_if(!src_file);
365 fail_if(ecore_file_remove(src_file) != EINA_TRUE);
366 fd = open(src_file, O_RDWR|O_CREAT, 0100);
367 fail_if(fd < 0);
368 fail_if(close(fd) != 0);
369 fail_if(ecore_file_can_read(src_file) != EINA_FALSE);
370 fail_if(ecore_file_can_write(src_file) != EINA_FALSE);
371 fail_if(ecore_file_can_exec(src_file) != EINA_TRUE);
372
373 fail_if(ecore_file_unlink(not_exist_file) != EINA_FALSE);
374 fail_if(ecore_file_remove(not_exist_file) != EINA_FALSE);
375 fail_if(ecore_file_cp(not_exist_file, "test_file") != EINA_FALSE);
376 fail_if(ecore_file_mv(not_exist_file, "test_file") != EINA_FALSE);
377
378 fail_if(ecore_file_mkpath(src_dir) != EINA_TRUE);
379 fail_if(ecore_file_mkpath(NULL) != EINA_FALSE);
380 fail_if(ecore_file_mkpaths(dirs) != 4);
381 fail_if(ecore_file_mkpaths(NULL) != -1);
382
383 fail_if(ecore_file_dir_get(NULL) != NULL);
384 fail_if(ecore_file_strip_ext(NULL) != NULL);
385 fail_if(ecore_file_escape_name(NULL) != NULL);
386
298 ret = ecore_file_shutdown(); 387 ret = ecore_file_shutdown();
299 fail_if(ret != 0); 388 fail_if(ret != 0);
300 389