18 #include "eet_suite.h"
20 START_TEST(eet_test_init)
32 typedef struct _Eet_Test_Basic_Type Eet_Test_Basic_Type;
33 struct _Eet_Test_Basic_Type
47 unsigned long long ul;
48 Eet_Test_Basic_Type *empty;
49 Eet_Test_Basic_Type *with;
52 #define EET_TEST_CHAR 0x42
53 #define EET_TEST_SHORT 0x4224
54 #define EET_TEST_INT 0x42211224
55 #define EET_TEST_LONG_LONG 0x84CB42211224BC48
56 #define EET_TEST_STRING "my little test with escape \\\""
57 #define EET_TEST_KEY1 "key1"
58 #define EET_TEST_KEY2 "key2"
59 #define EET_TEST_FLOAT 123.45689
60 #define EET_TEST_FLOAT2 1.0
61 #define EET_TEST_FLOAT3 0.25
62 #define EET_TEST_FLOAT4 0.0001234
63 #define EET_TEST_DOUBLE 123456789.9876543210
64 #define EET_TEST_DOUBLE2 1.0
65 #define EET_TEST_DOUBLE3 0.25
66 #define EET_TEST_FILE_KEY1 "keys/data/1"
67 #define EET_TEST_FILE_KEY2 "keys/data/2"
68 #define EET_TEST_FILE_IMAGE "keys/images/"
70 typedef struct _Eet_Test_Image Eet_Test_Image;
71 struct _Eet_Test_Image
79 static const Eet_Test_Image test_noalpha = {
82 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000,
83 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000,
84 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00,
85 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA,
86 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000,
87 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000,
88 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00,
89 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA
93 static const Eet_Test_Image test_alpha = {
96 0x0FAA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x0F110000,
97 0x0000AA00, 0x0F0000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x0F110000, 0x00AA0000,
98 0x000000AA, 0x00110000, 0x0FAA0000, 0x0000AA00, 0x000000AA, 0x0F110000, 0x00AA0000, 0x0000AA00,
99 0x00110000, 0x00AA0000, 0x0000AA00, 0x0F0000AA, 0x0F110000, 0x00AA0000, 0x0000AA00, 0x000000AA,
100 0x00AA0000, 0x0000AA00, 0x000000AA, 0x0F110000, 0x0FAA0000, 0x0000AA00, 0x000000AA, 0x00110000,
101 0x0000AA00, 0x000000AA, 0x0F110000, 0x00AA0000, 0x0000AA00, 0x0F0000AA, 0x00110000, 0x00AA0000,
102 0x000000AA, 0x0F110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x0FAA0000, 0x0000AA00,
103 0x0F110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x0F0000AA
108 _eet_test_basic_set(Eet_Test_Basic_Type *res, int i)
110 res->c = EET_TEST_CHAR;
111 res->s = EET_TEST_SHORT;
112 res->i = EET_TEST_INT + i;
113 res->l = EET_TEST_LONG_LONG;
114 res->str = EET_TEST_STRING;
115 res->istr = EET_TEST_STRING;
116 res->f1 = - EET_TEST_FLOAT;
117 res->d = - EET_TEST_DOUBLE;
118 res->f2 = EET_TEST_FLOAT4;
119 res->uc = EET_TEST_CHAR;
120 res->us = EET_TEST_SHORT;
121 res->ui = EET_TEST_INT;
122 res->ul = EET_TEST_LONG_LONG;
128 Eet_Test_Basic_Type *tmp;
130 tmp = malloc(sizeof (Eet_Test_Basic_Type));
134 tmp->c = EET_TEST_CHAR;
135 tmp->s = EET_TEST_SHORT;
136 tmp->i = EET_TEST_INT + i + 1;
137 tmp->l = EET_TEST_LONG_LONG;
138 tmp->str = EET_TEST_STRING;
139 tmp->istr = EET_TEST_STRING;
140 tmp->f1 = - EET_TEST_FLOAT;
141 tmp->d = - EET_TEST_DOUBLE;
142 tmp->f2 = EET_TEST_FLOAT4;
143 tmp->uc = EET_TEST_CHAR;
144 tmp->us = EET_TEST_SHORT;
145 tmp->ui = EET_TEST_INT;
146 tmp->ul = EET_TEST_LONG_LONG;
153 _eet_test_basic_check(Eet_Test_Basic_Type *result, int i)
157 fail_if(result->c != EET_TEST_CHAR);
158 fail_if(result->s != EET_TEST_SHORT);
159 fail_if(result->i != EET_TEST_INT + i);
160 fail_if(result->l != (long long) EET_TEST_LONG_LONG);
161 fail_if(strcmp(result->str, EET_TEST_STRING) != 0);
162 fail_if(strcmp(result->istr, EET_TEST_STRING) != 0);
163 fail_if(result->uc != EET_TEST_CHAR);
164 fail_if(result->us != EET_TEST_SHORT);
165 fail_if(result->ui != EET_TEST_INT);
166 fail_if(result->ul != EET_TEST_LONG_LONG);
168 tmp = (result->f1 + EET_TEST_FLOAT);
169 if (tmp < 0) tmp = -tmp;
170 fail_if(tmp > 0.005);
172 tmp = (result->f2 - EET_TEST_FLOAT4);
173 if (tmp < 0) tmp = -tmp;
174 fail_if(tmp > 0.005);
176 tmp = (result->d + EET_TEST_DOUBLE);
177 if (tmp < 0) tmp = -tmp;
178 fail_if(tmp > 0.00005);
180 fail_if(result->empty != NULL);
183 Eet_Test_Basic_Type *tmp;
186 fail_if(tmp == NULL);
188 fail_if(tmp->c != EET_TEST_CHAR);
189 fail_if(tmp->s != EET_TEST_SHORT);
190 fail_if(tmp->i != EET_TEST_INT + i + 1);
191 fail_if(tmp->l != (long long) EET_TEST_LONG_LONG);
192 fail_if(strcmp(tmp->str, EET_TEST_STRING) != 0);
193 fail_if(strcmp(tmp->istr, EET_TEST_STRING) != 0);
194 fail_if(tmp->uc != EET_TEST_CHAR);
195 fail_if(tmp->us != EET_TEST_SHORT);
196 fail_if(tmp->ui != EET_TEST_INT);
197 fail_if(tmp->ul != EET_TEST_LONG_LONG);
200 fail_if(result->with != NULL);
204 _eet_build_basic_descriptor(Eet_Data_Descriptor *edd)
206 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "c", c, EET_T_CHAR);
207 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "s", s, EET_T_SHORT);
208 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "i", i, EET_T_INT);
209 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "l", l, EET_T_LONG_LONG);
210 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "str", str, EET_T_STRING);
211 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "istr", istr, EET_T_INLINED_STRING);
212 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "f1", f1, EET_T_FLOAT);
213 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "f2", f2, EET_T_FLOAT);
214 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "d", d, EET_T_DOUBLE);
215 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "uc", uc, EET_T_UCHAR);
216 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "us", us, EET_T_USHORT);
217 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "ui", ui, EET_T_UINT);
218 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Basic_Type, "ul", ul, EET_T_ULONG_LONG);
220 EET_DATA_DESCRIPTOR_ADD_SUB(edd, Eet_Test_Basic_Type, "empty", empty, edd);
221 EET_DATA_DESCRIPTOR_ADD_SUB(edd, Eet_Test_Basic_Type, "with", with, edd);
224 START_TEST(eet_test_basic_data_type_encoding_decoding)
226 Eet_Data_Descriptor *edd;
227 Eet_Test_Basic_Type *result;
228 Eet_Data_Descriptor_Class eddc;
229 Eet_Test_Basic_Type etbt;
235 _eet_test_basic_set(&etbt, 0);
237 eet_test_setup_eddc(&eddc);
238 eddc.name = "Eet_Test_Basic_Type";
239 eddc.size = sizeof(Eet_Test_Basic_Type);
241 edd = eet_data_descriptor2_new(&eddc);
244 _eet_build_basic_descriptor(edd);
246 transfert = eet_data_descriptor_encode(edd, &etbt, &size);
247 fail_if(!transfert || size <= 0);
249 result = eet_data_descriptor_decode(edd, transfert, size);
252 _eet_test_basic_check(result, 0);
257 eet_data_descriptor_free(edd);
263 typedef struct _Eet_Test_Ex_Type Eet_Test_Ex_Type;
264 struct _Eet_Test_Ex_Type
269 unsigned long long l;
285 Eet_Test_Basic_Type sarray1[10];
286 unsigned int sarray2[5];
287 unsigned int varray1_count;
288 unsigned int *varray1;
289 unsigned int varray2_count;
290 Eet_Test_Basic_Type *varray2;
294 unsigned long long ul;
302 _eet_build_ex_descriptor(Eet_Data_Descriptor *edd)
304 Eet_Data_Descriptor_Class eddc;
305 Eet_Test_Ex_Type etbt;
306 Eet_Data_Descriptor *eddb;
308 eet_test_setup_eddc(&eddc);
309 eddc.name = "Eet_Test_Basic_Type";
310 eddc.size = sizeof(Eet_Test_Basic_Type);
311 eddb = eet_data_descriptor3_new(&eddc);
314 _eet_build_basic_descriptor(eddb);
316 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "c", c, EET_T_CHAR);
317 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "s", s, EET_T_SHORT);
318 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "i", i, EET_T_INT);
319 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "l", l, EET_T_LONG_LONG);
320 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "str", str, EET_T_STRING);
321 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "istr", istr, EET_T_INLINED_STRING);
322 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "f1", f1, EET_T_FLOAT);
323 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "f2", f2, EET_T_FLOAT);
324 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "f3", f3, EET_T_FLOAT);
325 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "f4", f4, EET_T_FLOAT);
326 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "d1", d1, EET_T_DOUBLE);
327 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "d2", d2, EET_T_DOUBLE);
328 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "d3", d3, EET_T_DOUBLE);
329 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "d4", d4, EET_T_DOUBLE);
330 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "uc", uc, EET_T_UCHAR);
331 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "us", us, EET_T_USHORT);
332 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "ui", ui, EET_T_UINT);
333 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "ul", ul, EET_T_ULONG_LONG);
334 EET_DATA_DESCRIPTOR_ADD_ARRAY(edd, Eet_Test_Ex_Type, "sarray1", sarray1, eddb);
335 EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY(edd, Eet_Test_Ex_Type, "varray2", varray2, eddb);
336 eet_data_descriptor_element_add(edd, "varray1", EET_T_INT, EET_G_VAR_ARRAY,
337 (char *)(&(etbt.varray1)) - (char *)(&(etbt)),
338 (char *)(&(etbt.varray1_count)) - (char *)(&(etbt)), /* 0, */NULL, NULL);
339 eet_data_descriptor_element_add(edd, "sarray2", EET_T_INT, EET_G_ARRAY,
340 (char *)(&(etbt.sarray2)) - (char *)(&(etbt)),
341 /* 0, */sizeof(etbt.sarray2)/sizeof(etbt.sarray2[0]), NULL, NULL);
342 EET_DATA_DESCRIPTOR_ADD_LIST(edd, Eet_Test_Ex_Type, "list", list, edd);
343 EET_DATA_DESCRIPTOR_ADD_HASH(edd, Eet_Test_Ex_Type, "hash", hash, edd);
344 eet_data_descriptor_element_add(edd, "ilist", EET_T_INT, EET_G_LIST,
345 (char *)(&(etbt.ilist)) - (char *)(&(etbt)),
346 0, /* 0, */NULL, NULL);
347 eet_data_descriptor_element_add(edd, "ihash", EET_T_INT, EET_G_HASH,
348 (char *)(&(etbt.ihash)) - (char *)(&(etbt)),
349 0, /* 0, */NULL, NULL);
350 eet_data_descriptor_element_add(edd, "slist", EET_T_STRING, EET_G_LIST,
351 (char *)(&(etbt.slist)) - (char *)(&(etbt)),
352 0, /* 0, */NULL, NULL);
355 static Eet_Test_Ex_Type*
356 _eet_test_ex_set(Eet_Test_Ex_Type *res, int offset)
360 if (!res) res = malloc( sizeof(Eet_Test_Ex_Type));
361 if (!res) return NULL;
363 res->c = EET_TEST_CHAR + offset;
364 res->s = EET_TEST_SHORT + offset;
365 res->i = EET_TEST_INT + offset;
366 res->l = EET_TEST_LONG_LONG + offset;
367 res->str = EET_TEST_STRING;
368 res->istr = EET_TEST_STRING;
369 res->f1 = EET_TEST_FLOAT + offset;
370 res->f2 = -(EET_TEST_FLOAT2 + offset);
371 res->f3 = EET_TEST_FLOAT3 + offset;
372 res->f4 = EET_TEST_FLOAT2 + offset;
373 res->d1 = EET_TEST_DOUBLE + offset;
374 res->d2 = -(EET_TEST_DOUBLE2 + offset);
375 res->d3 = EET_TEST_DOUBLE3 + offset;
376 res->d4 = EET_TEST_DOUBLE2 + offset;
383 res->varray2 = malloc(sizeof (Eet_Test_Basic_Type) * 10);
384 res->varray1 = malloc(sizeof (int) * 5);
385 fail_if(!res->varray1 || !res->varray2);
386 for (i = 0; i < 10; ++i)
388 _eet_test_basic_set(res->sarray1 + i, i);
389 _eet_test_basic_set(res->varray2 + i, i);
391 res->varray2_count = 10;
392 for (i = 0; i < 5; ++i)
394 res->sarray2[i] = i * 42 + 1;
395 res->varray1[i] = i * 42 + 1;
397 res->varray1_count = 5;
399 res->uc = EET_TEST_CHAR + offset;
400 res->us = EET_TEST_SHORT + offset;
401 res->ui = EET_TEST_INT + offset;
402 res->ul = EET_TEST_LONG_LONG + offset;
408 _eet_test_ex_check(Eet_Test_Ex_Type *stuff, int offset)
413 if (!stuff) return 1;
415 if (stuff->c != EET_TEST_CHAR + offset) return 1;
416 if (stuff->s != EET_TEST_SHORT + offset) return 1;
417 if (stuff->i != EET_TEST_INT + offset) return 1;
418 if (stuff->l != EET_TEST_LONG_LONG + offset) return 1;
419 if (strcmp(stuff->str, EET_TEST_STRING) != 0) return 1;
420 if (strcmp(stuff->istr, EET_TEST_STRING) != 0) return 1;
422 tmp = stuff->f1 - (EET_TEST_FLOAT + offset);
423 if (tmp < 0) tmp = -tmp;
424 if (tmp > 0.005) return 1;
426 tmp = stuff->d1 - (EET_TEST_DOUBLE + offset);
427 if (tmp < 0) tmp = -tmp;
428 if (tmp > 0.00005) return 1;
430 if (stuff->f2 != - (EET_TEST_FLOAT2 + offset)) return 1;
431 if (stuff->d2 != - (EET_TEST_DOUBLE2 + offset)) return 1;
433 if (stuff->f3 != EET_TEST_FLOAT3 + offset) return 1;
434 if (stuff->d3 != EET_TEST_DOUBLE3 + offset) return 1;
436 if (stuff->f4 != EET_TEST_FLOAT2 + offset) return 1;
437 if (stuff->d4 != EET_TEST_DOUBLE2 + offset) return 1;
439 if (stuff->uc != EET_TEST_CHAR + offset) return 1;
440 if (stuff->us != EET_TEST_SHORT + offset) return 1;
441 if (stuff->ui != (unsigned int) EET_TEST_INT + offset) return 1;
442 if (stuff->ul != EET_TEST_LONG_LONG + offset) return 1;
444 for (i = 0; i < 5; ++i)
445 if (stuff->sarray2[i] != i * 42 + 1)
448 for (i = 0; i < 10; ++i)
449 _eet_test_basic_check(stuff->sarray1 + i, i);
455 func(__UNUSED__ const Eina_Hash *hash, const char *key, void *data, void *fdata)
459 if (strcmp(key, EET_TEST_KEY1) != 0
460 && strcmp(key, EET_TEST_KEY2) != 0) *res = 1;
461 if (_eet_test_ex_check(data, 2)) *res = 1;
467 func7(__UNUSED__ const Eina_Hash *hash, __UNUSED__ const char *key, void *data, void *fdata)
474 if (*val != 7) *res = 1;
479 START_TEST(eet_test_data_type_encoding_decoding)
481 Eet_Data_Descriptor *edd;
482 Eet_Test_Ex_Type *result;
484 Eet_Data_Descriptor_Class eddc;
485 Eet_Test_Ex_Type etbt;
491 _eet_test_ex_set(&etbt, 0);
492 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
493 etbt.hash = eina_hash_string_superfast_new(NULL);
494 eina_hash_add(etbt.hash, EET_TEST_KEY1, _eet_test_ex_set(NULL, 2));
495 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
496 etbt.ihash = eina_hash_string_superfast_new(NULL);
497 eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7);
498 etbt.slist = eina_list_prepend(NULL, strdup("test"));
500 eet_test_setup_eddc(&eddc);
501 eddc.name = "Eet_Test_Ex_Type";
502 eddc.size = sizeof(Eet_Test_Ex_Type);
504 edd = eet_data_descriptor3_new(&eddc);
507 _eet_build_ex_descriptor(edd);
509 transfert = eet_data_descriptor_encode(edd, &etbt, &size);
510 fail_if(!transfert || size <= 0);
512 result = eet_data_descriptor_decode(edd, transfert, size);
515 fail_if(_eet_test_ex_check(result, 0) != 0);
516 fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1) != 0);
517 fail_if(eina_list_data_get(result->ilist) == NULL);
518 fail_if(*((int*)eina_list_data_get(result->ilist)) != 42);
519 fail_if(eina_list_data_get(result->slist) == NULL);
520 fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0);
523 eina_hash_foreach(result->hash, func, &test);
525 eina_hash_foreach(result->ihash, func7, &test);
533 append_string(void *data, const char *str)
535 char **string = data;
540 length = *string ? strlen(*string) : 0;
541 *string = realloc(*string, strlen(str) + length + 1);
543 memcpy((*string) + length, str, strlen(str) + 1);
546 START_TEST(eet_test_data_type_dump_undump)
548 Eet_Data_Descriptor *edd;
549 Eet_Test_Ex_Type *result;
550 Eet_Data_Descriptor_Class eddc;
551 Eet_Test_Ex_Type etbt;
562 _eet_test_ex_set(&etbt, 0);
563 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
564 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
565 etbt.hash = eina_hash_string_superfast_new(NULL);
566 eina_hash_add(etbt.hash, EET_TEST_KEY1, _eet_test_ex_set(NULL, 2));
567 etbt.hash = eina_hash_string_superfast_new(NULL);
568 eina_hash_add(etbt.hash, EET_TEST_KEY2, _eet_test_ex_set(NULL, 2));
569 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
570 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
571 etbt.ihash = eina_hash_string_superfast_new(NULL);
572 eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7);
573 etbt.ihash = eina_hash_string_superfast_new(NULL);
574 eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7);
575 etbt.slist = eina_list_prepend(NULL, strdup("test"));
577 eet_test_setup_eddc(&eddc);
578 eddc.name = "Eet_Test_Ex_Type";
579 eddc.size = sizeof(Eet_Test_Ex_Type);
581 edd = eet_data_descriptor3_new(&eddc);
584 _eet_build_ex_descriptor(edd);
586 transfert1 = eet_data_descriptor_encode(edd, &etbt, &size1);
587 fail_if(!transfert1 || size1 <= 0);
590 eet_data_text_dump(transfert1, size1, append_string, &string1);
593 transfert2 = eet_data_text_undump(string1, strlen(string1), &size2);
594 fail_if(!transfert2 && size2 <= 0);
595 fail_if(size1 != size2);
598 eet_data_text_dump(transfert2, size2, append_string, &string2);
601 fail_if(memcmp(transfert1, transfert2, size1) != 0);
603 result = eet_data_descriptor_decode(edd, transfert2, size2);
606 fail_if(_eet_test_ex_check(result, 0) != 0);
607 fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1) != 0);
608 fail_if(eina_list_data_get(result->ilist) == NULL);
609 fail_if(*((int*)eina_list_data_get(result->ilist)) != 42);
610 fail_if(eina_list_data_get(result->slist) == NULL);
611 fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0);
614 eina_hash_foreach(result->hash, func, &test);
616 eina_hash_foreach(result->ihash, func7, &test);
623 START_TEST(eet_file_simple_write)
625 const char *buffer = "Here is a string of data to save !";
628 char *file = strdup("/tmp/eet_suite_testXXXXXX");
635 fail_if(eet_mode_get(NULL) != EET_FILE_MODE_INVALID);
637 ef = eet_open(file, EET_FILE_MODE_WRITE);
640 fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 1));
642 fail_if(eet_mode_get(ef) != EET_FILE_MODE_WRITE);
644 fail_if(eet_list(ef, "*", &size) != NULL);
645 fail_if(eet_num_entries(ef) != -1);
649 /* Test read of simple file */
650 ef = eet_open(file, EET_FILE_MODE_READ);
653 test = eet_read(ef, "keys/tests", &size);
655 fail_if(size != (int) strlen(buffer) + 1);
657 fail_if(memcmp(test, buffer, strlen(buffer) + 1) != 0);
659 fail_if(eet_mode_get(ef) != EET_FILE_MODE_READ);
660 fail_if(eet_num_entries(ef) != 1);
664 /* Test eet cache system */
665 ef = eet_open(file, EET_FILE_MODE_READ);
668 test = eet_read(ef, "keys/tests", &size);
670 fail_if(size != (int) strlen(buffer) + 1);
672 fail_if(memcmp(test, buffer, strlen(buffer) + 1) != 0);
676 fail_if(unlink(file) != 0);
682 START_TEST(eet_file_data_test)
684 Eet_Data_Descriptor *edd;
685 Eet_Test_Ex_Type *result;
689 char *file = strdup("/tmp/eet_suite_testXXXXXX");
690 Eet_Data_Descriptor_Class eddc;
691 Eet_Test_Ex_Type etbt;
697 _eet_test_ex_set(&etbt, 0);
698 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
699 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
700 etbt.hash = eina_hash_string_superfast_new(NULL);
701 eina_hash_add(etbt.hash, EET_TEST_KEY1, _eet_test_ex_set(NULL, 2));
702 etbt.hash = eina_hash_string_superfast_new(NULL);
703 eina_hash_add(etbt.hash, EET_TEST_KEY2, _eet_test_ex_set(NULL, 2));
704 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
705 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
706 etbt.ihash = eina_hash_string_superfast_new(NULL);
707 eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7);
708 etbt.ihash = eina_hash_string_superfast_new(NULL);
709 eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7);
710 etbt.slist = eina_list_prepend(NULL, strdup("test"));
712 eet_test_setup_eddc(&eddc);
713 eddc.name = "Eet_Test_Ex_Type";
714 eddc.size = sizeof(Eet_Test_Ex_Type);
716 edd = eet_data_descriptor3_new(&eddc);
719 _eet_build_ex_descriptor(edd);
723 /* Insert an error in etbt. */
726 /* Save the encoded data in a file. */
727 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
730 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0));
732 result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1);
735 fail_if(eet_mode_get(ef) != EET_FILE_MODE_READ_WRITE);
737 /* Test string space. */
738 ed = eet_dictionary_get(ef);
740 fail_if(!eet_dictionary_string_check(ed, result->str));
741 fail_if(eet_dictionary_string_check(ed, result->istr));
745 /* Attempt to replace etbt by the correct one. */
746 etbt.i = EET_TEST_INT;
748 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
751 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0));
755 /* Read back the data. */
756 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
759 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY2, &etbt, 1));
761 result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1);
764 /* Test string space. */
765 ed = eet_dictionary_get(ef);
768 fail_if(!eet_dictionary_string_check(ed, result->str));
769 fail_if(eet_dictionary_string_check(ed, result->istr));
771 /* Test the resulting data. */
772 fail_if(_eet_test_ex_check(result, 0) != 0);
773 fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1) != 0);
774 fail_if(eina_list_data_get(result->ilist) == NULL);
775 fail_if(*((int*)eina_list_data_get(result->ilist)) != 42);
776 fail_if(eina_list_data_get(result->slist) == NULL);
777 fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0);
780 eina_hash_foreach(result->hash, func, &test);
782 eina_hash_foreach(result->ihash, func7, &test);
785 list = eet_list(ef, "keys/*", &size);
786 fail_if(eet_num_entries(ef) != 2);
788 fail_if(!(strcmp(list[0], EET_TEST_FILE_KEY1) == 0 && strcmp(list[1], EET_TEST_FILE_KEY2) == 0)
789 && !(strcmp(list[0], EET_TEST_FILE_KEY2) == 0 && strcmp(list[1], EET_TEST_FILE_KEY1) == 0));
792 fail_if(eet_delete(ef, NULL) != 0);
793 fail_if(eet_delete(NULL, EET_TEST_FILE_KEY1) != 0);
794 fail_if(eet_delete(ef, EET_TEST_FILE_KEY1) == 0);
796 list = eet_list(ef, "keys/*", &size);
798 fail_if(eet_num_entries(ef) != 1);
800 /* Test some more wrong case */
801 fail_if(eet_data_read(ef, edd, "plop") != NULL);
802 fail_if(eet_data_read(ef, edd, EET_TEST_FILE_KEY1) != NULL);
804 /* Reinsert and reread data */
805 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0));
806 fail_if(eet_data_read(ef, edd, EET_TEST_FILE_KEY1) == NULL);
807 fail_if(eet_read_direct(ef, EET_TEST_FILE_KEY1, &size) == NULL);
811 fail_if(unlink(file) != 0);
817 START_TEST(eet_file_data_dump_test)
819 Eet_Data_Descriptor *edd;
820 Eet_Test_Ex_Type *result;
821 Eet_Data_Descriptor_Class eddc;
822 Eet_Test_Ex_Type etbt;
825 char *file = strdup("/tmp/eet_suite_testXXXXXX");
830 _eet_test_ex_set(&etbt, 0);
831 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
832 etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1));
833 etbt.hash = eina_hash_string_superfast_new(NULL);
834 eina_hash_add(etbt.hash, EET_TEST_KEY1, _eet_test_ex_set(NULL, 2));
835 etbt.hash = eina_hash_string_superfast_new(NULL);
836 eina_hash_add(etbt.hash, EET_TEST_KEY2, _eet_test_ex_set(NULL, 2));
837 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
838 etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
839 etbt.ihash = eina_hash_string_superfast_new(NULL);
840 eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7);
841 etbt.ihash = eina_hash_string_superfast_new(NULL);
842 eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7);
843 etbt.slist = eina_list_prepend(NULL, strdup("test"));
845 eet_test_setup_eddc(&eddc);
846 eddc.name = "Eet_Test_Ex_Type";
847 eddc.size = sizeof(Eet_Test_Ex_Type);
849 edd = eet_data_descriptor3_new(&eddc);
852 _eet_build_ex_descriptor(edd);
856 /* Save the encoded data in a file. */
857 ef = eet_open(file, EET_FILE_MODE_WRITE);
860 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 1));
864 /* Use dump/undump in the middle */
865 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
869 fail_if(eet_data_dump(ef, EET_TEST_FILE_KEY1, append_string, &string1) != 1);
870 fail_if(eet_delete(ef, EET_TEST_FILE_KEY1) == 0);
871 fail_if(!eet_data_undump(ef, EET_TEST_FILE_KEY1, string1, strlen(string1), 1));
875 /* Test the correctness of the reinsertion. */
876 ef = eet_open(file, EET_FILE_MODE_READ);
879 result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1);
884 /* Test the resulting data. */
885 fail_if(_eet_test_ex_check(result, 0) != 0);
886 fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1) != 0);
887 fail_if(eina_list_data_get(result->ilist) == NULL);
888 fail_if(*((int*)eina_list_data_get(result->ilist)) != 42);
889 fail_if(eina_list_data_get(result->slist) == NULL);
890 fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0);
893 eina_hash_foreach(result->hash, func, &test);
895 eina_hash_foreach(result->ihash, func7, &test);
898 fail_if(unlink(file) != 0);
904 START_TEST(eet_image)
907 char *file = strdup("/tmp/eet_suite_testXXXXXX");
919 /* Save the encoded data in a file. */
920 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
923 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "0", test_noalpha.color,
924 test_noalpha.w, test_noalpha.h, test_noalpha.alpha,
926 fail_if(result == 0);
928 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "1", test_noalpha.color,
929 test_noalpha.w, test_noalpha.h, test_noalpha.alpha,
931 fail_if(result == 0);
933 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "2", test_noalpha.color,
934 test_noalpha.w, test_noalpha.h, test_noalpha.alpha,
936 fail_if(result == 0);
938 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "3", test_noalpha.color,
939 test_noalpha.w, test_noalpha.h, test_noalpha.alpha,
941 fail_if(result == 0);
943 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "4", test_noalpha.color,
944 test_noalpha.w, test_noalpha.h, test_noalpha.alpha,
946 fail_if(result == 0);
948 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "5", test_noalpha.color,
949 test_noalpha.w, test_noalpha.h, test_noalpha.alpha,
951 fail_if(result == 0);
953 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "6", test_noalpha.color,
954 test_noalpha.w, test_noalpha.h, test_noalpha.alpha,
956 fail_if(result == 0);
958 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "7", test_alpha.color,
959 test_alpha.w, test_alpha.h, test_alpha.alpha,
961 fail_if(result == 0);
963 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "8", test_alpha.color,
964 test_alpha.w, test_alpha.h, test_alpha.alpha,
966 fail_if(result == 0);
968 result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "9", test_alpha.color,
969 test_alpha.w, test_alpha.h, test_alpha.alpha,
971 fail_if(result == 0);
973 data = eet_data_image_read(ef, EET_TEST_FILE_IMAGE "2", &w, &h, &alpha, &compress, &quality, &lossy);
974 fail_if(data == NULL);
975 fail_if(w != test_noalpha.w);
976 fail_if(h != test_noalpha.h);
977 fail_if(alpha != test_noalpha.alpha);
978 fail_if(compress != 9);
980 fail_if(data[0] != test_noalpha.color[0]);
983 result = eet_data_image_header_read(ef, EET_TEST_FILE_IMAGE "2", &w, &h, &alpha, &compress, &quality, &lossy);
984 fail_if(result == 0);
985 fail_if(w != test_noalpha.w);
986 fail_if(h != test_noalpha.h);
987 fail_if(alpha != test_noalpha.alpha);
988 fail_if(compress != 9);
993 /* Test read of image */
994 ef = eet_open(file, EET_FILE_MODE_READ);
997 result = eet_data_image_header_read(ef, EET_TEST_FILE_IMAGE "0", &w, &h, &alpha, &compress, &quality, &lossy);
998 fail_if(result == 0);
999 fail_if(w != test_noalpha.w);
1000 fail_if(h != test_noalpha.h);
1001 fail_if(alpha != test_noalpha.alpha);
1002 fail_if(compress != 0);
1003 fail_if(lossy != 0);
1005 data = malloc(w * h * 4);
1006 fail_if(data == NULL);
1007 result = eet_data_image_read_to_surface(ef, EET_TEST_FILE_IMAGE "0", 4, 4, data, 2, 2, w * 4, &alpha, &compress, &quality, &lossy);
1008 fail_if(result != 1);
1009 fail_if(alpha != test_noalpha.alpha);
1010 fail_if(compress != 0);
1011 fail_if(quality != 100);
1012 fail_if(lossy != 0);
1013 fail_if(data[0] != test_noalpha.color[4 + 4 * w]);
1016 data = malloc(w * h * 4);
1017 fail_if(data == NULL);
1018 result = eet_data_image_read_to_surface(ef, EET_TEST_FILE_IMAGE "0", 0, 0, data, w, h, w * 4, &alpha, &compress, &quality, &lossy);
1019 fail_if(result != 1);
1020 fail_if(alpha != test_noalpha.alpha);
1021 fail_if(compress != 0);
1022 fail_if(quality != 100);
1023 fail_if(lossy != 0);
1024 fail_if(data[0] != test_noalpha.color[0]);
1027 data = eet_data_image_read(ef, EET_TEST_FILE_IMAGE "1", &w, &h, &alpha, &compress, &quality, &lossy);
1028 fail_if(data == NULL);
1029 fail_if(w != test_noalpha.w);
1030 fail_if(h != test_noalpha.h);
1031 fail_if(alpha != test_noalpha.alpha);
1032 fail_if(compress != 5);
1033 fail_if(quality != 100);
1034 fail_if(lossy != 0);
1035 fail_if(data[0] != test_noalpha.color[0]);
1038 data = eet_data_image_read(ef, EET_TEST_FILE_IMAGE "2", &w, &h, &alpha, &compress, &quality, &lossy);
1039 fail_if(data == NULL);
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);
1045 fail_if(data[0] != test_noalpha.color[0]);
1048 data = eet_data_image_read(ef, EET_TEST_FILE_IMAGE "3", &w, &h, &alpha, &compress, &quality, &lossy);
1049 fail_if(data == NULL);
1050 fail_if(w != test_noalpha.w);
1051 fail_if(h != test_noalpha.h);
1052 fail_if(alpha != test_noalpha.alpha);
1053 fail_if(lossy != 1);
1056 data = eet_data_image_read(ef, EET_TEST_FILE_IMAGE "5", &w, &h, &alpha, &compress, &quality, &lossy);
1057 fail_if(data == NULL);
1058 fail_if(w != test_noalpha.w);
1059 fail_if(h != test_noalpha.h);
1060 fail_if(alpha != test_noalpha.alpha);
1061 fail_if(lossy != 1);
1064 data = eet_data_image_read(ef, EET_TEST_FILE_IMAGE "6", &w, &h, &alpha, &compress, &quality, &lossy);
1065 fail_if(data == NULL);
1066 fail_if(w != test_noalpha.w);
1067 fail_if(h != test_noalpha.h);
1068 fail_if(alpha != test_noalpha.alpha);
1069 fail_if(lossy != 1);
1072 result = eet_data_image_header_read(ef, EET_TEST_FILE_IMAGE "7", &w, &h, &alpha, &compress, &quality, &lossy);
1073 fail_if(result == 0);
1074 fail_if(w != test_alpha.w);
1075 fail_if(h != test_alpha.h);
1076 fail_if(alpha != test_alpha.alpha);
1077 fail_if(compress != 9);
1078 fail_if(lossy != 0);
1080 data = eet_data_image_read(ef, EET_TEST_FILE_IMAGE "7", &w, &h, &alpha, &compress, &quality, &lossy);
1081 fail_if(data == NULL);
1082 fail_if(w != test_alpha.w);
1083 fail_if(h != test_alpha.h);
1084 fail_if(alpha != test_alpha.alpha);
1085 fail_if(compress != 9);
1086 fail_if(lossy != 0);
1087 fail_if(data[0] != test_alpha.color[0]);
1090 result = eet_data_image_header_read(ef, EET_TEST_FILE_IMAGE "9", &w, &h, &alpha, &compress, &quality, &lossy);
1091 fail_if(result == 0);
1092 fail_if(w != test_alpha.w);
1093 fail_if(h != test_alpha.h);
1094 fail_if(alpha != test_alpha.alpha);
1095 fail_if(lossy != 1);
1097 data = eet_data_image_read(ef, EET_TEST_FILE_IMAGE "9", &w, &h, &alpha, &compress, &quality, &lossy);
1098 fail_if(data == NULL);
1099 fail_if(w != test_alpha.w);
1100 fail_if(h != test_alpha.h);
1101 fail_if(alpha != test_alpha.alpha);
1102 fail_if(lossy != 1);
1111 #define IM0 0x00112233
1112 #define IM1 0x44556677
1113 #define IM2 0x8899aabb
1114 #define IM3 0xccddeeff
1116 START_TEST(eet_small_image)
1118 char *file = strdup("/tmp/eet_suite_testXXXXXX");
1119 unsigned int image[4];
1139 ef = eet_open(file, EET_FILE_MODE_WRITE);
1142 result = eet_data_image_write(ef, "/images/test", image, 2, 2, 1, 9, 100, 0);
1143 fail_if(result == 0);
1147 ef = eet_open(file, EET_FILE_MODE_READ);
1150 data = (unsigned int*) eet_data_image_read(ef, "/images/test", &w, &h, &alpha, &compression, &quality, &lossy);
1151 fail_if(data == NULL);
1155 fail_if(data[0] != IM0);
1156 fail_if(data[1] != IM1);
1157 fail_if(data[2] != IM2);
1158 fail_if(data[3] != IM3);
1166 START_TEST(eet_identity_simple)
1168 const char *buffer = "Here is a string of data to save !";
1173 char *file = strdup("/tmp/eet_suite_testXXXXXX");
1182 /* Sign an eet file. */
1183 ef = eet_open(file, EET_FILE_MODE_WRITE);
1186 fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 0));
1188 k = eet_identity_open("cert.pem", "key.pem", NULL);
1191 fail_if(eet_identity_set(ef, k) != EET_ERROR_NONE);
1195 /* Open a signed file. */
1196 ef = eet_open(file, EET_FILE_MODE_READ);
1199 test = eet_read(ef, "keys/tests", &size);
1201 fail_if(size != (int) strlen(buffer) + 1);
1203 fail_if(memcmp(test, buffer, strlen(buffer) + 1) != 0);
1205 tmp = eet_identity_x509(ef, &size);
1206 fail_if(tmp == NULL);
1210 /* As we are changing file contain in less than 1s, this could get unnoticed
1211 by eet cache system. */
1214 /* Corrupting the file. */
1215 fd = open(file, O_WRONLY);
1218 fail_if(lseek(fd, 200, SEEK_SET) != 200);
1219 fail_if(write(fd, "42", 2) != 2);
1220 fail_if(lseek(fd, 50, SEEK_SET) != 50);
1221 fail_if(write(fd, "42", 2) != 2);
1222 fail_if(lseek(fd, 88, SEEK_SET) != 88);
1223 fail_if(write(fd, "42", 2) != 2);
1227 /* Attempt to open a modified file. */
1228 ef = eet_open(file, EET_FILE_MODE_READ);
1231 fail_if(unlink(file) != 0);
1243 s = suite_create("Eet");
1245 tc = tcase_create("Eet_Init");
1246 tcase_add_test(tc, eet_test_init);
1247 suite_add_tcase(s, tc);
1249 tc = tcase_create("Eet Data Encoding/Decoding");
1250 tcase_add_test(tc, eet_test_basic_data_type_encoding_decoding);
1251 tcase_add_test(tc, eet_test_data_type_encoding_decoding);
1252 tcase_add_test(tc, eet_test_data_type_dump_undump);
1253 suite_add_tcase(s, tc);
1255 tc = tcase_create("Eet File");
1256 tcase_add_test(tc, eet_file_simple_write);
1257 tcase_add_test(tc, eet_file_data_test);
1258 tcase_add_test(tc, eet_file_data_dump_test);
1259 suite_add_tcase(s, tc);
1261 tc = tcase_create("Eet Image");
1262 tcase_add_test(tc, eet_image);
1263 tcase_add_test(tc, eet_small_image);
1264 suite_add_tcase(s, tc);
1266 #ifdef HAVE_SIGNATURE
1267 tc = tcase_create("Eet Identity");
1268 tcase_add_test(tc, eet_identity_simple);
1269 suite_add_tcase(s, tc);
1283 sr = srunner_create(s);
1284 srunner_run_all(sr, CK_NORMAL);
1285 failed_count = srunner_ntests_failed(sr);
1288 return (failed_count == 0) ? EXIT_SUCCESS : EXIT_FAILURE;