summaryrefslogtreecommitdiff
path: root/src/tests/eio/eio_test_job_xattr.c
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2016-04-12 16:00:23 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-05-25 21:32:03 -0300
commit7241b7375de1eb4327f5bca21dcfc5a889b9eb72 (patch)
treececbe8991d1b38db8f8c67965ae2a5e6cf2aa503 /src/tests/eio/eio_test_job_xattr.c
parentde9be13d458f2739a536e5863aa8caddd3f7f715 (diff)
eio: Adds Eo-based Eio API
The legacy Eio_File factory functions are replaced by an Eo object called Eo_Job that return promises wrapping the async file operations. With this commit, the legacy Eio callbacks are replaced by the following Eo/Promises counterparts : * Done_Cb -> Promise then success callback * Error_Cb -> Promise then error callback * Main_Cb -> Promise progress callback * Filter_Cb -> Job object event (more below) Events are used to deliver and get the filter data. To differentiate between the named and direct versions, they come in "filter,direct" and "filter,name" versions. Monitors were wrapped inside a new class Eo_Sentry. The user creates a sentry object and adds monitoring targets to it, listening to events on it. The sentry event info is composed of two strings. The source string is the path being monitored, i.e. the one passed to eio_sentry_add, and the trigger string is the path that actually triggered the event, e.g. a new file created in a monitored directory.
Diffstat (limited to '')
-rw-r--r--src/tests/eio/eio_test_job_xattr.c204
1 files changed, 204 insertions, 0 deletions
diff --git a/src/tests/eio/eio_test_job_xattr.c b/src/tests/eio/eio_test_job_xattr.c
new file mode 100644
index 0000000000..0cf5aca0fe
--- /dev/null
+++ b/src/tests/eio/eio_test_job_xattr.c
@@ -0,0 +1,204 @@
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#ifdef XATTR_TEST_DIR
19
20static const char *attribute[] =
21 {
22 "user.comment1",
23 "user.comment2",
24 "user.comment3"
25 };
26static const char *attr_data[] =
27 {
28 "This is a test file",
29 "This line is a comment",
30 "This file has extra attributes"
31 };
32
33struct eina_iterator
34{
35 Eina_Iterator* success_iterator;
36 Eina_Iterator* failure_iterator;
37};
38
39int total_attributes = sizeof(attribute)/sizeof(attribute[0]);
40
41static Eina_Bool
42_filter_cb(void *data EINA_UNUSED, const Eo_Event *event)
43{
44 Eio_Filter_Name_Data *event_info = event->info;
45
46 return event_info->filter = EINA_TRUE;
47}
48
49static void
50_main_cb(void *data, const char *attr)
51{
52 int *num_of_attr = (int *)data;
53 unsigned int i;
54
55 for (i = 0; i < sizeof (attribute) / sizeof (attribute[0]); ++i)
56 if (strcmp(attr, attribute[i]) == 0)
57 {
58 (*num_of_attr)++;
59 break;
60 }
61
62}
63
64static void
65_done_cb(void *data, void *value EINA_UNUSED)
66
67{
68 int *num_of_attr = (int *)data;
69
70 fail_if(*num_of_attr != total_attributes);
71
72 ecore_main_loop_quit();
73}
74
75static void
76_done_get_cb(void *data EINA_UNUSED, struct eina_iterator* it)
77{
78 int i = 0;
79 Eio_Xattr_Data *get_data;
80
81 while (eina_iterator_next(it->success_iterator, (void**)&get_data))
82 {
83 fail_if(!get_data);
84 fail_if(strcmp(get_data->data, attr_data[i]) != 0);
85 i++;
86 }
87
88 fail_if(i != total_attributes);
89
90 ecore_main_loop_quit();
91}
92
93static void
94_done_set_cb(void *data, struct eina_iterator* it)
95{
96 int *placeholder;
97 int *num_of_attr = data;
98 while(eina_iterator_next(it->success_iterator, (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", strerror(*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 job = eo_add(EIO_JOB_CLASS, NULL);
131
132 test_file_path = get_full_path(XATTR_TEST_DIR, filename);
133 fd = open(test_file_path,
134 O_WRONLY | O_CREAT | O_TRUNC,
135 S_IRWXU | S_IRWXG | S_IRWXO);
136 fail_if(fd == 0);
137
138 attrib_promises = (Eina_Promise **)calloc(total_attributes + 1, sizeof(Eina_Promise*));
139 attrib_promises[total_attributes] = NULL;
140
141 for (i = 0; i < sizeof(attribute) / sizeof(attribute[0]); ++i)
142 {
143 eio_job_file_xattr_set(job, test_file_path, attribute[i],
144 attr_data[i], strlen(attr_data[i]),
145 EINA_XATTR_INSERT,
146 &attrib_promises[i]);
147
148 fail_if(num_of_attr != 0); // test asynchronous
149 }
150 eina_promise_then(eina_promise_all(eina_carray_iterator_new((void**)attrib_promises)),
151 (Eina_Promise_Cb)_done_set_cb, (Eina_Promise_Error_Cb)_error_cb, &num_of_attr);
152
153 ecore_main_loop_begin();
154
155 free(attrib_promises);
156
157 num_of_attr = 0;
158
159 attrib_promises = (Eina_Promise **)calloc(total_attributes + 1, sizeof(Eina_Promise*));
160 attrib_promises[total_attributes] = NULL;
161
162 for (i = 0; i < sizeof(attribute) / sizeof(attribute[0]); ++i)
163 {
164 eio_job_file_xattr_get(job, test_file_path, attribute[i], &attrib_promises[i]);
165 }
166
167 eina_promise_then(eina_promise_all(eina_carray_iterator_new((void**)attrib_promises)),
168 (Eina_Promise_Cb)_done_get_cb, (Eina_Promise_Error_Cb)_error_cb, &num_of_attr);
169
170 ecore_main_loop_begin();
171
172 num_of_attr = 0;
173
174 eo_event_callback_add(job, EIO_JOB_EVENT_XATTR, _filter_cb, NULL);
175 eio_job_file_xattr(job, test_file_path, &list_promise);
176 eina_promise_progress_cb_add(list_promise, (Eina_Promise_Progress_Cb)_main_cb, &num_of_attr, NULL);
177 eina_promise_then(list_promise, (Eina_Promise_Cb)_done_cb, (Eina_Promise_Error_Cb)_error_cb, &num_of_attr);
178
179 fail_if(num_of_attr != 0);
180
181 ecore_main_loop_begin();
182
183 free(attrib_promises);
184
185 eo_unref(job);
186 close(fd);
187 unlink(test_file_path);
188 eina_tmpstr_del(test_file_path);
189 eio_shutdown();
190 eina_shutdown();
191 ecore_shutdown();
192}
193END_TEST
194
195#endif
196
197void eio_test_job_xattr(TCase *tc)
198{
199#ifdef XATTR_TEST_DIR
200 tcase_add_test(tc, eio_test_job_xattr_set);
201#else
202 (void)tc;
203#endif
204}