Ecore File : Added test suite for Ecore File module
authorkabeer khan <kabeer.khan@samsung.com>
Wed, 29 Oct 2014 13:01:59 +0000 (09:01 -0400)
committerChris Michael <cp.michael@samsung.com>
Wed, 29 Oct 2014 13:01:59 +0000 (09:01 -0400)
Summary:
Added 2 test cases. First to test initialise, shutdown Ecore_File module and second to test all file operation functions defined in the module.

Signed-off-by: kabeer khan <kabeer.khan@samsung.com>
Reviewers: devilhorns

Subscribers: cedric

Differential Revision: https://phab.enlightenment.org/D1600

src/Makefile_Ecore.am
src/tests/ecore/ecore_suite.c
src/tests/ecore/ecore_suite.h
src/tests/ecore/ecore_test_ecore_file.c [new file with mode: 0644]

index b562d0b8176e6826e8dbcc4ddfb5bd68a6a98d54..4cf1cbf236775c30764ec4e35f89f6414ac0c64e 100644 (file)
@@ -177,6 +177,7 @@ tests/ecore/ecore_test_timer.c \
 tests/ecore/ecore_test_ecore_evas.c \
 tests/ecore/ecore_test_animator.c \
 tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c \
+tests/ecore/ecore_test_ecore_file.c \
 tests/ecore/ecore_test_ecore_input.c \
 tests/ecore/ecore_suite.h
 
