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