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