index 44a3e62f46820be4d4cf1945dd7d9ecf68fb4554..ad3635d49726ff3c4f0b8ceeabc39bdb1f25d006 100644 (file)
@@ -30,6 +30,7 @@ static const Ecore_Test_Case etc[] = {
   { "Ecore_Evas", ecore_test_ecore_evas },
   { "Ecore_Animators", ecore_test_animator },
   { "Ecore_Test_Ccore_Thread_Eina_Thread_Queue", ecore_test_ecore_thread_eina_thread_queue },
+  { "Ecore_File", ecore_test_ecore_file },
 #if HAVE_ECORE_WAYLAND
   { "Ecore_Wayland", ecore_test_ecore_wayland },
 #endif
index 803f8f71500aee21ca4e1d40ce9831d3ad29e6d5..571e85dd4f5197ed1cf8177d0b6798d45eef0c5d 100644 (file)
@@ -16,6 +16,7 @@ void ecore_test_ecore_thread_eina_thread_queue(TCase *tc);
 void ecore_test_ecore_wayland(TCase *tc);
 void ecore_test_ecore_drm(TCase *tc);
 void ecore_test_ecore_fb(TCase *tc);
+void ecore_test_ecore_file(TCase *tc);
 void ecore_test_ecore_input(TCase *tc);
 
 #endif /* _ECORE_SUITE_H */
diff --git a/src/tests/ecore/ecore_test_ecore_file.c b/src/tests/ecore/ecore_test_ecore_file.c
new file mode 100644 (file)
index 0000000..ede09c1
--- /dev/null
@@ -0,0 +1,140 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <Ecore_File.h>
+#include <Ecore.h>
+#include <Eina.h>
+
+#include "ecore_suite.h"
+
+#define MAXSIZE 256
+
+void
+_writeToFile(char *filePath, char *text)
+{
+   FILE *f = fopen(filePath, "w");
+   fail_if(!f);
+   fprintf(f, "%s\n", text);
+   fclose(f);
+} 
+START_TEST(ecore_test_ecore_file_init)
+{
+   int ret;
+
+   ret = ecore_file_init();
+   fail_if(ret != 1);
+
+   ret = ecore_file_shutdown();
+   fail_if(ret != 0);
+}
+END_TEST
+
+START_TEST(ecore_test_ecore_file_operations)
+{
+   const char *srcDir = "/tmp/rootDir";
+   const char* dirs[] = {"b", "b/c", "b/c/d", "d"}; 
+   char *srcFile = "/tmp/EcoreFileSrc.txt";
+   const char *destFile = "/tmp/EcoreFileDest.txt";
+   char *randomText = "This is random test String";
+   char dir[MAXSIZE] = {'\0'};
+   int ret;
+   Eina_Bool res;
+   Eina_List *list;
+
+   char unqFile[MAXSIZE], unqDir[MAXSIZE];
+   char *ptr;
+
+   ret = ecore_file_init();
+   fail_if(ret != 1);
+   
+   ptr = tmpnam(unqFile);
+   fail_if(!ptr);
+
+   ptr = tmpnam(unqDir);
+   fail_if(!ptr);
+
+   res = ecore_file_exists(unqFile);
+   fail_if(res != EINA_FALSE);
+
+   res = ecore_file_is_dir(unqFile);
+   fail_if(res != EINA_FALSE);
+   res = ecore_file_is_dir(unqDir);
+   fail_if(res != EINA_FALSE);
+   
+   res = ecore_file_mkdir(srcDir);
+   fail_if(res != EINA_TRUE);
+   res = ecore_file_is_dir(srcDir);
+   fail_if(res != EINA_TRUE);
+   ret = ecore_file_dir_is_empty(srcDir);
+   fail_if(res != 1);
+   res = ecore_file_remove(srcDir);
+   fail_if(res != EINA_TRUE);
+
+   ret = ecore_file_mksubdirs(srcDir, dirs);
+   fail_if(ret != 4);
+   list = ecore_file_ls(srcDir);
+   fail_if(!list);
+   fail_if(eina_list_count(list) != 2);
+   res = ecore_file_recursive_rm(srcDir);
+   fail_if(res != EINA_TRUE);
+
+   strcat(dir, srcDir);
+   strcat(dir, "/");
+   strcat(dir, dirs[2]);
+   res = ecore_file_mkpath(dir);
+   fail_if(res != EINA_TRUE);
+   res = ecore_file_recursive_rm(srcDir);
+   fail_if(res != EINA_TRUE);
+
+   _writeToFile(srcFile, randomText);
+
+   ret = ecore_file_size(srcFile);
+   fail_if(ret != strlen(randomText)+1);
+
+   res = ecore_file_cp(srcFile, destFile);
+   fail_if(res != EINA_TRUE);
+   res = ecore_file_exists(destFile);
+   fail_if(res != EINA_TRUE);
+   fail_if(ecore_file_size(srcFile) != ecore_file_size(destFile));
+   res = ecore_file_remove(destFile);
+   fail_if(res != EINA_TRUE);
+  
+   res = ecore_file_symlink(srcFile, destFile);
+   fail_if(res != EINA_TRUE);
+   ck_assert_str_eq(ecore_file_readlink(destFile), srcFile);
+   res = ecore_file_unlink(destFile);
+   fail_if(res != EINA_TRUE);
+
+   res = ecore_file_mv(srcFile, destFile);
+   fail_if(res != EINA_TRUE);
+   res = ecore_file_exists(destFile);
+   fail_if(res != EINA_TRUE);
+   res = ecore_file_exists(srcFile);
+   fail_if(res != EINA_FALSE);
+
+   ck_assert_str_eq(ecore_file_file_get(destFile), "EcoreFileDest.txt");
+   ck_assert_str_eq(ecore_file_dir_get(destFile), "/tmp");
+   ck_assert_str_eq(ecore_file_realpath(destFile), destFile);
+   fail_if(ecore_file_mod_time(destFile) == 0);
+   fail_if(ecore_file_can_read(destFile) != EINA_TRUE);
+   fail_if(ecore_file_can_write(destFile) != EINA_TRUE);
+   fail_if(ecore_file_can_exec(destFile) != EINA_FALSE);
+   res = ecore_file_remove(destFile);
+   fail_if(res != EINA_TRUE);
+   ret = ecore_file_shutdown();
+   fail_if(ret != 0);
+
+}
+END_TEST
+
+void ecore_test_ecore_file(TCase *tc)
+{
+   tcase_add_test(tc, ecore_test_ecore_file_init);
+   tcase_add_test(tc, ecore_test_ecore_file_operations);
+}