15 #ifdef EFL_HAVE_POSIX_THREADS
23 #include "eet_suite.h"
25 START_TEST(eet_test_init)
37 typedef struct _Eet_Test_Basic_Type Eet_Test_Basic_Type;
38 struct _Eet_Test_Basic_Type
52 unsigned long long ul;
53 Eet_Test_Basic_Type *empty;
54 Eet_Test_Basic_Type *with;
57 #define EET_TEST_CHAR 0x42
58 #define EET_TEST_SHORT 0x4224
59 #define EET_TEST_INT 0x42211224
60 #define EET_TEST_LONG_LONG 0x84CB42211224BC48
61 #define EET_TEST_STRING "my little test with escape \\\""
62 #define EET_TEST_KEY1 "key1"
63 #define EET_TEST_KEY2 "key2"
64 #define EET_TEST_FLOAT 123.45689
65 #define EET_TEST_FLOAT2 1.0
66 #define EET_TEST_FLOAT3 0.25
67 #define EET_TEST_FLOAT4 0.0001234
68 #define EET_TEST_DOUBLE 123456789.9876543210
69 #define EET_TEST_DOUBLE2 1.0
70 #define EET_TEST_DOUBLE3 0.25
71 #define EET_TEST_FILE_KEY1 "keys/data/1"
72 #define EET_TEST_FILE_KEY2 "keys/data/2"
73 #define EET_TEST_FILE_IMAGE "keys/images/"
75 typedef struct _Eet_Test_Image Eet_Test_Image;
76 struct _Eet_Test_Image
81 unsigned int color[64];
84 static const Eet_Test_Image test_noalpha = {
87 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000,
88 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000,
89 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00,
90 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA,
91 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000,
92 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000,
93 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00,
94 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA
98 static const Eet_Test_Image test_alpha = {
101 0x0FAA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x0F110000,
102 0x0000AA00, 0x0F0000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x0F110000, 0x00AA0000,
103 0x000000AA, 0x00110000, 0x0FAA0000, 0x0000AA00, 0x000000AA, 0x0F110000, 0x00AA0000, 0x0000AA00,
104 0x00110000, 0x00AA0000, 0x0000AA00, 0x0F0000AA, 0x0F110000, 0x00AA0000, 0x0000AA00, 0x000000AA,
105 0x00AA0000, 0x0000AA00, 0x000000AA, 0x0F110000, 0x0FAA0000, 0x0000AA00, 0x000000AA, 0x00110000,
106 0x0000AA00, 0x000000AA, 0x0F110000, 0x00AA0000, 0x0000AA00, 0x0F0000AA, 0x00110000, 0x00AA0000,
107 0x000000AA, 0x0F110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x0FAA0000, 0x0000AA00,
108 0x0F110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x0F0000AA
113 _eet_test_basic_set(Eet_Test_Basic_Type *res, int i)
115 res->c = EET_TEST_CHAR;
116 res->s = EET_TEST_SHORT;
117 res->i = EET_TEST_INT + i;
118 res->l = EET_TEST_LONG_LONG;
119 res->str = EET_TEST_STRING;
120 res->istr = EET_TEST_STRING;
121 res->f1 = - EET_TEST_FLOAT;
122 res->d = - EET_TEST_DOUBLE;
123 res->f2 = EET_TEST_FLOAT4;
124 res->uc = EET_TEST_CHAR;
125 res->us = EET_TEST_SHORT;
126 res->ui = EET_TEST_INT;
127 res->ul = EET_TEST_LONG_LONG;
133 Eet_Test_Basic_Type *tmp;
135 tmp = malloc(sizeof (Eet_Test_Basic_Type));
139 tmp->c = EET_TEST_CHAR;
140 tmp->s = EET_TEST_SHORT;
141 tmp->i = EET_TEST_INT + i + 1;
142 tmp->l = EET_TEST_LONG_LONG;
143 tmp->str = EET_TEST_STRING;
144 tmp->istr = EET_TEST_STRING;
145 tmp->f1 = - EET_TEST_FLOAT;
146 tmp->d = - EET_TEST_DOUBLE;
147 tmp->f2 = EET_TEST_FLOAT4;
148 tmp->uc = EET_TEST_CHAR;
149 tmp->us = EET_TEST_SHORT;
150 tmp->ui = EET_TEST_INT;
151 tmp->ul = EET_TEST_LONG_LONG;
158 _eet_test_basic_check(Eet_Test_Basic_Type *result, int i)
162 fail_if(result->c != EET_TEST_CHAR);
163 fail_if(result->s != EET_TEST_SHORT);
164 fail_if(result->i != EET_TEST_INT + i);
165 fail_if(result->l != (long long) EET_TEST_LONG_LONG);
166 fail_if(strcmp(result->str, EET_TEST_STRING) != 0);
167 fail_if(strcmp(result->istr, EET_TEST_STRING) != 0);
168 fail_if(result->uc != EET_TEST_CHAR);
169 fail_if(result->us != EET_TEST_SHORT);
170 fail_if(result->ui != EET_TEST_INT);
171 fail_if(result->ul != EET_TEST_LONG_LONG);
173 tmp = (result->f1 + EET_TEST_FLOAT);
174 if (tmp < 0) tmp = -tmp;
175 fail_if(tmp > 0.005);
177 tmp = (result->f2 - EET_TEST_FLOAT4);
178 if (tmp < 0) tmp = -tmp;
179 fail_if(tmp > 0.005);
181 tmp = (result->d + EET_TEST_DOUBLE);
182 if (tmp < 0) tmp = -tmp;
183 fail_if(tmp > 0.00005);
185 fail_if(result->empty != NULL);
188 Eet_Test_Basic_Type *tmp;
191 fail_if(tmp == NULL);
193 fail_if(tmp->c != EET_TEST_CHAR);
194 fail_if(tmp->s != EET_TEST_SHORT);
195 fail_if(tmp->i != EET_TEST_INT + i + 1);
196 fail_if(tmp->l != (long long) EET_TEST_LONG_LONG);
197 fail_if(strcmp(tmp->str, EET_TEST_STRING) != 0);
198 fail_if(strcmp(tmp->istr, EET_TEST_STRING) != 0);
199 fail_if(tmp->uc != EET_TEST_CHAR);
200 fail_if(tmp->us != EET_TEST_SHORT);
201 fail_if(tmp->ui != EET_TEST_INT);
202 fail_if(tmp->ul != EET_TEST_LONG_LONG);
205 fail_if(result->with != NULL);
209 _eet_build_basic_descriptor(Eet_Data_Descriptor *edd)
211 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "c", c, EET_T_CHAR);
212 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "s", s, EET_T_SHORT);
213 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "i", i, EET_T_INT);
214 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "l", l, EET_T_LONG_LONG);
215 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "str", str, EET_T_STRING);
216 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "istr", istr, EET_T_INLINED_STRING);
217 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "f1", f1, EET_T_FLOAT);
218 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "f2", f2, EET_T_FLOAT);
219 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "d", d, EET_T_DOUBLE);
220 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "uc", uc, EET_T_UCHAR);
221 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "us", us, EET_T_USHORT);
222 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "ui", ui, EET_T_UINT);
223 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "ul", ul, EET_T_ULONG_LONG);
225 EET_DATA_DESCRIPTOR_ADD_SUB(edd, Eet_Test_Basic_Type, "empty", empty, edd);
226 EET_DATA_DESCRIPTOR_ADD_SUB(edd, Eet_Test_Basic_Type, "with", with, edd);
229 START_TEST(eet_test_basic_data_type_encoding_decoding)
231 Eet_Data_Descriptor *edd;
232 Eet_Test_Basic_Type *result;
233 Eet_Data_Descriptor_Class eddc;
234 Eet_Test_Basic_Type etbt;
240 _eet_test_basic_set(&etbt, 0);
242 eet_test_setup_eddc(&eddc);
243 eddc.name = "Eet_Test_Basic_Type";
244 eddc.size = sizeof(Eet_Test_Basic_Type);
246 edd = eet_data_descriptor_stream_new(&eddc);
249 _eet_build_basic_descriptor(edd);
251 transfert = eet_data_descriptor_encode(edd, &etbt, &size);
252 fail_if(!transfert || size <= 0);
254 result = eet_data_descriptor_decode(edd, transfert, size);
257 _eet_test_basic_check(result, 0);
262 eet_data_descriptor_free(edd);
268 typedef struct _Eet_Test_Ex_Type Eet_Test_Ex_Type;
269 struct _Eet_Test_Ex_Type
274 unsigned long long l;
291 Eet_Test_Basic_Type sarray1[10];
292 unsigned int sarray2[5];
293 unsigned int varray1_count;
294 unsigned int *varray1;
295 unsigned int varray2_count;
296 Eet_Test_Basic_Type *varray2;
300 unsigned long long ul;
309 _eet_build_ex_descriptor(Eet_Data_Descriptor *edd)
311 Eet_Data_Descriptor_Class eddc;
312 Eet_Test_Ex_Type etbt;
313 Eet_Data_Descriptor *eddb;
315 eet_test_setup_eddc(&eddc);
316 eddc.name = "Eet_Test_Basic_Type";
317 eddc.size = sizeof(Eet_Test_Basic_Type);
318 eddb = eet_data_descriptor_file_new(&eddc);
321 _eet_build_basic_descriptor(eddb);
323 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "c", c, EET_T_CHAR);
324 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "s", s, EET_T_SHORT);
325 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "i", i, EET_T_INT);
326 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "l", l, EET_T_LONG_LONG);
327 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "str", str, EET_T_STRING);
328 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "istr", istr, EET_T_INLINED_STRING);
329 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "f1", f1, EET_T_FLOAT);
330 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "f2", f2, EET_T_FLOAT);
331 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "f3", f3, EET_T_FLOAT);
332 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "f4", f4, EET_T_FLOAT);
333 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "d1", d1, EET_T_DOUBLE);
334 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "d2", d2, EET_T_DOUBLE);
335 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "d3", d3, EET_T_DOUBLE);
336 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "d4", d4, EET_T_DOUBLE);
337 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "uc", uc, EET_T_UCHAR);
338 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "us", us, EET_T_USHORT);
339 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "ui", ui, EET_T_UINT);
340 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "ul", ul, EET_T_ULONG_LONG);
341 EET_DATA_DESCRIPTOR_ADD_ARRAY(edd, Eet_Test_Ex_Type, "sarray1", sarray1, eddb);
342 EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY(edd, Eet_Test_Ex_Type, "varray2", varray2, eddb);
343 eet_data_descriptor_element_add(edd, "varray1", EET_T_INT, EET_G_VAR_ARRAY,
344 (char *)(&(etbt.varray1)) - (char *)(&(etbt)),
345 (char *)(&(etbt.varray1_count)) - (char *)(&(etbt)), /* 0, */NULL, NULL);
346 eet_data_descriptor_element_add(edd, "sarray2", EET_T_INT, EET_G_ARRAY,
347 (char *)(&(etbt.sarray2)) - (char *)(&(etbt)),
348 /* 0, */sizeof(etbt.sarray2)/sizeof(etbt.sarray2[0]), NULL, NULL);
349 eet_data_descriptor_element_add(edd, "charray", EET_T_STRING, EET_G_ARRAY,
350 (char *)(&(etbt.charray)) - (char *)(&(etbt)),
351 /* 0, */sizeof(etbt.charray)/sizeof(etbt.charray[0]), NULL, NULL);
352 EET_DATA_DESCRIPTOR_ADD_LIST(edd, Eet_Test_Ex_Type, "list", list, edd);
353 EET_DATA_DESCRIPTOR_ADD_HASH(edd, Eet_Test_Ex_Type, "hash", hash, edd);
354 eet_data_descriptor_element_add(edd, "ilist", EET_T_INT, EET_G_LIST,
355 (char *)(&(etbt.ilist)) - (char *)(&(etbt)),
356 0, /* 0, */NULL, NULL);
357 eet_data_descriptor_element_add(edd, "ihash", EET_T_INT, EET_G_HASH,
358 (char *)(&(etbt.ihash)) - (char *)(&(etbt)),
359 0, /* 0, */NULL, NULL);
360 eet_data_descriptor_element_add(edd, "slist", EET_T_STRING, EET_G_LIST,
361 (char *)(&(etbt.slist)) - (char *)(&(etbt)),
362 0, /* 0, */NULL, NULL);
363 eet_data_descriptor_element_add(edd, "shash", EET_T_STRING, EET_G_HASH,
364 (char *)(&(etbt.shash)) - (char *)(&(etbt)),
365 0, /* 0, */NULL, NULL);
368 static Eet_Test_Ex_Type*
369 _eet_test_ex_set(Eet_Test_Ex_Type *res, int offset)
373 if (!res) res = malloc( sizeof(Eet_Test_Ex_Type));
374 if (!res) return NULL;
376 res->c = EET_TEST_CHAR + offset;
377 res->s = EET_TEST_SHORT + offset;
378 res->i = EET_TEST_INT + offset;
379 res->l = EET_TEST_LONG_LONG + offset;
380 res->str = EET_TEST_STRING;
381 res->istr = EET_TEST_STRING;
382 res->f1 = EET_TEST_FLOAT + offset;
383 res->f2 = -(EET_TEST_FLOAT2 + offset);
384 res->f3 = EET_TEST_FLOAT3 + offset;
385 res->f4 = EET_TEST_FLOAT2 + offset;
386 res->d1 = EET_TEST_DOUBLE + offset;
387 res->d2 = -(EET_TEST_DOUBLE2 + offset);
388 res->d3 = EET_TEST_DOUBLE3 + offset;
389 res->d4 = EET_TEST_DOUBLE2 + offset;
396 for (i = 0; i < sizeof(res->charray)/sizeof(res->charray[0]); ++i)
397 res->charray[i] = NULL;
399 res->varray2 = malloc(sizeof (Eet_Test_Basic_Type) * 10);
400 res->varray1 = malloc(sizeof (int) * 5);
401 fail_if(!res->varray1 || !res->varray2);
402 for (i = 0; i < 10; ++i)
404 _eet_test_basic_set(res->sarray1 + i, i);
405 _eet_test_basic_set(res->varray2 + i, i);
407 res->varray2_count = 10;
408 for (i = 0; i < 5; ++i)
410 res->sarray2[i] = i * 42 + 1;
411 res->varray1[i] = i * 42 + 1;
413 res->varray1_count = 5;
415 res->uc = EET_TEST_CHAR + offset;
416 res->us = EET_TEST_SHORT + offset;
417 res->ui = EET_TEST_INT + offset;
418 res->ul = EET_TEST_LONG_LONG + offset;
424 _eet_test_ex_check(Eet_Test_Ex_Type *stuff, int offset)
429 if (!stuff) return 1;
431 if (stuff->c != EET_TEST_CHAR + offset) return 1;
432 if (stuff->s != EET_TEST_SHORT + offset) return 1;
433 if (stuff->i != EET_TEST_INT + offset) return 1;
434 if (stuff->l != EET_TEST_LONG_LONG + offset) return 1;
435 if (strcmp(stuff->str, EET_TEST_STRING) != 0) return 1;
436 if (strcmp(stuff->istr, EET_TEST_STRING) != 0) return 1;
438 tmp = stuff->f1 - (EET_TEST_FLOAT + offset);
439 if (tmp < 0) tmp = -tmp;
440 if (tmp > 0.005) return 1;
442 tmp = stuff->d1 - (EET_TEST_DOUBLE + offset);
443 if (tmp < 0) tmp = -tmp;
444 if (tmp > 0.00005) return 1;
446 if (stuff->f2 != - (EET_TEST_FLOAT2 + offset)) return 1;
447 if (stuff->d2 != - (EET_TEST_DOUBLE2 + offset)) return 1;
449 if (stuff->f3 != EET_TEST_FLOAT3 + offset) return 1;
450 if (stuff->d3 != EET_TEST_DOUBLE3 + offset) return 1;
452 if (stuff->f4 != EET_TEST_FLOAT2 + offset) return 1;
453 if (stuff->d4 != EET_TEST_DOUBLE2 + offset) return 1;
455 if (stuff->uc != EET_TEST_CHAR + offset) return 1;
456 if (stuff->us != EET_TEST_SHORT + offset) return 1;
457 if (stuff->ui != (unsigned int) EET_TEST_INT + offset) return 1;
458 if (stuff->ul != EET_TEST_LONG_LONG + offset) return 1;
460 if (stuff->varray1_count != 5) return 1;
461 if (stuff->varray2_count != 10) return 1;
463 for (i = 0; i < 5; ++i)
464 if (stuff->sarray2[i] != i * 42 + 1 && stuff->varray1[i] != i * 42 + 1)
467 for (i = 0; i < 10; ++i)
469 _eet_test_basic_check(stuff->sarray1 + i, i);
470 _eet_test_basic_check(stuff->varray2 + i, i);
477 func(__UNUSED__ const Eina_Hash *hash, const void *key, void *data, void *fdata)
481 if (strcmp(key, EET_TEST_KEY1) != 0
482 && strcmp(key, EET_TEST_KEY2) != 0) *res = 1;
483 if (_eet_test_ex_check(data, 2)) *res = 1;
489 func7(__UNUSED__ const Eina_Hash *hash, __UNUSED__ const void *key, void *data, void *fdata)
496 if (*val != 7) *res = 1;
501 START_TEST(eet_test_data_type_encoding_decoding)
503 Eet_Data_Descriptor *edd;
504 Eet_Test_Ex_Type *result;
506 Eet_Data_Descriptor_Class eddc;
507 Eet_Test_Ex_Type etbt;
513 _eet_test_ex_set(&etbt, 0);
514 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
515 etbt.hash = eina_hash_string_superfast_new(NULL);
516 eina_hash_add(etbt.hash, EET_TEST_KEY1, _eet_test_ex_set(NULL, 2));
517 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
518 etbt.ihash = eina_hash_string_superfast_new(NULL);
519 eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7);
520 etbt.slist = eina_list_prepend(NULL, "test");
521 etbt.shash = eina_hash_string_superfast_new(NULL);
522 eina_hash_add(etbt.shash, EET_TEST_KEY1, "test");
523 memset(&etbt.charray, 0, sizeof(etbt.charray));
524 etbt.charray[0] = "test";
525 etbt.charray[5] = "plouf";
527 eet_test_setup_eddc(&eddc);
528 eddc.name = "Eet_Test_Ex_Type";
529 eddc.size = sizeof(Eet_Test_Ex_Type);
531 edd = eet_data_descriptor_file_new(&eddc);
534 _eet_build_ex_descriptor(edd);
536 transfert = eet_data_descriptor_encode(edd, &etbt, &size);
537 fail_if(!transfert || size <= 0);
539 result = eet_data_descriptor_decode(edd, transfert, size);
542 fail_if(_eet_test_ex_check(result, 0) != 0);
543 fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1) != 0);
544 fail_if(eina_list_data_get(result->ilist) == NULL);
545 fail_if(*((int*)eina_list_data_get(result->ilist)) != 42);
546 fail_if(eina_list_data_get(result->slist) == NULL);
547 fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0);
548 fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL);
549 fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0);
550 fail_if(strcmp(result->charray[0], "test") != 0);
551 fail_if(strcmp(result->charray[5], "plouf") != 0);
554 if (result->hash) eina_hash_foreach(result->hash, func, &test);
556 if (result->ihash) eina_hash_foreach(result->ihash, func7, &test);
564 append_string(void *data, const char *str)
566 char **string = data;
571 length = *string ? strlen(*string) : 0;
572 *string = realloc(*string, strlen(str) + length + 1);
574 memcpy((*string) + length, str, strlen(str) + 1);
577 START_TEST(eet_test_data_type_dump_undump)
579 Eet_Data_Descriptor *edd;
580 Eet_Test_Ex_Type *result;
581 Eet_Data_Descriptor_Class eddc;
582 Eet_Test_Ex_Type etbt;
593 _eet_test_ex_set(&etbt, 0);
594 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
595 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
596 etbt.hash = eina_hash_string_superfast_new(NULL);
597 eina_hash_add(etbt.hash, EET_TEST_KEY1, _eet_test_ex_set(NULL, 2));
598 etbt.hash = eina_hash_string_superfast_new(NULL);
599 eina_hash_add(etbt.hash, EET_TEST_KEY2, _eet_test_ex_set(NULL, 2));
600 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
601 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
602 etbt.ihash = eina_hash_string_superfast_new(NULL);
603 eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7);
604 etbt.ihash = eina_hash_string_superfast_new(NULL);
605 eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7);
606 etbt.slist = eina_list_prepend(NULL, "test");
607 etbt.shash = eina_hash_string_superfast_new(NULL);
608 eina_hash_add(etbt.shash, EET_TEST_KEY1, "test");
609 memset(&etbt.charray, 0, sizeof(etbt.charray));
610 etbt.charray[0] = "test";
612 eet_test_setup_eddc(&eddc);
613 eddc.name = "Eet_Test_Ex_Type";
614 eddc.size = sizeof(Eet_Test_Ex_Type);
616 edd = eet_data_descriptor_file_new(&eddc);
619 _eet_build_ex_descriptor(edd);
621 transfert1 = eet_data_descriptor_encode(edd, &etbt, &size1);
622 fail_if(!transfert1 || size1 <= 0);
625 eet_data_text_dump(transfert1, size1, append_string, &string1);
628 transfert2 = eet_data_text_undump(string1, string1 ? strlen(string1) : 0, &size2);
629 fail_if(!transfert2 && size2 <= 0);
632 eet_data_text_dump(transfert2, size2, append_string, &string2);
635 fail_if(strlen(string2) != strlen(string1));
637 result = eet_data_descriptor_decode(edd, transfert2, size2);
640 fail_if(_eet_test_ex_check(result, 0) != 0);
641 fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1) != 0);
642 fail_if(eina_list_data_get(result->ilist) == NULL);
643 fail_if(*((int*)eina_list_data_get(result->ilist)) != 42);
644 fail_if(eina_list_data_get(result->slist) == NULL);
645 fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0);
646 fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL);
647 fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0);
648 fail_if(strcmp(result->charray[0], "test") != 0);
651 if (result->hash) eina_hash_foreach(result->hash, func, &test);
653 if (result->ihash) eina_hash_foreach(result->ihash, func7, &test);
660 START_TEST(eet_file_simple_write)
662 const char *buffer = "Here is a string of data to save !";
665 char *file = strdup("/tmp/eet_suite_testXXXXXX");
670 fail_if(!(file = tmpnam(file)));
672 fail_if(eet_mode_get(NULL) != EET_FILE_MODE_INVALID);
674 ef = eet_open(file, EET_FILE_MODE_WRITE);
677 fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 1));
678 fail_if(!eet_alias(ef, "keys/alias", "keys/tests", 0));
679 fail_if(!eet_alias(ef, "keys/alias2", "keys/alias", 1));
681 fail_if(eet_mode_get(ef) != EET_FILE_MODE_WRITE);
683 fail_if(eet_list(ef, "*", &size) != NULL);
684 fail_if(eet_num_entries(ef) != -1);
688 /* Test read of simple file */
689 ef = eet_open(file, EET_FILE_MODE_READ);
692 test = eet_read(ef, "keys/tests", &size);
694 fail_if(size != (int) strlen(buffer) + 1);
696 fail_if(memcmp(test, buffer, strlen(buffer) + 1) != 0);
698 test = eet_read(ef, "keys/alias2", &size);
700 fail_if(size != (int) strlen(buffer) + 1);
702 fail_if(eet_read_direct(ef, "key/alias2", &size));
704 fail_if(eet_mode_get(ef) != EET_FILE_MODE_READ);
705 fail_if(eet_num_entries(ef) != 3);
709 /* Test eet cache system */
710 ef = eet_open(file, EET_FILE_MODE_READ);
713 test = eet_read(ef, "keys/tests", &size);
715 fail_if(size != (int) strlen(buffer) + 1);
717 fail_if(memcmp(test, buffer, strlen(buffer) + 1) != 0);
721 fail_if(unlink(file) != 0);
727 START_TEST(eet_file_data_test)
729 Eet_Data_Descriptor *edd;
730 Eet_Test_Ex_Type *result;
734 char *file = strdup("/tmp/eet_suite_testXXXXXX");
735 Eet_Data_Descriptor_Class eddc;
736 Eet_Test_Ex_Type etbt;
742 _eet_test_ex_set(&etbt, 0);
743 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
744 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
745 etbt.hash = eina_hash_string_superfast_new(NULL);
746 eina_hash_add(etbt.hash, EET_TEST_KEY1, _eet_test_ex_set(NULL, 2));
747 etbt.hash = eina_hash_string_superfast_new(NULL);
748 eina_hash_add(etbt.hash, EET_TEST_KEY2, _eet_test_ex_set(NULL, 2));
749 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
750 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
751 etbt.ihash = eina_hash_string_superfast_new(NULL);
752 eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7);
753 etbt.ihash = eina_hash_string_superfast_new(NULL);
754 eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7);
755 etbt.slist = eina_list_prepend(NULL, "test");
756 etbt.shash = eina_hash_string_superfast_new(NULL);
757 eina_hash_add(etbt.shash, EET_TEST_KEY1, "test");
758 memset(&etbt.charray, 0, sizeof(etbt.charray));
759 etbt.charray[0] = "test";
761 eet_test_setup_eddc(&eddc);
762 eddc.name = "Eet_Test_Ex_Type";
763 eddc.size = sizeof(Eet_Test_Ex_Type);
765 edd = eet_data_descriptor_file_new(&eddc);
768 _eet_build_ex_descriptor(edd);
770 fail_if(!(file = tmpnam(file)));
772 /* Insert an error in etbt. */
775 /* Save the encoded data in a file. */
776 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
779 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0));
781 result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1);
784 fail_if(eet_mode_get(ef) != EET_FILE_MODE_READ_WRITE);
786 /* Test string space. */
787 ed = eet_dictionary_get(ef);
789 fail_if(!eet_dictionary_string_check(ed, result->str));
790 fail_if(eet_dictionary_string_check(ed, result->istr));
794 /* Attempt to replace etbt by the correct one. */
795 etbt.i = EET_TEST_INT;
797 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
800 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0));
804 /* Read back the data. */
805 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
808 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY2, &etbt, 0));
810 result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1);
813 /* Test string space. */
814 ed = eet_dictionary_get(ef);
817 fail_if(!eet_dictionary_string_check(ed, result->str));
818 fail_if(eet_dictionary_string_check(ed, result->istr));
820 /* Test the resulting data. */
821 fail_if(_eet_test_ex_check(result, 0) != 0);
822 fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1) != 0);
823 fail_if(eina_list_data_get(result->ilist) == NULL);
824 fail_if(*((int*)eina_list_data_get(result->ilist)) != 42);
825 fail_if(eina_list_data_get(result->slist) == NULL);
826 fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0);
827 fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL);
828 fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0);
829 fail_if(strcmp(result->charray[0], "test") != 0);
832 if (result->hash) eina_hash_foreach(result->hash, func, &test);
834 if (result->ihash) eina_hash_foreach(result->ihash, func7, &test);
837 list = eet_list(ef, "keys/*", &size);
838 fail_if(eet_num_entries(ef) != 2);
840 fail_if(!(strcmp(list[0], EET_TEST_FILE_KEY1) == 0 && strcmp(list[1], EET_TEST_FILE_KEY2) == 0)
841 && !(strcmp(list[0], EET_TEST_FILE_KEY2) == 0 && strcmp(list[1], EET_TEST_FILE_KEY1) == 0));
844 fail_if(eet_delete(ef, NULL) != 0);
845 fail_if(eet_delete(NULL, EET_TEST_FILE_KEY1) != 0);
846 fail_if(eet_delete(ef, EET_TEST_FILE_KEY1) == 0);
848 list = eet_list(ef, "keys/*", &size);
850 fail_if(eet_num_entries(ef) != 1);
852 /* Test some more wrong case */
853 fail_if(eet_data_read(ef, edd, "plop") != NULL);
854 fail_if(eet_data_read(ef, edd, EET_TEST_FILE_KEY1) != NULL);
856 /* Reinsert and reread data */
857 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0));
858 fail_if(eet_data_read(ef, edd, EET_TEST_FILE_KEY1) == NULL);
859 fail_if(eet_read_direct(ef, EET_TEST_FILE_KEY1, &size) == NULL);
863 fail_if(unlink(file) != 0);
869 START_TEST(eet_file_data_dump_test)
871 Eet_Data_Descriptor *edd;
872 Eet_Test_Ex_Type *result;
873 Eet_Data_Descriptor_Class eddc;
874 Eet_Test_Ex_Type etbt;
877 char *file = strdup("/tmp/eet_suite_testXXXXXX");
882 _eet_test_ex_set(&etbt, 0);
883 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
884 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
885 etbt.hash = eina_hash_string_superfast_new(NULL);
886 eina_hash_add(etbt.hash, EET_TEST_KEY1, _eet_test_ex_set(NULL, 2));
887 eina_hash_add(etbt.hash, EET_TEST_KEY2, _eet_test_ex_set(NULL, 2));
888 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
889 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
890 etbt.ihash = eina_hash_string_superfast_new(NULL);
891 eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7);
892 eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7);
893 etbt.slist = eina_list_prepend(NULL, "test");
894 etbt.shash = eina_hash_string_superfast_new(NULL);
895 eina_hash_add(etbt.shash, EET_TEST_KEY1, "test");
896 memset(&etbt.charray, 0, sizeof(etbt.charray));
897 etbt.charray[0] = "test";
899 eet_eina_file_data_descriptor_class_set(&eddc, "Eet_Test_Ex_Type", sizeof(Eet_Test_Ex_Type));
901 edd = eet_data_descriptor_file_new(&eddc);
904 _eet_build_ex_descriptor(edd);
906 fail_if(!(file = tmpnam(file)));
908 /* Save the encoded data in a file. */
909 ef = eet_open(file, EET_FILE_MODE_WRITE);
912 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0));
916 /* Use dump/undump in the middle */
917 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
921 fail_if(eet_data_dump(ef, EET_TEST_FILE_KEY1, append_string, &string1) != 1);
922 fail_if(eet_delete(ef, EET_TEST_FILE_KEY1) == 0);
923 fail_if(!eet_data_undump(ef, EET_TEST_FILE_KEY1, string1, strlen(string1), 1));
927 /* Test the correctness of the reinsertion. */
928 ef = eet_open(file, EET_FILE_MODE_READ);
931 result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1);
936 /* Test the resulting data. */
937 fail_if(_eet_test_ex_check(result, 0) != 0);
938 fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1) != 0);
939 fail_if(eina_list_data_get(result->ilist) == NULL);
940 fail_if(*((int*)eina_list_data_get(result->ilist)) != 42);
941 fail_if(eina_list_data_get(result->slist) == NULL);
942 fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0);
943 fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL);
944 fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0);
945 fail_if(strcmp(result->charray[0], "test") != 0);
948 if (result->hash) eina_hash_foreach(result->hash, func, &test);
950 if (result->ihash) eina_hash_foreach(result->ihash, func7, &test);
953 fail_if(unlink(file) != 0);
959 START_TEST(eet_image)
962 char *file = strdup("/tmp/eet_suite_testXXXXXX");
972 fail_if(!(file = tmpnam(file)));
974 /* Save the encoded data in a file. */
975 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
978 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "0", test_noalpha.color,
979 test_noalpha.w, test_noalpha.h, test_noalpha.alpha,
981 fail_if(result == 0);
983 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "1", test_noalpha.color,
984 test_noalpha.w, test_noalpha.h, test_noalpha.alpha,
986 fail_if(result == 0);
988 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "2", test_noalpha.color,
989 test_noalpha.w, test_noalpha.h, test_noalpha.alpha,
991 fail_if(result == 0);
993 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "3", test_noalpha.color,
994 test_noalpha.w, test_noalpha.h, test_noalpha.alpha,
996 fail_if(result == 0);
998 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "4", test_noalpha.color,
999 test_noalpha.w, test_noalpha.h, test_noalpha.alpha,
1001 fail_if(result == 0);
1003 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "5", test_noalpha.color,
1004 test_noalpha.w, test_noalpha.h, test_noalpha.alpha,
1006 fail_if(result == 0);
1008 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "6", test_noalpha.color,
1009 test_noalpha.w, test_noalpha.h, test_noalpha.alpha,
1011 fail_if(result == 0);
1013 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "7", test_alpha.color,
1014 test_alpha.w, test_alpha.h, test_alpha.alpha,
1016 fail_if(result == 0);
1018 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "8", test_alpha.color,
1019 test_alpha.w, test_alpha.h, test_alpha.alpha,
1021 fail_if(result == 0);
1023 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "9", test_alpha.color,
1024 test_alpha.w, test_alpha.h, test_alpha.alpha,
1026 fail_if(result == 0);
1028 data = eet_data_image_read(ef, EET_TEST_FILE_IMAGE "2", &w, &h, &alpha, &compress, &quality, &lossy);
1029 fail_if(data == NULL);
1030 fail_if(w != test_noalpha.w);
1031 fail_if(h != test_noalpha.h);
1032 fail_if(alpha != test_noalpha.alpha);
1033 fail_if(compress != 9);
1034 fail_if(lossy != 0);
1035 fail_if(data[0] != test_noalpha.color[0]);
1038 result = eet_data_image_header_read(ef, EET_TEST_FILE_IMAGE "2", &w, &h, &alpha, &compress, &quality, &lossy);
1039 fail_if(result == 0);
1040 fail_if(w != test_noalpha.w);
1041 fail_if(h != test_noalpha.h);
1042 fail_if(alpha != test_noalpha.alpha);
1043 fail_if(compress != 9);
1044 fail_if(lossy != 0);
1048 /* Test read of image */
1049 ef = eet_open(file, EET_FILE_MODE_READ);
1052 result = eet_data_image_header_read(ef, EET_TEST_FILE_IMAGE "0", &w, &h, &alpha, &compress, &quality, &lossy);
1053 fail_if(result == 0);
1054 fail_if(w != test_noalpha.w);
1055 fail_if(h != test_noalpha.h);
1056 fail_if(alpha != test_noalpha.alpha);
1057 fail_if(compress != 0);
1058 fail_if(lossy != 0);
1060 data = malloc(w * h * 4);
1061 fail_if(data == NULL);
1062 result = eet_data_image_read_to_surface(ef, EET_TEST_FILE_IMAGE "0", 4, 4, data, 2, 2, w * 4, &alpha, &compress, &quality, &lossy);
1063 fail_if(result != 1);
1064 fail_if(alpha != test_noalpha.alpha);
1065 fail_if(compress != 0);
1066 fail_if(quality != 100);
1067 fail_if(lossy != 0);
1068 fail_if(data[0] != test_noalpha.color[4 + 4 * w]);
1071 data = malloc(w * h * 4);
1072 fail_if(data == NULL);
1073 result = eet_data_image_read_to_surface(ef, EET_TEST_FILE_IMAGE "0", 0, 0, data, w, h, w * 4, &alpha, &compress, &quality, &lossy);
1074 fail_if(result != 1);
1075 fail_if(alpha != test_noalpha.alpha);
1076 fail_if(compress != 0);
1077 fail_if(quality != 100);
1078 fail_if(lossy != 0);
1079 fail_if(data[0] != test_noalpha.color[0]);
1082 data = eet_data_image_read(ef, EET_TEST_FILE_IMAGE "1", &w, &h, &alpha, &compress, &quality, &lossy);
1083 fail_if(data == NULL);
1084 fail_if(w != test_noalpha.w);
1085 fail_if(h != test_noalpha.h);
1086 fail_if(alpha != test_noalpha.alpha);
1087 fail_if(compress != 5);
1088 fail_if(quality != 100);
1089 fail_if(lossy != 0);
1090 fail_if(data[0] != test_noalpha.color[0]);
1093 data = eet_data_image_read(ef, EET_TEST_FILE_IMAGE "2", &w, &h, &alpha, &compress, &quality, &lossy);
1094 fail_if(data == NULL);
1095 fail_if(w != test_noalpha.w);
1096 fail_if(h != test_noalpha.h);
1097 fail_if(alpha != test_noalpha.alpha);
1098 fail_if(compress != 9);
1099 fail_if(lossy != 0);
1100 fail_if(data[0] != test_noalpha.color[0]);
1103 data = eet_data_image_read(ef, EET_TEST_FILE_IMAGE "3", &w, &h, &alpha, &compress, &quality, &lossy);
1104 fail_if(data == NULL);
1105 fail_if(w != test_noalpha.w);
1106 fail_if(h != test_noalpha.h);
1107 fail_if(alpha != test_noalpha.alpha);
1108 fail_if(lossy != 1);
1111 data = eet_data_image_read(ef, EET_TEST_FILE_IMAGE "5", &w, &h, &alpha, &compress, &quality, &lossy);
1112 fail_if(data == NULL);
1113 fail_if(w != test_noalpha.w);
1114 fail_if(h != test_noalpha.h);
1115 fail_if(alpha != test_noalpha.alpha);
1116 fail_if(lossy != 1);
1119 data = eet_data_image_read(ef, EET_TEST_FILE_IMAGE "6", &w, &h, &alpha, &compress, &quality, &lossy);
1120 fail_if(data == NULL);
1121 fail_if(w != test_noalpha.w);
1122 fail_if(h != test_noalpha.h);
1123 fail_if(alpha != test_noalpha.alpha);
1124 fail_if(lossy != 1);
1127 result = eet_data_image_header_read(ef, EET_TEST_FILE_IMAGE "7", &w, &h, &alpha, &compress, &quality, &lossy);
1128 fail_if(result == 0);
1129 fail_if(w != test_alpha.w);
1130 fail_if(h != test_alpha.h);
1131 fail_if(alpha != test_alpha.alpha);
1132 fail_if(compress != 9);
1133 fail_if(lossy != 0);
1135 data = eet_data_image_read(ef, EET_TEST_FILE_IMAGE "7", &w, &h, &alpha, &compress, &quality, &lossy);
1136 fail_if(data == NULL);
1137 fail_if(w != test_alpha.w);
1138 fail_if(h != test_alpha.h);
1139 fail_if(alpha != test_alpha.alpha);
1140 fail_if(compress != 9);
1141 fail_if(lossy != 0);
1142 fail_if(data[0] != test_alpha.color[0]);
1145 result = eet_data_image_header_read(ef, EET_TEST_FILE_IMAGE "9", &w, &h, &alpha, &compress, &quality, &lossy);
1146 fail_if(result == 0);
1147 fail_if(w != test_alpha.w);
1148 fail_if(h != test_alpha.h);
1149 fail_if(alpha != test_alpha.alpha);
1150 fail_if(lossy != 1);
1152 data = eet_data_image_read(ef, EET_TEST_FILE_IMAGE "9", &w, &h, &alpha, &compress, &quality, &lossy);
1153 fail_if(data == NULL);
1154 fail_if(w != test_alpha.w);
1155 fail_if(h != test_alpha.h);
1156 fail_if(alpha != test_alpha.alpha);
1157 fail_if(lossy != 1);
1162 fail_if(unlink(file) != 0);
1168 #define IM0 0x00112233
1169 #define IM1 0x44556677
1170 #define IM2 0x8899aabb
1171 #define IM3 0xccddeeff
1173 START_TEST(eet_small_image)
1175 char *file = strdup("/tmp/eet_suite_testXXXXXX");
1176 unsigned int image[4];
1194 fail_if(!(file = tmpnam(file)));
1196 ef = eet_open(file, EET_FILE_MODE_WRITE);
1199 result = eet_data_image_write(ef, "/images/test", image, 2, 2, 1, 9, 100, 0);
1200 fail_if(result == 0);
1204 ef = eet_open(file, EET_FILE_MODE_READ);
1207 data = (unsigned int*) eet_data_image_read(ef, "/images/test", &w, &h, &alpha, &compression, &quality, &lossy);
1208 fail_if(data == NULL);
1212 fail_if(unlink(file) != 0);
1214 fail_if(data[0] != IM0);
1215 fail_if(data[1] != IM1);
1216 fail_if(data[2] != IM2);
1217 fail_if(data[3] != IM3);
1225 START_TEST(eet_identity_simple)
1227 const char *buffer = "Here is a string of data to save !";
1233 char *file = strdup("/tmp/eet_suite_testXXXXXX");
1239 fail_if(!(file = tmpnam(file)));
1240 fail_if(chdir("src/tests"));
1241 fail_if(!(noread = fopen("/dev/null", "w")));
1243 /* Sign an eet file. */
1244 ef = eet_open(file, EET_FILE_MODE_WRITE);
1247 fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 0));
1249 k = eet_identity_open("cert.pem", "key.pem", NULL);
1252 fail_if(eet_identity_set(ef, k) != EET_ERROR_NONE);
1253 eet_identity_print(k, noread);
1257 /* Open a signed file. */
1258 ef = eet_open(file, EET_FILE_MODE_READ);
1261 test = eet_read(ef, "keys/tests", &size);
1263 fail_if(size != (int) strlen(buffer) + 1);
1265 fail_if(memcmp(test, buffer, strlen(buffer) + 1) != 0);
1267 tmp = eet_identity_x509(ef, &size);
1268 fail_if(tmp == NULL);
1270 eet_identity_certificate_print(tmp, size, noread);
1274 /* As we are changing file contain in less than 1s, this could get unnoticed
1275 by eet cache system. */
1278 /* Corrupting the file. */
1279 fd = open(file, O_WRONLY);
1282 fail_if(lseek(fd, 200, SEEK_SET) != 200);
1283 fail_if(write(fd, "42", 2) != 2);
1284 fail_if(lseek(fd, 50, SEEK_SET) != 50);
1285 fail_if(write(fd, "42", 2) != 2);
1286 fail_if(lseek(fd, 88, SEEK_SET) != 88);
1287 fail_if(write(fd, "42", 2) != 2);
1291 /* Attempt to open a modified file. */
1292 ef = eet_open(file, EET_FILE_MODE_READ);
1295 fail_if(unlink(file) != 0);
1301 START_TEST(eet_identity_open_simple)
1307 fail_if(chdir("src/tests"));
1309 k = eet_identity_open("cert.pem", "key.pem", NULL);
1312 if (k) eet_identity_close(k);
1318 START_TEST(eet_identity_open_pkcs8)
1324 fail_if(chdir("src/tests"));
1326 k = eet_identity_open("cert.pem", "key_enc_none.pem", NULL);
1329 if (k) eet_identity_close(k);
1335 static int pass_get(char *pass, int size, __UNUSED__ int rwflags, __UNUSED__ void *u)
1337 memset(pass, 0, size);
1339 if ((int) strlen("password") > size)
1341 snprintf(pass, size, "%s", "password");
1342 return strlen(pass);
1345 static int badpass_get(char *pass, int size, __UNUSED__ int rwflags, __UNUSED__ void *u)
1347 memset(pass, 0, size);
1349 if ((int) strlen("bad password") > size)
1351 snprintf(pass, size, "%s", "bad password");
1352 return strlen(pass);
1356 START_TEST(eet_identity_open_pkcs8_enc)
1362 fail_if(chdir("src/tests"));
1364 k = eet_identity_open("cert.pem", "key_enc.pem", NULL);
1367 if (k) eet_identity_close(k);
1369 k = eet_identity_open("cert.pem", "key_enc.pem", &badpass_get);
1372 if (k) eet_identity_close(k);
1374 k = eet_identity_open("cert.pem", "key_enc.pem", &pass_get);
1377 if (k) eet_identity_close(k);
1383 START_TEST(eet_cipher_decipher_simple)
1385 const char *buffer = "Here is a string of data to save !";
1386 const char *key = "This is a crypto key";
1387 const char *key_bad = "This is another crypto key";
1390 char *file = strdup("/tmp/eet_suite_testXXXXXX");
1395 fail_if(!(file = tmpnam(file)));
1396 fail_if(chdir("src/tests"));
1398 /* Crypt an eet file. */
1399 ef = eet_open(file, EET_FILE_MODE_WRITE);
1402 fail_if(!eet_write_cipher(ef, "keys/tests", buffer, strlen(buffer) + 1, 0, key));
1406 /* Decrypt an eet file. */
1407 ef = eet_open(file, EET_FILE_MODE_READ);
1410 test = eet_read_cipher(ef, "keys/tests", &size, key);
1412 fail_if(size != (int) strlen(buffer) + 1);
1414 fail_if(memcmp(test, buffer, strlen(buffer) + 1) != 0);
1418 /* Decrypt an eet file. */
1419 ef = eet_open(file, EET_FILE_MODE_READ);
1422 test = eet_read_cipher(ef, "keys/tests", &size, key_bad);
1424 if (size == (int) strlen(buffer) + 1)
1425 fail_if(memcmp(test, buffer, strlen(buffer) + 1) == 0);
1429 fail_if(unlink(file) != 0);
1435 #ifdef EFL_HAVE_THREADS
1437 static Eina_Bool open_worker_stop;
1439 # ifdef EFL_HAVE_POSIX_THREADS
1442 open_close_worker(void* path)
1444 while (!open_worker_stop)
1446 Eet_File* ef = eet_open((char const*)path, EET_FILE_MODE_READ);
1449 pthread_exit("eet_open() failed");
1453 Eet_Error err_code = eet_close(ef);
1454 if (err_code != EET_ERROR_NONE)
1455 pthread_exit("eet_close() failed");
1464 static unsigned int __stdcall
1465 open_close_worker(void *path)
1467 while (!open_worker_stop)
1469 Eet_File *ef = eet_open((char const *)path, EET_FILE_MODE_READ);
1476 Eet_Error err_code = eet_close(ef);
1477 if (err_code != EET_ERROR_NONE)
1487 START_TEST(eet_cache_concurrency)
1489 char *file = strdup("/tmp/eet_suite_testXXXXXX");
1490 const char *buffer = "test data";
1494 # ifdef EFL_HAVE_POSIX_THREADS
1498 unsigned int thread_id;
1504 /* create a file to test with */
1505 fail_if(!(file = tmpnam(file)));
1506 ef = eet_open(file, EET_FILE_MODE_WRITE);
1508 fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 0));
1510 /* start a thread that repeatedly opens and closes a file */
1511 open_worker_stop = 0;
1512 # ifdef EFL_HAVE_POSIX_THREADS
1513 pthread_create(&thread, NULL, open_close_worker, file);
1515 thread = _beginthreadex(NULL, 0, open_close_worker, file, 0, &thread_id);
1517 /* clear the cache repeatedly in this thread */
1518 for (n = 0; n < 50000; ++n)
1523 /* join the other thread, and fail if it returned an error message */
1524 open_worker_stop = 1;
1525 # ifdef EFL_HAVE_POSIX_THREADS
1526 fail_if(pthread_join(thread, &thread_ret) != 0);
1527 fail_unless(thread_ret == NULL, (char const*)thread_ret);
1529 ret = WaitForSingleObject((HANDLE)thread, INFINITE);
1530 fail_if(ret != WAIT_OBJECT_0);
1531 fail_if(GetExitCoeThread((HANDLE)thread, &ret) == FALSE);
1535 fail_if(unlink(file) != 0);
1540 #endif /* EFL_HAVE_THREADS */
1542 typedef struct _Eet_Connection_Data Eet_Connection_Data;
1543 struct _Eet_Connection_Data
1545 Eet_Connection *conn;
1546 Eet_Data_Descriptor *edd;
1551 _eet_connection_read(const void *eet_data, size_t size, void *user_data)
1553 Eet_Connection_Data *dt = user_data;
1554 Eet_Test_Ex_Type *result;
1558 result = eet_data_descriptor_decode(dt->edd, eet_data, size);
1559 node = eet_data_node_decode_cipher(eet_data, NULL, size);
1561 /* Test the resulting data. */
1563 fail_if(_eet_test_ex_check(result, 0) != 0);
1564 fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1) != 0);
1565 fail_if(eina_list_data_get(result->ilist) == NULL);
1566 fail_if(*((int*)eina_list_data_get(result->ilist)) != 42);
1567 fail_if(eina_list_data_get(result->slist) == NULL);
1568 fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0);
1569 fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL);
1570 fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0);
1571 fail_if(strcmp(result->charray[0], "test") != 0);
1574 if (result->hash) eina_hash_foreach(result->hash, func, &test);
1576 if (result->ihash) eina_hash_foreach(result->ihash, func7, &test);
1581 dt->test = EINA_TRUE;
1582 fail_if(!eet_connection_node_send(dt->conn, node, NULL));
1589 _eet_connection_write(const void *data, size_t size, void *user_data)
1591 Eet_Connection_Data *dt = user_data;
1596 int step = size / 3;
1598 eet_connection_received(dt->conn, data, step);
1599 eet_connection_received(dt->conn, (char*) data + step, step);
1601 still = eet_connection_received(dt->conn, (char*) data + 2 * step, size);
1604 still = eet_connection_received(dt->conn, data, size);
1610 START_TEST(eet_connection_check)
1612 Eet_Connection *conn;
1613 Eet_Data_Descriptor *edd;
1614 Eet_Data_Descriptor_Class eddc;
1615 Eet_Connection_Data ecd;
1616 Eet_Test_Ex_Type etbt;
1621 _eet_test_ex_set(&etbt, 0);
1622 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
1623 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
1624 etbt.hash = eina_hash_string_superfast_new(NULL);
1625 eina_hash_add(etbt.hash, EET_TEST_KEY1, _eet_test_ex_set(NULL, 2));
1626 eina_hash_add(etbt.hash, EET_TEST_KEY2, _eet_test_ex_set(NULL, 2));
1627 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
1628 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
1629 etbt.ihash = eina_hash_string_superfast_new(NULL);
1630 eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7);
1631 eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7);
1632 etbt.slist = eina_list_prepend(NULL, "test");
1633 etbt.shash = eina_hash_string_superfast_new(NULL);
1634 eina_hash_add(etbt.shash, EET_TEST_KEY1, "test");
1635 memset(&etbt.charray, 0, sizeof(etbt.charray));
1636 etbt.charray[0] = "test";
1638 eet_eina_file_data_descriptor_class_set(&eddc, "Eet_Test_Ex_Type", sizeof(Eet_Test_Ex_Type));
1640 edd = eet_data_descriptor_file_new(&eddc);
1643 _eet_build_ex_descriptor(edd);
1645 /* Create a connection. */
1646 conn = eet_connection_new(_eet_connection_read, _eet_connection_write, &ecd);
1650 ecd.test = EINA_FALSE;
1654 /* Test the connection. */
1655 fail_if(!eet_connection_send(conn, edd, &etbt, NULL));
1659 fail_if(!eet_connection_close(conn, &on_going));
1675 typedef struct _Eet_5FP Eet_5FP;
1685 typedef struct _Eet_5DBL Eet_5DBL;
1689 Eet_Data_Descriptor_Class eddc;
1690 Eet_Data_Descriptor *edd_5FP;
1691 Eet_Data_Descriptor *edd_5DBL;
1700 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_5FP);
1701 edd_5FP = eet_data_descriptor_stream_new(&eddc);
1703 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp32", fp32, EET_T_F32P32);
1704 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp16", fp16, EET_T_F16P16);
1705 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp8", fp8, EET_T_F8P24);
1706 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "f1", f1, EET_T_F32P32);
1707 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "f0", f0, EET_T_F32P32);
1709 eet_eina_stream_data_descriptor_class_set(&eddc, "Eet_5FP", sizeof (Eet_5DBL));
1710 edd_5DBL = eet_data_descriptor_stream_new(&eddc);
1712 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp32", fp32, EET_T_DOUBLE);
1713 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp16", fp16, EET_T_DOUBLE);
1714 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp8", fp8, EET_T_FLOAT);
1715 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "f1", f1, EET_T_DOUBLE);
1716 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "f0", f0, EET_T_DOUBLE);
1718 origin.fp32 = eina_f32p32_double_from(1.125);
1719 origin.fp16 = eina_f16p16_int_from(2000);
1720 origin.fp8 = eina_f8p24_int_from(125);
1721 origin.f1 = eina_f32p32_int_from(1);
1724 blob = eet_data_descriptor_encode(edd_5FP, &origin, &size);
1725 fail_if(!blob || size <= 0);
1727 build = eet_data_descriptor_decode(edd_5FP, blob, size);
1730 convert = eet_data_descriptor_decode(edd_5DBL, blob, size);
1733 fail_if(build->fp32 != eina_f32p32_double_from(1.125));
1734 fail_if(build->fp16 != eina_f16p16_int_from(2000));
1735 fail_if(build->fp8 != eina_f8p24_int_from(125));
1736 fail_if(build->f1 != eina_f32p32_int_from(1));
1737 fail_if(build->f0 != 0);
1739 fail_if(convert->fp32 != 1.125);
1740 fail_if(convert->fp16 != 2000);
1741 fail_if(convert->fp8 != 125);
1742 fail_if(convert->f1 != 1);
1743 fail_if(convert->f0 != 0);
1749 START_TEST(eet_file_fp)
1751 char *file = strdup("/tmp/eet_suite_testXXXXXX");
1752 Eet_Data_Descriptor_Class eddc;
1753 Eet_Data_Descriptor *edd_5FP;
1754 Eet_Data_Descriptor *edd_5DBL;
1762 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_5FP);
1763 edd_5FP = eet_data_descriptor_file_new(&eddc);
1765 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp32", fp32, EET_T_F32P32);
1766 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp16", fp16, EET_T_F16P16);
1767 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp8", fp8, EET_T_F8P24);
1768 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "f1", f1, EET_T_F32P32);
1769 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "f0", f0, EET_T_F32P32);
1771 eet_eina_file_data_descriptor_class_set(&eddc, "Eet_5FP", sizeof (Eet_5DBL));
1772 edd_5DBL = eet_data_descriptor_file_new(&eddc);
1774 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp32", fp32, EET_T_DOUBLE);
1775 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp16", fp16, EET_T_DOUBLE);
1776 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp8", fp8, EET_T_FLOAT);
1777 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "f1", f1, EET_T_DOUBLE);
1778 EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "f0", f0, EET_T_DOUBLE);
1780 origin.fp32 = eina_f32p32_double_from(1.125);
1781 origin.fp16 = eina_f16p16_int_from(2000);
1782 origin.fp8 = eina_f8p24_int_from(125);
1783 origin.f1 = eina_f32p32_int_from(1);
1786 fail_if(!(file = tmpnam(file)));
1788 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
1791 fail_if(!eet_data_write(ef, edd_5FP, EET_TEST_FILE_KEY1, &origin, 1));
1793 build = eet_data_read(ef, edd_5FP, EET_TEST_FILE_KEY1);
1796 convert = eet_data_read(ef, edd_5DBL, EET_TEST_FILE_KEY1);
1799 fail_if(build->fp32 != eina_f32p32_double_from(1.125));
1800 fail_if(build->fp16 != eina_f16p16_int_from(2000));
1801 fail_if(build->fp8 != eina_f8p24_int_from(125));
1802 fail_if(build->f1 != eina_f32p32_int_from(1));
1803 fail_if(build->f0 != 0);
1805 fail_if(convert->fp32 != 1.125);
1806 fail_if(convert->fp16 != 2000);
1807 fail_if(convert->fp8 != 125);
1808 fail_if(convert->f1 != 1);
1809 fail_if(convert->f0 != 0);
1813 fail_if(unlink(file) != 0);
1819 typedef struct _Eet_Union_Test Eet_Union_Test;
1820 typedef struct _Eet_Variant_Test Eet_Variant_Test;
1821 typedef struct _Eet_Variant_Type Eet_Variant_Type;
1822 typedef struct _Eet_Inherit_Test1 Eet_Inherit_Test1;
1823 typedef struct _Eet_Inherit_Test2 Eet_Inherit_Test2;
1824 typedef struct _Eet_Inherit_Test3 Eet_Inherit_Test3;
1825 typedef struct _Eet_St1 Eet_St1;
1826 typedef struct _Eet_St2 Eet_St2;
1827 typedef struct _Eet_St3 Eet_St3;
1828 typedef struct _Eet_List Eet_List;
1830 typedef enum _Eet_Union
1845 { EET_UNKNOWN, NULL }
1858 unsigned long long v1;
1866 struct _Eet_Union_Test
1877 struct _Eet_Variant_Type
1880 Eina_Bool unknow : 1;
1883 struct _Eet_Variant_Test
1888 Eina_List *data_list;
1891 struct _Eet_Inherit_Test1
1896 struct _Eet_Inherit_Test2
1901 struct _Eet_Inherit_Test3
1913 _eet_union_type_get(const void *data, Eina_Bool *unknow)
1915 const Eet_Union *u = data;
1918 if (unknow) *unknow = EINA_FALSE;
1919 for (i = 0; eet_mapping[i].name != NULL; ++i)
1920 if (*u == eet_mapping[i].u)
1921 return eet_mapping[i].name;
1923 if (unknow) *unknow = EINA_TRUE;
1928 _eet_union_type_set(const char *type, void *data, Eina_Bool unknow)
1930 Eet_Union *u = data;
1933 if (unknow) return EINA_FALSE;
1935 for (i = 0; eet_mapping[i].name != NULL; ++i)
1936 if (strcmp(eet_mapping[i].name, type) == 0)
1938 *u = eet_mapping[i].u;
1946 _eet_variant_type_get(const void *data, Eina_Bool *unknow)
1948 const Eet_Variant_Type *type = data;
1951 if (unknow) *unknow = type->unknow;
1952 for (i = 0; eet_mapping[i].name != NULL; ++i)
1953 if (strcmp(type->type, eet_mapping[i].name) == 0)
1954 return eet_mapping[i].name;
1956 if (unknow) *unknow = EINA_FALSE;
1961 _eet_variant_type_set(const char *type, void *data, Eina_Bool unknow)
1963 Eet_Variant_Type *vt = data;
1966 vt->unknow = unknow;
1970 static Eet_Data_Descriptor*
1973 Eet_Data_Descriptor_Class eddc;
1974 Eet_Data_Descriptor *res;
1976 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_St1);
1977 res = eet_data_descriptor_stream_new(&eddc);
1978 EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St1, "val1", val1, EET_T_DOUBLE);
1979 EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St1, "stuff", stuff, EET_T_INT);
1980 EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St1, "s1", s1, EET_T_STRING);
1986 _eet_st1_set(Eet_St1 *st1, int i)
1988 st1->val1 = EET_TEST_DOUBLE;
1989 st1->stuff = EET_TEST_INT + i;
1990 st1->s1 = EET_TEST_STRING;
1994 _eet_st1_cmp(Eet_St1 *st1, int i)
2000 tmp = st1->val1 - EET_TEST_DOUBLE;
2001 if (tmp < 0) tmp = -tmp;
2002 fail_if(tmp > 0.005);
2003 fail_if(st1->stuff != EET_TEST_INT + i);
2004 fail_if(strcmp(st1->s1, EET_TEST_STRING));
2007 static Eet_Data_Descriptor*
2010 Eet_Data_Descriptor_Class eddc;
2011 Eet_Data_Descriptor *res;
2013 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_St2);
2014 res = eet_data_descriptor_stream_new(&eddc);
2015 EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St2, "b1", b1, EET_T_UCHAR);
2016 EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St2, "v1", v1, EET_T_ULONG_LONG);
2022 _eet_st2_set(Eet_St2 *st2, int i)
2024 st2->b1 = EINA_TRUE;
2025 st2->v1 = EET_TEST_LONG_LONG + i;
2029 _eet_st2_cmp(Eet_St2 *st2, int i)
2032 fail_if(st2->v1 != EET_TEST_LONG_LONG + i);
2035 static Eet_Data_Descriptor*
2038 Eet_Data_Descriptor_Class eddc;
2039 Eet_Data_Descriptor *res;
2041 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_St3);
2042 res = eet_data_descriptor_stream_new(&eddc);
2043 EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St3, "boby", boby, EET_T_INT);
2049 _eet_st3_set(Eet_St3 *st3, int i)
2051 st3->boby = EET_TEST_INT + i;
2055 _eet_st3_cmp(Eet_St3 *st3, int i)
2057 fail_if(st3->boby != EET_TEST_INT + i);
2060 START_TEST(eet_test_union)
2062 Eet_Union_Test *eut;
2064 Eet_Data_Descriptor_Class eddc;
2065 Eet_Data_Descriptor *edd;
2066 Eet_Data_Descriptor *unified;
2067 Eet_Data_Descriptor *m;
2075 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_Union_Test);
2076 edd = eet_data_descriptor_stream_new(&eddc);
2078 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_Union_Test);
2079 m = eet_data_descriptor_stream_new(&eddc);
2081 eddc.version = EET_DATA_DESCRIPTOR_CLASS_VERSION;
2082 eddc.func.type_get = _eet_union_type_get;
2083 eddc.func.type_set = _eet_union_type_set;
2084 unified = eet_data_descriptor_stream_new(&eddc);
2086 EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST1", _eet_st1_dd());
2087 EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST2", _eet_st2_dd());
2088 EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST3", _eet_st3_dd());
2090 EET_DATA_DESCRIPTOR_ADD_UNION(edd, Eet_Union_Test, "u", u, type, unified);
2092 EET_DATA_DESCRIPTOR_ADD_LIST(m, Eet_List, "list", list, edd);
2094 l = calloc(1, sizeof (Eet_List));
2096 #define EUT_NEW(Type_Index) \
2097 eut = calloc(1, sizeof (Eet_Union_Test)); \
2098 eut->type = EET_ST##Type_Index; \
2099 _eet_st##Type_Index##_set(&(eut->u.st##Type_Index), i);
2101 for (i = 0; i < 3; ++i)
2104 l->list = eina_list_append(l->list, eut);
2107 l->list = eina_list_append(l->list, eut);
2110 l->list = eina_list_append(l->list, eut);
2113 blob = eet_data_descriptor_encode(m, l, &size);
2114 fail_if(!blob || size <= 0);
2116 l = eet_data_descriptor_decode(m, blob, size);
2119 fail_if(eina_list_count(l->list) != 9);
2121 #define EUT_CMP(Type_Index) \
2122 eut = eina_list_nth(l->list, i * 3 + Type_Index - 1); \
2123 fail_if(eut->type != EET_ST##Type_Index); \
2124 _eet_st##Type_Index##_cmp(&(eut->u.st##Type_Index), i);
2126 for (i = 0; i < 3; ++i)
2138 START_TEST(eet_test_variant)
2140 Eet_Variant_Test *evt;
2145 Eet_Data_Descriptor_Class eddc;
2146 Eet_Data_Descriptor *edd;
2147 Eet_Data_Descriptor *unified;
2148 Eet_Data_Descriptor *m;
2156 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_Variant_Test);
2157 edd = eet_data_descriptor_stream_new(&eddc);
2159 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_Variant_Test);
2160 m = eet_data_descriptor_stream_new(&eddc);
2162 eddc.version = EET_DATA_DESCRIPTOR_CLASS_VERSION;
2163 eddc.func.type_get = _eet_variant_type_get;
2164 eddc.func.type_set = _eet_variant_type_set;
2165 unified = eet_data_descriptor_stream_new(&eddc);
2167 EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST1", _eet_st1_dd());
2168 EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST2", _eet_st2_dd());
2169 EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST3", _eet_st3_dd());
2171 EET_DATA_DESCRIPTOR_ADD_VARIANT(edd, Eet_Variant_Test, "data", data, t, unified);
2173 unified = eet_data_descriptor_stream_new(&eddc);
2174 eet_data_descriptor_element_add(unified, "ST1",
2175 EET_T_UNKNOW, EET_G_LIST,
2176 0, 0, NULL, _eet_st1_dd());
2177 eet_data_descriptor_element_add(unified, "ST2",
2178 EET_T_UNKNOW, EET_G_LIST,
2179 0, 0, NULL, _eet_st2_dd());
2181 EET_DATA_DESCRIPTOR_ADD_VARIANT(edd, Eet_Variant_Test,
2182 "data_list", data_list, t, unified);
2184 EET_DATA_DESCRIPTOR_ADD_LIST(m, Eet_List, "list", list, edd);
2186 l = calloc(1, sizeof (Eet_List));
2188 #define EVT_NEW(Type_Index) \
2189 evt = calloc(1, sizeof (Eet_Variant_Test)); \
2190 evt->t.type = eet_mapping[Type_Index - 1].name; \
2191 st##Type_Index = calloc(1, sizeof (Eet_St##Type_Index)); \
2192 _eet_st##Type_Index##_set(st##Type_Index, i); \
2193 evt->data = st##Type_Index;
2195 for (i = 0; i < 3; ++i)
2198 l->list = eina_list_append(l->list, evt);
2200 st1 = calloc(1, sizeof (Eet_St1));
2201 _eet_st1_set(st1, i);
2202 evt->data_list = eina_list_append(evt->data_list, st1);
2205 l->list = eina_list_append(l->list, evt);
2208 l->list = eina_list_append(l->list, evt);
2211 blob = eet_data_descriptor_encode(m, l, &size);
2212 fail_if(!blob || size <= 0);
2214 l = eet_data_descriptor_decode(m, blob, size);
2217 fail_if(eina_list_count(l->list) != 9);
2219 #define EVT_CMP(Type_Index) \
2220 evt = eina_list_nth(l->list, i * 3 + Type_Index - 1); \
2221 fail_if(strcmp(evt->t.type, eet_mapping[Type_Index - 1].name) != 0); \
2222 _eet_st##Type_Index##_cmp(evt->data, i);
2224 for (i = 0; i < 3; ++i)
2228 fail_if(!evt->data_list);
2229 fail_if(eina_list_count(evt->data_list) != 1);
2231 st1 = eina_list_data_get(evt->data_list);
2232 _eet_st1_cmp(st1, i);
2249 s = suite_create("Eet");
2251 tc = tcase_create("Eet_Init");
2252 tcase_add_test(tc, eet_test_init);
2253 suite_add_tcase(s, tc);
2255 tc = tcase_create("Eet Data Encoding/Decoding");
2256 tcase_add_test(tc, eet_test_basic_data_type_encoding_decoding);
2257 tcase_add_test(tc, eet_test_data_type_encoding_decoding);
2258 tcase_add_test(tc, eet_test_data_type_dump_undump);
2259 tcase_add_test(tc, eet_fp);
2260 tcase_add_test(tc, eet_test_union);
2261 tcase_add_test(tc, eet_test_variant);
2262 suite_add_tcase(s, tc);
2264 tc = tcase_create("Eet File");
2265 tcase_add_test(tc, eet_file_simple_write);
2266 tcase_add_test(tc, eet_file_data_test);
2267 tcase_add_test(tc, eet_file_data_dump_test);
2268 tcase_add_test(tc, eet_file_fp);
2269 suite_add_tcase(s, tc);
2271 tc = tcase_create("Eet Image");
2272 tcase_add_test(tc, eet_image);
2273 tcase_add_test(tc, eet_small_image);
2274 suite_add_tcase(s, tc);
2276 #ifdef HAVE_SIGNATURE
2277 tc = tcase_create("Eet Identity");
2278 tcase_add_test(tc, eet_identity_simple);
2279 tcase_add_test(tc, eet_identity_open_simple);
2280 tcase_add_test(tc, eet_identity_open_pkcs8);
2281 tcase_add_test(tc, eet_identity_open_pkcs8_enc);
2282 suite_add_tcase(s, tc);
2286 tc = tcase_create("Eet Cipher");
2287 tcase_add_test(tc, eet_cipher_decipher_simple);
2288 suite_add_tcase(s, tc);
2291 #ifdef EFL_HAVE_THREADS
2292 tc = tcase_create("Eet Cache");
2293 tcase_add_test(tc, eet_cache_concurrency);
2294 suite_add_tcase(s, tc);
2297 tc = tcase_create("Eet Connection");
2298 tcase_add_test(tc, eet_connection_check);
2299 suite_add_tcase(s, tc);
2312 sr = srunner_create(s);
2313 srunner_run_all(sr, CK_NORMAL);
2314 failed_count = srunner_ntests_failed(sr);
2317 return (failed_count == 0) ? EXIT_SUCCESS : EXIT_FAILURE;