summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordmoity <damien.moity@amtrust.com>2015-11-06 12:22:13 +0100
committerdmoity <damien.moity@amtrust.com>2015-11-06 12:22:13 +0100
commita0ce9b9709b42209a1e147d71f452b8034864e93 (patch)
treeafc3c41ed88ce232c6781b5780c11d68d47b2677
parentd6364b98ee395103a1b6e8b0a559db3ba6d282ec (diff)
azy : add unit tests for deserialization of json
-rw-r--r--src/tests/azy/unit/azy_content_deserialize_json.c708
-rw-r--r--src/tests/azy/unit/t002_json.azy47
-rw-r--r--src/tests/azy/unit/t002_json.c25
-rw-r--r--src/tests/azy/unit/t002_json.h11
4 files changed, 791 insertions, 0 deletions
diff --git a/src/tests/azy/unit/azy_content_deserialize_json.c b/src/tests/azy/unit/azy_content_deserialize_json.c
new file mode 100644
index 0000000..af3686d
--- /dev/null
+++ b/src/tests/azy/unit/azy_content_deserialize_json.c
@@ -0,0 +1,708 @@
1#include "t002_json.h"
2
3#define ck_assert_double_eq(_a, _b) do { \
4 double epsilon = 0.00001; \
5 ck_assert_msg(_a >= _b - epsilon && _a <= _b + epsilon, "Assertion '%f==%f' failed", _a, _b); \
6} while (0)
7
8START_TEST(_azy_content_deserialize_json_int1)
9{
10 Azy_Content *content;
11 Eina_Bool r;
12 const char *s = "{\"test_int\":3}";
13 Eina_Value *ev;
14 T002_Integer *ti;
15
16 content = azy_content_new(NULL);
17 ck_assert_msg(!!content, "Error while allocating content.");
18
19 r = azy_content_deserialize_json(content, s, strlen(s));
20 ck_assert_msg(r, "Error while deserializing json.");
21
22 ev = azy_content_retval_get(content);
23 ck_assert_msg(!!ev, "Error while getting retval.");
24
25 r = azy_value_to_T002_Integer(ev, &ti);
26 ck_assert_msg(r, "Error while getting value of ti.");
27 ck_assert_msg(!!ti, "Error, value of ti is NULL.");
28 ck_assert_int_eq(ti->test_int, 3);
29
30 T002_Integer_free(ti);
31 azy_content_free(content);
32}
33END_TEST
34
35// todo : when value is not the true type for exemple string in place of int,
36// int must be equal to 0.
37// In this case azy_value_to_T002_Integer must display a warning message.
38START_TEST(_azy_content_deserialize_json_int2)
39{
40 Azy_Content *content;
41 Eina_Bool r;
42 const char *s = "{\"test_int\":\"3\"}";
43 Eina_Value *ev;
44 T002_Integer *ti;
45
46 content = azy_content_new(NULL);
47 ck_assert_msg(!!content, "Error while allocating content.");
48
49 r = azy_content_deserialize_json(content, s, strlen(s));
50 ck_assert_msg(r, "Error while deserializing json.");
51
52 ev = azy_content_retval_get(content);
53 ck_assert_msg(!!ev, "Error while getting retval.");
54
55 r = azy_value_to_T002_Integer(ev, &ti);
56 ck_assert_msg(r, "Error while getting value of ti.");
57 ck_assert_msg(!!ti, "Error, value of ti is NULL.");
58 ck_assert_int_eq(ti->test_int, 0);
59
60 T002_Integer_free(ti);
61 azy_content_free(content);
62}
63END_TEST
64
65// todo : when value not exist in json ignore it.
66// When value of int is not found, it must be equal to 0.
67// In this case azy_value_to_T002_String must display a warning message.
68START_TEST(_azy_content_deserialize_json_int3)
69{
70 Azy_Content *content;
71 Eina_Bool r;
72 const char *s = "{\"test_integer\":3}";
73 Eina_Value *ev;
74 T002_Integer *ti;
75
76 content = azy_content_new(NULL);
77 ck_assert_msg(!!content, "Error while allocating content.");
78
79 r = azy_content_deserialize_json(content, s, strlen(s));
80 ck_assert_msg(r, "Error while deserializing json.");
81
82 ev = azy_content_retval_get(content);
83 ck_assert_msg(!!ev, "Error while getting retval.");
84
85 r = azy_value_to_T002_Integer(ev, &ti);
86 ck_assert_msg(r, "Error while getting value of ti.");
87 ck_assert_msg(!!ti, "Error, value of ti is not NULL.");
88 ck_assert_int_eq(ti->test_int, 0);
89
90 T002_Integer_free(ti);
91 azy_content_free(content);
92}
93END_TEST
94
95START_TEST(_azy_content_deserialize_json_int4)
96{
97 Azy_Content *content;
98 Eina_Bool r;
99 const char *s = "";
100
101 content = azy_content_new(NULL);
102 ck_assert_msg(!!content, "Error while allocating content.");
103
104 r = azy_content_deserialize_json(content, s, strlen(s));
105 ck_assert_msg(!r, "Error, azy_content_deserialize_json must return EINA_FALSE.");
106
107 azy_content_free(content);
108}
109END_TEST
110
111START_TEST(_azy_content_deserialize_json_int5)
112{
113 Azy_Content *content;
114 Eina_Bool r;
115 const char *s = "{}";
116 Eina_Value *ev;
117
118 content = azy_content_new(NULL);
119 ck_assert_msg(!!content, "Error while allocating content.");
120
121 r = azy_content_deserialize_json(content, s, strlen(s));
122 ck_assert_msg(r, "Error while deserializing json.");
123
124 ev = azy_content_retval_get(content);
125 ck_assert_msg(!ev, "Error, azy_content_retval_get must return NULL.");
126
127 azy_content_free(content);
128}
129END_TEST
130
131START_TEST(_azy_content_deserialize_json_int6)
132{
133 Azy_Content *content;
134 Eina_Bool r;
135 const char *s = "{\"test_int\":}";
136
137 content = azy_content_new(NULL);
138 ck_assert_msg(!!content, "Error while allocating content.");
139
140 r = azy_content_deserialize_json(content, s, strlen(s));
141 ck_assert_msg(!r, "Error, azy_content_deserialize_json must return EINA_FALSE.");
142
143 azy_content_free(content);
144}
145END_TEST
146
147START_TEST(_azy_content_deserialize_json_double)
148{
149 Azy_Content *content;
150 Eina_Bool r;
151 const char *s = "{\"test_double\":3.3}";
152 Eina_Value *ev;
153 T002_Double *td;
154
155 content = azy_content_new(NULL);
156 ck_assert_msg(!!content, "Error while allocating content.");
157
158 r = azy_content_deserialize_json(content, s, strlen(s));
159 ck_assert_msg(r, "Error while deserializing json.");
160
161 ev = azy_content_retval_get(content);
162 ck_assert_msg(!!ev, "Error while getting retval.");
163
164 r = azy_value_to_T002_Double(ev, &td);
165 ck_assert_msg(r, "Error while getting value of td.");
166 ck_assert_msg(!!td, "Error, value of td is NULL.");
167 ck_assert_double_eq(td->test_double, 3.3);
168
169 T002_Double_free(td);
170 azy_content_free(content);
171}
172END_TEST
173
174START_TEST(_azy_content_deserialize_json_string1)
175{
176 Azy_Content *content;
177 Eina_Bool r;
178 const char *s = "{\"test_string\":\"damien\"}";
179 Eina_Value *ev;
180 T002_String *ts;
181
182 content = azy_content_new(NULL);
183 ck_assert_msg(!!content, "Error while allocating content.");
184
185 r = azy_content_deserialize_json(content, s, strlen(s));
186 ck_assert_msg(r, "Error while deserializing json.");
187
188 ev = azy_content_retval_get(content);
189 ck_assert_msg(!!ev, "Error while getting retval.");
190
191 r = azy_value_to_T002_String(ev, &ts);
192 ck_assert_msg(r, "Error while getting value of ts.");
193 ck_assert_msg(!!ts, "Error, value of ts is NULL.");
194 ck_assert_str_eq(ts->test_string, "damien");
195
196 T002_String_free(ts);
197 azy_content_free(content);
198}
199END_TEST
200
201// todo : when value is not the true type for exemple int in place of string,
202// string must be equal to empty.
203// In this case azy_value_to_T002_String must display a warning message and not segfault...
204START_TEST(_azy_content_deserialize_json_string2)
205{
206 Azy_Content *content;
207 Eina_Bool r;
208 const char *s = "{\"test_string\":3}";
209 Eina_Value *ev;
210 T002_String *ts;
211
212 content = azy_content_new(NULL);
213 ck_assert_msg(!!content, "Error while allocating content.");
214
215 r = azy_content_deserialize_json(content, s, strlen(s));
216 ck_assert_msg(r, "Error while deserializing json.");
217
218 ev = azy_content_retval_get(content);
219 ck_assert_msg(!!ev, "Error while getting retval.");
220
221 r = azy_value_to_T002_String(ev, &ts);
222 ck_assert_msg(r, "Error while getting value of ts.");
223 ck_assert_msg(!!ts, "Error, value of ts is NULL.");
224 ck_assert_str_eq(ts->test_string, "");
225
226 T002_String_free(ts);
227 azy_content_free(content);
228}
229END_TEST
230
231// todo : when value not exist in json ignore it.
232// When value of string is not found, it must be equal to "".
233// In this case azy_value_to_T002_String must display a warning message.
234START_TEST(_azy_content_deserialize_json_string3)
235{
236 Azy_Content *content;
237 Eina_Bool r;
238 const char *s = "{\"test_stringshare\":\"damien\"}";
239 Eina_Value *ev;
240 T002_String *ts;
241
242 content = azy_content_new(NULL);
243 ck_assert_msg(!!content, "Error while allocating content.");
244
245 r = azy_content_deserialize_json(content, s, strlen(s));
246 ck_assert_msg(r, "Error while deserializing json.");
247
248 ev = azy_content_retval_get(content);
249 ck_assert_msg(!!ev, "Error while getting retval.");
250
251 r = azy_value_to_T002_String(ev, &ts);
252 ck_assert_msg(r, "Error while getting value of ts.");
253 ck_assert_msg(!!ts, "Error, value of ts is not NULL.");
254 ck_assert_str_eq(ts->test_string, "");
255
256 T002_String_free(ts);
257 azy_content_free(content);
258}
259END_TEST
260
261START_TEST(_azy_content_deserialize_json_string4)
262{
263 Azy_Content *content;
264 Eina_Bool r;
265 const char *s = "";
266
267 content = azy_content_new(NULL);
268 ck_assert_msg(!!content, "Error while allocating content.");
269
270 r = azy_content_deserialize_json(content, s, strlen(s));
271 ck_assert_msg(!r, "Error, azy_content_deserialize_json must return EINA_FALSE.");
272
273 azy_content_free(content);
274}
275END_TEST
276
277START_TEST(_azy_content_deserialize_json_string5)
278{
279 Azy_Content *content;
280 Eina_Bool r;
281 const char *s = "{}";
282 Eina_Value *ev;
283
284 content = azy_content_new(NULL);
285 ck_assert_msg(!!content, "Error while allocating content.");
286
287 r = azy_content_deserialize_json(content, s, strlen(s));
288 ck_assert_msg(r, "Error while deserializing json.");
289
290 ev = azy_content_retval_get(content);
291 ck_assert_msg(!ev, "Error, azy_content_retval_get must return NULL.");
292
293 azy_content_free(content);
294}
295END_TEST
296
297START_TEST(_azy_content_deserialize_json_string6)
298{
299 Azy_Content *content;
300 Eina_Bool r;
301 const char *s = "{\"test_string\":}";
302
303 content = azy_content_new(NULL);
304 ck_assert_msg(!!content, "Error while allocating content.");
305
306 r = azy_content_deserialize_json(content, s, strlen(s));
307 ck_assert_msg(!r, "Error, azy_content_deserialize_json must return EINA_FALSE.");
308
309 azy_content_free(content);
310}
311END_TEST
312
313START_TEST(_azy_content_deserialize_json_array_string1)
314{
315 Azy_Content *content;
316 Eina_Bool r;
317 const char *s = "[\"string1\",\"string2\"]";
318 Eina_Value *ev;
319 Eina_List *el = NULL,
320 *el2;
321 Eina_Stringshare *data;
322
323 content = azy_content_new(NULL);
324 ck_assert_msg(!!content, "Error while allocating content.");
325
326 r = azy_content_deserialize_json(content, s, strlen(s));
327 ck_assert_msg(r, "Error while deserializing json.");
328
329 ev = azy_content_retval_get(content);
330 ck_assert_msg(!!ev, "Error while getting retval.");
331
332 r = azy_value_to_Array_string(ev, &el);
333 ck_assert_msg(r, "Error while getting eina list.");
334 ck_assert_msg(!!el, "Error, value of el is NULL.");
335 ck_assert_int_eq(eina_list_count(el), 2);
336 ck_assert_str_eq( (char *)eina_list_nth(el, 0), "string1");
337 ck_assert_str_eq( (char *)eina_list_nth(el, 1), "string2");
338
339 EINA_LIST_FOREACH(el, el2, data) eina_stringshare_del(data);
340 azy_content_free(content);
341}
342END_TEST
343
344// todo : when value is not the true type for exemple int in place of string,
345// string must be equal to empty.
346// In this case azy_value_to_Array_string must display a warning message and not segfault...
347START_TEST(_azy_content_deserialize_json_array_string2)
348{
349 Azy_Content *content;
350 Eina_Bool r;
351 const char *s = "[\"string1\",2]";
352 Eina_Value *ev;
353 Eina_List *el = NULL,
354 *el2;
355 Eina_Stringshare *data;
356
357 content = azy_content_new(NULL);
358 ck_assert_msg(!!content, "Error while allocating content.");
359
360 r = azy_content_deserialize_json(content, s, strlen(s));
361 ck_assert_msg(r, "Error while deserializing json.");
362
363 ev = azy_content_retval_get(content);
364 ck_assert_msg(!!ev, "Error while getting retval.");
365
366 r = azy_value_to_Array_string(ev, &el);
367 ck_assert_msg(r, "Error while getting eina list.");
368 ck_assert_msg(!!el, "Error, value of el is NULL.");
369 ck_assert_int_eq(eina_list_count(el), 2);
370 ck_assert_str_eq( (char *)eina_list_nth(el, 0), "string1");
371 ck_assert_str_eq( (char *)eina_list_nth(el, 1), "");
372
373 EINA_LIST_FOREACH(el, el2, data) eina_stringshare_del(data);
374 azy_content_free(content);
375}
376END_TEST
377
378START_TEST(_azy_content_deserialize_json_array_string3)
379{
380 Azy_Content *content;
381 Eina_Bool r;
382 const char *s = "";
383
384 content = azy_content_new(NULL);
385 ck_assert_msg(!!content, "Error while allocating content.");
386
387 r = azy_content_deserialize_json(content, s, strlen(s));
388 ck_assert_msg(!r, "Error, azy_content_deserialize_json must return EINA_FALSE.");
389
390 azy_content_free(content);
391}
392END_TEST
393
394START_TEST(_azy_content_deserialize_json_array_string4)
395{
396 Azy_Content *content;
397 Eina_Bool r;
398 const char *s = "[]";
399 Eina_Value *ev;
400 Eina_List *el = NULL;
401
402 content = azy_content_new(NULL);
403 ck_assert_msg(!!content, "Error while allocating content.");
404
405 r = azy_content_deserialize_json(content, s, strlen(s));
406 ck_assert_msg(r, "Error while deserializing json.");
407
408 ev = azy_content_retval_get(content);
409 ck_assert_msg(!!ev, "Error while getting retval.");
410
411 r = azy_value_to_Array_string(ev, &el);
412 ck_assert_msg(r, "Error while getting eina list.");
413 ck_assert_msg(!el, "Error, value of el isn't NULL.");
414
415 azy_content_free(content);
416}
417END_TEST
418
419START_TEST(_azy_content_deserialize_json_array_string5)
420{
421 Azy_Content *content;
422 Eina_Bool r;
423 const char *s = "{}";
424 Eina_Value *ev;
425 Eina_List *el = NULL;
426
427 content = azy_content_new(NULL);
428 ck_assert_msg(!!content, "Error while allocating content.");
429
430 r = azy_content_deserialize_json(content, s, strlen(s));
431 ck_assert_msg(r, "Error while deserializing json.");
432
433 ev = azy_content_retval_get(content);
434 ck_assert_msg(!ev, "Error, azy_content_retval_get must return NULL.");
435
436 r = azy_value_to_Array_string(ev, &el);
437 ck_assert_msg(!r, "Error, azy_value_to_Array_string must return EINA_FALSE.");
438 ck_assert_msg(!el, "Error, value of el isn't NULL.");
439
440 azy_content_free(content);
441}
442END_TEST
443
444START_TEST(_azy_content_deserialize_json_array_string6)
445{
446 Azy_Content *content;
447 Eina_Bool r;
448 const char *s = "[\"string1\",]";
449
450 content = azy_content_new(NULL);
451 ck_assert_msg(!!content, "Error while allocating content.");
452
453 r = azy_content_deserialize_json(content, s, strlen(s));
454 ck_assert_msg(!r, "Error, azy_content_deserialize_json must return EINA_FALSE.");
455
456 azy_content_free(content);
457}
458END_TEST
459
460START_TEST(_azy_content_deserialize_json_struct1)
461{
462 Azy_Content *content;
463 Eina_Bool r;
464 const char *s = "{"
465 "\"key\":\"abc123\","
466 "\"initialize\":true,"
467 "\"connexions\":3,"
468 "\"hash\":\"blabla\","
469 "\"volume\":12.56,"
470 "\"network\": {"
471 "\"ip\":\"192.168.4.4\","
472 "\"gateway\":\"192.168.4.1\","
473 "\"netmask\":\"255.255.255.0\","
474 "\"dns\":\"192.168.4.1\""
475 "},"
476 "\"computers\": ["
477 "{"
478 "\"name\":\"sango\","
479 "\"ip\":\"192.168.4.145\""
480 "},"
481 "{"
482 "\"name\":\"nath\","
483 "\"ip\":\"192.168.4.146\""
484 "}"
485 "],"
486 "\"licence\":\"lic123\""
487 "}";
488 Eina_Value *ev;
489 T002_Server *ts;
490 T002_Computer *tc;
491
492 content = azy_content_new(NULL);
493 ck_assert_msg(!!content, "Error while allocating content.");
494
495 r = azy_content_deserialize_json(content, s, strlen(s));
496 ck_assert_msg(r, "Error while deserializing json.");
497
498 ev = azy_content_retval_get(content);
499 ck_assert_msg(!!ev, "Error while getting retval.");
500
501 r = azy_value_to_T002_Server(ev, &ts);
502 ck_assert_msg(r, "Error while getting value of ts.");
503 ck_assert_msg(!!ts, "Error, value of ts is NULL.");
504 ck_assert_str_eq(ts->key, "abc123");
505 ck_assert_int_eq(ts->initialize, EINA_TRUE);
506 ck_assert_int_eq(ts->connexions, 3);
507 ck_assert_str_eq(ts->hash, "blabla");
508 ck_assert_double_eq(ts->volume, 12.56);
509 ck_assert_msg(!!ts->network, "Error while getting ts->network.");
510 ck_assert_str_eq(ts->network->ip, "192.168.4.4");
511 ck_assert_str_eq(ts->network->gateway, "192.168.4.1");
512 ck_assert_str_eq(ts->network->netmask, "255.255.255.0");
513 ck_assert_str_eq(ts->network->dns, "192.168.4.1");
514 ck_assert_msg(!!ts->computers, "Error while getting ts->network.");
515 ck_assert_int_eq(eina_list_count(ts->computers), 2);
516 tc = eina_list_nth(ts->computers, 0);
517 ck_assert_str_eq(tc->name, "sango");
518 ck_assert_str_eq(tc->ip, "192.168.4.145");
519 tc = eina_list_nth(ts->computers, 1);
520 ck_assert_str_eq(tc->name, "nath");
521 ck_assert_str_eq(tc->ip, "192.168.4.146");
522 ck_assert_str_eq(ts->licence, "lic123");
523
524 T002_Server_free(ts);
525 azy_content_free(content);
526}
527END_TEST
528
529START_TEST(_azy_content_deserialize_json_struct2)
530{
531 Azy_Content *content;
532 Eina_Bool r;
533 const char *s = "";
534
535 content = azy_content_new(NULL);
536 ck_assert_msg(!!content, "Error while allocating content.");
537
538 r = azy_content_deserialize_json(content, s, strlen(s));
539 ck_assert_msg(!r, "Error, azy_content_deserialize_json must return EINA_FALSE.");
540
541 azy_content_free(content);
542}
543END_TEST
544
545START_TEST(_azy_content_deserialize_json_struct3)
546{
547 Azy_Content *content;
548 Eina_Bool r;
549 const char *s = "{}";
550 Eina_Value *ev;
551
552 content = azy_content_new(NULL);
553 ck_assert_msg(!!content, "Error while allocating content.");
554
555 r = azy_content_deserialize_json(content, s, strlen(s));
556 ck_assert_msg(r, "Error while deserializing json.");
557
558 ev = azy_content_retval_get(content);
559 ck_assert_msg(!ev, "Error, azy_content_retval_get must return NULL.");
560
561 azy_content_free(content);
562}
563END_TEST
564
565START_TEST(_azy_content_deserialize_json_struct4)
566{
567 Azy_Content *content;
568 Eina_Bool r;
569 const char *s = "[]";
570 Eina_Value *ev;
571 T002_Server *ts;
572
573 content = azy_content_new(NULL);
574 ck_assert_msg(!!content, "Error while allocating content.");
575
576 r = azy_content_deserialize_json(content, s, strlen(s));
577 ck_assert_msg(r, "Error while deserializing json.");
578
579 ev = azy_content_retval_get(content);
580 ck_assert_msg(!!ev, "Error, azy_content_retval_get must return NULL.");
581
582 r = azy_value_to_T002_Server(ev, &ts);
583 ck_assert_msg(!r, "Error, azy_value_to_Array_string must return EINA_FALSE.");
584 ck_assert_msg(!ts, "Error, value of ts isn't NULL.");
585
586 azy_content_free(content);
587}
588END_TEST
589
590// todo : when value is not present in json init it and continue parsing.
591// ->key: abc123
592// ->initialize: yes
593// ->connexions: 3
594// ->hash:
595// ->volume: 0
596// ->network:
597// ->->ip: (null)
598// ->->gateway: (null)
599// ->->netmask: (null)
600// ->->dns: (null)
601// ->computers:
602// ->licence:
603// Currently, the data after hash are not set.
604// In this case azy_value_to_T002_Struct must display a warning message.
605START_TEST(_azy_content_deserialize_json_struct5)
606{
607 Azy_Content *content;
608 Eina_Bool r;
609 const char *s = "{"
610 "\"key\":\"abc123\","
611 "\"initialize\":true,"
612 "\"connexions\":3,"
613 "\"volume\":12.56,"
614 "\"network\": {"
615 "\"ip\":\"192.168.4.4\","
616 "\"gateway\":\"192.168.4.1\","
617 "\"netmask\":\"255.255.255.0\","
618 "\"dns\":\"192.168.4.1\""
619 "},"
620 "\"computers\": ["
621 "{"
622 "\"name\":\"sango\","
623 "\"ip\":\"192.168.4.145\""
624 "},"
625 "{"
626 "\"name\":\"nath\","
627 "\"ip\":\"192.168.4.146\""
628 "}"
629 "],"
630 "\"licence\":\"lic123\""
631 "}";
632 Eina_Value *ev;
633 T002_Server *ts;
634 T002_Computer *tc;
635
636 content = azy_content_new(NULL);
637 ck_assert_msg(!!content, "Error while allocating content.");
638
639 r = azy_content_deserialize_json(content, s, strlen(s));
640 ck_assert_msg(r, "Error while deserializing json.");
641
642 ev = azy_content_retval_get(content);
643 ck_assert_msg(!!ev, "Error while getting retval.");
644
645 r = azy_value_to_T002_Server(ev, &ts);
646 ck_assert_msg(r, "Error while getting value of ts.");
647 ck_assert_msg(!!ts, "Error, value of ts is NULL.");
648 ck_assert_str_eq(ts->key, "abc123");
649 ck_assert_int_eq(ts->initialize, EINA_TRUE);
650 ck_assert_int_eq(ts->connexions, 3);
651 ck_assert_str_eq(ts->hash, "");
652 ck_assert_double_eq(ts->volume, 12.56);
653 ck_assert_msg(!!ts->network, "Error while getting ts->network.");
654 ck_assert_str_eq(ts->network->ip, "192.168.4.4");
655 ck_assert_str_eq(ts->network->gateway, "192.168.4.1");
656 ck_assert_str_eq(ts->network->netmask, "255.255.255.0");
657 ck_assert_str_eq(ts->network->dns, "192.168.4.1");
658 ck_assert_msg(!!ts->computers, "Error while getting ts->network.");
659 ck_assert_int_eq(eina_list_count(ts->computers), 2);
660 tc = eina_list_nth(ts->computers, 0);
661 ck_assert_str_eq(tc->name, "sango");
662 ck_assert_str_eq(tc->ip, "192.168.4.145");
663 tc = eina_list_nth(ts->computers, 1);
664 ck_assert_str_eq(tc->name, "nath");
665 ck_assert_str_eq(tc->ip, "192.168.4.146");
666 ck_assert_str_eq(ts->licence, "lic123");
667
668 T002_Server_free(ts);
669 azy_content_free(content);
670}
671END_TEST
672
673TCase *
674azy_content_deserialize_json_init()
675{
676 TCase *tc_tests = tcase_create("Tests azy_content_deserialize_json");
677
678 tcase_add_test(tc_tests, _azy_content_deserialize_json_int1);
679 tcase_add_test(tc_tests, _azy_content_deserialize_json_int2);
680 tcase_add_test(tc_tests, _azy_content_deserialize_json_int3);
681 tcase_add_test(tc_tests, _azy_content_deserialize_json_int4);
682 tcase_add_test(tc_tests, _azy_content_deserialize_json_int5);
683 tcase_add_test(tc_tests, _azy_content_deserialize_json_int6);
684
685 tcase_add_test(tc_tests, _azy_content_deserialize_json_double);
686
687 tcase_add_test(tc_tests, _azy_content_deserialize_json_string1);
688 tcase_add_test(tc_tests, _azy_content_deserialize_json_string2);
689 tcase_add_test(tc_tests, _azy_content_deserialize_json_string3);
690 tcase_add_test(tc_tests, _azy_content_deserialize_json_string4);
691 tcase_add_test(tc_tests, _azy_content_deserialize_json_string5);
692 tcase_add_test(tc_tests, _azy_content_deserialize_json_string6);
693
694 tcase_add_test(tc_tests, _azy_content_deserialize_json_array_string1);
695 tcase_add_test(tc_tests, _azy_content_deserialize_json_array_string2);
696 tcase_add_test(tc_tests, _azy_content_deserialize_json_array_string3);
697 tcase_add_test(tc_tests, _azy_content_deserialize_json_array_string4);
698 tcase_add_test(tc_tests, _azy_content_deserialize_json_array_string5);
699 tcase_add_test(tc_tests, _azy_content_deserialize_json_array_string6);
700
701 tcase_add_test(tc_tests, _azy_content_deserialize_json_struct1);
702 tcase_add_test(tc_tests, _azy_content_deserialize_json_struct2);
703 tcase_add_test(tc_tests, _azy_content_deserialize_json_struct3);
704 tcase_add_test(tc_tests, _azy_content_deserialize_json_struct4);
705 tcase_add_test(tc_tests, _azy_content_deserialize_json_struct5);
706
707 return tc_tests;
708}
diff --git a/src/tests/azy/unit/t002_json.azy b/src/tests/azy/unit/t002_json.azy
new file mode 100644
index 0000000..e859b5c
--- /dev/null
+++ b/src/tests/azy/unit/t002_json.azy
@@ -0,0 +1,47 @@
1Azy_Namespace T002;
2
3struct Integer
4{
5 int test_int;
6};
7
8struct Double
9{
10 double test_double;
11};
12
13struct String
14{
15 string test_string;
16};
17
18struct Array
19{
20 array<string> test_array_string;
21};
22
23struct Computer
24{
25 string name;
26 string ip;
27};
28
29struct Network
30{
31 string ip;
32 string gateway;
33 string netmask;
34 string dns;
35};
36
37struct Server
38{
39 string key;
40 boolean initialize;
41 int connexions;
42 string hash;
43 double volume;
44 Network network;
45 array<Computer> computers;
46 string licence;
47};
diff --git a/src/tests/azy/unit/t002_json.c b/src/tests/azy/unit/t002_json.c
new file mode 100644
index 0000000..937277b
--- /dev/null
+++ b/src/tests/azy/unit/t002_json.c
@@ -0,0 +1,25 @@
1#include "t002_json.h"
2
3int
4main(int argc EINA_UNUSED,
5 char **argv EINA_UNUSED)
6{
7 int errors = 0;
8 Suite *s;
9 SRunner *sr;
10
11 eina_init();
12 azy_init();
13
14 s = suite_create("azy_content_deserialize_json");
15 suite_add_tcase(s, azy_content_deserialize_json_init());
16 sr = srunner_create(s);
17
18 srunner_run_all(sr, CK_NORMAL);
19 errors = srunner_ntests_failed(sr);
20 srunner_free(sr);
21
22 azy_shutdown();
23 eina_shutdown();
24 return (errors == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
25}
diff --git a/src/tests/azy/unit/t002_json.h b/src/tests/azy/unit/t002_json.h
new file mode 100644
index 0000000..08d5a86
--- /dev/null
+++ b/src/tests/azy/unit/t002_json.h
@@ -0,0 +1,11 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <stdio.h>
6#include <check.h>
7#include <Azy.h>
8#include "T002_Common.h"
9#include "T002_Common_Azy.h"
10
11TCase *azy_content_deserialize_json_init();