summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkabeer khan <kabeer.khan@samsung.com>2015-04-16 18:47:44 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-04-16 19:21:45 +0200
commit351a30cfc7479005b4ee9d3191590d81cab11356 (patch)
tree1f36e7ae8df8c99f147877ced3c5e2715c3d838a /src
parent04cf807b5f1df35b24953ff62bc339c6e690c9d4 (diff)
eio: add new tests for eio.
Summary: Signed-off-by: kabeer khan <kabeer.khan@samsung.com> Reviewers: cedric Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2360 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to '')
-rw-r--r--src/Makefile_Eio.am3
-rw-r--r--src/tests/eio/eio_suite.c1
-rw-r--r--src/tests/eio/eio_suite.h1
-rw-r--r--src/tests/eio/eio_test_file.c233
4 files changed, 237 insertions, 1 deletions
diff --git a/src/Makefile_Eio.am b/src/Makefile_Eio.am
index 3543adc698..c7615844fc 100644
--- a/src/Makefile_Eio.am
+++ b/src/Makefile_Eio.am
@@ -63,7 +63,8 @@ tests_eio_eio_suite_SOURCES = \
63tests/eio/eio_suite.c \ 63tests/eio/eio_suite.c \
64tests/eio/eio_model_test_file.c \ 64tests/eio/eio_model_test_file.c \
65tests/eio/eio_model_test_monitor_add.c \ 65tests/eio/eio_model_test_monitor_add.c \
66tests/eio/eio_test_monitor.c 66tests/eio/eio_test_monitor.c \
67tests/eio/eio_test_file.c
67 68
68tests_eio_eio_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \ 69tests_eio_eio_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
69-DTESTS_SRC_DIR=\"$(top_srcdir)/src/tests/eio\" \ 70-DTESTS_SRC_DIR=\"$(top_srcdir)/src/tests/eio\" \
diff --git a/src/tests/eio/eio_suite.c b/src/tests/eio/eio_suite.c
index ecc52247b3..7b3de1bb30 100644
--- a/src/tests/eio/eio_suite.c
+++ b/src/tests/eio/eio_suite.c
@@ -21,6 +21,7 @@ static const Eio_Test_Case etc[] = {
21 {"Eio_Monitor", eio_test_monitor}, 21 {"Eio_Monitor", eio_test_monitor},
22 {"Eio Model", eio_model_test_file}, 22 {"Eio Model", eio_model_test_file},
23 {"Eio Model Monitor", eio_model_test_monitor_add}, 23 {"Eio Model Monitor", eio_model_test_monitor_add},
24 {"Eio File", eio_test_file},
24 {NULL, NULL} 25 {NULL, NULL}
25}; 26};
26 27
diff --git a/src/tests/eio/eio_suite.h b/src/tests/eio/eio_suite.h
index d59a2ab6c0..d365f707b6 100644
--- a/src/tests/eio/eio_suite.h
+++ b/src/tests/eio/eio_suite.h
@@ -6,5 +6,6 @@
6void eio_test_monitor(TCase *tc); 6void eio_test_monitor(TCase *tc);
7void eio_model_test_file(TCase *tc); 7void eio_model_test_file(TCase *tc);
8void eio_model_test_monitor_add(TCase *tc); 8void eio_model_test_monitor_add(TCase *tc);
9void eio_test_file(TCase *tc);
9 10
10#endif /* _EIO_SUITE_H */ 11#endif /* _EIO_SUITE_H */
diff --git a/src/tests/eio/eio_test_file.c b/src/tests/eio/eio_test_file.c
new file mode 100644
index 0000000000..7284c04b38
--- /dev/null
+++ b/src/tests/eio/eio_test_file.c
@@ -0,0 +1,233 @@
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#include <sys/stat.h>
9#include <fcntl.h>
10
11#include <Eio.h>
12#include <Ecore.h>
13
14#include "eio_suite.h"
15
16static int default_rights = 0777;
17int test_count = 0;
18
19static Eina_Bool
20_filter_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, const char *file)
21{
22 char *last_slash = strrchr(file, '/');
23
24 //Check if it is a hidden file
25 if (last_slash != NULL && strlen(last_slash) > 1 && last_slash[1] == '.')
26 return EINA_FALSE;
27
28 return EINA_TRUE;
29}
30
31static Eina_Bool
32_delete_filter_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED,
33 const Eina_File_Direct_Info *info EINA_UNUSED)
34{
35 return EINA_TRUE;
36}
37
38static void
39_main_cb(void *data, Eio_File *handler EINA_UNUSED, const char *file)
40{
41 int *number_of_listed_files = (int *)data;
42
43 fprintf(stderr, "Processing file:%s\n", file);
44 (*number_of_listed_files)++;
45}
46
47static Eina_Bool
48_direct_filter_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED,
49 const Eina_File_Direct_Info *info)
50{
51 char *last_slash = strrchr(info->path, '/');
52
53 //Check if it is a hidden file
54 if (last_slash != NULL && strlen(last_slash) > 1 && last_slash[1] == '.')
55 return EINA_FALSE;
56
57 return EINA_TRUE;
58}
59
60static void
61_direct_main_cb(void *data, Eio_File *handler EINA_UNUSED, const Eina_File_Direct_Info *info)
62{
63 int *number_of_listed_files = (int *)data;
64
65 fprintf(stderr, "Processing file:%s\n", info->path);
66 (*number_of_listed_files)++;
67}
68
69static void
70_progress_cb(void *data, Eio_File *handler EINA_UNUSED, const Eio_Progress *info)
71{
72 int *number_of_listed_files = (int *)data;
73
74 fprintf(stderr, "Processing file:%s\n", info->source);
75 (*number_of_listed_files)++;
76}
77
78static void
79_done_cb(void *data, Eio_File *handler EINA_UNUSED)
80{
81 int *number_of_listed_files = (int *)data;
82 fail_if((*number_of_listed_files) != test_count);
83 ecore_main_loop_quit();
84}
85
86static void
87_error_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, int error)
88{
89 fprintf(stderr, "Something wrong has happend:%s\n", strerror(error));
90 ecore_main_loop_quit();
91}
92
93Eina_Tmpstr*
94get_full_path(const char* tmpdirname, const char* filename)
95{
96 char full_path[PATH_MAX] = "";
97 eina_str_join(full_path, sizeof(full_path), '/', tmpdirname, filename);
98 return eina_tmpstr_add(full_path);
99}
100
101Eina_Tmpstr*
102get_eio_test_file_tmp_dir()
103{
104 Eina_Tmpstr *tmp_dir;
105
106 Eina_Bool created = eina_file_mkdtemp("EioFileTestXXXXXX", &tmp_dir);
107
108 if (!created)
109 {
110 return NULL;
111 }
112
113 return tmp_dir;
114}
115
116Eina_Tmpstr*
117create_test_dirs(Eina_Tmpstr *test_dirname)
118{
119 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 *);
133 fail_if(test_dirname == NULL);
134
135 for (i = 0; i != count; ++i)
136 {
137 Eina_Tmpstr *dirname = get_full_path(test_dirname, good_dirs[i]);
138 fail_if(mkdir(dirname, default_rights) != 0);
139 eina_tmpstr_del(dirname);
140 }
141 count = sizeof(files) / sizeof(const char *);
142 for (i = 0; i != count; ++i)
143 {
144 Eina_Tmpstr *filename = get_full_path(test_dirname, files[i]);
145 fd = open(filename, O_RDWR|O_CREAT, default_rights);
146 fail_if(fd < 0);
147 fail_if(close(fd) != 0);
148 eina_tmpstr_del(filename);
149 }
150 Eina_Tmpstr *nested_dirname = get_full_path(test_dirname, good_dirs[0]);
151 for (i = 0; i != count; ++i)
152 {
153 Eina_Tmpstr *filename = get_full_path(nested_dirname, files[i]);
154 fd = open(filename, O_RDWR|O_CREAT, default_rights);
155 fail_if(fd < 0);
156 fail_if(close(fd) != 0);
157 eina_tmpstr_del(filename);
158 }
159 return nested_dirname;
160}
161
162START_TEST(eio_file_test_ls)
163{
164 int number_of_listed_files = 0, ret;
165
166 ret = ecore_init();
167 fail_if(ret < 1);
168 ret = eio_init();
169 fail_if(ret < 1);
170 ret = eina_init();
171 fail_if(ret < 1);
172
173 Eina_Tmpstr *test_dirname = get_eio_test_file_tmp_dir();
174 Eina_Tmpstr *nested_dirname = create_test_dirs(test_dirname);
175
176 eio_file_ls(test_dirname, _filter_cb, _main_cb, _done_cb, _error_cb,
177 &number_of_listed_files);
178 test_count = 5;
179 fail_if(number_of_listed_files != 0); //check asynchronous
180 ecore_main_loop_begin();
181
182 number_of_listed_files = 0;
183#ifdef _WIN32
184 eio_file_direct_ls(test_dirname, _direct_filter_cb, _direct_main_cb, _done_cb,
185 _error_cb, &number_of_listed_files);
186#else
187 eio_file_stat_ls(test_dirname, _direct_filter_cb, _direct_main_cb, _done_cb,
188 _error_cb, &number_of_listed_files);
189#endif
190 test_count = 5;
191 fail_if(number_of_listed_files != 0); //check asynchronous
192 ecore_main_loop_begin();
193
194 number_of_listed_files = 0;
195#ifdef _WIN32
196 eio_dir_direct_ls(test_dirname, _direct_filter_cb, _direct_main_cb, _done_cb,
197 _error_cb, &number_of_listed_files);
198#else
199 eio_dir_stat_ls(test_dirname, _direct_filter_cb, _direct_main_cb, _done_cb,
200 _error_cb, &number_of_listed_files);
201#endif
202 test_count = 8;
203 fail_if(number_of_listed_files != 0); //check asynchronous
204 ecore_main_loop_begin();
205
206 number_of_listed_files = 0;
207 eio_dir_unlink(nested_dirname, _delete_filter_cb, _progress_cb, _done_cb,
208 _error_cb, &number_of_listed_files);
209 test_count = 5; // 4 internal files + 1 nested_dir
210 fail_if(number_of_listed_files != 0); // check asynchronous
211 ecore_main_loop_begin();
212
213 number_of_listed_files = 0;
214 eio_dir_unlink(test_dirname, _delete_filter_cb, _progress_cb, _done_cb,
215 _error_cb, &number_of_listed_files);
216 test_count = 6; // 4 internal files + 1 dir + 1 test_dir
217 fail_if(number_of_listed_files != 0); // check asynchronous
218 ecore_main_loop_begin();
219
220 eina_tmpstr_del(nested_dirname);
221 eina_tmpstr_del(test_dirname);
222 eina_shutdown();
223 eio_shutdown();
224 ecore_shutdown();
225}
226END_TEST
227
228void
229eio_test_file(TCase *tc)
230{
231 tcase_add_test(tc, eio_file_test_ls);
232}
233