summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkabeer khan <kabeer.khan@samsung.com>2014-11-18 10:26:43 +0100
committerStefan Schmidt <s.schmidt@samsung.com>2014-11-18 10:51:42 +0100
commit9f65759387d4d8d8bb96bb997b40ac8f04214b63 (patch)
tree895a04aab433bcd27cd512af11b82b126dbc48e7
parent1608d3039076a0c6072c079a6b6ea8368b4f5b4a (diff)
Ecore File : Added test suite for Ecore File module
Summary: Added 3 test cases. First to test initialise, shutdown Ecore_File module. Second to test all file operation functions defined in the module. Third to test ecore file monitor Signed-off-by: kabeer khan <kabeer.khan@samsung.com> Reviewers: devilhorns, stefan_schmidt Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D1662
-rw-r--r--src/Makefile_Ecore.am1
-rw-r--r--src/tests/ecore/ecore_suite.c1
-rw-r--r--src/tests/ecore/ecore_suite.h1
-rw-r--r--src/tests/ecore/ecore_test_ecore_file.c280
4 files changed, 283 insertions, 0 deletions
diff --git a/src/Makefile_Ecore.am b/src/Makefile_Ecore.am
index 67452c63eb..94d472cc52 100644
--- a/src/Makefile_Ecore.am
+++ b/src/Makefile_Ecore.am
@@ -178,6 +178,7 @@ tests/ecore/ecore_test_ecore_evas.c \
178tests/ecore/ecore_test_animator.c \ 178tests/ecore/ecore_test_animator.c \
179tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c \ 179tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c \
180tests/ecore/ecore_test_ecore_input.c \ 180tests/ecore/ecore_test_ecore_input.c \
181tests/ecore/ecore_test_ecore_file.c \
181tests/ecore/ecore_suite.h 182tests/ecore/ecore_suite.h
182 183
183tests_ecore_ecore_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \ 184tests_ecore_ecore_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
diff --git a/src/tests/ecore/ecore_suite.c b/src/tests/ecore/ecore_suite.c
index 44a3e62f46..8fbc4b7147 100644
--- a/src/tests/ecore/ecore_suite.c
+++ b/src/tests/ecore/ecore_suite.c
@@ -40,6 +40,7 @@ static const Ecore_Test_Case etc[] = {
40 { "Ecore_Fb", ecore_test_ecore_fb }, 40 { "Ecore_Fb", ecore_test_ecore_fb },
41#endif 41#endif
42 { "Ecore_Input", ecore_test_ecore_input }, 42 { "Ecore_Input", ecore_test_ecore_input },
43 { "Ecore_File", ecore_test_ecore_file },
43 { NULL, NULL } 44 { NULL, NULL }
44}; 45};
45 46
diff --git a/src/tests/ecore/ecore_suite.h b/src/tests/ecore/ecore_suite.h
index 803f8f7150..11e101de23 100644
--- a/src/tests/ecore/ecore_suite.h
+++ b/src/tests/ecore/ecore_suite.h
@@ -17,5 +17,6 @@ void ecore_test_ecore_wayland(TCase *tc);
17void ecore_test_ecore_drm(TCase *tc); 17void ecore_test_ecore_drm(TCase *tc);
18void ecore_test_ecore_fb(TCase *tc); 18void ecore_test_ecore_fb(TCase *tc);
19void ecore_test_ecore_input(TCase *tc); 19void ecore_test_ecore_input(TCase *tc);
20void ecore_test_ecore_file(TCase *tc);
20 21
21#endif /* _ECORE_SUITE_H */ 22#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
index 0000000000..d850e1c030
--- /dev/null
+++ b/src/tests/ecore/ecore_test_ecore_file.c
@@ -0,0 +1,280 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <stdio.h>
6#include <unistd.h>
7#include <string.h>
8
9#include <Ecore_File.h>
10#include <Ecore.h>
11#include <Eina.h>
12
13#include "ecore_suite.h"
14
15#define MAXSIZE 256
16
17void
18_writeToFile(const char *filePath, char *text)
19{
20 FILE *f = fopen(filePath, "r+");
21 if (f == NULL)
22 f = fopen(filePath, "w");
23 fail_if(f == NULL);
24 fprintf(f, "%s\n", text);
25 fclose(f);
26}
27
28Eina_Tmpstr*
29get_tmp_dir()
30{
31 Eina_Tmpstr *tmp_dir;
32
33 Eina_Bool created = eina_file_mkdtemp("EcoreFileTestXXXXXX", &tmp_dir);
34
35 if (!created)
36 {
37 return NULL;
38 }
39
40 return tmp_dir;
41}
42
43Eina_Tmpstr*
44get_tmp_file()
45{
46 Eina_Tmpstr *tmp_file;
47
48 Eina_Bool created = eina_file_mkstemp("EcoreFileTestXXXXXX", &tmp_file);
49
50 if (!created)
51 {
52 return NULL;
53 }
54
55 return tmp_file;
56}
57
58static void
59file_monitor_cb(void *data EINA_UNUSED, Ecore_File_Monitor *em EINA_UNUSED,
60 Ecore_File_Event event, const char *path)
61{
62 switch (event)
63 {
64 case ECORE_FILE_EVENT_NONE:
65 case ECORE_FILE_EVENT_CREATED_FILE:
66 fprintf(stderr, "File created in %s", path);
67 break;
68 case ECORE_FILE_EVENT_DELETED_FILE:
69 fprintf(stderr, "File deleted in %s", path);
70 break;
71 case ECORE_FILE_EVENT_MODIFIED:
72 fprintf(stderr, "File modified in %s", path);
73 break;
74 case ECORE_FILE_EVENT_CLOSED:
75 fprintf(stderr, "File closed in %s", path);
76 break;
77 case ECORE_FILE_EVENT_DELETED_DIRECTORY:
78 fprintf(stderr, "Directory deleted in %s", path);
79 break;
80 case ECORE_FILE_EVENT_CREATED_DIRECTORY:
81 fprintf(stderr, "Directory created in %s", path);
82 break;
83 case ECORE_FILE_EVENT_DELETED_SELF:
84 fprintf(stderr, "Path %s deleted", path);
85 break;
86 }
87}
88
89START_TEST(ecore_test_ecore_file_init)
90{
91 int ret;
92
93 ret = ecore_file_init();
94 fail_if(ret != 1);
95
96 ret = ecore_file_shutdown();
97 fail_if(ret != 0);
98}
99END_TEST
100
101START_TEST(ecore_test_ecore_file_operations)
102{
103 const char* dirs[] = {"b", "b/c", "b/c/d", "d", 0};
104 const char *src_dir, *src_file, *dest_file;
105 const char *tmpdir = NULL;
106 char *random_text = "This is random test String";
107 char dir[MAXSIZE] = {'\0'};
108 unsigned int ret;
109 Eina_Bool res;
110 Eina_List *list;
111
112#ifndef HAVE_EVIL
113#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
114 if (getuid() == geteuid())
115#endif
116 {
117 tmpdir = getenv("TMPDIR");
118 if (!tmpdir) tmpdir = getenv("XDG_RUNTIME_DIR");
119 }
120 if (!tmpdir) tmpdir = "/tmp";
121#else
122 tmpdir = (char *)evil_tmpdir_get();
123#endif /* ! HAVE_EVIL */
124
125 ret = ecore_file_init();
126 fail_if(ret != 1);
127
128 src_dir = get_tmp_dir();
129 fail_if(!src_dir);
130
131 src_file = get_tmp_file();
132 fail_if(!src_file);
133
134 res = ecore_file_exists(src_file);
135 fail_if(res != EINA_TRUE);
136 res = ecore_file_is_dir(src_file);
137 fail_if(res != EINA_FALSE);
138 res = ecore_file_remove(src_file);
139 fail_if(res != EINA_TRUE);
140
141 res = ecore_file_is_dir(src_dir);
142 fail_if(res != EINA_TRUE);
143 ret = ecore_file_dir_is_empty(src_dir);
144 fail_if(ret != 1);
145 res = ecore_file_mkdir(src_dir);
146 fail_if(res != EINA_FALSE);
147 res = ecore_file_remove(src_dir);
148 fail_if(res != EINA_TRUE);
149
150 src_dir = get_tmp_dir();
151 fail_if(!src_dir);
152 ret = ecore_file_mksubdirs(src_dir, dirs);
153 fail_if(ret != 4);
154 list = ecore_file_ls(src_dir);
155 fail_if(!list);
156 fail_if(eina_list_count(list) != 2);
157 res = ecore_file_recursive_rm(src_dir);
158 fail_if(res != EINA_TRUE);
159
160 src_dir = get_tmp_dir();
161 fail_if(!src_dir);
162 strcat(dir, src_dir);
163 strcat(dir, "/");
164 strcat(dir, dirs[2]);
165 res = ecore_file_mkpath(dir);
166 fail_if(res != EINA_TRUE);
167 res = ecore_file_recursive_rm(src_dir);
168 fail_if(res != EINA_TRUE);
169
170 src_file = get_tmp_file();
171 fail_if(!src_file);
172 _writeToFile(src_file, random_text);
173
174 ret = ecore_file_size(src_file);
175 fail_if(ret != strlen(random_text)+1);
176 ret = ecore_file_is_dir(src_file);
177 fail_if(ret != EINA_FALSE);
178
179 dest_file = get_tmp_file();
180 fail_if(!dest_file);
181 res = ecore_file_cp(src_file, dest_file);
182 fail_if(res != EINA_TRUE);
183 res = ecore_file_exists(dest_file);
184 fail_if(res != EINA_TRUE);
185 fail_if(ecore_file_size(src_file) != ecore_file_size(dest_file));
186 res = ecore_file_remove(dest_file);
187 fail_if(res != EINA_TRUE);
188
189 res = ecore_file_symlink(src_file, dest_file);
190 fail_if(res != EINA_TRUE);
191 ck_assert_str_eq(ecore_file_readlink(dest_file), src_file);
192 ck_assert_str_eq(ecore_file_realpath(dest_file), src_file);
193 res = ecore_file_unlink(dest_file);
194 fail_if(res != EINA_TRUE);
195
196 dest_file = get_tmp_file();
197 fail_if(!dest_file);
198 res = ecore_file_mv(src_file, dest_file);
199 fail_if(res != EINA_TRUE);
200 res = ecore_file_exists(dest_file);
201 fail_if(res != EINA_TRUE);
202 res = ecore_file_exists(src_file);
203 fail_if(res != EINA_FALSE);
204
205 ck_assert_str_eq(ecore_file_dir_get(dest_file), tmpdir);
206 ck_assert_str_eq(ecore_file_realpath(dest_file), dest_file);
207 fail_if(ecore_file_mod_time(dest_file) == 0);
208 fail_if(ecore_file_can_read(dest_file) != EINA_TRUE);
209 fail_if(ecore_file_can_write(dest_file) != EINA_TRUE);
210 fail_if(ecore_file_can_exec(dest_file) != EINA_FALSE);
211 res = ecore_file_remove(dest_file);
212 fail_if(res != EINA_TRUE);
213
214 ret = ecore_file_shutdown();
215 fail_if(ret != 0);
216
217}
218END_TEST
219
220START_TEST(ecore_test_ecore_file_monitor)
221{
222 Ecore_File_Monitor *mon;
223 const char *src_dir;
224 const char *file = "EcoreFileDest";
225 const char *sub_dir[] = {"subdir1", 0};
226 char dir_name[MAXSIZE] = {'\0'};
227 char file_name[MAXSIZE] = {'\0'};
228 char *random_text = "This is random test String";
229 char *realp;
230 Eina_Bool res;
231 int ret;
232
233 ret = ecore_file_init();
234 fail_if(ret != 1);
235
236 src_dir = get_tmp_dir();
237 fail_if(!src_dir);
238
239 realp = ecore_file_realpath(src_dir);
240 fail_if(!realp);
241 mon = ecore_file_monitor_add(realp, file_monitor_cb, NULL);
242 fail_if(mon == NULL);
243
244 strcat(file_name, src_dir);
245 strcat(file_name, "/");
246 strcat(file_name, file);
247 _writeToFile(file_name, random_text);
248 _writeToFile(file_name, random_text);
249
250 ck_assert_str_eq(ecore_file_monitor_path_get(mon), realp);
251
252 ret = ecore_file_mksubdirs(src_dir, sub_dir);
253 fail_if(ret != 1);
254
255 res = ecore_file_remove(file_name);
256 fail_if(res != EINA_TRUE);
257
258 strcat(dir_name, src_dir);
259 strcat(dir_name, "/");
260 strcat(dir_name, sub_dir[0]);
261 res = ecore_file_rmdir(dir_name);
262 fail_if(res != EINA_TRUE);
263
264 res = ecore_file_recursive_rm(src_dir);
265 fail_if(res != EINA_TRUE);
266
267 ecore_file_monitor_del(mon);
268
269 ret = ecore_file_shutdown();
270 fail_if(ret != 0);
271
272}
273END_TEST
274
275void ecore_test_ecore_file(TCase *tc)
276{
277 tcase_add_test(tc, ecore_test_ecore_file_init);
278 tcase_add_test(tc, ecore_test_ecore_file_operations);
279 tcase_add_test(tc, ecore_test_ecore_file_monitor);
280}