summaryrefslogtreecommitdiff
path: root/src/tests/eio
diff options
context:
space:
mode:
authorVivek Ellur <vivek.ellur@samsung.com>2016-06-06 16:47:49 +0200
committerStefan Schmidt <stefan@osg.samsung.com>2016-09-13 11:28:52 +0200
commitfb73aabc61c5333d9461da19be15304b220d9e4e (patch)
tree1cae0404b63c4f9a95a1bda9971c2223865f7db7 /src/tests/eio
parent0ee0baf94e3c90c8b94c495e8a79df4c4e516cf6 (diff)
eio_eet: Added test suite for eio eet module.
Summary: Added new test suite for eio eet module Signed-off-by: Vivek Ellur <vivek.ellur@samsung.com> Reviewers: cedric Subscribers: stefan_schmidt, jpeg, cedric Tags: #efl Differential Revision: https://phab.enlightenment.org/D3316
Diffstat (limited to 'src/tests/eio')
-rw-r--r--src/tests/eio/eio_suite.c1
-rw-r--r--src/tests/eio/eio_suite.h2
-rw-r--r--src/tests/eio/eio_test_eet.c216
3 files changed, 218 insertions, 1 deletions
diff --git a/src/tests/eio/eio_suite.c b/src/tests/eio/eio_suite.c
index a252ed2141..e08cc8fd89 100644
--- a/src/tests/eio/eio_suite.c
+++ b/src/tests/eio/eio_suite.c
@@ -19,6 +19,7 @@ static const Efl_Test_Case etc[] = {
19 {"Eio Job Xattr", eio_test_job_xattr}, 19 {"Eio Job Xattr", eio_test_job_xattr},
20#endif 20#endif
21 {"Eio_Map", eio_test_map}, 21 {"Eio_Map", eio_test_map},
22 {"Eio_Eet", eio_test_eet},
22 {NULL, NULL} 23 {NULL, NULL}
23}; 24};
24 25
diff --git a/src/tests/eio/eio_suite.h b/src/tests/eio/eio_suite.h
index 45a5a325da..83f0303f6a 100644
--- a/src/tests/eio/eio_suite.h
+++ b/src/tests/eio/eio_suite.h
@@ -12,5 +12,5 @@ void eio_test_job(TCase *tc);
12void eio_test_job_xattr(TCase *tc); 12void eio_test_job_xattr(TCase *tc);
13void eio_test_xattr(TCase *tc); 13void eio_test_xattr(TCase *tc);
14void eio_test_map(TCase *tc); 14void eio_test_map(TCase *tc);
15 15void eio_test_eet(TCase *tc);
16#endif /* _EIO_SUITE_H */ 16#endif /* _EIO_SUITE_H */
diff --git a/src/tests/eio/eio_test_eet.c b/src/tests/eio/eio_test_eet.c
new file mode 100644
index 0000000000..d261be3be5
--- /dev/null
+++ b/src/tests/eio/eio_test_eet.c
@@ -0,0 +1,216 @@
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 <Ecore.h>
12#include <Eio.h>
13#include <Eet.h>
14
15#include "eio_suite.h"
16
17Eet_File *ee;
18
19static void
20_open_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, Eet_File *ef)
21{
22 ee = ef;
23 ecore_main_loop_quit();
24}
25
26static void
27_done_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED)
28{
29 ecore_main_loop_quit();
30}
31
32static void
33_write_done_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, int i)
34{
35 fail_if (i <= 0);
36 ecore_main_loop_quit();
37}
38
39static void
40_read_done_cb(void *data, Eio_File *handler EINA_UNUSED, void *read_data,
41 unsigned int size)
42{
43 char *str = data;
44 char *read_str = read_data;
45
46 fail_if(!read_str);
47 fail_if(size != strlen(str) + 1);
48 fail_if(memcmp(str, read_str, strlen(str) + 1) != 0);
49
50 ecore_main_loop_quit();
51}
52
53static void
54_error_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, int error)
55{
56 fail();
57 fprintf(stderr, "Error:%s\n", strerror(error));
58 ecore_main_loop_quit();
59}
60
61static void
62_eet_error_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, Eet_Error err EINA_UNUSED)
63{
64 fail();
65 ecore_main_loop_quit();
66}
67
68START_TEST(eio_test_eet_cipher_decipher)
69{
70 int ret;
71 char *file = strdup("/tmp/eio_eet_example_XXXXXX");
72 const char *data = "This is the data to save in file";
73 const char *key = "This is a secret key";
74 Eio_File *ef;
75
76 ecore_init();
77 eet_init();
78 eio_init();
79
80 ret = mkstemp(file);
81 fail_if(ret == -1);
82
83 ef = eio_eet_open(file, EET_FILE_MODE_WRITE, _open_cb, _error_cb, NULL);
84 ecore_main_loop_begin();
85 fail_if(!ef);
86
87 ef = eio_eet_write_cipher(ee, "keys/tests", data, strlen(data) + 1, 0,
88 key, _write_done_cb, _error_cb, NULL);
89 ecore_main_loop_begin();
90 fail_if(!ef);
91
92 ef = eio_eet_close(ee, _done_cb, _eet_error_cb, NULL);
93 ecore_main_loop_begin();
94 fail_if(!ef);
95
96 ef = eio_eet_open(file, EET_FILE_MODE_READ, _open_cb, _error_cb, NULL);
97 ecore_main_loop_begin();
98 fail_if(!ef);
99
100 ef = eio_eet_read_cipher(ee, "keys/tests", key, _read_done_cb,
101 _error_cb, data);
102 ecore_main_loop_begin();
103 fail_if(!ef);
104
105 ef = eio_eet_close(ee, _done_cb, _eet_error_cb, NULL);
106 ecore_main_loop_begin();
107 fail_if(!ef);
108
109 eio_shutdown();
110 eet_shutdown();
111 ecore_shutdown();
112}
113END_TEST
114
115typedef struct
116{
117 unsigned int id;
118 const char *name;
119} Test_Struct;
120
121static Eet_Data_Descriptor *_test_struct_descriptor;
122
123static void
124_test_struct_descriptor_init(void)
125{
126 Eet_Data_Descriptor_Class eddc;
127
128 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Test_Struct);
129 _test_struct_descriptor = eet_data_descriptor_stream_new(&eddc);
130
131 EET_DATA_DESCRIPTOR_ADD_BASIC(_test_struct_descriptor, Test_Struct,
132 "id", id, EET_T_INT);
133 EET_DATA_DESCRIPTOR_ADD_BASIC(_test_struct_descriptor, Test_Struct,
134 "name", name, EET_T_STRING);
135}
136
137static Test_Struct *
138_test_struct_new(void)
139{
140 Test_Struct *tc = calloc(1, sizeof(Test_Struct));
141 fail_if(!tc);
142
143 tc->id = 1234;
144 tc->name = "eio_eet_test";
145
146 return tc;
147}
148
149static void
150_data_read_done_cb(void *data, Eio_File *handler EINA_UNUSED, void *decoded)
151{
152 Test_Struct *res = decoded;
153 Test_Struct *orig = data;
154
155 fail_if(!res);
156 fail_if(res->id != orig->id);
157 fail_if(strcmp(res->name, orig->name) != 0);
158 ecore_main_loop_quit();
159}
160
161START_TEST(eio_test_eet_data_cipher_decipher)
162{
163 int ret;
164 char *file = strdup("/tmp/eio_eet_example_XXXXXX");
165 const char *key = "This is a secret key";
166 Eio_File *ef;
167 Test_Struct *tc;
168
169 ecore_init();
170 eet_init();
171 eio_init();
172
173 _test_struct_descriptor_init();
174 tc = _test_struct_new();
175
176 ret = mkstemp(file);
177 fail_if(ret == -1);
178
179 ef = eio_eet_open(file, EET_FILE_MODE_WRITE, _open_cb, _error_cb, NULL);
180 ecore_main_loop_begin();
181 fail_if(!ef);
182
183 ef = eio_eet_data_write_cipher(ee, _test_struct_descriptor, "test",
184 key, tc, 0, _write_done_cb, _error_cb, NULL);
185 ecore_main_loop_begin();
186 fail_if(!ef);
187
188 ef = eio_eet_close(ee, _done_cb, _eet_error_cb, NULL);
189 ecore_main_loop_begin();
190 fail_if(!ef);
191
192 ef = eio_eet_open(file, EET_FILE_MODE_READ, _open_cb, _error_cb, NULL);
193 ecore_main_loop_begin();
194 fail_if(!ef);
195
196 ef = eio_eet_data_read_cipher(ee, _test_struct_descriptor, "test",
197 key, _data_read_done_cb, _error_cb, tc);
198 ecore_main_loop_begin();
199 fail_if(!ef);
200
201 ef = eio_eet_close(ee, _done_cb, _eet_error_cb, NULL);
202 ecore_main_loop_begin();
203 fail_if(!ef);
204
205 eio_shutdown();
206 eet_shutdown();
207 ecore_shutdown();
208}
209END_TEST
210
211void
212eio_test_eet(TCase *tc)
213{
214 tcase_add_test(tc, eio_test_eet_cipher_decipher);
215 tcase_add_test(tc, eio_test_eet_data_cipher_decipher);
216}