summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile_Eio.am1
-rw-r--r--src/tests/eio/eio_suite.c3
-rw-r--r--src/tests/eio/eio_suite.h1
-rw-r--r--src/tests/eio/eio_test_xattr.c164
4 files changed, 169 insertions, 0 deletions
diff --git a/src/Makefile_Eio.am b/src/Makefile_Eio.am
index afa1ce3bf5..a41af55398 100644
--- a/src/Makefile_Eio.am
+++ b/src/Makefile_Eio.am
@@ -66,6 +66,7 @@ tests/eio/eio_model_test_file.c \
66tests/eio/eio_model_test_monitor_add.c \ 66tests/eio/eio_model_test_monitor_add.c \
67tests/eio/eio_test_monitor.c \ 67tests/eio/eio_test_monitor.c \
68tests/eio/eio_test_file.c \ 68tests/eio/eio_test_file.c \
69tests/eio/eio_test_xattr.c \
69tests/eio/eio_suite.h 70tests/eio/eio_suite.h
70 71
71tests_eio_eio_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \ 72tests_eio_eio_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
diff --git a/src/tests/eio/eio_suite.c b/src/tests/eio/eio_suite.c
index 7b3de1bb30..4dfdbfbc5a 100644
--- a/src/tests/eio/eio_suite.c
+++ b/src/tests/eio/eio_suite.c
@@ -22,6 +22,9 @@ static const Eio_Test_Case etc[] = {
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 {"Eio File", eio_test_file},
25#ifdef XATTR_TEST_DIR
26 {"Eio_Xattr", eio_test_xattr},
27#endif
25 {NULL, NULL} 28 {NULL, NULL}
26}; 29};
27 30
diff --git a/src/tests/eio/eio_suite.h b/src/tests/eio/eio_suite.h
index d365f707b6..170a060c73 100644
--- a/src/tests/eio/eio_suite.h
+++ b/src/tests/eio/eio_suite.h
@@ -7,5 +7,6 @@ void 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); 9void eio_test_file(TCase *tc);
10void eio_test_xattr(TCase *tc);
10 11
11#endif /* _EIO_SUITE_H */ 12#endif /* _EIO_SUITE_H */
diff --git a/src/tests/eio/eio_test_xattr.c b/src/tests/eio/eio_test_xattr.c
new file mode 100644
index 0000000000..6d12c3b990
--- /dev/null
+++ b/src/tests/eio/eio_test_xattr.c
@@ -0,0 +1,164 @@
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 <Eio.h>
11#include <Ecore.h>
12#include <Ecore_File.h>
13
14#include "eio_suite.h"
15
16const char *attribute[] =
17 {
18 "user.comment1",
19 "user.comment2",
20 "user.comment3"
21 };
22const char *attr_data[] =
23 {
24 "This is a test file",
25 "This line is a comment",
26 "This file has extra attributes"
27 };
28
29Eina_Tmpstr*
30get_file_path(const char* tmpdirname, const char* filename)
31{
32 char file_path[PATH_MAX] = "";
33 eina_str_join(file_path, sizeof(file_path), '/', tmpdirname, filename);
34 return eina_tmpstr_add(file_path);
35}
36
37static Eina_Bool
38_filter_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, const char *attr EINA_UNUSED)
39{
40 return EINA_TRUE;
41}
42
43static void
44_main_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, const char *attr)
45{
46 int *num_of_attr = (int *)data;
47 unsigned int i;
48
49 for (i = 0; i < sizeof (attribute) / sizeof (attribute[0]); ++i)
50 if (strcmp(attr, attribute[i]) == 0)
51 break;
52
53 fail_if(i == sizeof (attribute) / sizeof (attribute[0]));
54 (*num_of_attr)++;
55}
56
57static void
58_done_cb(void *data, Eio_File *handler EINA_UNUSED)
59
60{
61 int *num_of_attr = (int *)data;
62
63 (*num_of_attr)++;
64
65 if (((*num_of_attr) + 1) == (sizeof (attribute) / sizeof (attribute[0])))
66 ecore_main_loop_quit();
67}
68
69static void
70_done_once_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED)
71{
72 ecore_main_loop_quit();
73}
74
75static void
76_done_get_cb(void *data, Eio_File *handler EINA_UNUSED, const char *name, unsigned int len EINA_UNUSED)
77
78{
79 int i = (int)(uintptr_t)data;
80
81 fail_if(strcmp(name, attr_data[i]) != 0);
82
83 if ((i + 1) == (sizeof (attribute) / sizeof (attribute[0])))
84 ecore_main_loop_quit();
85}
86
87static void
88_error_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, int error)
89
90{
91 fprintf(stderr, "Something wrong has happend:%s\n", strerror(error));
92 abort();
93
94 ecore_main_loop_quit();
95}
96
97#ifdef XATTR_TEST_DIR
98START_TEST(eio_test_xattr_set)
99{
100 char *filename = "eio-tmpfile";
101 Eina_Tmpstr *test_file_path;
102 Eio_File *fp;
103 int num_of_attr = 0, fd;
104 unsigned int i;
105
106 ecore_init();
107 eina_init();
108 eio_init();
109
110 test_file_path = get_file_path(XATTR_TEST_DIR, filename);
111 fd = open(test_file_path,
112 O_WRONLY | O_CREAT | O_TRUNC,
113 S_IRWXU | S_IRWXG | S_IRWXO);
114 fail_if(fd == 0);
115
116 for (i = 0; i < sizeof(attribute) / sizeof(attribute[0]); ++i)
117 {
118 fp = eio_file_xattr_set(test_file_path, attribute[i],
119 attr_data[i], strlen(attr_data[i]),
120 EINA_XATTR_INSERT,
121 _done_cb, _error_cb, &num_of_attr);
122
123 fail_if(num_of_attr != 0); // test asynchronous
124 fail_if(!fp);
125 }
126
127 ecore_main_loop_begin();
128
129 for (i = 0; i < sizeof(attribute) / sizeof(attribute[0]); ++i)
130 {
131 fp = eio_file_xattr_get(test_file_path, attribute[i],
132 _done_get_cb, _error_cb, (void*)(uintptr_t) i);
133 fail_if(!fp);
134 }
135
136 ecore_main_loop_begin();
137
138 num_of_attr = 0;
139 fp = eio_file_xattr(test_file_path,
140 _filter_cb, _main_cb, _done_once_cb, _error_cb,
141 &num_of_attr);
142 fail_if(num_of_attr != 0);
143 fail_if(!fp);
144
145 ecore_main_loop_begin();
146
147 fail_if(num_of_attr != sizeof (attribute) / sizeof (attribute[0]));
148
149 close(fd);
150 unlink(test_file_path);
151 eio_shutdown();
152 ecore_shutdown();
153}
154END_TEST
155#endif
156
157void eio_test_xattr(TCase *tc)
158{
159#ifdef XATTR_TEST_DIR
160 tcase_add_test(tc, eio_test_xattr_set);
161#else
162 (void)tc
163#endif
164}