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