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