summaryrefslogtreecommitdiff
path: root/src/tests/eio/eio_test_manager_xattr.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2016-06-16 15:13:22 -0700
committerCedric BAIL <cedric@osg.samsung.com>2016-06-22 13:19:13 -0700
commit10aadafcfd01d972a50fb9e1e6b3d3c28924feb0 (patch)
treeca3375665c23b8ba1c683c8c97695a37336f3f69 /src/tests/eio/eio_test_manager_xattr.c
parentae207a5be683c3f89087552a11fc7bd91128d71e (diff)
eio: rename eio_job to efl_io_manager.
There is still a lot of work to do in this API to make it efficient and stable. Will try to get at it before 1.18 release.
Diffstat (limited to 'src/tests/eio/eio_test_manager_xattr.c')
-rw-r--r--src/tests/eio/eio_test_manager_xattr.c205
1 files changed, 205 insertions, 0 deletions
diff --git a/src/tests/eio/eio_test_manager_xattr.c b/src/tests/eio/eio_test_manager_xattr.c
new file mode 100644
index 0000000000..94f5b49425
--- /dev/null
+++ b/src/tests/eio/eio_test_manager_xattr.c
@@ -0,0 +1,205 @@
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 <fcntl.h>
9
10#include <Ecore.h>
11#include <Ecore_File.h>
12#include <Eio.h>
13
14#include "eio_suite.h"
15#include "eio_test_common.h"
16
17
18#ifndef XATTR_TEST_DIR
19#define DISABLE_XATTR_TEST
20#define XATTR_TEST_DIR ""
21#endif
22
23static const char *attribute[] =
24 {
25 "user.comment1",
26 "user.comment2",
27 "user.comment3"
28 };
29static const char *attr_data[] =
30 {
31 "This is a test file",
32 "This line is a comment",
33 "This file has extra attributes"
34 };
35
36int total_attributes = sizeof(attribute)/sizeof(attribute[0]);
37
38static void
39_filter_cb(void *data EINA_UNUSED, const Eo_Event *event)
40{
41 Eio_Filter_Name_Data *event_info = event->info;
42
43 event_info->filter = EINA_TRUE;
44}
45
46static void
47_main_cb(void *data, void *v)
48{
49 const char* attr = v;
50 int *num_of_attr = (int *)data;
51 unsigned int i;
52
53 for (i = 0; i < sizeof (attribute) / sizeof (attribute[0]); ++i)
54 if (strcmp(attr, attribute[i]) == 0)
55 {
56 (*num_of_attr)++;
57 break;
58 }
59
60}
61
62static void
63_done_cb(void *data, void *value EINA_UNUSED)
64
65{
66 int *num_of_attr = (int *)data;
67
68 fail_if(*num_of_attr != total_attributes);
69
70 ecore_main_loop_quit();
71}
72
73static void
74_done_get_cb(void *data EINA_UNUSED, void* v)
75{
76 Eina_Iterator** it = (Eina_Iterator**)v;
77 int i = 0;
78 Eio_Xattr_Data *get_data;
79
80 while (eina_iterator_next((*it), (void**)&get_data))
81 {
82 fail_if(!get_data);
83 fail_if(strcmp(get_data->data, attr_data[i]) != 0);
84 i++;
85 }
86
87 fail_if(i != total_attributes);
88
89 ecore_main_loop_quit();
90}
91
92static void
93_done_set_cb(void *data, void* v)
94{
95 Eina_Iterator** it = (Eina_Iterator**)v;
96 int *placeholder;
97 int *num_of_attr = data;
98 while(eina_iterator_next((*it), (void**)&placeholder))
99 *num_of_attr += 1;
100
101 fail_if(*num_of_attr != total_attributes);
102
103 ecore_main_loop_quit();
104}
105
106static void
107_error_cb(void *data EINA_UNUSED, Eina_Error error)
108
109{
110 fprintf(stderr, "Something has gone wrong:%s\n", eina_error_msg_get(error));
111 abort();
112
113 ecore_main_loop_quit();
114}
115
116START_TEST(eio_test_job_xattr_set)
117{
118 char *filename = "eio-tmpfile";
119 Eina_Tmpstr *test_file_path;
120 int num_of_attr = 0, fd;
121 unsigned int i;
122 Eo *job;
123 Eina_Promise *list_promise = NULL;
124 Eina_Promise **attrib_promises = NULL;
125
126 ecore_init();
127 eina_init();
128 eio_init();
129
130 fprintf(stderr, "eio_test_job_xattr_set\n"); fflush(stderr);
131
132 job = eo_add(EFL_IO_MANAGER_CLASS, NULL);
133
134 test_file_path = get_full_path(XATTR_TEST_DIR, filename);
135 fd = open(test_file_path,
136 O_WRONLY | O_CREAT | O_TRUNC,
137 S_IRWXU | S_IRWXG | S_IRWXO);
138 fail_if(fd == 0);
139
140 attrib_promises = (Eina_Promise**)calloc(total_attributes + 1, sizeof(Eina_Promise*));
141 attrib_promises[total_attributes] = NULL;
142
143 for (i = 0; i < sizeof(attribute) / sizeof(attribute[0]); ++i)
144 {
145 attrib_promises[i] = efl_io_manager_file_xattr_set
146 (job, test_file_path, attribute[i],
147 attr_data[i], strlen(attr_data[i]),
148 EINA_XATTR_INSERT);
149
150 fail_if(num_of_attr != 0); // test asynchronous
151 }
152 eina_promise_then(eina_promise_all(eina_carray_iterator_new((void**)attrib_promises)),
153 &_done_set_cb, _error_cb, &num_of_attr);
154
155 ecore_main_loop_begin();
156
157 free(attrib_promises);
158
159 num_of_attr = 0;
160
161 attrib_promises = (Eina_Promise**)calloc(total_attributes + 1, sizeof(Eina_Promise*));
162 attrib_promises[total_attributes] = NULL;
163
164 for (i = 0; i < sizeof(attribute) / sizeof(attribute[0]); ++i)
165 {
166 attrib_promises[i] = efl_io_manager_file_xattr_get(job, test_file_path, attribute[i]);
167 }
168
169 eina_promise_then(eina_promise_all(eina_carray_iterator_new((void**)attrib_promises)),
170 _done_get_cb, _error_cb, &num_of_attr);
171
172 ecore_main_loop_begin();
173
174 num_of_attr = 0;
175
176 eo_event_callback_add(job, EFL_IO_MANAGER_EVENT_XATTR, _filter_cb, NULL);
177 list_promise = efl_io_manager_file_xattr_list_get(job, test_file_path);
178 eina_promise_progress_cb_add(list_promise, _main_cb, &num_of_attr, NULL);
179 eina_promise_then(list_promise, _done_cb, _error_cb, &num_of_attr);
180
181 fail_if(num_of_attr != 0);
182
183 ecore_main_loop_begin();
184
185 free(attrib_promises);
186
187 eo_unref(job);
188 close(fd);
189 unlink(test_file_path);
190 eina_tmpstr_del(test_file_path);
191 eio_shutdown();
192 eina_shutdown();
193 ecore_shutdown();
194}
195END_TEST
196
197void eio_test_job_xattr(TCase *tc)
198{
199#ifndef DISABLE_XATTR_TEST
200 tcase_add_test(tc, eio_test_job_xattr_set);
201#else
202 (void)eio_test_job_xattr_set;
203 (void)tc;
204#endif
205}