summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkabeer khan <kabeer.khan@samsung.com>2014-11-03 08:16:57 -0500
committerChris Michael <cp.michael@samsung.com>2014-11-03 08:16:57 -0500
commitcb84017a3f4ae6b3c13ee9fe7c0dca04a16aa43c (patch)
tree57b22d92e337647bc00e16fd78f07509be00e658
parent61d2e8cdf624748656067fb9ea481daad94f314f (diff)
Ecore File: Added test case for Ecore File Monitor
Summary: Signed-off-by: kabeer khan <kabeer.khan@samsung.com> Reviewers: devilhorns Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D1634
-rw-r--r--src/tests/ecore/ecore_test_ecore_file.c98
1 files changed, 94 insertions, 4 deletions
diff --git a/src/tests/ecore/ecore_test_ecore_file.c b/src/tests/ecore/ecore_test_ecore_file.c
index ede09c171a..dfeb72de0d 100644
--- a/src/tests/ecore/ecore_test_ecore_file.c
+++ b/src/tests/ecore/ecore_test_ecore_file.c
@@ -17,11 +17,47 @@
17void 17void
18_writeToFile(char *filePath, char *text) 18_writeToFile(char *filePath, char *text)
19{ 19{
20 FILE *f = fopen(filePath, "w"); 20 FILE *f = fopen(filePath, "r+");
21 fail_if(!f); 21 if(f == NULL)
22 {
23 f = fopen(filePath, "w");
24 }
25 fail_if(f == NULL);
22 fprintf(f, "%s\n", text); 26 fprintf(f, "%s\n", text);
23 fclose(f); 27 fclose(f);
24} 28}
29
30static void
31file_monitor_cb(void *data EINA_UNUSED, Ecore_File_Monitor *em EINA_UNUSED,
32 Ecore_File_Event event, const char *path)
33{
34 switch (event)
35 {
36 case ECORE_FILE_EVENT_NONE:
37 case ECORE_FILE_EVENT_CREATED_FILE:
38 fprintf(stderr, "File created in %s", path);
39 break;
40 case ECORE_FILE_EVENT_DELETED_FILE:
41 fprintf(stderr, "File deleted in %s", path);
42 break;
43 case ECORE_FILE_EVENT_MODIFIED:
44 fprintf(stderr, "File modified in %s", path);
45 break;
46 case ECORE_FILE_EVENT_CLOSED:
47 fprintf(stderr, "File closed in %s", path);
48 break;
49 case ECORE_FILE_EVENT_DELETED_DIRECTORY:
50 fprintf(stderr, "Directory deleted in %s", path);
51 break;
52 case ECORE_FILE_EVENT_CREATED_DIRECTORY:
53 fprintf(stderr, "Directory created in %s", path);
54 break;
55 case ECORE_FILE_EVENT_DELETED_SELF:
56 fprintf(stderr, "Path %s deleted", path);
57 break;
58 }
59}
60
25START_TEST(ecore_test_ecore_file_init) 61START_TEST(ecore_test_ecore_file_init)
26{ 62{
27 int ret; 63 int ret;
@@ -42,7 +78,7 @@ START_TEST(ecore_test_ecore_file_operations)
42 const char *destFile = "/tmp/EcoreFileDest.txt"; 78 const char *destFile = "/tmp/EcoreFileDest.txt";
43 char *randomText = "This is random test String"; 79 char *randomText = "This is random test String";
44 char dir[MAXSIZE] = {'\0'}; 80 char dir[MAXSIZE] = {'\0'};
45 int ret; 81 unsigned int ret;
46 Eina_Bool res; 82 Eina_Bool res;
47 Eina_List *list; 83 Eina_List *list;
48 84
@@ -95,6 +131,8 @@ START_TEST(ecore_test_ecore_file_operations)
95 131
96 ret = ecore_file_size(srcFile); 132 ret = ecore_file_size(srcFile);
97 fail_if(ret != strlen(randomText)+1); 133 fail_if(ret != strlen(randomText)+1);
134 ret = ecore_file_is_dir(srcFile);
135 fail_if(ret != EINA_FALSE);
98 136
99 res = ecore_file_cp(srcFile, destFile); 137 res = ecore_file_cp(srcFile, destFile);
100 fail_if(res != EINA_TRUE); 138 fail_if(res != EINA_TRUE);
@@ -107,6 +145,7 @@ START_TEST(ecore_test_ecore_file_operations)
107 res = ecore_file_symlink(srcFile, destFile); 145 res = ecore_file_symlink(srcFile, destFile);
108 fail_if(res != EINA_TRUE); 146 fail_if(res != EINA_TRUE);
109 ck_assert_str_eq(ecore_file_readlink(destFile), srcFile); 147 ck_assert_str_eq(ecore_file_readlink(destFile), srcFile);
148 ck_assert_str_eq(ecore_file_realpath(destFile), srcFile);
110 res = ecore_file_unlink(destFile); 149 res = ecore_file_unlink(destFile);
111 fail_if(res != EINA_TRUE); 150 fail_if(res != EINA_TRUE);
112 151
@@ -133,8 +172,59 @@ START_TEST(ecore_test_ecore_file_operations)
133} 172}
134END_TEST 173END_TEST
135 174
175START_TEST(ecore_test_ecore_file_monitor)
176{
177 Ecore_File_Monitor *mon;
178 char *path = "/tmp/rootDir/";
179 char *file = "/tmp/rootDir/EcoreFileDest.txt";
180 const char *subDir[] = {"subdir"};
181 char dirName[MAXSIZE] = {'\0'};
182 char *randomText = "This is random test String";
183 char *realp;
184 Eina_Bool res;
185 int ret;
186
187 ret = ecore_file_init();
188 fail_if(ret != 1);
189
190 res = ecore_file_mkdir(path);
191 fail_if(res != EINA_TRUE);
192
193 realp = ecore_file_realpath(path);
194 fail_if(!realp);
195 mon = ecore_file_monitor_add(realp, file_monitor_cb, NULL);
196 fail_if(mon == NULL);
197
198 _writeToFile(file, randomText);
199 _writeToFile(file, randomText);
200
201 ck_assert_str_eq(ecore_file_monitor_path_get(mon), realp);
202
203 ret = ecore_file_mksubdirs(path, subDir);
204 fail_if(ret != 1);
205
206 res = ecore_file_remove(file);
207 fail_if(res != EINA_TRUE);
208
209 strcat(dirName, path);
210 strcat(dirName, subDir[0]);
211 res = ecore_file_rmdir(dirName);
212 fail_if(res != EINA_TRUE);
213
214 res = ecore_file_recursive_rm(path);
215 fail_if(res != EINA_TRUE);
216
217 ecore_file_monitor_del(mon);
218
219 ret = ecore_file_shutdown();
220 fail_if(ret != 0);
221
222}
223END_TEST
224
136void ecore_test_ecore_file(TCase *tc) 225void ecore_test_ecore_file(TCase *tc)
137{ 226{
138 tcase_add_test(tc, ecore_test_ecore_file_init); 227 tcase_add_test(tc, ecore_test_ecore_file_init);
139 tcase_add_test(tc, ecore_test_ecore_file_operations); 228 tcase_add_test(tc, ecore_test_ecore_file_operations);
229 tcase_add_test(tc, ecore_test_ecore_file_monitor);
140} 230}