summaryrefslogtreecommitdiff
path: root/src/tests/eio/eio_test_xattr.c
diff options
context:
space:
mode:
authorvivek <vivek.ellur@samsung.com>2015-04-18 17:40:59 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-04-18 18:50:27 +0200
commit2e7c348acabca6e0c60d37c41a841d18fe5c6abe (patch)
tree5434448566b774bdf458df701169cfe37ed16e09 /src/tests/eio/eio_test_xattr.c
parent0784d5cc2a71b1e238e1962dc461b706fdc761a6 (diff)
eio: add test cases for eio xattr module.
Summary: Added test cases for eio_file_xattr, eio_file_xattr_set and eio_file_xattr_get functions Signed-off-by: vivek <vivek.ellur@samsung.com> Reviewers: cedric Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2374 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/tests/eio/eio_test_xattr.c')
-rw-r--r--src/tests/eio/eio_test_xattr.c164
1 files changed, 164 insertions, 0 deletions
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}