aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eina/src/tests/eina_test_value.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2013-01-13 17:29:19 +1000
committerDavid Walter Seikel2013-01-13 17:29:19 +1000
commit07274513e984f0b5544586c74508ccd16e7dcafa (patch)
treeb32ff2a9136fbc1a4a6a0ed1e4d79cde0f5f16d9 /libraries/eina/src/tests/eina_test_value.c
parentAdded Irrlicht 1.8, but without all the Windows binaries. (diff)
downloadSledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.zip
SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.gz
SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.bz2
SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.xz
Remove EFL, since it's been released now.
Diffstat (limited to 'libraries/eina/src/tests/eina_test_value.c')
-rw-r--r--libraries/eina/src/tests/eina_test_value.c1874
1 files changed, 0 insertions, 1874 deletions
diff --git a/libraries/eina/src/tests/eina_test_value.c b/libraries/eina/src/tests/eina_test_value.c
deleted file mode 100644
index 94a5ab7..0000000
--- a/libraries/eina/src/tests/eina_test_value.c
+++ /dev/null
@@ -1,1874 +0,0 @@
1/* EINA - EFL data type library
2 * Copyright (C) 2012 ProFUSION embedded systems
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifdef HAVE_CONFIG_H
20# include "config.h"
21#endif
22
23#include <stdio.h>
24#include <inttypes.h>
25
26#include "eina_suite.h"
27#include "Eina.h"
28
29#define FP_ERR (0.0000001)
30#define CHECK_FP(a, b) ((a - b) < FP_ERR)
31
32START_TEST(eina_value_test_simple)
33{
34 Eina_Value *value;
35 char c;
36 short s;
37 int i;
38 long l;
39 int64_t i64;
40 unsigned char uc;
41 unsigned short us;
42 unsigned int ui;
43 unsigned long ul;
44 uint64_t u64;
45 float f;
46 double d;
47
48 eina_init();
49
50 value = eina_value_new(EINA_VALUE_TYPE_CHAR);
51 fail_unless(value != NULL);
52 fail_unless(eina_value_set(value, 'x'));
53 fail_unless(eina_value_get(value, &c));
54 fail_unless(c == 'x');
55 eina_value_flush(value);
56
57 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_SHORT));
58 fail_unless(eina_value_set(value, 300));
59 fail_unless(eina_value_get(value, &s));
60 fail_unless(s == 300);
61 eina_value_flush(value);
62
63 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_INT));
64 fail_unless(eina_value_set(value, -12345));
65 fail_unless(eina_value_get(value, &i));
66 fail_unless(i == -12345);
67 eina_value_flush(value);
68
69 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_LONG));
70 fail_unless(eina_value_set(value, 0xb33f));
71 fail_unless(eina_value_get(value, &l));
72 fail_unless(l == 0xb33f);
73 eina_value_flush(value);
74
75 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_INT64));
76 fail_unless(eina_value_set(value, 0x0011223344556677));
77 fail_unless(eina_value_get(value, &i64));
78 fail_unless(i64 == 0x0011223344556677);
79 eina_value_flush(value);
80
81 /* unsigned: */
82
83 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_UCHAR));
84 fail_unless(eina_value_set(value, 200));
85 fail_unless(eina_value_get(value, &uc));
86 fail_unless(uc == 200);
87 eina_value_flush(value);
88
89 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_USHORT));
90 fail_unless(eina_value_set(value, 65535));
91 fail_unless(eina_value_get(value, &us));
92 fail_unless(us == 65535);
93 eina_value_flush(value);
94
95 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_UINT));
96 fail_unless(eina_value_set(value, 4000000000U));
97 fail_unless(eina_value_get(value, &ui));
98 fail_unless(ui == 4000000000U);
99 eina_value_flush(value);
100
101 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_ULONG));
102 fail_unless(eina_value_set(value, 3000000001U));
103 fail_unless(eina_value_get(value, &ul));
104 fail_unless(ul == 3000000001U);
105 eina_value_flush(value);
106
107 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_UINT64));
108 fail_unless(eina_value_set(value, 0x1122334455667788));
109 fail_unless(eina_value_get(value, &u64));
110 fail_unless(u64 == 0x1122334455667788);
111 eina_value_flush(value);
112
113 /* floating point */
114 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_FLOAT));
115 fail_unless(eina_value_set(value, 0.1234));
116 fail_unless(eina_value_get(value, &f));
117 fail_unless(CHECK_FP(0.1234, f));
118 eina_value_flush(value);
119
120 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_DOUBLE));
121 fail_unless(eina_value_set(value, 34567.8));
122 fail_unless(eina_value_get(value, &d));
123 fail_unless(CHECK_FP(34567.8, d));
124 eina_value_flush(value);
125
126 eina_value_free(value);
127 eina_shutdown();
128}
129END_TEST
130
131START_TEST(eina_value_test_compare)
132{
133 Eina_Value *a, *b;
134
135 eina_init();
136
137 a = eina_value_new(EINA_VALUE_TYPE_CHAR);
138 fail_unless(a != NULL);
139 b = eina_value_new(EINA_VALUE_TYPE_CHAR);
140 fail_unless(b != NULL);
141
142 fail_unless(eina_value_set(a, 123));
143 fail_unless(eina_value_set(b, 123));
144 fail_unless(eina_value_compare(a, b) == 0);
145 fail_unless(eina_value_set(a, -10));
146 fail_unless(eina_value_set(b, 123));
147 fail_unless(eina_value_compare(a, b) < 0);
148 fail_unless(eina_value_set(a, 123));
149 fail_unless(eina_value_set(b, 10));
150 fail_unless(eina_value_compare(a, b) > 0);
151 eina_value_flush(a);
152 eina_value_flush(b);
153
154 fail_unless(eina_value_setup(a, EINA_VALUE_TYPE_SHORT));
155 fail_unless(eina_value_setup(b, EINA_VALUE_TYPE_SHORT));
156 fail_unless(eina_value_set(a, 1230));
157 fail_unless(eina_value_set(b, 1230));
158 fail_unless(eina_value_compare(a, b) == 0);
159 fail_unless(eina_value_set(a, -100));
160 fail_unless(eina_value_set(b, 1230));
161 fail_unless(eina_value_compare(a, b) < 0);
162 fail_unless(eina_value_set(a, 1230));
163 fail_unless(eina_value_set(b, -100));
164 fail_unless(eina_value_compare(a, b) > 0);
165 eina_value_flush(a);
166 eina_value_flush(b);
167
168 fail_unless(eina_value_setup(a, EINA_VALUE_TYPE_INT));
169 fail_unless(eina_value_setup(b, EINA_VALUE_TYPE_INT));
170 fail_unless(eina_value_set(a, 300000));
171 fail_unless(eina_value_set(b, 300000));
172 fail_unless(eina_value_compare(a, b) == 0);
173 fail_unless(eina_value_set(a, -100));
174 fail_unless(eina_value_set(b, 300000));
175 fail_unless(eina_value_compare(a, b) < 0);
176 fail_unless(eina_value_set(a, 300000));
177 fail_unless(eina_value_set(b, -100));
178 fail_unless(eina_value_compare(a, b) > 0);
179 eina_value_flush(a);
180 eina_value_flush(b);
181
182 fail_unless(eina_value_setup(a, EINA_VALUE_TYPE_LONG));
183 fail_unless(eina_value_setup(b, EINA_VALUE_TYPE_LONG));
184 fail_unless(eina_value_set(a, 300000L));
185 fail_unless(eina_value_set(b, 300000L));
186 fail_unless(eina_value_compare(a, b) == 0);
187 fail_unless(eina_value_set(a, -100L));
188 fail_unless(eina_value_set(b, 300000L));
189 fail_unless(eina_value_compare(a, b) < 0);
190 fail_unless(eina_value_set(a, 300000L));
191 fail_unless(eina_value_set(b, -100L));
192 fail_unless(eina_value_compare(a, b) > 0);
193 eina_value_flush(a);
194 eina_value_flush(b);
195
196 fail_unless(eina_value_setup(a, EINA_VALUE_TYPE_INT64));
197 fail_unless(eina_value_setup(b, EINA_VALUE_TYPE_INT64));
198 fail_unless(eina_value_set(a, (int64_t)800000));
199 fail_unless(eina_value_set(b, (int64_t)800000));
200 fail_unless(eina_value_compare(a, b) == 0);
201 fail_unless(eina_value_set(a, (int64_t)-100));
202 fail_unless(eina_value_set(b, (int64_t)8000000));
203 fail_unless(eina_value_compare(a, b) < 0);
204 fail_unless(eina_value_set(a, (int64_t)8000000));
205 fail_unless(eina_value_set(b, (int64_t)-100));
206 fail_unless(eina_value_compare(a, b) > 0);
207 eina_value_flush(a);
208 eina_value_flush(b);
209
210 fail_unless(eina_value_setup(a, EINA_VALUE_TYPE_UCHAR));
211 fail_unless(eina_value_setup(b, EINA_VALUE_TYPE_UCHAR));
212 fail_unless(eina_value_set(a, 123));
213 fail_unless(eina_value_set(b, 123));
214 fail_unless(eina_value_compare(a, b) == 0);
215 fail_unless(eina_value_set(a, 10));
216 fail_unless(eina_value_set(b, 123));
217 fail_unless(eina_value_compare(a, b) < 0);
218 fail_unless(eina_value_set(a, 123));
219 fail_unless(eina_value_set(b, 10));
220 fail_unless(eina_value_compare(a, b) > 0);
221 eina_value_flush(a);
222 eina_value_flush(b);
223
224 fail_unless(eina_value_setup(a, EINA_VALUE_TYPE_USHORT));
225 fail_unless(eina_value_setup(b, EINA_VALUE_TYPE_USHORT));
226 fail_unless(eina_value_set(a, 1230));
227 fail_unless(eina_value_set(b, 1230));
228 fail_unless(eina_value_compare(a, b) == 0);
229 fail_unless(eina_value_set(a, 100));
230 fail_unless(eina_value_set(b, 1230));
231 fail_unless(eina_value_compare(a, b) < 0);
232 fail_unless(eina_value_set(a, 1230));
233 fail_unless(eina_value_set(b, 100));
234 fail_unless(eina_value_compare(a, b) > 0);
235 eina_value_flush(a);
236 eina_value_flush(b);
237
238 fail_unless(eina_value_setup(a, EINA_VALUE_TYPE_UINT));
239 fail_unless(eina_value_setup(b, EINA_VALUE_TYPE_UINT));
240 fail_unless(eina_value_set(a, 300000));
241 fail_unless(eina_value_set(b, 300000));
242 fail_unless(eina_value_compare(a, b) == 0);
243 fail_unless(eina_value_set(a, 100));
244 fail_unless(eina_value_set(b, 300000));
245 fail_unless(eina_value_compare(a, b) < 0);
246 fail_unless(eina_value_set(a, 300000));
247 fail_unless(eina_value_set(b, 100));
248 fail_unless(eina_value_compare(a, b) > 0);
249 eina_value_flush(a);
250 eina_value_flush(b);
251
252 fail_unless(eina_value_setup(a, EINA_VALUE_TYPE_ULONG));
253 fail_unless(eina_value_setup(b, EINA_VALUE_TYPE_ULONG));
254 fail_unless(eina_value_set(a, 300000UL));
255 fail_unless(eina_value_set(b, 300000UL));
256 fail_unless(eina_value_compare(a, b) == 0);
257 fail_unless(eina_value_set(a, 100UL));
258 fail_unless(eina_value_set(b, 300000UL));
259 fail_unless(eina_value_compare(a, b) < 0);
260 fail_unless(eina_value_set(a, 300000UL));
261 fail_unless(eina_value_set(b, 100UL));
262 fail_unless(eina_value_compare(a, b) > 0);
263 eina_value_flush(a);
264 eina_value_flush(b);
265
266 fail_unless(eina_value_setup(a, EINA_VALUE_TYPE_UINT64));
267 fail_unless(eina_value_setup(b, EINA_VALUE_TYPE_UINT64));
268 fail_unless(eina_value_set(a, (uint64_t)8000000));
269 fail_unless(eina_value_set(b, (uint64_t)8000000));
270 fail_unless(eina_value_compare(a, b) == 0);
271 fail_unless(eina_value_set(a, (uint64_t)100));
272 fail_unless(eina_value_set(b, (uint64_t)8000000));
273 fail_unless(eina_value_compare(a, b) < 0);
274 fail_unless(eina_value_set(a, (uint64_t)8000000));
275 fail_unless(eina_value_set(b, (uint64_t)100));
276 fail_unless(eina_value_compare(a, b) > 0);
277 eina_value_flush(a);
278 eina_value_flush(b);
279
280 fail_unless(eina_value_setup(a, EINA_VALUE_TYPE_STRING));
281 fail_unless(eina_value_setup(b, EINA_VALUE_TYPE_STRING));
282 fail_unless(eina_value_set(a, "aaa"));
283 fail_unless(eina_value_set(b, "aaa"));
284 fail_unless(eina_value_compare(a, b) == 0);
285 fail_unless(eina_value_set(a, "abc"));
286 fail_unless(eina_value_set(b, "acd"));
287 fail_unless(eina_value_compare(a, b) < 0);
288 fail_unless(eina_value_set(a, "acd"));
289 fail_unless(eina_value_set(b, "abc"));
290 fail_unless(eina_value_compare(a, b) > 0);
291 eina_value_flush(a);
292 eina_value_flush(b);
293
294 fail_unless(eina_value_array_setup(a, EINA_VALUE_TYPE_CHAR, 0));
295 fail_unless(eina_value_array_setup(b, EINA_VALUE_TYPE_CHAR, 0));
296 fail_unless(eina_value_compare(a, b) == 0);
297
298 fail_unless(eina_value_array_append(a, 1));
299 fail_unless(eina_value_array_append(a, 2));
300 fail_unless(eina_value_array_append(a, 3));
301
302 fail_unless(eina_value_array_append(b, 1));
303 fail_unless(eina_value_array_append(b, 2));
304 fail_unless(eina_value_array_append(b, 3));
305
306 fail_unless(eina_value_compare(a, b) == 0);
307
308 fail_unless(eina_value_array_set(a, 0, 0));
309 fail_unless(eina_value_compare(a, b) < 0);
310
311 fail_unless(eina_value_array_set(a, 0, 10));
312 fail_unless(eina_value_compare(a, b) > 0);
313
314 fail_unless(eina_value_array_set(a, 0, 1));
315
316 fail_unless(eina_value_array_set(b, 0, 0));
317 fail_unless(eina_value_compare(a, b) > 0);
318
319 fail_unless(eina_value_array_set(b, 0, 10));
320 fail_unless(eina_value_compare(a, b) < 0);
321
322 fail_unless(eina_value_array_set(b, 0, 1));
323 fail_unless(eina_value_compare(a, b) == 0);
324
325 /* bigger arrays are greater */
326 fail_unless(eina_value_array_append(b, 0));
327 fail_unless(eina_value_compare(a, b) < 0);
328
329 fail_unless(eina_value_array_append(a, 0));
330 fail_unless(eina_value_array_append(a, 0));
331 fail_unless(eina_value_compare(a, b) > 0);
332
333 /* bigger arrays are greater, unless an element says otherwise */
334 fail_unless(eina_value_array_set(b, 0, 10));
335 fail_unless(eina_value_compare(a, b) < 0);
336
337 eina_value_flush(a);
338 eina_value_flush(b);
339
340 fail_unless(eina_value_list_setup(a, EINA_VALUE_TYPE_CHAR));
341 fail_unless(eina_value_list_setup(b, EINA_VALUE_TYPE_CHAR));
342 fail_unless(eina_value_compare(a, b) == 0);
343
344 fail_unless(eina_value_list_append(a, 1));
345 fail_unless(eina_value_list_append(a, 2));
346 fail_unless(eina_value_list_append(a, 3));
347
348 fail_unless(eina_value_list_append(b, 1));
349 fail_unless(eina_value_list_append(b, 2));
350 fail_unless(eina_value_list_append(b, 3));
351
352 fail_unless(eina_value_compare(a, b) == 0);
353
354 fail_unless(eina_value_list_set(a, 0, 0));
355 fail_unless(eina_value_compare(a, b) < 0);
356
357 fail_unless(eina_value_list_set(a, 0, 10));
358 fail_unless(eina_value_compare(a, b) > 0);
359
360 fail_unless(eina_value_list_set(a, 0, 1));
361
362 fail_unless(eina_value_list_set(b, 0, 0));
363 fail_unless(eina_value_compare(a, b) > 0);
364
365 fail_unless(eina_value_list_set(b, 0, 10));
366 fail_unless(eina_value_compare(a, b) < 0);
367
368 fail_unless(eina_value_list_set(b, 0, 1));
369 fail_unless(eina_value_compare(a, b) == 0);
370
371 /* bigger lists are greater */
372 fail_unless(eina_value_list_append(b, 0));
373 fail_unless(eina_value_compare(a, b) < 0);
374
375 fail_unless(eina_value_list_append(a, 0));
376 fail_unless(eina_value_list_append(a, 0));
377 fail_unless(eina_value_compare(a, b) > 0);
378
379 /* bigger lists are greater, unless an element says otherwise */
380 fail_unless(eina_value_list_set(b, 0, 10));
381 fail_unless(eina_value_compare(a, b) < 0);
382
383 eina_value_flush(a);
384 eina_value_flush(b);
385
386 fail_unless(eina_value_hash_setup(a, EINA_VALUE_TYPE_CHAR, 0));
387 fail_unless(eina_value_hash_setup(b, EINA_VALUE_TYPE_CHAR, 0));
388 fail_unless(eina_value_compare(a, b) == 0);
389
390 fail_unless(eina_value_hash_set(a, "abc", 1));
391 fail_unless(eina_value_hash_set(a, "xyz", 2));
392 fail_unless(eina_value_hash_set(a, "hello", 3));
393
394 fail_unless(eina_value_hash_set(b, "abc", 1));
395 fail_unless(eina_value_hash_set(b, "xyz", 2));
396 fail_unless(eina_value_hash_set(b, "hello", 3));
397
398 fail_unless(eina_value_compare(a, b) == 0);
399
400 fail_unless(eina_value_hash_set(a, "abc", 0));
401 fail_unless(eina_value_compare(a, b) < 0);
402
403 fail_unless(eina_value_hash_set(a, "abc", 10));
404 fail_unless(eina_value_compare(a, b) > 0);
405
406 fail_unless(eina_value_hash_set(a, "abc", 1));
407
408 fail_unless(eina_value_hash_set(b, "abc", 0));
409 fail_unless(eina_value_compare(a, b) > 0);
410
411 fail_unless(eina_value_hash_set(b, "abc", 10));
412 fail_unless(eina_value_compare(a, b) < 0);
413
414 fail_unless(eina_value_hash_set(b, "abc", 1));
415 fail_unless(eina_value_compare(a, b) == 0);
416
417 /* bigger hashs are greater */
418 fail_unless(eina_value_hash_set(b,"newkey", 0));
419 fail_unless(eina_value_compare(a, b) < 0);
420
421 fail_unless(eina_value_hash_set(a, "newkey", 0));
422 fail_unless(eina_value_hash_set(a, "onemorenewkey", 0));
423 fail_unless(eina_value_compare(a, b) > 0);
424
425 /* bigger hashs are greater, unless an element says otherwise */
426 fail_unless(eina_value_hash_set(b, "abc", 10));
427 fail_unless(eina_value_compare(a, b) < 0);
428
429 eina_value_free(a);
430 eina_value_free(b);
431 eina_shutdown();
432}
433END_TEST
434
435START_TEST(eina_value_test_string)
436{
437 Eina_Value *value;
438 const char *s;
439
440 eina_init();
441
442 value = eina_value_new(EINA_VALUE_TYPE_STRING);
443 fail_unless(value != NULL);
444 fail_unless(eina_value_set(value, "hello world!"));
445 fail_unless(eina_value_get(value, &s));
446 fail_unless(strcmp(s, "hello world!") == 0);
447
448 fail_unless(eina_value_set(value, "eina-value"));
449 fail_unless(eina_value_get(value, &s));
450 fail_unless(strcmp(s, "eina-value") == 0);
451
452 eina_value_flush(value);
453 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_STRING));
454
455 fail_unless(eina_value_set(value, "profusion"));
456 fail_unless(eina_value_get(value, &s));
457 fail_unless(strcmp(s, "profusion") == 0);
458
459 eina_value_free(value);
460 eina_shutdown();
461}
462END_TEST
463
464START_TEST(eina_value_test_pvariant)
465{
466 Eina_Value *value;
467 char c, in_c;
468 short s, in_s;
469 int i, in_i;
470 long l, in_l;
471 int64_t i64, in_i64;
472 unsigned char uc, in_uc;
473 unsigned short us, in_us;
474 unsigned int ui, in_ui;
475 unsigned long ul, in_ul;
476 uint64_t u64, in_u64;
477 float f, in_f;
478 double d, in_d;
479 const char *str, *in_str;
480
481 eina_init();
482
483 value = eina_value_new(EINA_VALUE_TYPE_CHAR);
484 fail_unless(value != NULL);
485 in_c = 'x';
486 fail_unless(eina_value_pset(value, &in_c));
487 fail_unless(eina_value_pget(value, &c));
488 fail_unless(c == 'x');
489 eina_value_flush(value);
490
491 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_SHORT));
492 in_s = 300;
493 fail_unless(eina_value_pset(value, &in_s));
494 fail_unless(eina_value_pget(value, &s));
495 fail_unless(s == 300);
496 eina_value_flush(value);
497
498 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_INT));
499 in_i = -12345;
500 fail_unless(eina_value_pset(value, &in_i));
501 fail_unless(eina_value_pget(value, &i));
502 fail_unless(i == -12345);
503 eina_value_flush(value);
504
505 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_LONG));
506 in_l = 0xb33f;
507 fail_unless(eina_value_pset(value, &in_l));
508 fail_unless(eina_value_pget(value, &l));
509 fail_unless(l == 0xb33f);
510 eina_value_flush(value);
511
512 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_INT64));
513 in_i64 = 0x0011223344556677;
514 fail_unless(eina_value_pset(value, &in_i64));
515 fail_unless(eina_value_pget(value, &i64));
516 fail_unless(i64 == 0x0011223344556677);
517 eina_value_flush(value);
518
519 /* unsigned: */
520
521 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_UCHAR));
522 in_uc = 200;
523 fail_unless(eina_value_pset(value, &in_uc));
524 fail_unless(eina_value_pget(value, &uc));
525 fail_unless(uc == 200);
526 eina_value_flush(value);
527
528 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_USHORT));
529 in_us = 65535;
530 fail_unless(eina_value_pset(value, &in_us));
531 fail_unless(eina_value_pget(value, &us));
532 fail_unless(us == 65535);
533 eina_value_flush(value);
534
535 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_UINT));
536 in_ui = 4000000000U;
537 fail_unless(eina_value_pset(value, &in_ui));
538 fail_unless(eina_value_pget(value, &ui));
539 fail_unless(ui == 4000000000U);
540 eina_value_flush(value);
541
542 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_ULONG));
543 in_ul = 3000000001U;
544 fail_unless(eina_value_pset(value, &in_ul));
545 fail_unless(eina_value_pget(value, &ul));
546 fail_unless(ul == 3000000001U);
547 eina_value_flush(value);
548
549 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_UINT64));
550 in_u64 = 0x1122334455667788;
551 fail_unless(eina_value_pset(value, &in_u64));
552 fail_unless(eina_value_pget(value, &u64));
553 fail_unless(u64 == 0x1122334455667788);
554 eina_value_flush(value);
555
556 /* floating point */
557 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_FLOAT));
558 in_f = 0.1234;
559 fail_unless(eina_value_pset(value, &in_f));
560 fail_unless(eina_value_pget(value, &f));
561 fail_unless(CHECK_FP(0.1234, f));
562 eina_value_flush(value);
563
564 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_DOUBLE));
565 in_d = 34567.8;
566 fail_unless(eina_value_pset(value, &in_d));
567 fail_unless(eina_value_pget(value, &d));
568 fail_unless(CHECK_FP(34567.8, d));
569 eina_value_flush(value);
570
571 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_STRING));
572 in_str = "hello world!";
573 fail_unless(eina_value_pset(value, &in_str));
574 fail_unless(eina_value_pget(value, &str));
575 fail_unless(strcmp(str, "hello world!") == 0);
576
577 in_str = "eina-value";
578 fail_unless(eina_value_pset(value, &in_str));
579 fail_unless(eina_value_pget(value, &str));
580 fail_unless(strcmp(str, "eina-value") == 0);
581
582 eina_value_flush(value);
583 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_STRING));
584
585 in_str = "profusion";
586 fail_unless(eina_value_pset(value, &in_str));
587 fail_unless(eina_value_pget(value, &str));
588 fail_unless(strcmp(str, "profusion") == 0);
589
590 eina_value_free(value);
591 eina_shutdown();
592}
593END_TEST
594
595START_TEST(eina_value_test_to_string)
596{
597 Eina_Value *value;
598 char c, in_c;
599 short s, in_s;
600 int i, in_i;
601 long l, in_l;
602 int64_t i64, in_i64;
603 unsigned char uc, in_uc;
604 unsigned short us, in_us;
605 unsigned int ui, in_ui;
606 unsigned long ul, in_ul;
607 uint64_t u64, in_u64;
608 float f, in_f;
609 double d, in_d;
610 const char *str, *in_str;
611 char *out;
612 char buf[256];
613
614 eina_init();
615
616 value = eina_value_new(EINA_VALUE_TYPE_CHAR);
617 fail_unless(value != NULL);
618 in_c = 'x';
619 fail_unless(eina_value_pset(value, &in_c));
620 fail_unless(eina_value_pget(value, &c));
621 fail_unless(c == 'x');
622 snprintf(buf, sizeof(buf), "%hhd", in_c);
623 out = eina_value_to_string(value);
624 fail_unless(out != NULL);
625 fail_unless(strcmp(buf, out) == 0);
626 free(out);
627 eina_value_flush(value);
628
629 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_SHORT));
630 in_s = 300;
631 fail_unless(eina_value_pset(value, &in_s));
632 fail_unless(eina_value_pget(value, &s));
633 fail_unless(s == 300);
634 snprintf(buf, sizeof(buf), "%hd", in_s);
635 out = eina_value_to_string(value);
636 fail_unless(out != NULL);
637 fail_unless(strcmp(buf, out) == 0);
638 free(out);
639 eina_value_flush(value);
640
641 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_INT));
642 in_i = -12345;
643 fail_unless(eina_value_pset(value, &in_i));
644 fail_unless(eina_value_pget(value, &i));
645 fail_unless(i == -12345);
646 snprintf(buf, sizeof(buf), "%d", in_i);
647 out = eina_value_to_string(value);
648 fail_unless(out != NULL);
649 fail_unless(strcmp(buf, out) == 0);
650 free(out);
651 eina_value_flush(value);
652
653 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_LONG));
654 in_l = 0xb33f;
655 fail_unless(eina_value_pset(value, &in_l));
656 fail_unless(eina_value_pget(value, &l));
657 fail_unless(l == 0xb33f);
658 snprintf(buf, sizeof(buf), "%ld", in_l);
659 out = eina_value_to_string(value);
660 fail_unless(out != NULL);
661 fail_unless(strcmp(buf, out) == 0);
662 free(out);
663 eina_value_flush(value);
664
665 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_INT64));
666 in_i64 = 0x0011223344556677;
667 fail_unless(eina_value_pset(value, &in_i64));
668 fail_unless(eina_value_pget(value, &i64));
669 fail_unless(i64 == 0x0011223344556677);
670 snprintf(buf, sizeof(buf), "%"PRId64, in_i64);
671 out = eina_value_to_string(value);
672 fail_unless(out != NULL);
673 fail_unless(strcmp(buf, out) == 0);
674 free(out);
675 eina_value_flush(value);
676
677 /* unsigned: */
678
679 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_UCHAR));
680 in_uc = 200;
681 fail_unless(eina_value_pset(value, &in_uc));
682 fail_unless(eina_value_pget(value, &uc));
683 fail_unless(uc == 200);
684 snprintf(buf, sizeof(buf), "%hhu", in_uc);
685 out = eina_value_to_string(value);
686 fail_unless(out != NULL);
687 fail_unless(strcmp(buf, out) == 0);
688 free(out);
689 eina_value_flush(value);
690
691 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_USHORT));
692 in_us = 65535;
693 fail_unless(eina_value_pset(value, &in_us));
694 fail_unless(eina_value_pget(value, &us));
695 fail_unless(us == 65535);
696 snprintf(buf, sizeof(buf), "%hu", in_us);
697 out = eina_value_to_string(value);
698 fail_unless(out != NULL);
699 fail_unless(strcmp(buf, out) == 0);
700 free(out);
701 eina_value_flush(value);
702
703 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_UINT));
704 in_ui = 4000000000U;
705 fail_unless(eina_value_pset(value, &in_ui));
706 fail_unless(eina_value_pget(value, &ui));
707 fail_unless(ui == 4000000000U);
708 snprintf(buf, sizeof(buf), "%u", in_ui);
709 out = eina_value_to_string(value);
710 fail_unless(out != NULL);
711 fail_unless(strcmp(buf, out) == 0);
712 free(out);
713 eina_value_flush(value);
714
715 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_ULONG));
716 in_ul = 3000000001U;
717 fail_unless(eina_value_pset(value, &in_ul));
718 fail_unless(eina_value_pget(value, &ul));
719 fail_unless(ul == 3000000001U);
720 snprintf(buf, sizeof(buf), "%lu", in_ul);
721 out = eina_value_to_string(value);
722 fail_unless(out != NULL);
723 fail_unless(strcmp(buf, out) == 0);
724 free(out);
725 eina_value_flush(value);
726
727 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_UINT64));
728 in_u64 = 0x1122334455667788;
729 fail_unless(eina_value_pset(value, &in_u64));
730 fail_unless(eina_value_pget(value, &u64));
731 fail_unless(u64 == 0x1122334455667788);
732 snprintf(buf, sizeof(buf), "%"PRIu64, in_u64);
733 out = eina_value_to_string(value);
734 fail_unless(out != NULL);
735 fail_unless(strcmp(buf, out) == 0);
736 free(out);
737 eina_value_flush(value);
738
739 /* floating point */
740 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_FLOAT));
741 in_f = 0.1234;
742 fail_unless(eina_value_pset(value, &in_f));
743 fail_unless(eina_value_pget(value, &f));
744 fail_unless(CHECK_FP(0.1234, f));
745 snprintf(buf, sizeof(buf), "%g", in_f);
746 out = eina_value_to_string(value);
747 fail_unless(out != NULL);
748 fail_unless(strncmp(buf, out, 6) == 0); /* stupid float... */
749 free(out);
750 eina_value_flush(value);
751
752 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_DOUBLE));
753 in_d = 34567.8;
754 fail_unless(eina_value_pset(value, &in_d));
755 fail_unless(eina_value_pget(value, &d));
756 fail_unless(CHECK_FP(34567.8, d));
757 snprintf(buf, sizeof(buf), "%g", in_d);
758 out = eina_value_to_string(value);
759 fail_unless(out != NULL);
760 fail_unless(strncmp(buf, out, 7) == 0); /* stupid double... */
761 free(out);
762 eina_value_flush(value);
763
764 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_STRING));
765 in_str = "hello world!";
766 fail_unless(eina_value_pset(value, &in_str));
767 fail_unless(eina_value_pget(value, &str));
768 fail_unless(strcmp(str, "hello world!") == 0);
769 out = eina_value_to_string(value);
770 fail_unless(out != NULL);
771 fail_unless(strcmp(in_str, out) == 0);
772 free(out);
773
774 in_str = "eina-value";
775 fail_unless(eina_value_pset(value, &in_str));
776 fail_unless(eina_value_pget(value, &str));
777 fail_unless(strcmp(str, "eina-value") == 0);
778 out = eina_value_to_string(value);
779 fail_unless(out != NULL);
780 fail_unless(strcmp(in_str, out) == 0);
781 free(out);
782
783 eina_value_flush(value);
784 fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_STRING));
785
786 in_str = "profusion";
787 fail_unless(eina_value_pset(value, &in_str));
788 fail_unless(eina_value_pget(value, &str));
789 fail_unless(strcmp(str, "profusion") == 0);
790 out = eina_value_to_string(value);
791 fail_unless(out != NULL);
792 fail_unless(strcmp(in_str, out) == 0);
793 free(out);
794
795 eina_value_free(value);
796 eina_shutdown();
797}
798END_TEST
799
800START_TEST(eina_value_test_convert_char)
801{
802 Eina_Value *value, conv;
803 char c;
804 short s;
805 int i;
806 long l;
807 int64_t i64;
808 unsigned char uc;
809 unsigned short us;
810 unsigned int ui;
811 unsigned long ul;
812 uint64_t u64;
813 float f;
814 double d;
815 const char *str;
816
817 eina_init();
818
819 value = eina_value_new(EINA_VALUE_TYPE_CHAR);
820 fail_unless(value != NULL);
821
822 fail_unless(eina_value_set(value, 123));
823
824 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
825 fail_unless(eina_value_convert(value, &conv));
826 fail_unless(eina_value_get(&conv, &uc));
827 fail_unless(uc == 123);
828 eina_value_flush(&conv);
829
830 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
831 fail_unless(eina_value_convert(value, &conv));
832 fail_unless(eina_value_get(&conv, &us));
833 fail_unless(us == 123);
834 eina_value_flush(&conv);
835
836 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
837 fail_unless(eina_value_convert(value, &conv));
838 fail_unless(eina_value_get(&conv, &ui));
839 fail_unless(ui == 123);
840 eina_value_flush(&conv);
841
842 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
843 fail_unless(eina_value_convert(value, &conv));
844 fail_unless(eina_value_get(&conv, &ul));
845 fail_unless(ul == 123);
846 eina_value_flush(&conv);
847
848 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
849 fail_unless(eina_value_convert(value, &conv));
850 fail_unless(eina_value_get(&conv, &u64));
851 fail_unless(u64 == 123);
852 eina_value_flush(&conv);
853
854 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
855 fail_unless(eina_value_convert(value, &conv));
856 fail_unless(eina_value_get(&conv, &c));
857 fail_unless(c == 123);
858 eina_value_flush(&conv);
859
860 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
861 fail_unless(eina_value_convert(value, &conv));
862 fail_unless(eina_value_get(&conv, &s));
863 fail_unless(s == 123);
864 eina_value_flush(&conv);
865
866 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT));
867 fail_unless(eina_value_convert(value, &conv));
868 fail_unless(eina_value_get(&conv, &i));
869 fail_unless(i == 123);
870 eina_value_flush(&conv);
871
872 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_LONG));
873 fail_unless(eina_value_convert(value, &conv));
874 fail_unless(eina_value_get(&conv, &l));
875 fail_unless(l == 123);
876 eina_value_flush(&conv);
877
878 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT64));
879 fail_unless(eina_value_convert(value, &conv));
880 fail_unless(eina_value_get(&conv, &i64));
881 fail_unless(i64 == 123);
882 eina_value_flush(&conv);
883
884 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
885 fail_unless(eina_value_convert(value, &conv));
886 fail_unless(eina_value_get(&conv, &f));
887 fail_unless(CHECK_FP(f, 123));
888 eina_value_flush(&conv);
889
890 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
891 fail_unless(eina_value_convert(value, &conv));
892 fail_unless(eina_value_get(&conv, &d));
893 fail_unless(CHECK_FP(d, 123));
894 eina_value_flush(&conv);
895
896 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_STRING));
897 fail_unless(eina_value_convert(value, &conv));
898 fail_unless(eina_value_get(&conv, &str));
899 fail_unless(str != NULL);
900 fail_unless(strcmp(str, "123") == 0);
901 eina_value_flush(&conv);
902
903 /* negative tests */
904 fail_unless(eina_value_set(value, -123));
905
906 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
907 fail_if(eina_value_convert(value, &conv));
908 eina_value_flush(&conv);
909
910 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
911 fail_if(eina_value_convert(value, &conv));
912 eina_value_flush(&conv);
913
914 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
915 fail_if(eina_value_convert(value, &conv));
916 eina_value_flush(&conv);
917
918 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
919 fail_if(eina_value_convert(value, &conv));
920 eina_value_flush(&conv);
921
922 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
923 fail_if(eina_value_convert(value, &conv));
924 eina_value_flush(&conv);
925
926 eina_value_free(value);
927 eina_shutdown();
928}
929END_TEST
930
931START_TEST(eina_value_test_convert_uchar)
932{
933 Eina_Value *value, conv;
934 char c;
935 short s;
936 int i;
937 long l;
938 int64_t i64;
939 unsigned char uc;
940 unsigned short us;
941 unsigned int ui;
942 unsigned long ul;
943 uint64_t u64;
944 float f;
945 double d;
946 const char *str;
947
948 eina_init();
949
950 value = eina_value_new(EINA_VALUE_TYPE_UCHAR);
951 fail_unless(value != NULL);
952
953 fail_unless(eina_value_set(value, 31));
954
955 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
956 fail_unless(eina_value_convert(value, &conv));
957 fail_unless(eina_value_get(&conv, &uc));
958 fail_unless(uc == 31);
959 eina_value_flush(&conv);
960
961 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
962 fail_unless(eina_value_convert(value, &conv));
963 fail_unless(eina_value_get(&conv, &us));
964 fail_unless(us == 31);
965 eina_value_flush(&conv);
966
967 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
968 fail_unless(eina_value_convert(value, &conv));
969 fail_unless(eina_value_get(&conv, &ui));
970 fail_unless(ui == 31);
971 eina_value_flush(&conv);
972
973 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
974 fail_unless(eina_value_convert(value, &conv));
975 fail_unless(eina_value_get(&conv, &ul));
976 fail_unless(ul == 31);
977 eina_value_flush(&conv);
978
979 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
980 fail_unless(eina_value_convert(value, &conv));
981 fail_unless(eina_value_get(&conv, &u64));
982 fail_unless(u64 == 31);
983 eina_value_flush(&conv);
984
985 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
986 fail_unless(eina_value_convert(value, &conv));
987 fail_unless(eina_value_get(&conv, &c));
988 fail_unless(c == 31);
989 eina_value_flush(&conv);
990
991 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
992 fail_unless(eina_value_convert(value, &conv));
993 fail_unless(eina_value_get(&conv, &s));
994 fail_unless(s == 31);
995 eina_value_flush(&conv);
996
997 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT));
998 fail_unless(eina_value_convert(value, &conv));
999 fail_unless(eina_value_get(&conv, &i));
1000 fail_unless(i == 31);
1001 eina_value_flush(&conv);
1002
1003 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_LONG));
1004 fail_unless(eina_value_convert(value, &conv));
1005 fail_unless(eina_value_get(&conv, &l));
1006 fail_unless(l == 31);
1007 eina_value_flush(&conv);
1008
1009 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT64));
1010 fail_unless(eina_value_convert(value, &conv));
1011 fail_unless(eina_value_get(&conv, &i64));
1012 fail_unless(i64 == 31);
1013 eina_value_flush(&conv);
1014
1015 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
1016 fail_unless(eina_value_convert(value, &conv));
1017 fail_unless(eina_value_get(&conv, &f));
1018 fail_unless(CHECK_FP(f, 31));
1019 eina_value_flush(&conv);
1020
1021 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
1022 fail_unless(eina_value_convert(value, &conv));
1023 fail_unless(eina_value_get(&conv, &d));
1024 fail_unless(CHECK_FP(d, 31));
1025 eina_value_flush(&conv);
1026
1027 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_STRING));
1028 fail_unless(eina_value_convert(value, &conv));
1029 fail_unless(eina_value_get(&conv, &str));
1030 fail_unless(str != NULL);
1031 fail_unless(strcmp(str, "31") == 0);
1032 eina_value_flush(&conv);
1033
1034 /* negative tests */
1035 fail_unless(eina_value_set(value, 200));
1036
1037 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
1038 fail_if(eina_value_convert(value, &conv));
1039 eina_value_flush(&conv);
1040
1041 eina_value_free(value);
1042 eina_shutdown();
1043}
1044END_TEST
1045
1046
1047START_TEST(eina_value_test_array)
1048{
1049 Eina_Value *value, other;
1050 Eina_Value_Array desc;
1051 Eina_Inarray *inarray;
1052 char c;
1053 char buf[1024];
1054 char *str;
1055
1056 eina_init();
1057
1058 value = eina_value_array_new(EINA_VALUE_TYPE_CHAR, 0);
1059 fail_unless(value != NULL);
1060
1061 fail_unless(eina_value_array_append(value, 'k'));
1062 fail_unless(eina_value_array_append(value, '-'));
1063 fail_unless(eina_value_array_append(value, 's'));
1064
1065 fail_unless(eina_value_array_get(value, 0, &c));
1066 fail_unless(c == 'k');
1067 fail_unless(eina_value_array_get(value, 1, &c));
1068 fail_unless(c == '-');
1069 fail_unless(eina_value_array_get(value, 2, &c));
1070 fail_unless(c == 's');
1071
1072 fail_unless(eina_value_array_insert(value, 0, '!'));
1073 fail_unless(eina_value_array_get(value, 0, &c));
1074 fail_unless(c == '!');
1075 fail_unless(eina_value_array_get(value, 1, &c));
1076 fail_unless(c == 'k');
1077 fail_unless(eina_value_array_get(value, 2, &c));
1078 fail_unless(c == '-');
1079 fail_unless(eina_value_array_get(value, 3, &c));
1080 fail_unless(c == 's');
1081
1082 fail_unless(eina_value_array_set(value, 0, '*'));
1083 fail_unless(eina_value_array_get(value, 0, &c));
1084 fail_unless(c == '*');
1085 fail_unless(eina_value_array_get(value, 1, &c));
1086 fail_unless(c == 'k');
1087 fail_unless(eina_value_array_get(value, 2, &c));
1088 fail_unless(c == '-');
1089 fail_unless(eina_value_array_get(value, 3, &c));
1090 fail_unless(c == 's');
1091
1092 snprintf(buf, sizeof(buf), "[%hhd, %hhd, %hhd, %hhd]",
1093 '*', 'k', '-', 's');
1094
1095 str = eina_value_to_string(value);
1096 fail_unless(str != NULL);
1097 fail_unless(strcmp(str, buf) == 0);
1098 free(str);
1099
1100 eina_value_flush(value);
1101 fail_unless(eina_value_array_setup(value, EINA_VALUE_TYPE_STRINGSHARE, 2));
1102
1103 fail_unless(eina_value_array_append(value, "Enlightenment.org"));
1104 fail_unless(eina_value_array_append(value, "X11"));
1105 fail_unless(eina_value_array_append(value, "Pants"));
1106 fail_unless(eina_value_array_append(value, "on!!!"));
1107 fail_unless(eina_value_array_append(value, "k-s"));
1108
1109 str = eina_value_to_string(value);
1110 fail_unless(str != NULL);
1111 fail_unless(strcmp(str, "[Enlightenment.org, X11, Pants, on!!!, k-s]") == 0);
1112 free(str);
1113
1114 eina_value_flush(value);
1115 fail_unless(eina_value_array_setup(value, EINA_VALUE_TYPE_CHAR, 0));
1116 fail_unless(eina_value_setup(&other, EINA_VALUE_TYPE_CHAR));
1117
1118 fail_unless(eina_value_set(&other, 100));
1119 fail_unless(eina_value_get(&other, &c));
1120 fail_unless(c == 100);
1121
1122 fail_unless(eina_value_convert(&other, value));
1123 str = eina_value_to_string(value);
1124 fail_unless(str != NULL);
1125 fail_unless(strcmp(str, "[100]") == 0);
1126 free(str);
1127
1128 fail_unless(eina_value_array_set(value, 0, 33));
1129 fail_unless(eina_value_convert(value, &other));
1130 fail_unless(eina_value_get(&other, &c));
1131 fail_unless(c == 33);
1132
1133 inarray = eina_inarray_new(sizeof(char), 0);
1134 fail_unless(inarray != NULL);
1135 c = 11;
1136 fail_unless(eina_inarray_append(inarray, &c) >= 0);
1137 c = 21;
1138 fail_unless(eina_inarray_append(inarray, &c) >= 0);
1139 c = 31;
1140 fail_unless(eina_inarray_append(inarray, &c) >= 0);
1141 desc.subtype = EINA_VALUE_TYPE_CHAR;
1142 desc.step = 0;
1143 desc.array = inarray;
1144 fail_unless(eina_value_set(value, desc)); /* manually configure */
1145 eina_inarray_free(inarray);
1146
1147 fail_unless(eina_value_array_get(value, 0, &c));
1148 fail_unless(c == 11);
1149 fail_unless(eina_value_array_get(value, 1, &c));
1150 fail_unless(c == 21);
1151 fail_unless(eina_value_array_get(value, 2, &c));
1152 fail_unless(c == 31);
1153
1154 eina_value_free(value);
1155 eina_shutdown();
1156}
1157END_TEST
1158
1159START_TEST(eina_value_test_list)
1160{
1161 Eina_Value *value, other;
1162 Eina_Value_List desc;
1163 char c;
1164 char buf[1024];
1165 char *str;
1166 const char *s;
1167
1168 eina_init();
1169
1170 value = eina_value_list_new(EINA_VALUE_TYPE_CHAR);
1171 fail_unless(value != NULL);
1172
1173 fail_unless(eina_value_list_append(value, 'k'));
1174 fail_unless(eina_value_list_append(value, '-'));
1175 fail_unless(eina_value_list_append(value, 's'));
1176
1177 fail_unless(eina_value_list_get(value, 0, &c));
1178 fail_unless(c == 'k');
1179 fail_unless(eina_value_list_get(value, 1, &c));
1180 fail_unless(c == '-');
1181 fail_unless(eina_value_list_get(value, 2, &c));
1182 fail_unless(c == 's');
1183
1184 fail_unless(eina_value_list_insert(value, 0, '!'));
1185 fail_unless(eina_value_list_get(value, 0, &c));
1186 fail_unless(c == '!');
1187 fail_unless(eina_value_list_get(value, 1, &c));
1188 fail_unless(c == 'k');
1189 fail_unless(eina_value_list_get(value, 2, &c));
1190 fail_unless(c == '-');
1191 fail_unless(eina_value_list_get(value, 3, &c));
1192 fail_unless(c == 's');
1193
1194 fail_unless(eina_value_list_set(value, 0, '*'));
1195 fail_unless(eina_value_list_get(value, 0, &c));
1196 fail_unless(c == '*');
1197 fail_unless(eina_value_list_get(value, 1, &c));
1198 fail_unless(c == 'k');
1199 fail_unless(eina_value_list_get(value, 2, &c));
1200 fail_unless(c == '-');
1201 fail_unless(eina_value_list_get(value, 3, &c));
1202 fail_unless(c == 's');
1203
1204 snprintf(buf, sizeof(buf), "[%hhd, %hhd, %hhd, %hhd]",
1205 '*', 'k', '-', 's');
1206
1207 str = eina_value_to_string(value);
1208 fail_unless(str != NULL);
1209 fail_unless(strcmp(str, buf) == 0);
1210 free(str);
1211
1212 eina_value_flush(value);
1213 fail_unless(eina_value_list_setup(value, EINA_VALUE_TYPE_STRINGSHARE));
1214
1215 fail_unless(eina_value_list_append(value, "Enlightenment.org"));
1216 fail_unless(eina_value_list_append(value, "X11"));
1217 fail_unless(eina_value_list_append(value, "Pants"));
1218 fail_unless(eina_value_list_append(value, "on!!!"));
1219 fail_unless(eina_value_list_append(value, "k-s"));
1220
1221 str = eina_value_to_string(value);
1222 fail_unless(str != NULL);
1223 fail_unless(strcmp(str, "[Enlightenment.org, X11, Pants, on!!!, k-s]") == 0);
1224 free(str);
1225
1226 eina_value_flush(value);
1227 fail_unless(eina_value_list_setup(value, EINA_VALUE_TYPE_CHAR));
1228 fail_unless(eina_value_setup(&other, EINA_VALUE_TYPE_CHAR));
1229
1230 fail_unless(eina_value_set(&other, 100));
1231 fail_unless(eina_value_get(&other, &c));
1232 fail_unless(c == 100);
1233
1234 fail_unless(eina_value_convert(&other, value));
1235 str = eina_value_to_string(value);
1236 fail_unless(str != NULL);
1237 fail_unless(strcmp(str, "[100]") == 0);
1238 free(str);
1239
1240 fail_unless(eina_value_list_set(value, 0, 33));
1241 fail_unless(eina_value_convert(value, &other));
1242 fail_unless(eina_value_get(&other, &c));
1243 fail_unless(c == 33);
1244
1245 desc.subtype = EINA_VALUE_TYPE_STRING;
1246 desc.list = NULL;
1247 desc.list = eina_list_append(desc.list, "hello");
1248 desc.list = eina_list_append(desc.list, "world");
1249 desc.list = eina_list_append(desc.list, "eina");
1250 fail_unless(eina_list_count(desc.list) == 3);
1251 fail_unless(eina_value_set(value, desc));
1252 eina_list_free(desc.list);
1253
1254 fail_unless(eina_value_list_get(value, 0, &s));
1255 fail_unless(s != NULL);
1256 fail_unless(strcmp(s, "hello") == 0);
1257 fail_unless(eina_value_list_get(value, 1, &s));
1258 fail_unless(s != NULL);
1259 fail_unless(strcmp(s, "world") == 0);
1260 fail_unless(eina_value_list_get(value, 2, &s));
1261 fail_unless(s != NULL);
1262 fail_unless(strcmp(s, "eina") == 0);
1263
1264 eina_value_free(value);
1265 eina_shutdown();
1266}
1267END_TEST
1268
1269START_TEST(eina_value_test_hash)
1270{
1271 Eina_Value *value, other;
1272 Eina_Value_Hash desc;
1273 char c;
1274 char buf[1024];
1275 char **ptr;
1276 char *str;
1277 const char *s;
1278
1279 eina_init();
1280
1281 value = eina_value_hash_new(EINA_VALUE_TYPE_CHAR, 0);
1282 fail_unless(value != NULL);
1283
1284 fail_unless(eina_value_hash_set(value, "first", 'k'));
1285 fail_unless(eina_value_hash_set(value, "second", '-'));
1286 fail_unless(eina_value_hash_set(value, "third", 's'));
1287
1288 fail_unless(eina_value_hash_get(value, "first", &c));
1289 fail_unless(c == 'k');
1290 fail_unless(eina_value_hash_get(value, "second", &c));
1291 fail_unless(c == '-');
1292 fail_unless(eina_value_hash_get(value, "third", &c));
1293 fail_unless(c == 's');
1294
1295 fail_unless(eina_value_hash_set(value, "first", '!'));
1296 fail_unless(eina_value_hash_get(value, "first", &c));
1297 fail_unless(c == '!');
1298 fail_unless(eina_value_hash_get(value, "second", &c));
1299 fail_unless(c == '-');
1300 fail_unless(eina_value_hash_get(value, "third", &c));
1301 fail_unless(c == 's');
1302
1303 puts("testing hash to string -- may fail due hash algorithm changes!");
1304
1305 /* watchout, this is the order I got -- hash algorithm changes may change
1306 * the order!
1307 */
1308 snprintf(buf, sizeof(buf), "{first: %hhd, second: %hhd, third: %hhd}",
1309 '!', '-', 's');
1310
1311 str = eina_value_to_string(value);
1312 fail_unless(str != NULL);
1313 printf("want: %s\n", buf);
1314 printf("got.: %s\n", str);
1315 fail_unless(strcmp(str, buf) == 0);
1316 free(str);
1317
1318 eina_value_flush(value);
1319 fail_unless(eina_value_hash_setup(value, EINA_VALUE_TYPE_STRINGSHARE, 0));
1320
1321 fail_unless(eina_value_hash_set(value, "a", "Enlightenment.org"));
1322 fail_unless(eina_value_hash_set(value, "b", "X11"));
1323 fail_unless(eina_value_hash_set(value, "c", "Pants"));
1324 fail_unless(eina_value_hash_set(value, "d", "on!!!"));
1325 fail_unless(eina_value_hash_set(value, "e", "k-s"));
1326
1327 /* watchout, this is the order I got -- hash algorithm changes may change
1328 * the order!
1329 */
1330 strcpy(buf, "{e: k-s, d: on!!!, a: Enlightenment.org, b: X11, c: Pants}");
1331
1332 str = eina_value_to_string(value);
1333 fail_unless(str != NULL);
1334 printf("want: %s\n", buf);
1335 printf("got.: %s\n", str);
1336 fail_unless(strcmp(str, buf) == 0);
1337 free(str);
1338
1339 eina_value_flush(value);
1340 fail_unless(eina_value_hash_setup(value, EINA_VALUE_TYPE_CHAR, 0));
1341 fail_unless(eina_value_setup(&other, EINA_VALUE_TYPE_CHAR));
1342
1343 fail_unless(eina_value_set(&other, 100));
1344 fail_unless(eina_value_get(&other, &c));
1345 fail_unless(c == 100);
1346
1347 fail_unless(eina_value_hash_set(value, "first", 33));
1348 fail_unless(eina_value_convert(value, &other));
1349 fail_unless(eina_value_get(&other, &c));
1350 fail_unless(c == 33);
1351
1352 desc.subtype = EINA_VALUE_TYPE_STRING;
1353 desc.buckets_power_size = 0;
1354 desc.hash = eina_hash_string_small_new(NULL);
1355 fail_unless(desc.hash != NULL);
1356 /* watch out hash pointer is to a size of subtype->value_size! */
1357 ptr = malloc(sizeof(char *));
1358 *ptr = "there";
1359 fail_unless(eina_hash_add(desc.hash, "hi", ptr));
1360 ptr = malloc(sizeof(char *));
1361 *ptr = "y";
1362 fail_unless(eina_hash_add(desc.hash, "x", ptr));
1363 fail_unless(eina_value_set(value, desc));
1364
1365 free(eina_hash_find(desc.hash, "hi"));
1366 free(eina_hash_find(desc.hash, "x"));
1367 eina_hash_free(desc.hash);
1368
1369 fail_unless(eina_value_hash_get(value, "hi", &s));
1370 fail_unless(s != NULL);
1371 fail_unless(strcmp(s, "there") == 0);
1372
1373 fail_unless(eina_value_hash_get(value, "x", &s));
1374 fail_unless(s != NULL);
1375 fail_unless(strcmp(s, "y") == 0);
1376
1377 eina_value_free(value);
1378 eina_shutdown();
1379}
1380END_TEST
1381
1382
1383START_TEST(eina_value_test_timeval)
1384{
1385 Eina_Value *value, other;
1386 struct timeval itv, otv;
1387 char c;
1388 char *str;
1389
1390 eina_init();
1391
1392 value = eina_value_new(EINA_VALUE_TYPE_TIMEVAL);
1393 fail_unless(value != NULL);
1394
1395 itv.tv_sec = 1;
1396 itv.tv_usec = 123;
1397 fail_unless(eina_value_set(value, itv));
1398 fail_unless(eina_value_get(value, &otv));
1399 fail_unless(memcmp(&itv, &otv, sizeof(struct timeval)) == 0);
1400
1401 itv.tv_sec = 3;
1402 itv.tv_usec = -1;
1403 fail_unless(eina_value_set(value, itv));
1404 fail_unless(eina_value_get(value, &otv));
1405 itv.tv_sec = 2;
1406 itv.tv_usec = 999999;
1407 fail_unless(memcmp(&itv, &otv, sizeof(struct timeval)) == 0);
1408
1409 fail_unless(eina_value_setup(&other, EINA_VALUE_TYPE_CHAR));
1410 fail_unless(eina_value_convert(value, &other));
1411 fail_unless(eina_value_get(&other, &c));
1412 fail_unless(c == 2);
1413 eina_value_flush(&other);
1414
1415 itv.tv_sec = 12345;
1416 itv.tv_usec = 6789;
1417 fail_unless(eina_value_set(value, itv));
1418 str = eina_value_to_string(value);
1419 fail_unless(str != NULL);
1420 fail_unless(strcmp(str, "12345.006789") == 0);
1421 free(str);
1422
1423 fail_unless(eina_value_setup(&other, EINA_VALUE_TYPE_TIMEVAL));
1424 fail_unless(eina_value_set(&other, itv));
1425 fail_unless(eina_value_compare(value, &other) == 0);
1426
1427 itv.tv_sec++;
1428 fail_unless(eina_value_set(&other, itv));
1429 fail_unless(eina_value_compare(value, &other) < 0);
1430
1431 itv.tv_sec -= 2;
1432 fail_unless(eina_value_set(&other, itv));
1433 fail_unless(eina_value_compare(value, &other) > 0);
1434
1435 itv.tv_sec++;
1436 fail_unless(eina_value_set(&other, itv));
1437 fail_unless(eina_value_compare(value, &other) == 0);
1438
1439 itv.tv_usec++;
1440 fail_unless(eina_value_set(&other, itv));
1441 fail_unless(eina_value_compare(value, &other) < 0);
1442
1443 itv.tv_usec -= 2;
1444 fail_unless(eina_value_set(&other, itv));
1445 fail_unless(eina_value_compare(value, &other) > 0);
1446
1447 itv.tv_usec++;
1448 fail_unless(eina_value_set(&other, itv));
1449 fail_unless(eina_value_compare(value, &other) == 0);
1450
1451 eina_value_flush(&other);
1452
1453
1454 eina_value_free(value);
1455 eina_shutdown();
1456}
1457END_TEST
1458
1459
1460START_TEST(eina_value_test_blob)
1461{
1462 Eina_Value *value, other;
1463 Eina_Value_Blob in, out;
1464 unsigned char blob[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
1465 int i = 0x11223344;
1466 char *str;
1467
1468 eina_init();
1469
1470 value = eina_value_new(EINA_VALUE_TYPE_BLOB);
1471 fail_unless(value != NULL);
1472
1473 in.ops = NULL;
1474 in.memory = blob;
1475 in.size = sizeof(blob);
1476 fail_unless(eina_value_set(value, in));
1477 fail_unless(eina_value_get(value, &out));
1478 fail_unless(out.memory == blob);
1479 fail_unless(out.size == sizeof(blob));
1480 fail_unless(memcmp(&in, &out, sizeof(Eina_Value_Blob)) == 0);
1481
1482 str = eina_value_to_string(value);
1483 fail_unless(str != NULL);
1484 fail_unless(strcmp(str, "BLOB(10, [01 02 03 04 05 06 07 08 09 0a])") == 0);
1485 free(str);
1486
1487 fail_unless(eina_value_setup(&other, EINA_VALUE_TYPE_INT));
1488 fail_unless(eina_value_set(&other, i));
1489 fail_unless(eina_value_convert(&other, value));
1490 fail_unless(eina_value_get(value, &out));
1491
1492 fail_unless(out.memory != NULL);
1493 fail_unless(out.size == sizeof(int));
1494 fail_unless(memcmp(&i, out.memory, sizeof(int)) == 0);
1495
1496 eina_value_flush(&other);
1497
1498 fail_unless(eina_value_setup(&other, EINA_VALUE_TYPE_STRING));
1499 fail_unless(eina_value_set(&other, "hi there!"));
1500 fail_unless(eina_value_convert(&other, value));
1501 fail_unless(eina_value_get(value, &out));
1502 fail_unless(out.memory != NULL);
1503 fail_unless(out.size == sizeof("hi there!"));
1504 fail_unless(strcmp(out.memory, "hi there!") == 0);
1505
1506 str = eina_value_to_string(value);
1507 fail_unless(str != NULL);
1508 fail_unless(strcmp(str, "BLOB(10, [68 69 20 74 68 65 72 65 21 00])") == 0);
1509 free(str);
1510
1511 eina_value_flush(&other);
1512
1513 fail_unless(eina_value_array_setup(&other, EINA_VALUE_TYPE_CHAR, 0));
1514 fail_unless(eina_value_array_append(&other, 0xa));
1515 fail_unless(eina_value_array_append(&other, 0xb));
1516 fail_unless(eina_value_array_append(&other, 0xc));
1517 fail_unless(eina_value_convert(&other, value));
1518 fail_unless(eina_value_get(value, &out));
1519 fail_unless(out.memory != NULL);
1520 fail_unless(out.size == 3);
1521
1522 str = eina_value_to_string(value);
1523 fail_unless(str != NULL);
1524 fail_unless(strcmp(str, "BLOB(3, [0a 0b 0c])") == 0);
1525 free(str);
1526
1527 eina_value_flush(&other);
1528
1529 fail_unless(eina_value_setup(&other, EINA_VALUE_TYPE_BLOB));
1530 fail_unless(eina_value_set(&other, in));
1531 fail_unless(eina_value_convert(value, &other));
1532 fail_unless(eina_value_get(&other, &out));
1533 fail_unless(out.memory != NULL);
1534 fail_unless(out.size == 3);
1535
1536 str = eina_value_to_string(&other);
1537 fail_unless(str != NULL);
1538 fail_unless(strcmp(str, "BLOB(3, [0a 0b 0c])") == 0);
1539 free(str);
1540
1541 eina_value_flush(&other);
1542
1543 eina_value_free(value);
1544 eina_shutdown();
1545}
1546END_TEST
1547
1548
1549START_TEST(eina_value_test_struct)
1550{
1551 struct mybigst {
1552 int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, x;
1553 };
1554 const Eina_Value_Struct_Member mybigst_members[] = {
1555 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, a),
1556 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, b),
1557 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, c),
1558 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, d),
1559 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, e),
1560 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, f),
1561 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, g),
1562 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, h),
1563 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, i),
1564 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, j),
1565 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, k),
1566 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, l),
1567 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, m),
1568 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, n),
1569 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, o),
1570 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, p),
1571 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, q),
1572 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, r),
1573 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, s),
1574 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, t),
1575 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, u),
1576 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, v),
1577 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, x),
1578 EINA_VALUE_STRUCT_MEMBER_SENTINEL
1579 };
1580 const Eina_Value_Struct_Desc mybigst_desc = {
1581 EINA_VALUE_STRUCT_DESC_VERSION,
1582 EINA_VALUE_STRUCT_OPERATIONS_BINSEARCH,
1583 mybigst_members, 23, sizeof(struct mybigst)
1584 };
1585 struct myst {
1586 int i;
1587 char c;
1588 };
1589 const Eina_Value_Struct_Member myst_members[] = {
1590 {"i", EINA_VALUE_TYPE_INT, 0},
1591 {"c", EINA_VALUE_TYPE_CHAR, 4},
1592 {NULL, NULL, 0}
1593 };
1594 const Eina_Value_Struct_Desc myst_desc = {
1595 EINA_VALUE_STRUCT_DESC_VERSION,
1596 NULL, myst_members, 2, sizeof(struct myst)
1597 };
1598 Eina_Value *value, other;
1599 int i;
1600 char c;
1601 char *str;
1602
1603 eina_init();
1604
1605 value = eina_value_struct_new(&myst_desc);
1606 fail_unless(value != NULL);
1607
1608 fail_unless(eina_value_struct_set(value, "i", 5678));
1609 fail_unless(eina_value_struct_set(value, "c", 0xf));
1610
1611 fail_unless(eina_value_struct_get(value, "i", &i));
1612 fail_unless(i == 5678);
1613 fail_unless(eina_value_struct_get(value, "c", &c));
1614 fail_unless(c == 0xf);
1615
1616 fail_unless(eina_value_struct_member_value_get
1617 (value, myst_members + 0, &other));
1618 fail_unless(other.type == EINA_VALUE_TYPE_INT);
1619 fail_unless(eina_value_get(&other, &i));
1620 fail_unless(i == 5678);
1621 eina_value_flush(&other);
1622
1623 fail_unless(eina_value_struct_member_value_get
1624 (value, myst_members + 1, &other));
1625 fail_unless(other.type == EINA_VALUE_TYPE_CHAR);
1626 fail_unless(eina_value_get(&other, &c));
1627 fail_unless(c = 0xf);
1628 eina_value_flush(&other);
1629
1630 str = eina_value_to_string(value);
1631 fail_unless(str != NULL);
1632 fail_unless(strcmp(str, "{i: 5678, c: 15}") == 0);
1633 free(str);
1634
1635 fail_if(eina_value_struct_get(value, "x", 1234));
1636
1637 i = 0x11223344;
1638 fail_unless(eina_value_struct_pset(value, "i", &i));
1639 i = -1;
1640 fail_unless(eina_value_struct_pget(value, "i", &i));
1641 fail_unless(i == 0x11223344);
1642
1643 fail_unless(eina_value_copy(value, &other));
1644 str = eina_value_to_string(&other);
1645 fail_unless(str != NULL);
1646 fail_unless(strcmp(str, "{i: 287454020, c: 15}") == 0);
1647 free(str);
1648
1649 eina_value_flush(&other);
1650
1651 fail_unless(eina_value_struct_setup(&other, &mybigst_desc));
1652 fail_unless(eina_value_struct_set(&other, "a", 1) );
1653 fail_unless(eina_value_struct_set(&other, "b", 2));
1654 fail_unless(eina_value_struct_set(&other, "c", 3));
1655 fail_unless(eina_value_struct_set(&other, "d", 4));
1656 fail_unless(eina_value_struct_set(&other, "e", 5));
1657 fail_unless(eina_value_struct_set(&other, "f", 6));
1658 fail_unless(eina_value_struct_set(&other, "g", 7));
1659 fail_unless(eina_value_struct_set(&other, "h", 8));
1660 fail_unless(eina_value_struct_set(&other, "i", 9));
1661 fail_unless(eina_value_struct_set(&other, "j", 10));
1662 fail_unless(eina_value_struct_set(&other, "k", 12));
1663 fail_unless(eina_value_struct_set(&other, "l", 13));
1664 fail_unless(eina_value_struct_set(&other, "m", 14));
1665 fail_unless(eina_value_struct_set(&other, "n", 15));
1666 fail_unless(eina_value_struct_set(&other, "o", 16));
1667 fail_unless(eina_value_struct_set(&other, "p", 17));
1668 fail_unless(eina_value_struct_set(&other, "q", 18));
1669 fail_unless(eina_value_struct_set(&other, "r", 19));
1670 fail_unless(eina_value_struct_set(&other, "s", 20));
1671 fail_unless(eina_value_struct_set(&other, "t", 21));
1672 fail_unless(eina_value_struct_set(&other, "u", 22));
1673 fail_unless(eina_value_struct_set(&other, "v", 23));
1674 fail_unless(eina_value_struct_set(&other, "x", 24));
1675
1676 fail_unless(eina_value_struct_get(&other, "a", &i));
1677 fail_unless(i == 1);
1678 fail_unless(eina_value_struct_get(&other, "b", &i));
1679 fail_unless(i == 2);
1680 fail_unless(eina_value_struct_get(&other, "c", &i));
1681 fail_unless(i == 3);
1682 fail_unless(eina_value_struct_get(&other, "d", &i));
1683 fail_unless(i == 4);
1684 fail_unless(eina_value_struct_get(&other, "e", &i));
1685 fail_unless(i == 5);
1686 fail_unless(eina_value_struct_get(&other, "f", &i));
1687 fail_unless(i == 6);
1688 fail_unless(eina_value_struct_get(&other, "g", &i));
1689 fail_unless(i == 7);
1690 fail_unless(eina_value_struct_get(&other, "h", &i));
1691 fail_unless(i == 8);
1692 fail_unless(eina_value_struct_get(&other, "i", &i));
1693 fail_unless(i == 9);
1694 fail_unless(eina_value_struct_get(&other, "j", &i));
1695 fail_unless(i == 10);
1696 fail_unless(eina_value_struct_get(&other, "k", &i));
1697 fail_unless(i == 12);
1698 fail_unless(eina_value_struct_get(&other, "l", &i));
1699 fail_unless(i == 13);
1700 fail_unless(eina_value_struct_get(&other, "m", &i));
1701 fail_unless(i == 14);
1702 fail_unless(eina_value_struct_get(&other, "n", &i));
1703 fail_unless(i == 15);
1704 fail_unless(eina_value_struct_get(&other, "o", &i));
1705 fail_unless(i == 16);
1706 fail_unless(eina_value_struct_get(&other, "p", &i));
1707 fail_unless(i == 17);
1708 fail_unless(eina_value_struct_get(&other, "q", &i));
1709 fail_unless(i == 18);
1710 fail_unless(eina_value_struct_get(&other, "r", &i));
1711 fail_unless(i == 19);
1712 fail_unless(eina_value_struct_get(&other, "s", &i));
1713 fail_unless(i == 20);
1714 fail_unless(eina_value_struct_get(&other, "t", &i));
1715 fail_unless(i == 21);
1716 fail_unless(eina_value_struct_get(&other, "u", &i));
1717 fail_unless(i == 22);
1718 fail_unless(eina_value_struct_get(&other, "v", &i));
1719 fail_unless(i == 23);
1720 fail_unless(eina_value_struct_get(&other, "x", &i));
1721 fail_unless(i == 24);
1722
1723 str = eina_value_to_string(&other);
1724 fail_unless(str != NULL);
1725 fail_unless(strcmp(str, "{a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10, k: 12, l: 13, m: 14, n: 15, o: 16, p: 17, q: 18, r: 19, s: 20, t: 21, u: 22, v: 23, x: 24}") == 0);
1726 free(str);
1727
1728 eina_value_flush(&other);
1729 eina_value_free(value);
1730 eina_shutdown();
1731}
1732END_TEST
1733
1734
1735START_TEST(eina_value_test_array_of_struct)
1736{
1737 struct myst {
1738 int a, b, c;
1739 const char *s;
1740 };
1741 const Eina_Value_Struct_Member myst_members[] = {
1742 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct myst, a),
1743 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct myst, b),
1744 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct myst, c),
1745 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_STRING, struct myst, s),
1746 EINA_VALUE_STRUCT_MEMBER_SENTINEL
1747 };
1748 const Eina_Value_Struct_Desc myst_desc = {
1749 EINA_VALUE_STRUCT_DESC_VERSION,
1750 EINA_VALUE_STRUCT_OPERATIONS_BINSEARCH,
1751 myst_members, 4, sizeof(struct myst)
1752 };
1753 Eina_Value *value, array_item;
1754 char *str;
1755 int i;
1756
1757 eina_init();
1758
1759 value = eina_value_array_new(EINA_VALUE_TYPE_STRUCT, 0);
1760 fail_unless(value != NULL);
1761
1762 for (i = 0; i < 10; i++)
1763 {
1764 Eina_Value_Struct desc;
1765 struct myst st;
1766 char buf[64];
1767
1768 snprintf(buf, sizeof(buf), "item%02d", i);
1769 st.a = i;
1770 st.b = i * 10;
1771 st.c = i * 100;
1772 st.s = buf;
1773
1774 desc.desc = &myst_desc;
1775 desc.memory = &st;
1776 fail_unless(eina_value_array_append(value, desc));
1777 }
1778
1779 str = eina_value_to_string(value);
1780 fail_unless(str != NULL);
1781 fail_unless(strcmp(str, "["
1782 "{a: 0, b: 0, c: 0, s: item00}, "
1783 "{a: 1, b: 10, c: 100, s: item01}, "
1784 "{a: 2, b: 20, c: 200, s: item02}, "
1785 "{a: 3, b: 30, c: 300, s: item03}, "
1786 "{a: 4, b: 40, c: 400, s: item04}, "
1787 "{a: 5, b: 50, c: 500, s: item05}, "
1788 "{a: 6, b: 60, c: 600, s: item06}, "
1789 "{a: 7, b: 70, c: 700, s: item07}, "
1790 "{a: 8, b: 80, c: 800, s: item08}, "
1791 "{a: 9, b: 90, c: 900, s: item09}"
1792 "]") == 0);
1793 free(str);
1794
1795 eina_value_array_value_get(value, 2, &array_item);
1796 eina_value_struct_get(&array_item, "a", &i);
1797 ck_assert_int_eq(i, 2);
1798 eina_value_struct_get(&array_item, "b", &i);
1799 ck_assert_int_eq(i, 20);
1800 eina_value_struct_get(&array_item, "c", &i);
1801 ck_assert_int_eq(i, 200);
1802 eina_value_struct_get(&array_item, "s", &str);
1803 ck_assert_str_eq(str, "item02");
1804 eina_value_flush(&array_item);
1805
1806 eina_value_free(value);
1807 eina_shutdown();
1808}
1809END_TEST
1810
1811
1812START_TEST(eina_value_test_model)
1813{
1814 Eina_Value *value, inv;
1815 Eina_Model *model, *m;
1816 char *str;
1817
1818 eina_init();
1819
1820 value = eina_value_new(EINA_VALUE_TYPE_MODEL);
1821 fail_unless(value != NULL);
1822
1823 model = eina_model_new(EINA_MODEL_TYPE_GENERIC);
1824 fail_unless(model != NULL);
1825
1826 fail_unless(eina_value_setup(&inv, EINA_VALUE_TYPE_INT));
1827 fail_unless(eina_value_set(&inv, 1234));
1828 fail_unless(eina_model_property_set(model, "i", &inv));
1829 eina_value_flush(&inv);
1830
1831 fail_unless(eina_value_set(value, model));
1832 fail_unless(eina_model_refcount(model) == 2);
1833
1834 fail_unless(eina_value_get(value, &m));
1835 fail_unless(m == model);
1836 fail_unless(eina_model_refcount(m) == 2);
1837
1838 fail_unless(eina_value_pset(value, &model));
1839 fail_unless(eina_model_refcount(model) == 2);
1840
1841 str = eina_value_to_string(value);
1842 fail_unless(str != NULL);
1843 fail_unless(strcmp(str, "Eina_Model_Type_Generic({i: 1234}, [])") == 0);
1844 free(str);
1845
1846 eina_value_free(value);
1847
1848 fail_unless(eina_model_refcount(model) == 1);
1849 eina_model_unref(model);
1850
1851 eina_shutdown();
1852}
1853END_TEST
1854
1855void
1856eina_test_value(TCase *tc)
1857{
1858 tcase_add_test(tc, eina_value_test_simple);
1859 tcase_add_test(tc, eina_value_test_string);
1860 tcase_add_test(tc, eina_value_test_pvariant);
1861 tcase_add_test(tc, eina_value_test_compare);
1862 tcase_add_test(tc, eina_value_test_to_string);
1863 tcase_add_test(tc, eina_value_test_convert_char);
1864 tcase_add_test(tc, eina_value_test_convert_uchar);
1865 // TODO: other converters...
1866 tcase_add_test(tc, eina_value_test_array);
1867 tcase_add_test(tc, eina_value_test_list);
1868 tcase_add_test(tc, eina_value_test_hash);
1869 tcase_add_test(tc, eina_value_test_timeval);
1870 tcase_add_test(tc, eina_value_test_blob);
1871 tcase_add_test(tc, eina_value_test_struct);
1872 tcase_add_test(tc, eina_value_test_array_of_struct);
1873 tcase_add_test(tc, eina_value_test_model);
1874}