summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/Makefile.am2
-rw-r--r--src/tests/eet/Makefile.am19
-rw-r--r--src/tests/eet/TODO3
-rw-r--r--src/tests/eet/cert.pem22
-rw-r--r--src/tests/eet/eet_data_suite.c73
-rw-r--r--src/tests/eet/eet_suite.c2779
-rw-r--r--src/tests/eet/eet_suite.h9
-rw-r--r--src/tests/eet/key.pem15
-rw-r--r--src/tests/eet/key_enc.pem17
-rw-r--r--src/tests/eet/key_enc_none.pem16
10 files changed, 2954 insertions, 1 deletions
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index b8f642fb72..45fa7fe5f4 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -1,3 +1,3 @@
1MAINTAINERCLEANFILES = Makefile.in 1MAINTAINERCLEANFILES = Makefile.in
2 2
3SUBDIRS = eina 3SUBDIRS = eina eet
diff --git a/src/tests/eet/Makefile.am b/src/tests/eet/Makefile.am
new file mode 100644
index 0000000000..b1a6ee94d0
--- /dev/null
+++ b/src/tests/eet/Makefile.am
@@ -0,0 +1,19 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3AM_CPPFLAGS = \
4-I$(top_srcdir)/src/lib/eet \
5-I$(top_builddir)/src/lib/eet \
6-DTESTS_SRC_DIR=\"$(top_srcdir)/src/tests\" \
7@CHECK_CFLAGS@ \
8@EET_CFLAGS@
9
10if EFL_ENABLE_TESTS
11
12check_PROGRAMS = eet_suite
13
14eet_suite_SOURCES = eet_suite.c eet_data_suite.c eet_suite.h
15eet_suite_LDADD = @CHECK_LIBS@ $(top_builddir)/src/lib/eet/libeet.la @EET_LIBS@
16
17endif
18
19EXTRA_DIST = cert.pem key_enc_none.pem key_enc.pem key.pem
diff --git a/src/tests/eet/TODO b/src/tests/eet/TODO
new file mode 100644
index 0000000000..da5fa1bd19
--- /dev/null
+++ b/src/tests/eet/TODO
@@ -0,0 +1,3 @@
1The purpose of the current test is to check the validity of the result in a
2normal environment. But we should at some point also test the robustness of
3this library when for example malloc fail.
diff --git a/src/tests/eet/cert.pem b/src/tests/eet/cert.pem
new file mode 100644
index 0000000000..3265462d7b
--- /dev/null
+++ b/src/tests/eet/cert.pem
@@ -0,0 +1,22 @@
1-----BEGIN CERTIFICATE-----
2MIIDmTCCAwKgAwIBAgIJAIKWPcLUT5FAMA0GCSqGSIb3DQEBBQUAMIGQMQswCQYD
3VQQGEwJGUjEWMBQGA1UECBMNSWxlLURlLUZyYW5jZTEOMAwGA1UEBxMFUGFyaXMx
4FjAUBgNVBAoTDUVubGlnaHRlbm1lbnQxDjAMBgNVBAsTBVRlc3RzMQ0wCwYDVQQD
5EwRCQUlMMSIwIAYJKoZIhvcNAQkBFhNjZWRyaWMuYmFpbEBmcmVlLmZyMB4XDTA4
6MDczMDEzNDU1OVoXDTA5MDczMDEzNDU1OVowgZAxCzAJBgNVBAYTAkZSMRYwFAYD
7VQQIEw1JbGUtRGUtRnJhbmNlMQ4wDAYDVQQHEwVQYXJpczEWMBQGA1UEChMNRW5s
8aWdodGVubWVudDEOMAwGA1UECxMFVGVzdHMxDTALBgNVBAMTBEJBSUwxIjAgBgkq
9hkiG9w0BCQEWE2NlZHJpYy5iYWlsQGZyZWUuZnIwgZ8wDQYJKoZIhvcNAQEBBQAD
10gY0AMIGJAoGBAMiE486eROKePG0/639D4XTTDR9XSRWp1xqZzq7P+jjWRFbZ/MWV
11IVzkc4MRm83UOolbPj76LjM10cseaVAhK7G9CHp2dur4alWvdCXPH5Q+LPOFS9gM
12x0Jz9EZeHHOHZKLyJdKSmot+zluwJTLe081RRUwzNKct6JrVVG/7SmITAgMBAAGj
13gfgwgfUwHQYDVR0OBBYEFEFar6doT5ImL2rf0rJX7EYQqtYQMIHFBgNVHSMEgb0w
14gbqAFEFar6doT5ImL2rf0rJX7EYQqtYQoYGWpIGTMIGQMQswCQYDVQQGEwJGUjEW
15MBQGA1UECBMNSWxlLURlLUZyYW5jZTEOMAwGA1UEBxMFUGFyaXMxFjAUBgNVBAoT
16DUVubGlnaHRlbm1lbnQxDjAMBgNVBAsTBVRlc3RzMQ0wCwYDVQQDEwRCQUlMMSIw
17IAYJKoZIhvcNAQkBFhNjZWRyaWMuYmFpbEBmcmVlLmZyggkAgpY9wtRPkUAwDAYD
18VR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQCpZJhk8BgQh0foiMkOwOMKvObq
19GxAzqjbr7iU9tEvJgwukCBv59ndBM0B5l5ybQdIYWQJOfZE1HTvB60swZMwqap9X
205QXgewymuXiVk+roVh34wg8Pg8F588G2BtLIoujY/gN3WJQR7YPD34iTPc4koV+A
214vs6nmL6wtW21+hsaw==
22-----END CERTIFICATE-----
diff --git a/src/tests/eet/eet_data_suite.c b/src/tests/eet/eet_data_suite.c
new file mode 100644
index 0000000000..c4d5e5096b
--- /dev/null
+++ b/src/tests/eet/eet_data_suite.c
@@ -0,0 +1,73 @@
1#include <string.h>
2#include <stdio.h>
3
4#include <Eina.h>
5
6#include "eet_suite.h"
7
8static char *
9_eet_str_direct_alloc(const char *str)
10{
11 return (char *)str;
12} /* _eet_str_direct_alloc */
13
14static void
15_eet_str_direct_free(const char *str)
16{
17 /* FIXME: Use attribute unused */
18 (void)str;
19} /* _eet_str_direct_free */
20
21static void
22_eet_eina_hash_foreach(void *hash,
23 Eina_Hash_Foreach cb,
24 void *fdata)
25{
26 if (hash)
27 eina_hash_foreach(hash, cb, fdata);
28} /* _eet_eina_hash_foreach */
29
30/* Internal wrapper for eina_hash */
31static Eina_Hash *
32_eet_eina_hash_add(Eina_Hash *hash,
33 const char *key,
34 const void *data)
35{
36 if (!hash)
37 hash = eina_hash_string_superfast_new(NULL);
38
39 if (!hash)
40 return NULL;
41
42 eina_hash_add(hash, key, data);
43 return hash;
44} /* _eet_eina_hash_add */
45
46static void
47_eet_eina_hash_free(Eina_Hash *hash)
48{
49 if (hash)
50 eina_hash_free(hash);
51} /* _eet_eina_hash_free */
52
53void
54eet_test_setup_eddc(Eet_Data_Descriptor_Class *eddc)
55{
56 eddc->version = EET_DATA_DESCRIPTOR_CLASS_VERSION;
57 eddc->func.mem_alloc = NULL;
58 eddc->func.mem_free = NULL;
59 eddc->func.str_alloc = NULL;
60 eddc->func.str_free = NULL;
61 eddc->func.list_next = (void *)eina_list_next;
62 eddc->func.list_append = (void *)eina_list_append;
63 eddc->func.list_data = (void *)eina_list_data_get;
64 eddc->func.list_free = (void *)eina_list_free;
65 eddc->func.hash_foreach = (void *)_eet_eina_hash_foreach;
66 eddc->func.hash_add = (void *)_eet_eina_hash_add;
67 eddc->func.hash_free = (void *)_eet_eina_hash_free;
68 eddc->func.str_direct_alloc = (void *)_eet_str_direct_alloc;
69 eddc->func.str_direct_free = (void *)_eet_str_direct_free;
70 eddc->func.array_alloc = NULL;
71 eddc->func.array_free = NULL;
72} /* eet_test_setup_eddc */
73
diff --git a/src/tests/eet/eet_suite.c b/src/tests/eet/eet_suite.c
new file mode 100644
index 0000000000..91ef2a73ae
--- /dev/null
+++ b/src/tests/eet/eet_suite.c
@@ -0,0 +1,2779 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif /* ifdef HAVE_CONFIG_H */
4
5#include <sys/types.h>
6#include <sys/stat.h>
7#include <stdlib.h>
8#include <string.h>
9#include <strings.h>
10#include <stdio.h>
11#include <fcntl.h>
12#include <unistd.h>
13
14#include <Eina.h>
15
16#ifdef EINA_HAVE_THREADS
17#if ((!defined(_WIN32_WCE)) && (!defined(_WIN32)))
18# include <pthread.h>
19# define _EET_INCLUDED_PTHREAD
20#endif
21#endif /* ifdef EINA_HAVE_THREADS */
22
23#include <check.h>
24
25#include "eet_suite.h"
26
27#define CERT_DIR ((*TESTS_SRC_DIR == '/') ? TESTS_SRC_DIR : "src/tests/" TESTS_SRC_DIR)
28
29START_TEST(eet_test_init)
30{
31 int ret;
32
33 ret = eet_init();
34 fail_if(ret != 1);
35
36 ret = eet_shutdown();
37 fail_if(ret != 0);
38}
39END_TEST
40
41typedef struct _Eet_Test_Basic_Type Eet_Test_Basic_Type;
42struct _Eet_Test_Basic_Type
43{
44 char c;
45 short s;
46 int i;
47 long long l;
48 char *str;
49 char *istr;
50 float f1;
51 float f2;
52 double d;
53 unsigned char uc;
54 unsigned short us;
55 unsigned int ui;
56 unsigned long long ul;
57 Eet_Test_Basic_Type *empty;
58 Eet_Test_Basic_Type *with;
59};
60
61#define EET_TEST_CHAR 0x42
62#define EET_TEST_SHORT 0x4224
63#define EET_TEST_INT 0x42211224
64#define EET_TEST_LONG_LONG 0x84CB42211224BC48
65#define EET_TEST_STRING "my little test with escape \\\""
66#define EET_TEST_KEY1 "key1"
67#define EET_TEST_KEY2 "key2"
68#define EET_TEST_FLOAT 123.45689
69#define EET_TEST_FLOAT2 1.0
70#define EET_TEST_FLOAT3 0.25
71#define EET_TEST_FLOAT4 0.0001234
72#define EET_TEST_DOUBLE 123456789.9876543210
73#define EET_TEST_DOUBLE2 1.0
74#define EET_TEST_DOUBLE3 0.25
75#define EET_TEST_FILE_KEY1 "keys/data/1"
76#define EET_TEST_FILE_KEY2 "keys/data/2"
77#define EET_TEST_FILE_IMAGE "keys/images/"
78
79typedef struct _Eet_Test_Image Eet_Test_Image;
80struct _Eet_Test_Image
81{
82 unsigned int w;
83 unsigned int h;
84 int alpha;
85 unsigned int color[64];
86};
87
88static const Eet_Test_Image test_noalpha = {
89 8, 8, 0,
90 {
91 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00,
92 0x000000AA, 0x00110000,
93 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA,
94 0x00110000, 0x00AA0000,
95 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000,
96 0x00AA0000, 0x0000AA00,
97 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000,
98 0x0000AA00, 0x000000AA,
99 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00,
100 0x000000AA, 0x00110000,
101 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA,
102 0x00110000, 0x00AA0000,
103 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000,
104 0x00AA0000, 0x0000AA00,
105 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000,
106 0x0000AA00, 0x000000AA
107 }
108};
109
110static const Eet_Test_Image test_alpha = {
111 8, 8, 1,
112 {
113 0x0FAA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00,
114 0x000000AA, 0x0F110000,
115 0x0000AA00, 0x0F0000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA,
116 0x0F110000, 0x00AA0000,
117 0x000000AA, 0x00110000, 0x0FAA0000, 0x0000AA00, 0x000000AA, 0x0F110000,
118 0x00AA0000, 0x0000AA00,
119 0x00110000, 0x00AA0000, 0x0000AA00, 0x0F0000AA, 0x0F110000, 0x00AA0000,
120 0x0000AA00, 0x000000AA,
121 0x00AA0000, 0x0000AA00, 0x000000AA, 0x0F110000, 0x0FAA0000, 0x0000AA00,
122 0x000000AA, 0x00110000,
123 0x0000AA00, 0x000000AA, 0x0F110000, 0x00AA0000, 0x0000AA00, 0x0F0000AA,
124 0x00110000, 0x00AA0000,
125 0x000000AA, 0x0F110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000,
126 0x0FAA0000, 0x0000AA00,
127 0x0F110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000,
128 0x0000AA00, 0x0F0000AA
129 }
130};
131
132static void
133_eet_test_basic_set(Eet_Test_Basic_Type *res,
134 int i)
135{
136 res->c = EET_TEST_CHAR;
137 res->s = EET_TEST_SHORT;
138 res->i = EET_TEST_INT + i;
139 res->l = EET_TEST_LONG_LONG;
140 res->str = EET_TEST_STRING;
141 res->istr = EET_TEST_STRING;
142 res->f1 = -EET_TEST_FLOAT;
143 res->d = -EET_TEST_DOUBLE;
144 res->f2 = EET_TEST_FLOAT4;
145 res->uc = EET_TEST_CHAR;
146 res->us = EET_TEST_SHORT;
147 res->ui = EET_TEST_INT;
148 res->ul = EET_TEST_LONG_LONG;
149 res->empty = NULL;
150 res->with = NULL;
151
152 if (i == 0)
153 {
154 Eet_Test_Basic_Type *tmp;
155
156 tmp = malloc(sizeof (Eet_Test_Basic_Type));
157 fail_if(!tmp);
158
159 res->with = tmp;
160 tmp->c = EET_TEST_CHAR;
161 tmp->s = EET_TEST_SHORT;
162 tmp->i = EET_TEST_INT + i + 1;
163 tmp->l = EET_TEST_LONG_LONG;
164 tmp->str = EET_TEST_STRING;
165 tmp->istr = EET_TEST_STRING;
166 tmp->f1 = -EET_TEST_FLOAT;
167 tmp->d = -EET_TEST_DOUBLE;
168 tmp->f2 = EET_TEST_FLOAT4;
169 tmp->uc = EET_TEST_CHAR;
170 tmp->us = EET_TEST_SHORT;
171 tmp->ui = EET_TEST_INT;
172 tmp->ul = EET_TEST_LONG_LONG;
173 tmp->empty = NULL;
174 tmp->with = NULL;
175 }
176} /* _eet_test_basic_set */
177
178static void
179_eet_test_basic_check(Eet_Test_Basic_Type *result,
180 int i)
181{
182 float tmp;
183
184 fail_if(result->c != EET_TEST_CHAR);
185 fail_if(result->s != EET_TEST_SHORT);
186 fail_if(result->i != EET_TEST_INT + i);
187 fail_if(result->l != (long long)EET_TEST_LONG_LONG);
188 fail_if(strcmp(result->str, EET_TEST_STRING) != 0);
189 fail_if(strcmp(result->istr, EET_TEST_STRING) != 0);
190 fail_if(result->uc != EET_TEST_CHAR);
191 fail_if(result->us != EET_TEST_SHORT);
192 fail_if(result->ui != EET_TEST_INT);
193 fail_if(result->ul != EET_TEST_LONG_LONG);
194
195 tmp = (result->f1 + EET_TEST_FLOAT);
196 if (tmp < 0)
197 tmp = -tmp;
198
199 fail_if(tmp > 0.005);
200
201 tmp = (result->f2 - EET_TEST_FLOAT4);
202 if (tmp < 0)
203 tmp = -tmp;
204
205 fail_if(tmp > 0.005);
206
207 tmp = (result->d + EET_TEST_DOUBLE);
208 if (tmp < 0)
209 tmp = -tmp;
210
211 fail_if(tmp > 0.00005);
212
213 fail_if(result->empty != NULL);
214 if (i == 0)
215 {
216 Eet_Test_Basic_Type *tmp2;
217
218 tmp2 = result->with;
219 fail_if(tmp2 == NULL);
220
221 fail_if(tmp2->c != EET_TEST_CHAR);
222 fail_if(tmp2->s != EET_TEST_SHORT);
223 fail_if(tmp2->i != EET_TEST_INT + i + 1);
224 fail_if(tmp2->l != (long long)EET_TEST_LONG_LONG);
225 fail_if(strcmp(tmp2->str, EET_TEST_STRING) != 0);
226 fail_if(strcmp(tmp2->istr, EET_TEST_STRING) != 0);
227 fail_if(tmp2->uc != EET_TEST_CHAR);
228 fail_if(tmp2->us != EET_TEST_SHORT);
229 fail_if(tmp2->ui != EET_TEST_INT);
230 fail_if(tmp2->ul != EET_TEST_LONG_LONG);
231 }
232 else
233 fail_if(result->with != NULL);
234} /* _eet_test_basic_check */
235
236static void
237_eet_build_basic_descriptor(Eet_Data_Descriptor *edd)
238{
239 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
240 Eet_Test_Basic_Type,
241 "c",
242 c,
243 EET_T_CHAR);
244 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
245 Eet_Test_Basic_Type,
246 "s",
247 s,
248 EET_T_SHORT);
249 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
250 Eet_Test_Basic_Type,
251 "i",
252 i,
253 EET_T_INT);
254 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
255 Eet_Test_Basic_Type,
256 "l",
257 l,
258 EET_T_LONG_LONG);
259 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
260 Eet_Test_Basic_Type,
261 "str",
262 str,
263 EET_T_STRING);
264 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
265 Eet_Test_Basic_Type,
266 "istr",
267 istr,
268 EET_T_INLINED_STRING);
269 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
270 Eet_Test_Basic_Type,
271 "f1",
272 f1,
273 EET_T_FLOAT);
274 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
275 Eet_Test_Basic_Type,
276 "f2",
277 f2,
278 EET_T_FLOAT);
279 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
280 Eet_Test_Basic_Type,
281 "d",
282 d,
283 EET_T_DOUBLE);
284 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
285 Eet_Test_Basic_Type,
286 "uc",
287 uc,
288 EET_T_UCHAR);
289 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
290 Eet_Test_Basic_Type,
291 "us",
292 us,
293 EET_T_USHORT);
294 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
295 Eet_Test_Basic_Type,
296 "ui",
297 ui,
298 EET_T_UINT);
299 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
300 Eet_Test_Basic_Type,
301 "ul",
302 ul,
303 EET_T_ULONG_LONG);
304
305 EET_DATA_DESCRIPTOR_ADD_SUB(edd, Eet_Test_Basic_Type, "empty", empty, edd);
306 EET_DATA_DESCRIPTOR_ADD_SUB(edd, Eet_Test_Basic_Type, "with", with, edd);
307} /* _eet_build_basic_descriptor */
308
309START_TEST(eet_test_basic_data_type_encoding_decoding)
310{
311 Eet_Data_Descriptor *edd;
312 Eet_Test_Basic_Type *result;
313 Eet_Data_Descriptor_Class eddc;
314 Eet_Test_Basic_Type etbt;
315 void *transfert;
316 int size;
317
318 eet_init();
319
320 _eet_test_basic_set(&etbt, 0);
321
322 eet_test_setup_eddc(&eddc);
323 eddc.name = "Eet_Test_Basic_Type";
324 eddc.size = sizeof(Eet_Test_Basic_Type);
325
326 edd = eet_data_descriptor_stream_new(&eddc);
327 fail_if(!edd);
328
329 _eet_build_basic_descriptor(edd);
330
331 transfert = eet_data_descriptor_encode(edd, &etbt, &size);
332 fail_if(!transfert || size <= 0);
333
334 result = eet_data_descriptor_decode(edd, transfert, size);
335 fail_if(!result);
336
337 _eet_test_basic_check(result, 0);
338
339 free(result->str);
340 free(result);
341
342 eet_data_descriptor_free(edd);
343
344 eet_shutdown();
345}
346END_TEST
347
348typedef struct _Eet_Test_Ex_Type Eet_Test_Ex_Type;
349struct _Eet_Test_Ex_Type
350{
351 char c;
352 short s;
353 int i;
354 unsigned long long l;
355 char *str;
356 char *istr;
357 float f1;
358 float f2;
359 float f3;
360 float f4;
361 double d1;
362 double d2;
363 double d3;
364 double d4;
365 Eina_List *list;
366 Eina_Hash *hash;
367 Eina_List *ilist;
368 Eina_List *slist;
369 Eina_Hash *ihash;
370 Eina_Hash *shash;
371 Eet_Test_Basic_Type sarray1[10];
372 unsigned int sarray2[5];
373 unsigned int varray1_count;
374 unsigned int *varray1;
375 unsigned int varray2_count;
376 Eet_Test_Basic_Type *varray2;
377 unsigned char uc;
378 unsigned short us;
379 unsigned int ui;
380 unsigned long long ul;
381 char *charray[10];
382};
383
384static int i42 = 42;
385static int i7 = 7;
386
387static void
388_eet_build_ex_descriptor(Eet_Data_Descriptor *edd)
389{
390 Eet_Data_Descriptor_Class eddc;
391 Eet_Test_Ex_Type etbt;
392 Eet_Data_Descriptor *eddb;
393
394 eet_test_setup_eddc(&eddc);
395 eddc.name = "Eet_Test_Basic_Type";
396 eddc.size = sizeof(Eet_Test_Basic_Type);
397 eddb = eet_data_descriptor_file_new(&eddc);
398 fail_if(!eddb);
399
400 _eet_build_basic_descriptor(eddb);
401
402 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
403 Eet_Test_Ex_Type,
404 "c",
405 c,
406 EET_T_CHAR);
407 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
408 Eet_Test_Ex_Type,
409 "s",
410 s,
411 EET_T_SHORT);
412 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "i", i, EET_T_INT);
413 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
414 Eet_Test_Ex_Type,
415 "l",
416 l,
417 EET_T_LONG_LONG);
418 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
419 Eet_Test_Ex_Type,
420 "str",
421 str,
422 EET_T_STRING);
423 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
424 Eet_Test_Ex_Type,
425 "istr",
426 istr,
427 EET_T_INLINED_STRING);
428 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
429 Eet_Test_Ex_Type,
430 "f1",
431 f1,
432 EET_T_FLOAT);
433 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
434 Eet_Test_Ex_Type,
435 "f2",
436 f2,
437 EET_T_FLOAT);
438 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
439 Eet_Test_Ex_Type,
440 "f3",
441 f3,
442 EET_T_FLOAT);
443 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
444 Eet_Test_Ex_Type,
445 "f4",
446 f4,
447 EET_T_FLOAT);
448 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
449 Eet_Test_Ex_Type,
450 "d1",
451 d1,
452 EET_T_DOUBLE);
453 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
454 Eet_Test_Ex_Type,
455 "d2",
456 d2,
457 EET_T_DOUBLE);
458 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
459 Eet_Test_Ex_Type,
460 "d3",
461 d3,
462 EET_T_DOUBLE);
463 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
464 Eet_Test_Ex_Type,
465 "d4",
466 d4,
467 EET_T_DOUBLE);
468 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
469 Eet_Test_Ex_Type,
470 "uc",
471 uc,
472 EET_T_UCHAR);
473 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
474 Eet_Test_Ex_Type,
475 "us",
476 us,
477 EET_T_USHORT);
478 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
479 Eet_Test_Ex_Type,
480 "ui",
481 ui,
482 EET_T_UINT);
483 EET_DATA_DESCRIPTOR_ADD_BASIC(edd,
484 Eet_Test_Ex_Type,
485 "ul",
486 ul,
487 EET_T_ULONG_LONG);
488 EET_DATA_DESCRIPTOR_ADD_ARRAY(edd,
489 Eet_Test_Ex_Type,
490 "sarray1",
491 sarray1,
492 eddb);
493 EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY(edd,
494 Eet_Test_Ex_Type,
495 "varray2",
496 varray2,
497 eddb);
498 eet_data_descriptor_element_add(edd,
499 "varray1",
500 EET_T_INT,
501 EET_G_VAR_ARRAY,
502 (char *)(&(etbt.varray1)) - (char *)(&(etbt)),
503 (char *)(&(etbt.varray1_count)) -
504 (char *)(&(etbt)),
505 /* 0, */ NULL,
506 NULL);
507 eet_data_descriptor_element_add(edd, "sarray2", EET_T_INT, EET_G_ARRAY,
508 (char *)(&(etbt.sarray2)) - (char *)(&(etbt)),
509 /* 0, */ sizeof(etbt.sarray2) /
510 sizeof(etbt.sarray2[0]), NULL, NULL);
511 eet_data_descriptor_element_add(edd, "charray", EET_T_STRING, EET_G_ARRAY,
512 (char *)(&(etbt.charray)) - (char *)(&(etbt)),
513 /* 0, */ sizeof(etbt.charray) /
514 sizeof(etbt.charray[0]), NULL, NULL);
515 EET_DATA_DESCRIPTOR_ADD_LIST(edd, Eet_Test_Ex_Type, "list", list, edd);
516 EET_DATA_DESCRIPTOR_ADD_HASH(edd, Eet_Test_Ex_Type, "hash", hash, edd);
517 eet_data_descriptor_element_add(edd, "ilist", EET_T_INT, EET_G_LIST,
518 (char *)(&(etbt.ilist)) - (char *)(&(etbt)),
519 0, /* 0, */ NULL, NULL);
520 eet_data_descriptor_element_add(edd, "ihash", EET_T_INT, EET_G_HASH,
521 (char *)(&(etbt.ihash)) - (char *)(&(etbt)),
522 0, /* 0, */ NULL, NULL);
523 eet_data_descriptor_element_add(edd, "slist", EET_T_STRING, EET_G_LIST,
524 (char *)(&(etbt.slist)) - (char *)(&(etbt)),
525 0, /* 0, */ NULL, NULL);
526 eet_data_descriptor_element_add(edd, "shash", EET_T_STRING, EET_G_HASH,
527 (char *)(&(etbt.shash)) - (char *)(&(etbt)),
528 0, /* 0, */ NULL, NULL);
529} /* _eet_build_ex_descriptor */
530
531static Eet_Test_Ex_Type *
532_eet_test_ex_set(Eet_Test_Ex_Type *res,
533 int offset)
534{
535 unsigned int i;
536
537 if (!res)
538 res = malloc(sizeof(Eet_Test_Ex_Type));
539
540 if (!res)
541 return NULL;
542
543 res->c = EET_TEST_CHAR + offset;
544 res->s = EET_TEST_SHORT + offset;
545 res->i = EET_TEST_INT + offset;
546 res->l = EET_TEST_LONG_LONG + offset;
547 res->str = EET_TEST_STRING;
548 res->istr = EET_TEST_STRING;
549 res->f1 = EET_TEST_FLOAT + offset;
550 res->f2 = -(EET_TEST_FLOAT2 + offset);
551 res->f3 = EET_TEST_FLOAT3 + offset;
552 res->f4 = EET_TEST_FLOAT2 + offset;
553 res->d1 = EET_TEST_DOUBLE + offset;
554 res->d2 = -(EET_TEST_DOUBLE2 + offset);
555 res->d3 = EET_TEST_DOUBLE3 + offset;
556 res->d4 = EET_TEST_DOUBLE2 + offset;
557 res->list = NULL;
558 res->hash = NULL;
559 res->ilist = NULL;
560 res->ihash = NULL;
561 res->slist = NULL;
562 res->shash = NULL;
563 for (i = 0; i < sizeof(res->charray) / sizeof(res->charray[0]); ++i)
564 res->charray[i] = NULL;
565
566 res->varray2 = malloc(sizeof (Eet_Test_Basic_Type) * 10);
567 res->varray1 = malloc(sizeof (int) * 5);
568 fail_if(!res->varray1 || !res->varray2);
569 for (i = 0; i < 10; ++i)
570 {
571 _eet_test_basic_set(res->sarray1 + i, i);
572 _eet_test_basic_set(res->varray2 + i, i);
573 }
574 res->varray2_count = 10;
575 for (i = 0; i < 5; ++i)
576 {
577 res->sarray2[i] = i * 42 + 1;
578 res->varray1[i] = i * 42 + 1;
579 }
580 res->varray1_count = 5;
581
582 res->uc = EET_TEST_CHAR + offset;
583 res->us = EET_TEST_SHORT + offset;
584 res->ui = EET_TEST_INT + offset;
585 res->ul = EET_TEST_LONG_LONG + offset;
586
587 return res;
588} /* _eet_test_ex_set */
589
590static int
591_eet_test_ex_check(Eet_Test_Ex_Type *stuff,
592 int offset)
593{
594 double tmp;
595 unsigned int i;
596
597 if (!stuff)
598 return 1;
599
600 if (stuff->c != EET_TEST_CHAR + offset)
601 return 1;
602
603 if (stuff->s != EET_TEST_SHORT + offset)
604 return 1;
605
606 if (stuff->i != EET_TEST_INT + offset)
607 return 1;
608
609 if (stuff->l != EET_TEST_LONG_LONG + offset)
610 return 1;
611
612 if (strcmp(stuff->str, EET_TEST_STRING) != 0)
613 return 1;
614
615 if (strcmp(stuff->istr, EET_TEST_STRING) != 0)
616 return 1;
617
618 tmp = stuff->f1 - (EET_TEST_FLOAT + offset);
619 if (tmp < 0)
620 tmp = -tmp;
621
622 if (tmp > 0.005)
623 return 1;
624
625 tmp = stuff->d1 - (EET_TEST_DOUBLE + offset);
626 if (tmp < 0)
627 tmp = -tmp;
628
629 if (tmp > 0.00005)
630 return 1;
631
632 if (stuff->f2 != -(EET_TEST_FLOAT2 + offset))
633 return 1;
634
635 if (stuff->d2 != -(EET_TEST_DOUBLE2 + offset))
636 return 1;
637
638 if (stuff->f3 != EET_TEST_FLOAT3 + offset)
639 return 1;
640
641 if (stuff->d3 != EET_TEST_DOUBLE3 + offset)
642 return 1;
643
644 if (stuff->f4 != EET_TEST_FLOAT2 + offset)
645 return 1;
646
647 if (stuff->d4 != EET_TEST_DOUBLE2 + offset)
648 return 1;
649
650 if (stuff->uc != EET_TEST_CHAR + offset)
651 return 1;
652
653 if (stuff->us != EET_TEST_SHORT + offset)
654 return 1;
655
656 if (stuff->ui != (unsigned int)EET_TEST_INT + offset)
657 return 1;
658
659 if (stuff->ul != EET_TEST_LONG_LONG + offset)
660 return 1;
661
662 if (stuff->varray1_count != 5)
663 return 1;
664
665 if (stuff->varray2_count != 10)
666 return 1;
667
668 for (i = 0; i < 5; ++i)
669 if (stuff->sarray2[i] != i * 42 + 1 && stuff->varray1[i] != i * 42 + 1)
670 return 1;
671
672 for (i = 0; i < 10; ++i)
673 {
674 _eet_test_basic_check(stuff->sarray1 + i, i);
675 _eet_test_basic_check(stuff->varray2 + i, i);
676 }
677
678 return 0;
679} /* _eet_test_ex_check */
680
681static Eina_Bool
682func(__UNUSED__ const Eina_Hash *hash,
683 const void *key,
684 void *data,
685 void *fdata)
686{
687 int *res = fdata;
688
689 if (strcmp(key, EET_TEST_KEY1) != 0
690 && strcmp(key, EET_TEST_KEY2) != 0)
691 *res = 1;
692
693 if (_eet_test_ex_check(data, 2))
694 *res = 1;
695
696 return EINA_TRUE;
697} /* func */
698
699static Eina_Bool
700func7(__UNUSED__ const Eina_Hash *hash,
701 __UNUSED__ const void *key,
702 void *data,
703 void *fdata)
704{
705 int *res = fdata;
706 int *val;
707
708 val = data;
709 if (!val)
710 *res = 1;
711
712 if (*val != 7)
713 *res = 1;
714
715 return EINA_TRUE;
716} /* func7 */
717
718START_TEST(eet_test_data_type_encoding_decoding)
719{
720 Eet_Data_Descriptor *edd;
721 Eet_Test_Ex_Type *result;
722 void *transfert;
723 Eet_Data_Descriptor_Class eddc;
724 Eet_Test_Ex_Type etbt;
725 int size;
726 int test;
727
728 eet_init();
729
730 _eet_test_ex_set(&etbt, 0);
731 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
732 etbt.hash = eina_hash_string_superfast_new(NULL);
733 eina_hash_add(etbt.hash, EET_TEST_KEY1, _eet_test_ex_set(NULL, 2));
734 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
735 etbt.ihash = eina_hash_string_superfast_new(NULL);
736 eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7);
737 etbt.slist = eina_list_prepend(NULL, "test");
738 etbt.shash = eina_hash_string_superfast_new(NULL);
739 eina_hash_add(etbt.shash, EET_TEST_KEY1, "test");
740 memset(&etbt.charray, 0, sizeof(etbt.charray));
741 etbt.charray[0] = "test";
742 etbt.charray[5] = "plouf";
743
744 eet_test_setup_eddc(&eddc);
745 eddc.name = "Eet_Test_Ex_Type";
746 eddc.size = sizeof(Eet_Test_Ex_Type);
747
748 edd = eet_data_descriptor_file_new(&eddc);
749 fail_if(!edd);
750
751 _eet_build_ex_descriptor(edd);
752
753 transfert = eet_data_descriptor_encode(edd, &etbt, &size);
754 fail_if(!transfert || size <= 0);
755
756 result = eet_data_descriptor_decode(edd, transfert, size);
757 fail_if(!result);
758
759 fail_if(_eet_test_ex_check(result, 0) != 0);
760 fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1) != 0);
761 fail_if(eina_list_data_get(result->ilist) == NULL);
762 fail_if(*((int *)eina_list_data_get(result->ilist)) != 42);
763 fail_if(eina_list_data_get(result->slist) == NULL);
764 fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0);
765 fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL);
766 fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0);
767 fail_if(strcmp(result->charray[0], "test") != 0);
768 fail_if(strcmp(result->charray[5], "plouf") != 0);
769
770 test = 0;
771 if (result->hash)
772 eina_hash_foreach(result->hash, func, &test);
773
774 fail_if(test != 0);
775 if (result->ihash)
776 eina_hash_foreach(result->ihash, func7, &test);
777
778 fail_if(test != 0);
779
780 eet_shutdown();
781}
782END_TEST
783
784static void
785append_string(void *data,
786 const char *str)
787{
788 char **string = data;
789 int length;
790
791 if (!data)
792 return;
793
794 length = *string ? strlen(*string) : 0;
795 *string = realloc(*string, strlen(str) + length + 1);
796
797 memcpy((*string) + length, str, strlen(str) + 1);
798} /* append_string */
799
800START_TEST(eet_test_data_type_dump_undump)
801{
802 Eet_Data_Descriptor *edd;
803 Eet_Test_Ex_Type *result;
804 Eet_Data_Descriptor_Class eddc;
805 Eet_Test_Ex_Type etbt;
806 char *transfert1;
807 char *transfert2;
808 char *string1;
809 char *string2;
810 int size1;
811 int size2;
812 int test;
813
814 eet_init();
815
816 _eet_test_ex_set(&etbt, 0);
817 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
818 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
819 etbt.hash = eina_hash_string_superfast_new(NULL);
820 eina_hash_add(etbt.hash, EET_TEST_KEY1, _eet_test_ex_set(NULL, 2));
821 etbt.hash = eina_hash_string_superfast_new(NULL);
822 eina_hash_add(etbt.hash, EET_TEST_KEY2, _eet_test_ex_set(NULL, 2));
823 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
824 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
825 etbt.ihash = eina_hash_string_superfast_new(NULL);
826 eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7);
827 etbt.ihash = eina_hash_string_superfast_new(NULL);
828 eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7);
829 etbt.slist = eina_list_prepend(NULL, "test");
830 etbt.shash = eina_hash_string_superfast_new(NULL);
831 eina_hash_add(etbt.shash, EET_TEST_KEY1, "test");
832 memset(&etbt.charray, 0, sizeof(etbt.charray));
833 etbt.charray[0] = "test";
834
835 eet_test_setup_eddc(&eddc);
836 eddc.name = "Eet_Test_Ex_Type";
837 eddc.size = sizeof(Eet_Test_Ex_Type);
838
839 edd = eet_data_descriptor_file_new(&eddc);
840 fail_if(!edd);
841
842 _eet_build_ex_descriptor(edd);
843
844 transfert1 = eet_data_descriptor_encode(edd, &etbt, &size1);
845 fail_if(!transfert1 || size1 <= 0);
846
847 string1 = NULL;
848 eet_data_text_dump(transfert1, size1, append_string, &string1);
849 fail_if(!string1);
850
851 transfert2 = eet_data_text_undump(string1, string1 ? strlen(
852 string1) : 0, &size2);
853 fail_if(!transfert2 && size2 <= 0);
854
855 string2 = NULL;
856 eet_data_text_dump(transfert2, size2, append_string, &string2);
857 fail_if(!string2);
858
859 fail_if(strlen(string2) != strlen(string1));
860
861 result = eet_data_descriptor_decode(edd, transfert2, size2);
862 fail_if(!result);
863
864 fail_if(_eet_test_ex_check(result, 0) != 0);
865 fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1) != 0);
866 fail_if(eina_list_data_get(result->ilist) == NULL);
867 fail_if(*((int *)eina_list_data_get(result->ilist)) != 42);
868 fail_if(eina_list_data_get(result->slist) == NULL);
869 fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0);
870 fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL);
871 fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0);
872 fail_if(strcmp(result->charray[0], "test") != 0);
873
874 test = 0;
875 if (result->hash)
876 eina_hash_foreach(result->hash, func, &test);
877
878 fail_if(test != 0);
879 if (result->ihash)
880 eina_hash_foreach(result->ihash, func7, &test);
881
882 fail_if(test != 0);
883
884 eet_shutdown();
885}
886END_TEST
887START_TEST(eet_file_simple_write)
888{
889 const char *buffer = "Here is a string of data to save !";
890 Eet_File *ef;
891 char *test;
892 char *file = strdup("/tmp/eet_suite_testXXXXXX");
893 int size;
894
895 eet_init();
896
897 fail_if(!(file = tmpnam(file)));
898
899 fail_if(eet_mode_get(NULL) != EET_FILE_MODE_INVALID);
900
901 ef = eet_open(file, EET_FILE_MODE_WRITE);
902 fail_if(!ef);
903
904 fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 1));
905 fail_if(!eet_alias(ef, "keys/alias", "keys/tests", 0));
906 fail_if(!eet_alias(ef, "keys/alias2", "keys/alias", 1));
907
908 fail_if(eet_mode_get(ef) != EET_FILE_MODE_WRITE);
909
910 fail_if(eet_list(ef, "*", &size) != NULL);
911 fail_if(eet_num_entries(ef) != -1);
912
913 eet_close(ef);
914
915 /* Test read of simple file */
916 ef = eet_open(file, EET_FILE_MODE_READ);
917 fail_if(!ef);
918
919 test = eet_read(ef, "keys/tests", &size);
920 fail_if(!test);
921 fail_if(size != (int)strlen(buffer) + 1);
922
923 fail_if(memcmp(test, buffer, strlen(buffer) + 1) != 0);
924
925 test = eet_read(ef, "keys/alias2", &size);
926 fail_if(!test);
927 fail_if(size != (int)strlen(buffer) + 1);
928
929 fail_if(eet_read_direct(ef, "key/alias2", &size));
930
931 fail_if(eet_mode_get(ef) != EET_FILE_MODE_READ);
932 fail_if(eet_num_entries(ef) != 3);
933
934 eet_close(ef);
935
936 /* Test eet cache system */
937 ef = eet_open(file, EET_FILE_MODE_READ);
938 fail_if(!ef);
939
940 test = eet_read(ef, "keys/tests", &size);
941 fail_if(!test);
942 fail_if(size != (int)strlen(buffer) + 1);
943
944 fail_if(memcmp(test, buffer, strlen(buffer) + 1) != 0);
945
946 eet_close(ef);
947
948 fail_if(unlink(file) != 0);
949
950 eet_shutdown();
951} /* START_TEST */
952
953END_TEST
954START_TEST(eet_file_data_test)
955{
956 Eet_Data_Descriptor *edd;
957 Eet_Test_Ex_Type *result;
958 Eet_Dictionary *ed;
959 Eet_File *ef;
960 char **list;
961 char *file = strdup("/tmp/eet_suite_testXXXXXX");
962 Eet_Data_Descriptor_Class eddc;
963 Eet_Test_Ex_Type etbt;
964 int size;
965 int test;
966
967 eet_init();
968
969 _eet_test_ex_set(&etbt, 0);
970 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
971 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
972 etbt.hash = eina_hash_string_superfast_new(NULL);
973 eina_hash_add(etbt.hash, EET_TEST_KEY1, _eet_test_ex_set(NULL, 2));
974 etbt.hash = eina_hash_string_superfast_new(NULL);
975 eina_hash_add(etbt.hash, EET_TEST_KEY2, _eet_test_ex_set(NULL, 2));
976 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
977 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
978 etbt.ihash = eina_hash_string_superfast_new(NULL);
979 eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7);
980 etbt.ihash = eina_hash_string_superfast_new(NULL);
981 eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7);
982 etbt.slist = eina_list_prepend(NULL, "test");
983 etbt.shash = eina_hash_string_superfast_new(NULL);
984 eina_hash_add(etbt.shash, EET_TEST_KEY1, "test");
985 memset(&etbt.charray, 0, sizeof(etbt.charray));
986 etbt.charray[0] = "test";
987
988 eet_test_setup_eddc(&eddc);
989 eddc.name = "Eet_Test_Ex_Type";
990 eddc.size = sizeof(Eet_Test_Ex_Type);
991
992 edd = eet_data_descriptor_file_new(&eddc);
993 fail_if(!edd);
994
995 _eet_build_ex_descriptor(edd);
996
997 fail_if(!(file = tmpnam(file)));
998
999 /* Insert an error in etbt. */
1000 etbt.i = 0;
1001
1002 /* Save the encoded data in a file. */
1003 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
1004 fail_if(!ef);
1005
1006 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0));
1007
1008 result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1);
1009 fail_if(!result);
1010
1011 fail_if(eet_mode_get(ef) != EET_FILE_MODE_READ_WRITE);
1012
1013 /* Test string space. */
1014 ed = eet_dictionary_get(ef);
1015
1016 fail_if(!eet_dictionary_string_check(ed, result->str));
1017 fail_if(eet_dictionary_string_check(ed, result->istr));
1018
1019 eet_close(ef);
1020
1021 /* Attempt to replace etbt by the correct one. */
1022 etbt.i = EET_TEST_INT;
1023
1024 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
1025 fail_if(!ef);
1026
1027 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0));
1028
1029 result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1);
1030 fail_if(!result);
1031
1032 /* Test the resulting data. */
1033 fail_if(_eet_test_ex_check(result, 0) != 0);
1034
1035 eet_close(ef);
1036
1037 /* Read back the data. */
1038 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
1039 fail_if(!ef);
1040
1041 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY2, &etbt, 0));
1042
1043 result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1);
1044 fail_if(!result);
1045
1046 /* Test string space. */
1047 ed = eet_dictionary_get(ef);
1048 fail_if(!ed);
1049
1050 fail_if(!eet_dictionary_string_check(ed, result->str));
1051 fail_if(eet_dictionary_string_check(ed, result->istr));
1052
1053 /* Test the resulting data. */
1054 fail_if(_eet_test_ex_check(result, 0) != 0);
1055 fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1) != 0);
1056 fail_if(eina_list_data_get(result->ilist) == NULL);
1057 fail_if(*((int *)eina_list_data_get(result->ilist)) != 42);
1058 fail_if(eina_list_data_get(result->slist) == NULL);
1059 fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0);
1060 fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL);
1061 fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0);
1062 fail_if(strcmp(result->charray[0], "test") != 0);
1063
1064 test = 0;
1065 if (result->hash)
1066 eina_hash_foreach(result->hash, func, &test);
1067
1068 fail_if(test != 0);
1069 if (result->ihash)
1070 eina_hash_foreach(result->ihash, func7, &test);
1071
1072 fail_if(test != 0);
1073
1074 list = eet_list(ef, "keys/*", &size);
1075 fail_if(eet_num_entries(ef) != 2);
1076 fail_if(size != 2);
1077 fail_if(!(strcmp(list[0],
1078 EET_TEST_FILE_KEY1) == 0 &&
1079 strcmp(list[1], EET_TEST_FILE_KEY2) == 0)
1080 && !(strcmp(list[0],
1081 EET_TEST_FILE_KEY2) == 0 &&
1082 strcmp(list[1], EET_TEST_FILE_KEY1) == 0));
1083 free(list);
1084
1085 fail_if(eet_delete(ef, NULL) != 0);
1086 fail_if(eet_delete(NULL, EET_TEST_FILE_KEY1) != 0);
1087 fail_if(eet_delete(ef, EET_TEST_FILE_KEY1) == 0);
1088
1089 list = eet_list(ef, "keys/*", &size);
1090 fail_if(size != 1);
1091 fail_if(eet_num_entries(ef) != 1);
1092
1093 /* Test some more wrong case */
1094 fail_if(eet_data_read(ef, edd, "plop") != NULL);
1095 fail_if(eet_data_read(ef, edd, EET_TEST_FILE_KEY1) != NULL);
1096
1097 /* Reinsert and reread data */
1098 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0));
1099 fail_if(eet_data_read(ef, edd, EET_TEST_FILE_KEY1) == NULL);
1100 fail_if(eet_read_direct(ef, EET_TEST_FILE_KEY1, &size) == NULL);
1101
1102 eet_close(ef);
1103
1104 fail_if(unlink(file) != 0);
1105
1106 eet_shutdown();
1107} /* START_TEST */
1108
1109END_TEST
1110START_TEST(eet_file_data_dump_test)
1111{
1112 Eet_Data_Descriptor *edd;
1113 Eet_Test_Ex_Type *result;
1114 Eet_Data_Descriptor_Class eddc;
1115 Eet_Test_Ex_Type etbt;
1116 Eet_File *ef;
1117 char *string1;
1118 char *file = strdup("/tmp/eet_suite_testXXXXXX");
1119 int test;
1120
1121 eet_init();
1122
1123 _eet_test_ex_set(&etbt, 0);
1124 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
1125 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
1126 etbt.hash = eina_hash_string_superfast_new(NULL);
1127 eina_hash_add(etbt.hash, EET_TEST_KEY1, _eet_test_ex_set(NULL, 2));
1128 eina_hash_add(etbt.hash, EET_TEST_KEY2, _eet_test_ex_set(NULL, 2));
1129 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
1130 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
1131 etbt.ihash = eina_hash_string_superfast_new(NULL);
1132 eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7);
1133 eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7);
1134 etbt.slist = eina_list_prepend(NULL, "test");
1135 etbt.shash = eina_hash_string_superfast_new(NULL);
1136 eina_hash_add(etbt.shash, EET_TEST_KEY1, "test");
1137 memset(&etbt.charray, 0, sizeof(etbt.charray));
1138 etbt.charray[0] = "test";
1139
1140 eet_eina_file_data_descriptor_class_set(&eddc, sizeof (eddc),
1141 "Eet_Test_Ex_Type",
1142 sizeof(Eet_Test_Ex_Type));
1143
1144 edd = eet_data_descriptor_file_new(&eddc);
1145 fail_if(!edd);
1146
1147 _eet_build_ex_descriptor(edd);
1148
1149 fail_if(!(file = tmpnam(file)));
1150
1151 /* Save the encoded data in a file. */
1152 ef = eet_open(file, EET_FILE_MODE_WRITE);
1153 fail_if(!ef);
1154
1155 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0));
1156
1157 eet_close(ef);
1158
1159 /* Use dump/undump in the middle */
1160 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
1161 fail_if(!ef);
1162
1163 string1 = NULL;
1164 fail_if(eet_data_dump(ef, EET_TEST_FILE_KEY1, append_string, &string1) != 1);
1165 fail_if(eet_delete(ef, EET_TEST_FILE_KEY1) == 0);
1166 fail_if(!eet_data_undump(ef, EET_TEST_FILE_KEY1, string1, strlen(string1), 1));
1167
1168 eet_close(ef);
1169
1170 /* Test the correctness of the reinsertion. */
1171 ef = eet_open(file, EET_FILE_MODE_READ);
1172 fail_if(!ef);
1173
1174 result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1);
1175 fail_if(!result);
1176
1177 eet_close(ef);
1178
1179 /* Test the resulting data. */
1180 fail_if(_eet_test_ex_check(result, 0) != 0);
1181 fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1) != 0);
1182 fail_if(eina_list_data_get(result->ilist) == NULL);
1183 fail_if(*((int *)eina_list_data_get(result->ilist)) != 42);
1184 fail_if(eina_list_data_get(result->slist) == NULL);
1185 fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0);
1186 fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL);
1187 fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0);
1188 fail_if(strcmp(result->charray[0], "test") != 0);
1189
1190 test = 0;
1191 if (result->hash)
1192 eina_hash_foreach(result->hash, func, &test);
1193
1194 fail_if(test != 0);
1195 if (result->ihash)
1196 eina_hash_foreach(result->ihash, func7, &test);
1197
1198 fail_if(test != 0);
1199
1200 fail_if(unlink(file) != 0);
1201
1202 eet_shutdown();
1203} /* START_TEST */
1204
1205END_TEST
1206START_TEST(eet_image)
1207{
1208 Eet_File *ef;
1209 char *file = strdup("/tmp/eet_suite_testXXXXXX");
1210 unsigned int *data;
1211 int compress;
1212 int quality;
1213 int result;
1214 int lossy;
1215 int alpha;
1216 unsigned int w;
1217 unsigned int h;
1218
1219 eet_init();
1220
1221 fail_if(!(file = tmpnam(file)));
1222
1223 /* Save the encoded data in a file. */
1224 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
1225 fail_if(!ef);
1226
1227 result = eet_data_image_write(ef,
1228 EET_TEST_FILE_IMAGE "0",
1229 test_noalpha.color,
1230 test_noalpha.w,
1231 test_noalpha.h,
1232 test_noalpha.alpha,
1233 0,
1234 100,
1235 0);
1236 fail_if(result == 0);
1237
1238 result = eet_data_image_write(ef,
1239 EET_TEST_FILE_IMAGE "1",
1240 test_noalpha.color,
1241 test_noalpha.w,
1242 test_noalpha.h,
1243 test_noalpha.alpha,
1244 5,
1245 100,
1246 0);
1247 fail_if(result == 0);
1248
1249 result = eet_data_image_write(ef,
1250 EET_TEST_FILE_IMAGE "2",
1251 test_noalpha.color,
1252 test_noalpha.w,
1253 test_noalpha.h,
1254 test_noalpha.alpha,
1255 9,
1256 100,
1257 0);
1258 fail_if(result == 0);
1259
1260 result = eet_data_image_write(ef,
1261 EET_TEST_FILE_IMAGE "3",
1262 test_noalpha.color,
1263 test_noalpha.w,
1264 test_noalpha.h,
1265 test_noalpha.alpha,
1266 0,
1267 100,
1268 1);
1269 fail_if(result == 0);
1270
1271 result = eet_data_image_write(ef,
1272 EET_TEST_FILE_IMAGE "4",
1273 test_noalpha.color,
1274 test_noalpha.w,
1275 test_noalpha.h,
1276 test_noalpha.alpha,
1277 0,
1278 60,
1279 1);
1280 fail_if(result == 0);
1281
1282 result = eet_data_image_write(ef,
1283 EET_TEST_FILE_IMAGE "5",
1284 test_noalpha.color,
1285 test_noalpha.w,
1286 test_noalpha.h,
1287 test_noalpha.alpha,
1288 0,
1289 10,
1290 1);
1291 fail_if(result == 0);
1292
1293 result = eet_data_image_write(ef,
1294 EET_TEST_FILE_IMAGE "6",
1295 test_noalpha.color,
1296 test_noalpha.w,
1297 test_noalpha.h,
1298 test_noalpha.alpha,
1299 0,
1300 0,
1301 1);
1302 fail_if(result == 0);
1303
1304 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "7", test_alpha.color,
1305 test_alpha.w, test_alpha.h, test_alpha.alpha,
1306 9, 100, 0);
1307 fail_if(result == 0);
1308
1309 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "8", test_alpha.color,
1310 test_alpha.w, test_alpha.h, test_alpha.alpha,
1311 0, 80, 1);
1312 fail_if(result == 0);
1313
1314 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "9", test_alpha.color,
1315 test_alpha.w, test_alpha.h, test_alpha.alpha,
1316 0, 100, 1);
1317 fail_if(result == 0);
1318
1319 data = eet_data_image_read(ef,
1320 EET_TEST_FILE_IMAGE "2",
1321 &w,
1322 &h,
1323 &alpha,
1324 &compress,
1325 &quality,
1326 &lossy);
1327 fail_if(data == NULL);
1328 fail_if(w != test_noalpha.w);
1329 fail_if(h != test_noalpha.h);
1330 fail_if(alpha != test_noalpha.alpha);
1331 fail_if(compress != 9);
1332 fail_if(lossy != 0);
1333 fail_if(data[0] != test_noalpha.color[0]);
1334 free(data);
1335
1336 result = eet_data_image_header_read(ef,
1337 EET_TEST_FILE_IMAGE "2",
1338 &w,
1339 &h,
1340 &alpha,
1341 &compress,
1342 &quality,
1343 &lossy);
1344 fail_if(result == 0);
1345 fail_if(w != test_noalpha.w);
1346 fail_if(h != test_noalpha.h);
1347 fail_if(alpha != test_noalpha.alpha);
1348 fail_if(compress != 9);
1349 fail_if(lossy != 0);
1350
1351 eet_close(ef);
1352
1353 /* Test read of image */
1354 ef = eet_open(file, EET_FILE_MODE_READ);
1355 fail_if(!ef);
1356
1357 result = eet_data_image_header_read(ef,
1358 EET_TEST_FILE_IMAGE "0",
1359 &w,
1360 &h,
1361 &alpha,
1362 &compress,
1363 &quality,
1364 &lossy);
1365 fail_if(result == 0);
1366 fail_if(w != test_noalpha.w);
1367 fail_if(h != test_noalpha.h);
1368 fail_if(alpha != test_noalpha.alpha);
1369 fail_if(compress != 0);
1370 fail_if(lossy != 0);
1371
1372 data = malloc(w * h * 4);
1373 fail_if(data == NULL);
1374 result = eet_data_image_read_to_surface(ef,
1375 EET_TEST_FILE_IMAGE "0",
1376 4,
1377 4,
1378 data,
1379 2,
1380 2,
1381 w * 4,
1382 &alpha,
1383 &compress,
1384 &quality,
1385 &lossy);
1386 fail_if(result != 1);
1387 fail_if(alpha != test_noalpha.alpha);
1388 fail_if(compress != 0);
1389 fail_if(quality != 100);
1390 fail_if(lossy != 0);
1391 fail_if(data[0] != test_noalpha.color[4 + 4 * w]);
1392 free(data);
1393
1394 data = malloc(w * h * 4);
1395 fail_if(data == NULL);
1396 result = eet_data_image_read_to_surface(ef,
1397 EET_TEST_FILE_IMAGE "0",
1398 0,
1399 0,
1400 data,
1401 w,
1402 h,
1403 w * 4,
1404 &alpha,
1405 &compress,
1406 &quality,
1407 &lossy);
1408 fail_if(result != 1);
1409 fail_if(alpha != test_noalpha.alpha);
1410 fail_if(compress != 0);
1411 fail_if(quality != 100);
1412 fail_if(lossy != 0);
1413 fail_if(data[0] != test_noalpha.color[0]);
1414 free(data);
1415
1416 data = eet_data_image_read(ef,
1417 EET_TEST_FILE_IMAGE "1",
1418 &w,
1419 &h,
1420 &alpha,
1421 &compress,
1422 &quality,
1423 &lossy);
1424 fail_if(data == NULL);
1425 fail_if(w != test_noalpha.w);
1426 fail_if(h != test_noalpha.h);
1427 fail_if(alpha != test_noalpha.alpha);
1428 fail_if(compress != 5);
1429 fail_if(quality != 100);
1430 fail_if(lossy != 0);
1431 fail_if(data[0] != test_noalpha.color[0]);
1432 free(data);
1433
1434 data = eet_data_image_read(ef,
1435 EET_TEST_FILE_IMAGE "2",
1436 &w,
1437 &h,
1438 &alpha,
1439 &compress,
1440 &quality,
1441 &lossy);
1442 fail_if(data == NULL);
1443 fail_if(w != test_noalpha.w);
1444 fail_if(h != test_noalpha.h);
1445 fail_if(alpha != test_noalpha.alpha);
1446 fail_if(compress != 9);
1447 fail_if(lossy != 0);
1448 fail_if(data[0] != test_noalpha.color[0]);
1449 free(data);
1450
1451 data = eet_data_image_read(ef,
1452 EET_TEST_FILE_IMAGE "3",
1453 &w,
1454 &h,
1455 &alpha,
1456 &compress,
1457 &quality,
1458 &lossy);
1459 fail_if(data == NULL);
1460 fail_if(w != test_noalpha.w);
1461 fail_if(h != test_noalpha.h);
1462 fail_if(alpha != test_noalpha.alpha);
1463 fail_if(lossy != 1);
1464 free(data);
1465
1466 data = eet_data_image_read(ef,
1467 EET_TEST_FILE_IMAGE "5",
1468 &w,
1469 &h,
1470 &alpha,
1471 &compress,
1472 &quality,
1473 &lossy);
1474 fail_if(data == NULL);
1475 fail_if(w != test_noalpha.w);
1476 fail_if(h != test_noalpha.h);
1477 fail_if(alpha != test_noalpha.alpha);
1478 fail_if(lossy != 1);
1479 free(data);
1480
1481 data = eet_data_image_read(ef,
1482 EET_TEST_FILE_IMAGE "6",
1483 &w,
1484 &h,
1485 &alpha,
1486 &compress,
1487 &quality,
1488 &lossy);
1489 fail_if(data == NULL);
1490 fail_if(w != test_noalpha.w);
1491 fail_if(h != test_noalpha.h);
1492 fail_if(alpha != test_noalpha.alpha);
1493 fail_if(lossy != 1);
1494 free(data);
1495
1496 result = eet_data_image_header_read(ef,
1497 EET_TEST_FILE_IMAGE "7",
1498 &w,
1499 &h,
1500 &alpha,
1501 &compress,
1502 &quality,
1503 &lossy);
1504 fail_if(result == 0);
1505 fail_if(w != test_alpha.w);
1506 fail_if(h != test_alpha.h);
1507 fail_if(alpha != test_alpha.alpha);
1508 fail_if(compress != 9);
1509 fail_if(lossy != 0);
1510
1511 data = eet_data_image_read(ef,
1512 EET_TEST_FILE_IMAGE "7",
1513 &w,
1514 &h,
1515 &alpha,
1516 &compress,
1517 &quality,
1518 &lossy);
1519 fail_if(data == NULL);
1520 fail_if(w != test_alpha.w);
1521 fail_if(h != test_alpha.h);
1522 fail_if(alpha != test_alpha.alpha);
1523 fail_if(compress != 9);
1524 fail_if(lossy != 0);
1525 fail_if(data[0] != test_alpha.color[0]);
1526 free(data);
1527
1528 result = eet_data_image_header_read(ef,
1529 EET_TEST_FILE_IMAGE "9",
1530 &w,
1531 &h,
1532 &alpha,
1533 &compress,
1534 &quality,
1535 &lossy);
1536 fail_if(result == 0);
1537 fail_if(w != test_alpha.w);
1538 fail_if(h != test_alpha.h);
1539 fail_if(alpha != test_alpha.alpha);
1540 fail_if(lossy != 1);
1541
1542 data = eet_data_image_read(ef,
1543 EET_TEST_FILE_IMAGE "9",
1544 &w,
1545 &h,
1546 &alpha,
1547 &compress,
1548 &quality,
1549 &lossy);
1550 fail_if(data == NULL);
1551 fail_if(w != test_alpha.w);
1552 fail_if(h != test_alpha.h);
1553 fail_if(alpha != test_alpha.alpha);
1554 fail_if(lossy != 1);
1555 free(data);
1556
1557 eet_close(ef);
1558
1559 fail_if(unlink(file) != 0);
1560
1561 eet_shutdown();
1562} /* START_TEST */
1563
1564END_TEST
1565
1566#define IM0 0x00112233
1567#define IM1 0x44556677
1568#define IM2 0x8899aabb
1569#define IM3 0xccddeeff
1570
1571START_TEST(eet_small_image)
1572{
1573 char *file = strdup("/tmp/eet_suite_testXXXXXX");
1574 unsigned int image[4];
1575 unsigned int *data;
1576 Eet_File *ef;
1577 unsigned int w;
1578 unsigned int h;
1579 int alpha;
1580 int compression;
1581 int quality;
1582 int lossy;
1583 int result;
1584
1585 image[0] = IM0;
1586 image[1] = IM1;
1587 image[2] = IM2;
1588 image[3] = IM3;
1589
1590 eet_init();
1591
1592 fail_if(!(file = tmpnam(file)));
1593
1594 ef = eet_open(file, EET_FILE_MODE_WRITE);
1595 fail_if(!ef);
1596
1597 result = eet_data_image_write(ef, "/images/test", image, 2, 2, 1, 9, 100, 0);
1598 fail_if(result == 0);
1599
1600 eet_close(ef);
1601
1602 ef = eet_open(file, EET_FILE_MODE_READ);
1603 fail_if(!ef);
1604
1605 data = (unsigned int *)eet_data_image_read(ef,
1606 "/images/test",
1607 &w,
1608 &h,
1609 &alpha,
1610 &compression,
1611 &quality,
1612 &lossy);
1613 fail_if(data == NULL);
1614
1615 eet_close(ef);
1616
1617 fail_if(unlink(file) != 0);
1618
1619 fail_if(data[0] != IM0);
1620 fail_if(data[1] != IM1);
1621 fail_if(data[2] != IM2);
1622 fail_if(data[3] != IM3);
1623
1624 free(data);
1625
1626 eet_shutdown();
1627} /* START_TEST */
1628
1629END_TEST
1630START_TEST(eet_identity_simple)
1631{
1632 const char *buffer = "Here is a string of data to save !";
1633 const void *tmp;
1634 Eet_File *ef;
1635 Eet_Key *k;
1636 FILE *noread;
1637 char *test;
1638 char *file = strdup("/tmp/eet_suite_testXXXXXX");
1639 int size;
1640 int fd;
1641
1642 eet_init();
1643
1644 fail_if(!(file = tmpnam(file)));
1645 fail_if(chdir(CERT_DIR));
1646 fail_if(!(noread = fopen("/dev/null", "w")));
1647
1648 /* Sign an eet file. */
1649 ef = eet_open(file, EET_FILE_MODE_WRITE);
1650 fail_if(!ef);
1651
1652 fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 0));
1653
1654 k = eet_identity_open("cert.pem", "key.pem", NULL);
1655 fail_if(!k);
1656
1657 fail_if(eet_identity_set(ef, k) != EET_ERROR_NONE);
1658 eet_identity_print(k, noread);
1659
1660 eet_close(ef);
1661
1662 /* Open a signed file. */
1663 ef = eet_open(file, EET_FILE_MODE_READ);
1664 fail_if(!ef);
1665
1666 test = eet_read(ef, "keys/tests", &size);
1667 fail_if(!test);
1668 fail_if(size != (int)strlen(buffer) + 1);
1669
1670 fail_if(memcmp(test, buffer, strlen(buffer) + 1) != 0);
1671
1672 tmp = eet_identity_x509(ef, &size);
1673 fail_if(tmp == NULL);
1674
1675 eet_identity_certificate_print(tmp, size, noread);
1676
1677 eet_close(ef);
1678
1679 /* As we are changing file contain in less than 1s, this could get unnoticed
1680 by eet cache system. */
1681 eet_clearcache();
1682
1683 /* Corrupting the file. */
1684 fd = open(file, O_WRONLY);
1685 fail_if(fd < 0);
1686
1687 fail_if(lseek(fd, 200, SEEK_SET) != 200);
1688 fail_if(write(fd, "42", 2) != 2);
1689 fail_if(lseek(fd, 50, SEEK_SET) != 50);
1690 fail_if(write(fd, "42", 2) != 2);
1691 fail_if(lseek(fd, 88, SEEK_SET) != 88);
1692 fail_if(write(fd, "42", 2) != 2);
1693
1694 close(fd);
1695
1696 /* Attempt to open a modified file. */
1697 ef = eet_open(file, EET_FILE_MODE_READ);
1698 fail_if(ef);
1699
1700 fail_if(unlink(file) != 0);
1701
1702 eet_shutdown();
1703} /* START_TEST */
1704
1705END_TEST
1706START_TEST(eet_identity_open_simple)
1707{
1708 Eet_Key *k = NULL;
1709
1710 eet_init();
1711
1712 fail_if(chdir(CERT_DIR));
1713
1714 k = eet_identity_open("cert.pem", "key.pem", NULL);
1715 fail_if(!k);
1716
1717 if (k)
1718 eet_identity_close(k);
1719
1720 eet_shutdown();
1721} /* START_TEST */
1722
1723END_TEST
1724START_TEST(eet_identity_open_pkcs8)
1725{
1726 Eet_Key *k = NULL;
1727
1728 eet_init();
1729
1730 fail_if(chdir(CERT_DIR));
1731
1732 k = eet_identity_open("cert.pem", "key_enc_none.pem", NULL);
1733 fail_if(!k);
1734
1735 if (k)
1736 eet_identity_close(k);
1737
1738 eet_shutdown();
1739} /* START_TEST */
1740
1741END_TEST
1742
1743static int
1744pass_get(char *pass,
1745 int size,
1746 __UNUSED__ int rwflags,
1747 __UNUSED__ void *u)
1748{
1749 memset(pass, 0, size);
1750
1751 if ((int)strlen("password") > size)
1752 return 0;
1753
1754 snprintf(pass, size, "%s", "password");
1755 return strlen(pass);
1756} /* pass_get */
1757
1758static int
1759badpass_get(char *pass,
1760 int size,
1761 __UNUSED__ int rwflags,
1762 __UNUSED__ void *u)
1763{
1764 memset(pass, 0, size);
1765
1766 if ((int)strlen("bad password") > size)
1767 return 0;
1768
1769 snprintf(pass, size, "%s", "bad password");
1770 return strlen(pass);
1771} /* badpass_get */
1772
1773START_TEST(eet_identity_open_pkcs8_enc)
1774{
1775 Eet_Key *k = NULL;
1776
1777 eet_init();
1778
1779 fail_if(chdir(CERT_DIR));
1780
1781 k = eet_identity_open("cert.pem", "key_enc.pem", NULL);
1782 fail_if(k);
1783
1784 if (k)
1785 eet_identity_close(k);
1786
1787 k = eet_identity_open("cert.pem", "key_enc.pem", &badpass_get);
1788 fail_if(k);
1789
1790 if (k)
1791 eet_identity_close(k);
1792
1793 k = eet_identity_open("cert.pem", "key_enc.pem", &pass_get);
1794 fail_if(!k);
1795
1796 if (k)
1797 eet_identity_close(k);
1798
1799 eet_shutdown();
1800}
1801END_TEST
1802START_TEST(eet_cipher_decipher_simple)
1803{
1804 const char *buffer = "Here is a string of data to save !";
1805 const char *key = "This is a crypto key";
1806 const char *key_bad = "This is another crypto key";
1807 Eet_File *ef;
1808 char *test;
1809 char *file = strdup("/tmp/eet_suite_testXXXXXX");
1810 int size;
1811
1812 eet_init();
1813
1814 fail_if(!(file = tmpnam(file)));
1815 fail_if(chdir(CERT_DIR));
1816
1817 /* Crypt an eet file. */
1818 ef = eet_open(file, EET_FILE_MODE_WRITE);
1819 fail_if(!ef);
1820
1821 fail_if(!eet_write_cipher(ef, "keys/tests", buffer, strlen(buffer) + 1, 0,
1822 key));
1823
1824 eet_close(ef);
1825
1826 /* Decrypt an eet file. */
1827 ef = eet_open(file, EET_FILE_MODE_READ);
1828 fail_if(!ef);
1829
1830 test = eet_read_cipher(ef, "keys/tests", &size, key);
1831 fail_if(!test);
1832 fail_if(size != (int)strlen(buffer) + 1);
1833
1834 fail_if(memcmp(test, buffer, strlen(buffer) + 1) != 0);
1835
1836 eet_close(ef);
1837
1838 /* Decrypt an eet file. */
1839 ef = eet_open(file, EET_FILE_MODE_READ);
1840 fail_if(!ef);
1841
1842 test = eet_read_cipher(ef, "keys/tests", &size, key_bad);
1843
1844 if (size == (int)strlen(buffer) + 1)
1845 fail_if(memcmp(test, buffer, strlen(buffer) + 1) == 0);
1846
1847 eet_close(ef);
1848
1849 fail_if(unlink(file) != 0);
1850
1851 eet_shutdown();
1852} /* START_TEST */
1853
1854END_TEST
1855
1856#ifdef EINA_HAVE_THREADS
1857
1858static Eina_Bool open_worker_stop;
1859
1860# ifdef _EET_INCLUDED_PTHREAD
1861
1862static void *
1863open_close_worker(void *path)
1864{
1865 while (!open_worker_stop)
1866 {
1867 Eet_File *ef = eet_open((char const *)path, EET_FILE_MODE_READ);
1868 if (ef == NULL)
1869 pthread_exit("eet_open() failed");
1870 else
1871 {
1872 Eet_Error err_code = eet_close(ef);
1873 if (err_code != EET_ERROR_NONE)
1874 pthread_exit("eet_close() failed");
1875 }
1876 }
1877
1878 pthread_exit(NULL);
1879} /* open_close_worker */
1880
1881# else /* ifdef _EET_INCLUDED_PTHREAD */
1882
1883static unsigned int __stdcall
1884open_close_worker(void *path)
1885{
1886 while (!open_worker_stop)
1887 {
1888 Eet_File *ef = eet_open((char const *)path, EET_FILE_MODE_READ);
1889 if (ef == NULL)
1890 _endthreadex(-1);
1891 else
1892 {
1893 Eet_Error err_code = eet_close(ef);
1894 if (err_code != EET_ERROR_NONE)
1895 _endthreadex(-2);
1896 }
1897 }
1898
1899 _endthreadex(0);
1900} /* open_close_worker */
1901
1902# endif /* ifdef _EET_INCLUDED_PTHREAD */
1903
1904START_TEST(eet_cache_concurrency)
1905{
1906 char *file = strdup("/tmp/eet_suite_testXXXXXX");
1907 const char *buffer = "test data";
1908 Eet_File *ef;
1909 void *thread_ret;
1910 unsigned int n;
1911# ifdef _EET_INCLUDED_PTHREAD
1912 pthread_t thread;
1913# else /* ifdef _EET_INCLUDED_PTHREAD */
1914 uintptr_t thread;
1915 unsigned int thread_id;
1916 DWORD ret;
1917# endif /* ifdef _EET_INCLUDED_PTHREAD */
1918
1919 eet_init();
1920 eina_threads_init();
1921
1922 /* create a file to test with */
1923 fail_if(!(file = tmpnam(file)));
1924 ef = eet_open(file, EET_FILE_MODE_WRITE);
1925 fail_if(!ef);
1926 fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 0));
1927
1928 /* start a thread that repeatedly opens and closes a file */
1929 open_worker_stop = 0;
1930# ifdef _EET_INCLUDED_PTHREAD
1931 pthread_create(&thread, NULL, open_close_worker, file);
1932# else /* ifdef _EET_INCLUDED_PTHREAD */
1933 thread = _beginthreadex(NULL, 0, open_close_worker, file, 0, &thread_id);
1934# endif /* ifdef _EET_INCLUDED_PTHREAD */
1935 /* clear the cache repeatedly in this thread */
1936 for (n = 0; n < 20000; ++n)
1937 {
1938 eet_clearcache();
1939 }
1940
1941 /* join the other thread, and fail if it returned an error message */
1942 open_worker_stop = 1;
1943# ifdef _EET_INCLUDED_PTHREAD
1944 fail_if(pthread_join(thread, &thread_ret) != 0);
1945 fail_unless(thread_ret == NULL, (char const *)thread_ret);
1946# else /* ifdef _EET_INCLUDED_PTHREAD */
1947 ret = WaitForSingleObject((HANDLE)thread, INFINITE);
1948 fail_if(ret != WAIT_OBJECT_0);
1949 fail_if(GetExitCodeThread((HANDLE)thread, &ret) == FALSE);
1950 fail_if(ret != 0);
1951# endif /* ifdef _EET_INCLUDED_PTHREAD */
1952
1953 fail_if(unlink(file) != 0);
1954
1955 eina_threads_shutdown();
1956 eet_shutdown();
1957}
1958END_TEST
1959
1960#endif /* EINA_HAVE_THREADS */
1961
1962typedef struct _Eet_Connection_Data Eet_Connection_Data;
1963struct _Eet_Connection_Data
1964{
1965 Eet_Connection *conn;
1966 Eet_Data_Descriptor *edd;
1967 Eina_Bool test;
1968};
1969
1970static Eina_Bool
1971_eet_connection_read(const void *eet_data,
1972 size_t size,
1973 void *user_data)
1974{
1975 Eet_Connection_Data *dt = user_data;
1976 Eet_Test_Ex_Type *result;
1977 Eet_Node *node;
1978 int test;
1979
1980 result = eet_data_descriptor_decode(dt->edd, eet_data, size);
1981 node = eet_data_node_decode_cipher(eet_data, NULL, size);
1982
1983 /* Test the resulting data. */
1984 fail_if(!node);
1985 fail_if(_eet_test_ex_check(result, 0) != 0);
1986 fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1) != 0);
1987 fail_if(eina_list_data_get(result->ilist) == NULL);
1988 fail_if(*((int *)eina_list_data_get(result->ilist)) != 42);
1989 fail_if(eina_list_data_get(result->slist) == NULL);
1990 fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0);
1991 fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL);
1992 fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0);
1993 fail_if(strcmp(result->charray[0], "test") != 0);
1994
1995 test = 0;
1996 if (result->hash)
1997 eina_hash_foreach(result->hash, func, &test);
1998
1999 fail_if(test != 0);
2000 if (result->ihash)
2001 eina_hash_foreach(result->ihash, func7, &test);
2002
2003 fail_if(test != 0);
2004
2005 if (!dt->test)
2006 {
2007 dt->test = EINA_TRUE;
2008 fail_if(!eet_connection_node_send(dt->conn, node, NULL));
2009 }
2010
2011 return EINA_TRUE;
2012} /* _eet_connection_read */
2013
2014static Eina_Bool
2015_eet_connection_write(const void *data,
2016 size_t size,
2017 void *user_data)
2018{
2019 Eet_Connection_Data *dt = user_data;
2020 int still;
2021
2022 if (!dt->test)
2023 {
2024 int step = size / 3;
2025
2026 eet_connection_received(dt->conn, data, step);
2027 eet_connection_received(dt->conn, (char *)data + step, step);
2028 size -= 2 * step;
2029 still = eet_connection_received(dt->conn, (char *)data + 2 * step, size);
2030 }
2031 else
2032 still = eet_connection_received(dt->conn, data, size);
2033
2034 fail_if(still);
2035
2036 return EINA_TRUE;
2037} /* _eet_connection_write */
2038
2039START_TEST(eet_connection_check)
2040{
2041 Eet_Connection *conn;
2042 Eet_Data_Descriptor *edd;
2043 Eet_Data_Descriptor_Class eddc;
2044 Eet_Connection_Data ecd;
2045 Eet_Test_Ex_Type etbt;
2046 Eina_Bool on_going;
2047
2048 eet_init();
2049
2050 _eet_test_ex_set(&etbt, 0);
2051 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
2052 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
2053 etbt.hash = eina_hash_string_superfast_new(NULL);
2054 eina_hash_add(etbt.hash, EET_TEST_KEY1, _eet_test_ex_set(NULL, 2));
2055 eina_hash_add(etbt.hash, EET_TEST_KEY2, _eet_test_ex_set(NULL, 2));
2056 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
2057 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
2058 etbt.ihash = eina_hash_string_superfast_new(NULL);
2059 eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7);
2060 eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7);
2061 etbt.slist = eina_list_prepend(NULL, "test");
2062 etbt.shash = eina_hash_string_superfast_new(NULL);
2063 eina_hash_add(etbt.shash, EET_TEST_KEY1, "test");
2064 memset(&etbt.charray, 0, sizeof(etbt.charray));
2065 etbt.charray[0] = "test";
2066
2067 eet_eina_file_data_descriptor_class_set(&eddc, sizeof (eddc),
2068 "Eet_Test_Ex_Type",
2069 sizeof(Eet_Test_Ex_Type));
2070
2071 edd = eet_data_descriptor_file_new(&eddc);
2072 fail_if(!edd);
2073
2074 _eet_build_ex_descriptor(edd);
2075
2076 /* Create a connection. */
2077 conn = eet_connection_new(_eet_connection_read, _eet_connection_write, &ecd);
2078 fail_if(!conn);
2079
2080 /* Init context. */
2081 ecd.test = EINA_FALSE;
2082 ecd.conn = conn;
2083 ecd.edd = edd;
2084
2085 /* Test the connection. */
2086 fail_if(!eet_connection_send(conn, edd, &etbt, NULL));
2087
2088 fail_if(!ecd.test);
2089
2090 fail_if(!eet_connection_close(conn, &on_going));
2091
2092 fail_if(on_going);
2093
2094 eet_shutdown();
2095}
2096END_TEST
2097
2098struct _Eet_5FP
2099{
2100 Eina_F32p32 fp32;
2101 Eina_F16p16 fp16;
2102 Eina_F8p24 fp8;
2103 Eina_F32p32 f1;
2104 Eina_F32p32 f0;
2105};
2106typedef struct _Eet_5FP Eet_5FP;
2107
2108struct _Eet_5DBL
2109{
2110 double fp32;
2111 double fp16;
2112 float fp8;
2113 double f1;
2114 double f0;
2115};
2116typedef struct _Eet_5DBL Eet_5DBL;
2117
2118START_TEST(eet_fp)
2119{
2120 Eet_Data_Descriptor_Class eddc;
2121 Eet_Data_Descriptor *edd_5FP;
2122 Eet_Data_Descriptor *edd_5DBL;
2123 Eet_5FP origin;
2124 Eet_5DBL *convert;
2125 Eet_5FP *build;
2126 void *blob;
2127 int size;
2128
2129 eet_init();
2130
2131 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_5FP);
2132 edd_5FP = eet_data_descriptor_stream_new(&eddc);
2133
2134 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp32", fp32, EET_T_F32P32);
2135 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp16", fp16, EET_T_F16P16);
2136 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp8", fp8, EET_T_F8P24);
2137 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "f1", f1, EET_T_F32P32);
2138 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "f0", f0, EET_T_F32P32);
2139
2140 eet_eina_stream_data_descriptor_class_set(&eddc, sizeof (eddc), "Eet_5FP", sizeof (Eet_5DBL));
2141 edd_5DBL = eet_data_descriptor_stream_new(&eddc);
2142
2143 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp32", fp32, EET_T_DOUBLE);
2144 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp16", fp16, EET_T_DOUBLE);
2145 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp8", fp8, EET_T_FLOAT);
2146 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "f1", f1, EET_T_DOUBLE);
2147 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "f0", f0, EET_T_DOUBLE);
2148
2149 origin.fp32 = eina_f32p32_double_from(1.125);
2150 origin.fp16 = eina_f16p16_int_from(2000);
2151 origin.fp8 = eina_f8p24_int_from(125);
2152 origin.f1 = eina_f32p32_int_from(1);
2153 origin.f0 = 0;
2154
2155 blob = eet_data_descriptor_encode(edd_5FP, &origin, &size);
2156 fail_if(!blob || size <= 0);
2157
2158 build = eet_data_descriptor_decode(edd_5FP, blob, size);
2159 fail_if(!build);
2160
2161 convert = eet_data_descriptor_decode(edd_5DBL, blob, size);
2162 fail_if(!convert);
2163
2164 fail_if(build->fp32 != eina_f32p32_double_from(1.125));
2165 fail_if(build->fp16 != eina_f16p16_int_from(2000));
2166 fail_if(build->fp8 != eina_f8p24_int_from(125));
2167 fail_if(build->f1 != eina_f32p32_int_from(1));
2168 fail_if(build->f0 != 0);
2169
2170 fail_if(convert->fp32 != 1.125);
2171 fail_if(convert->fp16 != 2000);
2172 fail_if(convert->fp8 != 125);
2173 fail_if(convert->f1 != 1);
2174 fail_if(convert->f0 != 0);
2175
2176 eet_shutdown();
2177}
2178END_TEST
2179START_TEST(eet_file_fp)
2180{
2181 char *file = strdup("/tmp/eet_suite_testXXXXXX");
2182 Eet_Data_Descriptor_Class eddc;
2183 Eet_Data_Descriptor *edd_5FP;
2184 Eet_Data_Descriptor *edd_5DBL;
2185 Eet_File *ef;
2186 Eet_5FP origin;
2187 Eet_5DBL *convert;
2188 Eet_5FP *build;
2189
2190 eet_init();
2191
2192 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_5FP);
2193 edd_5FP = eet_data_descriptor_file_new(&eddc);
2194
2195 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp32", fp32, EET_T_F32P32);
2196 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp16", fp16, EET_T_F16P16);
2197 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp8", fp8, EET_T_F8P24);
2198 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "f1", f1, EET_T_F32P32);
2199 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "f0", f0, EET_T_F32P32);
2200
2201 eet_eina_file_data_descriptor_class_set(&eddc, sizeof (eddc), "Eet_5FP", sizeof (Eet_5DBL));
2202 edd_5DBL = eet_data_descriptor_file_new(&eddc);
2203
2204 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp32", fp32, EET_T_DOUBLE);
2205 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp16", fp16, EET_T_DOUBLE);
2206 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp8", fp8, EET_T_FLOAT);
2207 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "f1", f1, EET_T_DOUBLE);
2208 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "f0", f0, EET_T_DOUBLE);
2209
2210 origin.fp32 = eina_f32p32_double_from(1.125);
2211 origin.fp16 = eina_f16p16_int_from(2000);
2212 origin.fp8 = eina_f8p24_int_from(125);
2213 origin.f1 = eina_f32p32_int_from(1);
2214 origin.f0 = 0;
2215
2216 fail_if(!(file = tmpnam(file)));
2217
2218 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
2219 fail_if(!ef);
2220
2221 fail_if(!eet_data_write(ef, edd_5FP, EET_TEST_FILE_KEY1, &origin, 1));
2222
2223 build = eet_data_read(ef, edd_5FP, EET_TEST_FILE_KEY1);
2224 fail_if(!build);
2225
2226 convert = eet_data_read(ef, edd_5DBL, EET_TEST_FILE_KEY1);
2227 fail_if(!convert);
2228
2229 fail_if(build->fp32 != eina_f32p32_double_from(1.125));
2230 fail_if(build->fp16 != eina_f16p16_int_from(2000));
2231 fail_if(build->fp8 != eina_f8p24_int_from(125));
2232 fail_if(build->f1 != eina_f32p32_int_from(1));
2233 fail_if(build->f0 != 0);
2234
2235 fail_if(convert->fp32 != 1.125);
2236 fail_if(convert->fp16 != 2000);
2237 fail_if(convert->fp8 != 125);
2238 fail_if(convert->f1 != 1);
2239 fail_if(convert->f0 != 0);
2240
2241 eet_close(ef);
2242
2243 fail_if(unlink(file) != 0);
2244
2245 eet_shutdown();
2246} /* START_TEST */
2247
2248END_TEST
2249
2250typedef struct _Eet_Union_Test Eet_Union_Test;
2251typedef struct _Eet_Variant_Test Eet_Variant_Test;
2252typedef struct _Eet_Variant_Type Eet_Variant_Type;
2253typedef struct _Eet_Inherit_Test1 Eet_Inherit_Test1;
2254typedef struct _Eet_Inherit_Test2 Eet_Inherit_Test2;
2255typedef struct _Eet_Inherit_Test3 Eet_Inherit_Test3;
2256typedef struct _Eet_St1 Eet_St1;
2257typedef struct _Eet_St2 Eet_St2;
2258typedef struct _Eet_St3 Eet_St3;
2259typedef struct _Eet_List Eet_List;
2260
2261typedef enum _Eet_Union
2262{
2263 EET_UNKNOWN,
2264 EET_ST1,
2265 EET_ST2,
2266 EET_ST3
2267} Eet_Union;
2268
2269struct
2270{
2271 Eet_Union u;
2272 const char *name;
2273} eet_mapping[] = {
2274 { EET_ST1, "ST1" },
2275 { EET_ST2, "ST2" },
2276 { EET_ST3, "ST3" },
2277 { EET_UNKNOWN, NULL }
2278};
2279
2280struct _Eet_St1
2281{
2282 double val1;
2283 int stuff;
2284 char *s1;
2285};
2286
2287struct _Eet_St2
2288{
2289 Eina_Bool b1;
2290 unsigned long long v1;
2291};
2292
2293struct _Eet_St3
2294{
2295 int boby;
2296};
2297
2298struct _Eet_Union_Test
2299{
2300 Eet_Union type;
2301
2302 union {
2303 Eet_St1 st1;
2304 Eet_St2 st2;
2305 Eet_St3 st3;
2306 } u;
2307};
2308
2309struct _Eet_Variant_Type
2310{
2311 const char *type;
2312 Eina_Bool unknow : 1;
2313};
2314
2315struct _Eet_Variant_Test
2316{
2317 Eet_Variant_Type t;
2318
2319 void *data;
2320 Eina_List *data_list;
2321};
2322
2323struct _Eet_Inherit_Test1
2324{
2325 Eet_Union type;
2326 Eet_St1 st1;
2327};
2328struct _Eet_Inherit_Test2
2329{
2330 Eet_Union type;
2331 Eet_St2 st2;
2332};
2333struct _Eet_Inherit_Test3
2334{
2335 Eet_Union type;
2336 Eet_St3 st3;
2337};
2338
2339struct _Eet_List
2340{
2341 Eina_List *list;
2342};
2343
2344static const char *
2345_eet_union_type_get(const void *data,
2346 Eina_Bool *unknow)
2347{
2348 const Eet_Union *u = data;
2349 int i;
2350
2351 if (unknow)
2352 *unknow = EINA_FALSE;
2353
2354 for (i = 0; eet_mapping[i].name != NULL; ++i)
2355 if (*u == eet_mapping[i].u)
2356 return eet_mapping[i].name;
2357
2358 if (unknow)
2359 *unknow = EINA_TRUE;
2360
2361 return NULL;
2362} /* _eet_union_type_get */
2363
2364static Eina_Bool
2365_eet_union_type_set(const char *type,
2366 void *data,
2367 Eina_Bool unknow)
2368{
2369 Eet_Union *u = data;
2370 int i;
2371
2372 if (unknow)
2373 return EINA_FALSE;
2374
2375 for (i = 0; eet_mapping[i].name != NULL; ++i)
2376 if (strcmp(eet_mapping[i].name, type) == 0)
2377 {
2378 *u = eet_mapping[i].u;
2379 return EINA_TRUE;
2380 }
2381
2382 return EINA_FALSE;
2383} /* _eet_union_type_set */
2384
2385static const char *
2386_eet_variant_type_get(const void *data,
2387 Eina_Bool *unknow)
2388{
2389 const Eet_Variant_Type *type = data;
2390 int i;
2391
2392 if (unknow)
2393 *unknow = type->unknow;
2394
2395 for (i = 0; eet_mapping[i].name != NULL; ++i)
2396 if (strcmp(type->type, eet_mapping[i].name) == 0)
2397 return eet_mapping[i].name;
2398
2399 if (unknow)
2400 *unknow = EINA_FALSE;
2401
2402 return type->type;
2403} /* _eet_variant_type_get */
2404
2405static Eina_Bool
2406_eet_variant_type_set(const char *type,
2407 void *data,
2408 Eina_Bool unknow)
2409{
2410 Eet_Variant_Type *vt = data;
2411
2412 vt->type = type;
2413 vt->unknow = unknow;
2414 return EINA_TRUE;
2415} /* _eet_variant_type_set */
2416
2417static Eet_Data_Descriptor *
2418_eet_st1_dd(void)
2419{
2420 Eet_Data_Descriptor_Class eddc;
2421 Eet_Data_Descriptor *res;
2422
2423 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_St1);
2424 res = eet_data_descriptor_stream_new(&eddc);
2425 EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St1, "val1", val1, EET_T_DOUBLE);
2426 EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St1, "stuff", stuff, EET_T_INT);
2427 EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St1, "s1", s1, EET_T_STRING);
2428
2429 return res;
2430} /* _eet_st1_dd */
2431
2432static void
2433_eet_st1_set(Eet_St1 *st1,
2434 int i)
2435{
2436 st1->val1 = EET_TEST_DOUBLE;
2437 st1->stuff = EET_TEST_INT + i;
2438 st1->s1 = EET_TEST_STRING;
2439} /* _eet_st1_set */
2440
2441static void
2442_eet_st1_cmp(Eet_St1 *st1,
2443 int i)
2444{
2445 double tmp;
2446
2447 fail_if(!st1);
2448
2449 tmp = st1->val1 - EET_TEST_DOUBLE;
2450 if (tmp < 0)
2451 tmp = -tmp;
2452
2453 fail_if(tmp > 0.005);
2454 fail_if(st1->stuff != EET_TEST_INT + i);
2455 fail_if(strcmp(st1->s1, EET_TEST_STRING));
2456} /* _eet_st1_cmp */
2457
2458static Eet_Data_Descriptor *
2459_eet_st2_dd(void)
2460{
2461 Eet_Data_Descriptor_Class eddc;
2462 Eet_Data_Descriptor *res;
2463
2464 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_St2);
2465 res = eet_data_descriptor_stream_new(&eddc);
2466 EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St2, "b1", b1, EET_T_UCHAR);
2467 EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St2, "v1", v1, EET_T_ULONG_LONG);
2468
2469 return res;
2470} /* _eet_st2_dd */
2471
2472static void
2473_eet_st2_set(Eet_St2 *st2,
2474 int i)
2475{
2476 st2->b1 = EINA_TRUE;
2477 st2->v1 = EET_TEST_LONG_LONG + i;
2478} /* _eet_st2_set */
2479
2480static void
2481_eet_st2_cmp(Eet_St2 *st2,
2482 int i)
2483{
2484 fail_if(!st2->b1);
2485 fail_if(st2->v1 != EET_TEST_LONG_LONG + i);
2486} /* _eet_st2_cmp */
2487
2488static Eet_Data_Descriptor *
2489_eet_st3_dd(void)
2490{
2491 Eet_Data_Descriptor_Class eddc;
2492 Eet_Data_Descriptor *res;
2493
2494 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_St3);
2495 res = eet_data_descriptor_stream_new(&eddc);
2496 EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St3, "boby", boby, EET_T_INT);
2497
2498 return res;
2499} /* _eet_st3_dd */
2500
2501static void
2502_eet_st3_set(Eet_St3 *st3,
2503 int i)
2504{
2505 st3->boby = EET_TEST_INT + i;
2506} /* _eet_st3_set */
2507
2508static void
2509_eet_st3_cmp(Eet_St3 *st3,
2510 int i)
2511{
2512 fail_if(st3->boby != EET_TEST_INT + i);
2513} /* _eet_st3_cmp */
2514
2515START_TEST(eet_test_union)
2516{
2517 Eet_Union_Test *eut;
2518 Eet_List *l;
2519 Eet_Data_Descriptor_Class eddc;
2520 Eet_Data_Descriptor *edd;
2521 Eet_Data_Descriptor *unified;
2522 Eet_Data_Descriptor *m;
2523 void *blob;
2524 int size;
2525 int i;
2526
2527 eina_init();
2528 eet_init();
2529
2530 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_Union_Test);
2531 edd = eet_data_descriptor_stream_new(&eddc);
2532
2533 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_Union_Test);
2534 m = eet_data_descriptor_stream_new(&eddc);
2535
2536 eddc.version = EET_DATA_DESCRIPTOR_CLASS_VERSION;
2537 eddc.func.type_get = _eet_union_type_get;
2538 eddc.func.type_set = _eet_union_type_set;
2539 unified = eet_data_descriptor_stream_new(&eddc);
2540
2541 EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST1", _eet_st1_dd());
2542 EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST2", _eet_st2_dd());
2543 EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST3", _eet_st3_dd());
2544
2545 EET_DATA_DESCRIPTOR_ADD_UNION(edd, Eet_Union_Test, "u", u, type, unified);
2546
2547 EET_DATA_DESCRIPTOR_ADD_LIST(m, Eet_List, "list", list, edd);
2548
2549 l = calloc(1, sizeof (Eet_List));
2550
2551#define EUT_NEW(Type_Index) \
2552 eut = calloc(1, sizeof (Eet_Union_Test)); \
2553 eut->type = EET_ST ## Type_Index; \
2554 _eet_st ## Type_Index ## _set(&(eut->u.st ## Type_Index), i);
2555
2556 for (i = 0; i < 3; ++i)
2557 {
2558 EUT_NEW(1);
2559 l->list = eina_list_append(l->list, eut);
2560
2561 EUT_NEW(2);
2562 l->list = eina_list_append(l->list, eut);
2563
2564 EUT_NEW(3);
2565 l->list = eina_list_append(l->list, eut);
2566 }
2567
2568 blob = eet_data_descriptor_encode(m, l, &size);
2569 fail_if(!blob || size <= 0);
2570
2571 l = eet_data_descriptor_decode(m, blob, size);
2572 fail_if(!l);
2573
2574 fail_if(eina_list_count(l->list) != 9);
2575
2576#define EUT_CMP(Type_Index) \
2577 eut = eina_list_nth(l->list, i * 3 + Type_Index - 1); \
2578 fail_if(eut->type != EET_ST ## Type_Index); \
2579 _eet_st ## Type_Index ## _cmp(&(eut->u.st ## Type_Index), i);
2580
2581 for (i = 0; i < 3; ++i)
2582 {
2583 EUT_CMP(1);
2584 EUT_CMP(2);
2585 EUT_CMP(3);
2586 }
2587
2588 eet_shutdown();
2589 eina_shutdown();
2590}
2591END_TEST
2592START_TEST(eet_test_variant)
2593{
2594 Eet_Variant_Test *evt;
2595 Eet_List *l;
2596 Eet_St1 *st1;
2597 Eet_St2 *st2;
2598 Eet_St3 *st3;
2599 Eet_Data_Descriptor_Class eddc;
2600 Eet_Data_Descriptor *edd;
2601 Eet_Data_Descriptor *unified;
2602 Eet_Data_Descriptor *m;
2603 void *blob;
2604 int size;
2605 int i;
2606
2607 eina_init();
2608 eet_init();
2609
2610 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_Variant_Test);
2611 edd = eet_data_descriptor_stream_new(&eddc);
2612
2613 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_Variant_Test);
2614 m = eet_data_descriptor_stream_new(&eddc);
2615
2616 eddc.version = EET_DATA_DESCRIPTOR_CLASS_VERSION;
2617 eddc.func.type_get = _eet_variant_type_get;
2618 eddc.func.type_set = _eet_variant_type_set;
2619 unified = eet_data_descriptor_stream_new(&eddc);
2620
2621 EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST1", _eet_st1_dd());
2622 EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST2", _eet_st2_dd());
2623 EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST3", _eet_st3_dd());
2624
2625 EET_DATA_DESCRIPTOR_ADD_VARIANT(edd,
2626 Eet_Variant_Test,
2627 "data",
2628 data,
2629 t,
2630 unified);
2631
2632 unified = eet_data_descriptor_stream_new(&eddc);
2633 eet_data_descriptor_element_add(unified, "ST1",
2634 EET_T_UNKNOW, EET_G_LIST,
2635 0, 0, NULL, _eet_st1_dd());
2636 eet_data_descriptor_element_add(unified, "ST2",
2637 EET_T_UNKNOW, EET_G_LIST,
2638 0, 0, NULL, _eet_st2_dd());
2639
2640 EET_DATA_DESCRIPTOR_ADD_VARIANT(edd, Eet_Variant_Test,
2641 "data_list", data_list, t, unified);
2642
2643 EET_DATA_DESCRIPTOR_ADD_LIST(m, Eet_List, "list", list, edd);
2644
2645 l = calloc(1, sizeof (Eet_List));
2646
2647#define EVT_NEW(Type_Index) \
2648 evt = calloc(1, sizeof (Eet_Variant_Test)); \
2649 evt->t.type = eet_mapping[Type_Index - 1].name; \
2650 st ## Type_Index = calloc(1, sizeof (Eet_St ## Type_Index)); \
2651 _eet_st ## Type_Index ## _set(st ## Type_Index, i); \
2652 evt->data = st ## Type_Index;
2653
2654 for (i = 0; i < 3; ++i)
2655 {
2656 EVT_NEW(1);
2657 l->list = eina_list_append(l->list, evt);
2658
2659 st1 = calloc(1, sizeof (Eet_St1));
2660 _eet_st1_set(st1, i);
2661 evt->data_list = eina_list_append(evt->data_list, st1);
2662
2663 EVT_NEW(2);
2664 l->list = eina_list_append(l->list, evt);
2665
2666 EVT_NEW(3);
2667 l->list = eina_list_append(l->list, evt);
2668 }
2669
2670 blob = eet_data_descriptor_encode(m, l, &size);
2671 fail_if(!blob || size <= 0);
2672
2673 l = eet_data_descriptor_decode(m, blob, size);
2674 fail_if(!l);
2675
2676 fail_if(eina_list_count(l->list) != 9);
2677
2678#define EVT_CMP(Type_Index) \
2679 evt = eina_list_nth(l->list, i * 3 + Type_Index - 1); \
2680 fail_if(strcmp(evt->t.type, eet_mapping[Type_Index - 1].name) != 0); \
2681 _eet_st ## Type_Index ## _cmp(evt->data, i);
2682
2683 for (i = 0; i < 3; ++i)
2684 {
2685 EVT_CMP(1);
2686
2687 fail_if(!evt->data_list);
2688 fail_if(eina_list_count(evt->data_list) != 1);
2689
2690 st1 = eina_list_data_get(evt->data_list);
2691 _eet_st1_cmp(st1, i);
2692
2693 EVT_CMP(2);
2694 EVT_CMP(3);
2695 }
2696
2697 eet_shutdown();
2698 eina_shutdown();
2699} /* START_TEST */
2700
2701END_TEST
2702
2703Suite *
2704eet_suite(void)
2705{
2706 Suite *s;
2707 TCase *tc;
2708
2709 s = suite_create("Eet");
2710
2711 tc = tcase_create("Eet_Init");
2712 tcase_add_test(tc, eet_test_init);
2713 suite_add_tcase(s, tc);
2714
2715 tc = tcase_create("Eet Data Encoding/Decoding");
2716 tcase_add_test(tc, eet_test_basic_data_type_encoding_decoding);
2717 tcase_add_test(tc, eet_test_data_type_encoding_decoding);
2718 tcase_add_test(tc, eet_test_data_type_dump_undump);
2719 tcase_add_test(tc, eet_fp);
2720 tcase_add_test(tc, eet_test_union);
2721 tcase_add_test(tc, eet_test_variant);
2722 suite_add_tcase(s, tc);
2723
2724 tc = tcase_create("Eet File");
2725 tcase_add_test(tc, eet_file_simple_write);
2726 tcase_add_test(tc, eet_file_data_test);
2727 tcase_add_test(tc, eet_file_data_dump_test);
2728 tcase_add_test(tc, eet_file_fp);
2729 suite_add_tcase(s, tc);
2730
2731 tc = tcase_create("Eet Image");
2732 tcase_add_test(tc, eet_image);
2733 tcase_add_test(tc, eet_small_image);
2734 suite_add_tcase(s, tc);
2735
2736#ifdef HAVE_SIGNATURE
2737 tc = tcase_create("Eet Identity");
2738 tcase_add_test(tc, eet_identity_simple);
2739 tcase_add_test(tc, eet_identity_open_simple);
2740 tcase_add_test(tc, eet_identity_open_pkcs8);
2741 tcase_add_test(tc, eet_identity_open_pkcs8_enc);
2742 suite_add_tcase(s, tc);
2743#endif /* ifdef HAVE_SIGNATURE */
2744
2745#ifdef HAVE_CIPHER
2746 tc = tcase_create("Eet Cipher");
2747 tcase_add_test(tc, eet_cipher_decipher_simple);
2748 suite_add_tcase(s, tc);
2749#endif /* ifdef HAVE_CIPHER */
2750
2751#ifdef EINA_HAVE_THREADS
2752 tc = tcase_create("Eet Cache");
2753 tcase_add_test(tc, eet_cache_concurrency);
2754 suite_add_tcase(s, tc);
2755#endif /* ifdef EFL_HAVE_THREADS */
2756
2757 tc = tcase_create("Eet Connection");
2758 tcase_add_test(tc, eet_connection_check);
2759 suite_add_tcase(s, tc);
2760
2761 return s;
2762} /* eet_suite */
2763
2764int
2765main(void)
2766{
2767 Suite *s;
2768 SRunner *sr;
2769 int failed_count;
2770
2771 s = eet_suite();
2772 sr = srunner_create(s);
2773 srunner_run_all(sr, CK_ENV);
2774 failed_count = srunner_ntests_failed(sr);
2775 srunner_free(sr);
2776
2777 return (failed_count == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
2778} /* main */
2779
diff --git a/src/tests/eet/eet_suite.h b/src/tests/eet/eet_suite.h
new file mode 100644
index 0000000000..c5c91aaee1
--- /dev/null
+++ b/src/tests/eet/eet_suite.h
@@ -0,0 +1,9 @@
1#ifndef _EET_SUITE_H
2# define _EET_SUITE_H
3
4#include "Eet.h"
5
6void
7eet_test_setup_eddc(Eet_Data_Descriptor_Class *eddc);
8
9#endif /* _EET_SUITE_H */
diff --git a/src/tests/eet/key.pem b/src/tests/eet/key.pem
new file mode 100644
index 0000000000..74763ca8c8
--- /dev/null
+++ b/src/tests/eet/key.pem
@@ -0,0 +1,15 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIICXAIBAAKBgQDIhOPOnkTinjxtP+t/Q+F00w0fV0kVqdcamc6uz/o41kRW2fzF
3lSFc5HODEZvN1DqJWz4++i4zNdHLHmlQISuxvQh6dnbq+GpVr3Qlzx+UPizzhUvY
4DMdCc/RGXhxzh2Si8iXSkpqLfs5bsCUy3tPNUUVMMzSnLeia1VRv+0piEwIDAQAB
5AoGAfLLHyNJ8HEIzae16UmawaqplWrw5YxOABbbo5aXJAledoDVoEKexW8dmXngw
64Eu/K3RmvVtwJ8CsexiqfX5jYMU+YKRbww6Vqr/punIUhiEHVarHMFKG9yo14qSa
7z2xPgXvC5p7/Rhci+rAUp36S5kIHch5sLhEEcJayymyzDyECQQD/5B3JdpcovrSI
8+nyZ8Iub2+I3f3uox6m1DKxHead26ICoIr7VCnPV5J1gLIB2MofVCbKhmy4PNi5a
90QdvazJfAkEAyJq9Y+9SQ4sCOVDrFklJxhXuZE4WbnR32XsBdnQ9dauo0E2vDVkv
106mHnzMWroTjLv4hH5nufE5NvMo8PNGB0zQJAFOKkf737JmsyRv/Szamxa14t/4Ob
11LzJkqo9HPGo0feMKJS74zmCVBb8sDR50ubD0HzI0bzZAMyOj8uuepLxmFwJAH+RR
125bhfeLN52AjgRvvBycckzjeH42mKwD2I/v794l43CV7ATLv4HSgRhQGMBqaT5dBR
13tffDU4Zl8EDEJwyKpQJBAJ2NNacURTyavU699QJOIdGAsA4KXici8H3PuuWMtHLR
14RKdPFeaCRn+9p7Tglf0rH9hUGOpUXHYD3+ECt6gnVDc=
15-----END RSA PRIVATE KEY-----
diff --git a/src/tests/eet/key_enc.pem b/src/tests/eet/key_enc.pem
new file mode 100644
index 0000000000..83c1ba235b
--- /dev/null
+++ b/src/tests/eet/key_enc.pem
@@ -0,0 +1,17 @@
1-----BEGIN ENCRYPTED PRIVATE KEY-----
2MIICxjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQILLqDZE1i0Y8CAggA
3MBQGCCqGSIb3DQMHBAjwbnSdTCCDOASCAoB0rMuSIXrzqFQnCexMkC9A5jyd+HvC
42UV6EWIfFU4yBvp+2dfHg6RKUoZ0wGk8FxAkaAj+boVwf16PPXXQ70AQBb0iGeb4
5YLdjDF2zSoIK3SbsWrhAfJhSMbcMftEZnLTYxLSkTv5R8jb0IPybVNTqFf+KmGav
6DwyRVQrdAxIYdJSPwd61Fhs1VqzptmQ8DLKHy35X1fIro3py4jncBhsuqf6H3yj1
7ZFuzCPnwB8unASgbTPD43yObrjyWTjbTtp59WavVdnNS+m7QNW+OfxznHUUJXtMz
8/EniglUhR1Uf75wpMpQIPfC77Cary0Y4iLGQZiF1C0WjQzMBufckJFJVRFGfkkMl
9ijlaijLUYMqENJ6wsyK5lihsoBCzIDoqI375s9pdeln8sd33Yu+L/Gu4Xo8Bh5cM
106mlo9WUgw5KibmlZHGEAGdKxcvL0ywswuwQ6yhwcdvCAt6MfrWJNpksa9JmpXJi8
11c21lHwnoyG1DgSqY5VhRyitfnuY3Jegj+7njhooiAJM9w7fxpafN9oxiaJBvPFqd
12lfJ42Pj5rkjjVqXOJX7Cf7sF85tW7ygwdGWyXvHn2fhQ+vjaDtZalry//Xytet4r
13lvTerO6M6WVMk2yM7vdeBU7c74LVIJmwGR6d837OPax1V+Z9yq6zDuJAQ3l9mtmu
14gowV3xInTFRsnSOQcYW5y8dNnugR9FBh8f1NI7SPyW0reeVbPXXhRxg+TyogIXhh
15yAfWJ6dDLZ31EVCdqRKxK7b9u2r3dsuaiwT1jFg59Eu2AifFi0j7aDA1lGIKoj3C
16cPDwJd8weC+UoWpWX/O4KOpaU62Rwt5wRoOxELG6lHy7cOjZgLmwjg1G
17-----END ENCRYPTED PRIVATE KEY-----
diff --git a/src/tests/eet/key_enc_none.pem b/src/tests/eet/key_enc_none.pem
new file mode 100644
index 0000000000..1163851906
--- /dev/null
+++ b/src/tests/eet/key_enc_none.pem
@@ -0,0 +1,16 @@
1-----BEGIN PRIVATE KEY-----
2MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMiE486eROKePG0/
3639D4XTTDR9XSRWp1xqZzq7P+jjWRFbZ/MWVIVzkc4MRm83UOolbPj76LjM10cse
4aVAhK7G9CHp2dur4alWvdCXPH5Q+LPOFS9gMx0Jz9EZeHHOHZKLyJdKSmot+zluw
5JTLe081RRUwzNKct6JrVVG/7SmITAgMBAAECgYB8ssfI0nwcQjNp7XpSZrBqqmVa
6vDljE4AFtujlpckCV52gNWgQp7Fbx2ZeeDDgS78rdGa9W3AnwKx7GKp9fmNgxT5g
7pFvDDpWqv+m6chSGIQdVqscwUob3KjXipJrPbE+Be8Lmnv9GFyL6sBSnfpLmQgdy
8HmwuEQRwlrLKbLMPIQJBAP/kHcl2lyi+tIj6fJnwi5vb4jd/e6jHqbUMrEd5p3bo
9gKgivtUKc9XknWAsgHYyh9UJsqGbLg82LlrRB29rMl8CQQDImr1j71JDiwI5UOsW
10SUnGFe5kThZudHfZewF2dD11q6jQTa8NWS/qYefMxauhOMu/iEfme58Tk28yjw80
11YHTNAkAU4qR/vfsmazJG/9LNqbFrXi3/g5svMmSqj0c8ajR94wolLvjOYJUFvywN
12HnS5sPQfMjRvNkAzI6Py656kvGYXAkAf5FHluF94s3nYCOBG+8HJxyTON4fjaYrA
13PYj+/v3iXjcJXsBMu/gdKBGFAYwGppPl0FG198NThmXwQMQnDIqlAkEAnY01pxRF
14PJq9Tr31Ak4h0YCwDgpeJyLwfc+65Yy0ctFEp08V5oJGf72ntOCV/Ssf2FQY6lRc
15dgPf4QK3qCdUNw==
16-----END PRIVATE KEY-----