summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordmoity <damien.moity@amtrust.com>2015-11-13 11:59:06 +0100
committerdmoity <damien.moity@amtrust.com>2015-11-13 11:59:06 +0100
commit48a3ad58c761fe667c1d699474678e49a2e9a674 (patch)
treec1a20d72d03ba57a535198c02b93189c04d2445f
parentd96ae895f9cc8c7f25a19d5588ef8d032c365ae8 (diff)
azy :
- correction of segfault when eina value contain data with a different type - rewrite a part of azy_parser_main.c unit test : - add message to explain test
-rw-r--r--src/bin/azy/azy_parser_main.c111
-rw-r--r--src/lib/azy/azy_content_json.c10
-rw-r--r--src/tests/azy/unit/azy_content_deserialize_json.c138
3 files changed, 202 insertions, 57 deletions
diff --git a/src/bin/azy/azy_parser_main.c b/src/bin/azy/azy_parser_main.c
index 35ade0c..a64eaaf 100644
--- a/src/bin/azy/azy_parser_main.c
+++ b/src/bin/azy/azy_parser_main.c
@@ -224,18 +224,13 @@ gen_type_marshalizers(Azy_Typedef *t,
224 EL(1, "EINA_SAFETY_ON_NULL_RETURN_VAL(azy_user_type, EINA_FALSE);"); 224 EL(1, "EINA_SAFETY_ON_NULL_RETURN_VAL(azy_user_type, EINA_FALSE);");
225 EL(1, "EINA_SAFETY_ON_NULL_RETURN_VAL(value_struct, EINA_FALSE);"); 225 EL(1, "EINA_SAFETY_ON_NULL_RETURN_VAL(value_struct, EINA_FALSE);");
226 NL; 226 NL;
227 EL(1, "if(eina_value_type_get(value_struct) != EINA_VALUE_TYPE_STRUCT)");
228 EL(1, "{");
229 EL(2, "*azy_user_type = %s_new();", t->cname);
230 EL(2, "EINA_LOG_ERR(\"eina_value_type_get(value_struct) != EINA_VALUE_TYPE_STRUCT is true\");");
231 EL(2, "return EINA_FALSE;");
232 EL(1, "}");
233 NL;
234 EL(1, "azy_user_type_tmp = %s_new();", t->cname); 227 EL(1, "azy_user_type_tmp = %s_new();", t->cname);
235 228
236 EINA_LIST_FOREACH(t->struct_members, l, m) 229 EINA_LIST_FOREACH(t->struct_members, l, m)
237 { 230 {
238 EL(1, "if ((!arg) && eina_value_struct_value_get(value_struct, \"%s\", &val))", m->strname ? m->strname : m->name); 231 NL;
232 EL(1, "if(eina_value_type_get(value_struct) != EINA_VALUE_TYPE_STRUCT) found = EINA_FALSE;");
233 EL(1, "else if ((!arg) && eina_value_struct_value_get(value_struct, \"%s\", &val))", m->strname ? m->strname : m->name);
239 EL(2, "found = EINA_TRUE;"); 234 EL(2, "found = EINA_TRUE;");
240 EL(1, "else"); 235 EL(1, "else");
241 EL(1, "{"); 236 EL(1, "{");
@@ -243,43 +238,93 @@ gen_type_marshalizers(Azy_Typedef *t,
243 EL(2, "snprintf(buf, sizeof(buf), \"arg%%d\", arg++);"); 238 EL(2, "snprintf(buf, sizeof(buf), \"arg%%d\", arg++);");
244 EL(2, "if (eina_value_struct_value_get(value_struct, buf, &val))"); 239 EL(2, "if (eina_value_struct_value_get(value_struct, buf, &val))");
245 EL(3, "found = EINA_TRUE;"); 240 EL(3, "found = EINA_TRUE;");
241 EL(2, "else arg--;");
246 EL(1, "}"); 242 EL(1, "}");
247 EL(1, "if (found)"); 243
248 EL(1, "{");
249 if (m->type->ctype == c) //eldbus does NOT stringshare. bastard. 244 if (m->type->ctype == c) //eldbus does NOT stringshare. bastard.
250 { 245 {
246 EL(1, "if (!found || eina_value_type_get(&val) != EINA_VALUE_TYPE_STRINGSHARE)");
247 EL(1, "{");
248 EL(2, "EINA_LOG_WARN(\"%s is not found or not in true type set to empty string.\");", m->name);
249 EL(2, "azy_user_type_tmp->%s = eina_stringshare_add(\"\");", m->name);
250 EL(1, "}");
251 EL(1, "else");
252 EL(1, "{");
251 EL(2, "if (arg)"); 253 EL(2, "if (arg)");
252 EL(3, "{"); 254 EL(2, "{");
253 EL(4, "char *str = NULL;"); 255 EL(3, "char *str = NULL;");
254 NL; 256 NL;
255 EL(4, "if (eina_value_get(&val, &str))"); 257 EL(3, "if (eina_value_get(&val, &str))");
256 EL(5, "azy_user_type_tmp->%s = eina_stringshare_add(str);", m->name); 258 EL(4, "azy_user_type_tmp->%s = eina_stringshare_add(str);", m->name);
257 EL(3, "}"); 259 EL(2, "}");
258 EL(2, "else"); 260 EL(2, "else");
259 EL(3, "%s(&val, &azy_user_type_tmp->%s);", m->type->demarch_name, m->name); 261 EL(3, "%s(&val, &azy_user_type_tmp->%s);", m->type->demarch_name, m->name);
262 EL(2, "eina_value_flush(&val);");
263 EL(1, "}");
260 } 264 }
261 else if (m->type->ctype == d) 265 else if (m->type->ctype == d)
262 { 266 {
263 EL(2, "if(eina_value_type_get(&val) == EINA_VALUE_TYPE_DOUBLE)"); 267 EL(1, "if (!found)");
264 EL(3, "%s(&val, &azy_user_type_tmp->%s);", m->type->demarch_name, m->name); 268 EL(1, "{");
265 EL(2, "else"); 269 EL(2, "EINA_LOG_WARN(\"%s is not found set to 0.\");", m->name);
266 EL(3, "{"); 270 EL(2, "azy_user_type_tmp->%s = 0;", m->name);
267 EL(4, "int int_to_double;"); 271 EL(1, "}");
268 EL(4, "%s(&val, &int_to_double);", m->type->demarch_name); 272 EL(1, "else if(eina_value_type_get(&val) == EINA_VALUE_TYPE_DOUBLE || "
269 EL(4, "azy_user_type_tmp->%s = (double) int_to_double;", m->name); 273 "eina_value_type_get(&val) == EINA_VALUE_TYPE_FLOAT)");
270 EL(3, "}"); 274 EL(2, "%s(&val, &azy_user_type_tmp->%s);", m->type->demarch_name, m->name);
275 EL(1, "else if(eina_value_type_get(&val) == EINA_VALUE_TYPE_INT || "
276 "eina_value_type_get(&val) == EINA_VALUE_TYPE_LONG || "
277 "eina_value_type_get(&val) == EINA_VALUE_TYPE_INT64)");
278 EL(1, "{");
279 EL(2, "int int_to_double;");
280 EL(2, "%s(&val, &int_to_double);", m->type->demarch_name);
281 EL(2, "azy_user_type_tmp->%s = (double) int_to_double;", m->name);
282 EL(1, "}");
283 EL(1, "else");
284 EL(1, "{");
285 EL(2, "EINA_LOG_WARN(\"%s not in true type set to 0.\");", m->name);
286 EL(2, "azy_user_type_tmp->%s = 0;", m->name);
287 EL(1, "}");
288 }
289 else if (m->type->ctype == i)
290 {
291 EL(1, "if (!found)");
292 EL(1, "{");
293 EL(2, "EINA_LOG_WARN(\"%s is not found set to 0.\");", m->name);
294 EL(2, "azy_user_type_tmp->%s = 0;", m->name);
295 EL(1, "}");
296 EL(1, "else if(eina_value_type_get(&val) == EINA_VALUE_TYPE_INT || "
297 "eina_value_type_get(&val) == EINA_VALUE_TYPE_LONG || "
298 "eina_value_type_get(&val) == EINA_VALUE_TYPE_INT64)");
299 EL(2, "%s(&val, &azy_user_type_tmp->%s);", m->type->demarch_name, m->name);
300 EL(1, "else");
301 EL(1, "{");
302 EL(2, "EINA_LOG_WARN(\"%s not in true type set to 0.\");", m->name);
303 EL(2, "azy_user_type_tmp->%s = 0;", m->name);
304 EL(1, "}");
305 }
306 else if (m->type->ctype == b)
307 {
308 EL(1, "if (!found)");
309 EL(1, "{");
310 EL(2, "EINA_LOG_WARN(\"%s is not found set to 0.\");", m->name);
311 EL(2, "azy_user_type_tmp->%s = EINA_FALSE;", m->name);
312 EL(1, "}");
313 EL(1, "else if(eina_value_type_get(&val) == EINA_VALUE_TYPE_UCHAR)");
314 EL(2, "%s(&val, &azy_user_type_tmp->%s);", m->type->demarch_name, m->name);
315 EL(1, "else");
316 EL(1, "{");
317 EL(2, "EINA_LOG_WARN(\"%s not in true type set to 0.\");", m->name);
318 EL(2, "azy_user_type_tmp->%s = EINA_FALSE;", m->name);
319 EL(1, "}");
271 } 320 }
272 else 321 else
273 EL(2, "%s(&val, &azy_user_type_tmp->%s);", m->type->demarch_name, m->name); 322 {
274 EL(2, "eina_value_flush(&val);"); 323 EL(1, "if(!found)");
275 EL(1, "}"); 324 EL(2, "EINA_LOG_WARN(\"%s is not found.\");", m->name);
276 EL(1, "else"); 325 EL(1, "%s(&val, &azy_user_type_tmp->%s);", m->type->demarch_name, m->name);
277 EL(1, "{"); 326 }
278 if (m->type->ctype == c) 327
279 EL(2, "azy_user_type_tmp->%s = eina_stringshare_add(\"\");", m->name);
280 else if (m->type->type == TD_STRUCT)
281 EL(2, "%s(&val, &azy_user_type_tmp->%s);", m->type->demarch_name, m->name);
282 EL(1, "}");
283 if(eina_list_next(l)) EL(1, "found = EINA_FALSE;"); 328 if(eina_list_next(l)) EL(1, "found = EINA_FALSE;");
284 } 329 }
285 330
diff --git a/src/lib/azy/azy_content_json.c b/src/lib/azy/azy_content_json.c
index 301ce07..3fc0a24 100644
--- a/src/lib/azy/azy_content_json.c
+++ b/src/lib/azy/azy_content_json.c
@@ -286,7 +286,15 @@ azy_value_deserialize_array_json(cJSON *object)
286 arr = eina_value_array_new(type, 0); 286 arr = eina_value_array_new(type, 0);
287 for (; x < cJSON_GetArraySize(object); x++) 287 for (; x < cJSON_GetArraySize(object); x++)
288 { 288 {
289 if (x) child = cJSON_GetArrayItem(object, x); 289 if (x)
290 {
291 child = cJSON_GetArrayItem(object, x);
292 if(_azy_value_type_get(child) != type)
293 {
294 EINA_LOG_ERR("We have different type of data in array.");
295 continue;
296 }
297 }
290 if (type == EINA_VALUE_TYPE_ARRAY) 298 if (type == EINA_VALUE_TYPE_ARRAY)
291 { 299 {
292 Eina_Value_Array inner_array; 300 Eina_Value_Array inner_array;
diff --git a/src/tests/azy/unit/azy_content_deserialize_json.c b/src/tests/azy/unit/azy_content_deserialize_json.c
index af3686d..15415b9 100644
--- a/src/tests/azy/unit/azy_content_deserialize_json.c
+++ b/src/tests/azy/unit/azy_content_deserialize_json.c
@@ -1,10 +1,15 @@
1#include "t002_json.h" 1#include "t002_json.h"
2 2
3#define ck_assert_double_eq(_a, _b) do { \ 3#define ck_assert_double_eq(_a, _b) do { \
4 double epsilon = 0.00001; \ 4 double epsilon = 0.00001; \
5 ck_assert_msg(_a >= _b - epsilon && _a <= _b + epsilon, "Assertion '%f==%f' failed", _a, _b); \ 5 ck_assert_msg(_a >= _b - epsilon && _a <= _b + epsilon, "Assertion '%f==%f' failed", _a, _b); \
6} while (0) 6} while (0)
7 7
8#define PRINT(_func, _test, _result) do { \
9 printf("\n\n\e[4mFunction : %s, line : %d\e[24m\n- test : %s\n- result : %s\n", _func, __LINE__, _test, _result); \
10} while (0)
11
12
8START_TEST(_azy_content_deserialize_json_int1) 13START_TEST(_azy_content_deserialize_json_int1)
9{ 14{
10 Azy_Content *content; 15 Azy_Content *content;
@@ -13,6 +18,8 @@ START_TEST(_azy_content_deserialize_json_int1)
13 Eina_Value *ev; 18 Eina_Value *ev;
14 T002_Integer *ti; 19 T002_Integer *ti;
15 20
21 PRINT("_azy_content_deserialize_json_int1", "correct int data.", "test_int = 3.");
22
16 content = azy_content_new(NULL); 23 content = azy_content_new(NULL);
17 ck_assert_msg(!!content, "Error while allocating content."); 24 ck_assert_msg(!!content, "Error while allocating content.");
18 25
@@ -32,9 +39,6 @@ START_TEST(_azy_content_deserialize_json_int1)
32} 39}
33END_TEST 40END_TEST
34 41
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) 42START_TEST(_azy_content_deserialize_json_int2)
39{ 43{
40 Azy_Content *content; 44 Azy_Content *content;
@@ -43,6 +47,10 @@ START_TEST(_azy_content_deserialize_json_int2)
43 Eina_Value *ev; 47 Eina_Value *ev;
44 T002_Integer *ti; 48 T002_Integer *ti;
45 49
50 PRINT("_azy_content_deserialize_json_int2",
51 "bad type of value for data test_int, string in place of int.",
52 "tests_int = 0.");
53
46 content = azy_content_new(NULL); 54 content = azy_content_new(NULL);
47 ck_assert_msg(!!content, "Error while allocating content."); 55 ck_assert_msg(!!content, "Error while allocating content.");
48 56
@@ -62,9 +70,6 @@ START_TEST(_azy_content_deserialize_json_int2)
62} 70}
63END_TEST 71END_TEST
64 72
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) 73START_TEST(_azy_content_deserialize_json_int3)
69{ 74{
70 Azy_Content *content; 75 Azy_Content *content;
@@ -73,6 +78,9 @@ START_TEST(_azy_content_deserialize_json_int3)
73 Eina_Value *ev; 78 Eina_Value *ev;
74 T002_Integer *ti; 79 T002_Integer *ti;
75 80
81 PRINT("_azy_content_deserialize_json_int3", "data test_int does not exit.",
82 "\n-- test_int = 0,\n-- test_integer is ignored.");
83
76 content = azy_content_new(NULL); 84 content = azy_content_new(NULL);
77 ck_assert_msg(!!content, "Error while allocating content."); 85 ck_assert_msg(!!content, "Error while allocating content.");
78 86
@@ -98,6 +106,10 @@ START_TEST(_azy_content_deserialize_json_int4)
98 Eina_Bool r; 106 Eina_Bool r;
99 const char *s = ""; 107 const char *s = "";
100 108
109 PRINT("_azy_content_deserialize_json_int4",
110 "json is not a in valid format, equal to empty string.",
111 "azy_content_deserialize_json return an error.");
112
101 content = azy_content_new(NULL); 113 content = azy_content_new(NULL);
102 ck_assert_msg(!!content, "Error while allocating content."); 114 ck_assert_msg(!!content, "Error while allocating content.");
103 115
@@ -115,6 +127,9 @@ START_TEST(_azy_content_deserialize_json_int5)
115 const char *s = "{}"; 127 const char *s = "{}";
116 Eina_Value *ev; 128 Eina_Value *ev;
117 129
130 PRINT("_azy_content_deserialize_json_int5", "json data is empty, equal to {}.",
131 "azy_content_retval_get return NULL.");
132
118 content = azy_content_new(NULL); 133 content = azy_content_new(NULL);
119 ck_assert_msg(!!content, "Error while allocating content."); 134 ck_assert_msg(!!content, "Error while allocating content.");
120 135
@@ -134,6 +149,10 @@ START_TEST(_azy_content_deserialize_json_int6)
134 Eina_Bool r; 149 Eina_Bool r;
135 const char *s = "{\"test_int\":}"; 150 const char *s = "{\"test_int\":}";
136 151
152 PRINT("_azy_content_deserialize_json_int6",
153 "json is not in a valid format, value of data is not set.",
154 "azy_content_deserialize_json return an error.");
155
137 content = azy_content_new(NULL); 156 content = azy_content_new(NULL);
138 ck_assert_msg(!!content, "Error while allocating content."); 157 ck_assert_msg(!!content, "Error while allocating content.");
139 158
@@ -152,6 +171,9 @@ START_TEST(_azy_content_deserialize_json_double)
152 Eina_Value *ev; 171 Eina_Value *ev;
153 T002_Double *td; 172 T002_Double *td;
154 173
174 PRINT("_azy_content_deserialize_json_double", "correct double data.",
175 "test_double = 3.3.");
176
155 content = azy_content_new(NULL); 177 content = azy_content_new(NULL);
156 ck_assert_msg(!!content, "Error while allocating content."); 178 ck_assert_msg(!!content, "Error while allocating content.");
157 179
@@ -179,6 +201,9 @@ START_TEST(_azy_content_deserialize_json_string1)
179 Eina_Value *ev; 201 Eina_Value *ev;
180 T002_String *ts; 202 T002_String *ts;
181 203
204 PRINT("_azy_content_deserialize_json_string1", "correct string data.",
205 "test_string = damien.");
206
182 content = azy_content_new(NULL); 207 content = azy_content_new(NULL);
183 ck_assert_msg(!!content, "Error while allocating content."); 208 ck_assert_msg(!!content, "Error while allocating content.");
184 209
@@ -198,9 +223,6 @@ START_TEST(_azy_content_deserialize_json_string1)
198} 223}
199END_TEST 224END_TEST
200 225
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) 226START_TEST(_azy_content_deserialize_json_string2)
205{ 227{
206 Azy_Content *content; 228 Azy_Content *content;
@@ -209,6 +231,10 @@ START_TEST(_azy_content_deserialize_json_string2)
209 Eina_Value *ev; 231 Eina_Value *ev;
210 T002_String *ts; 232 T002_String *ts;
211 233
234 PRINT("_azy_content_deserialize_json_string2",
235 "bad type of value for data test_string, int in place of string.",
236 "test_string = \"\".");
237
212 content = azy_content_new(NULL); 238 content = azy_content_new(NULL);
213 ck_assert_msg(!!content, "Error while allocating content."); 239 ck_assert_msg(!!content, "Error while allocating content.");
214 240
@@ -228,9 +254,6 @@ START_TEST(_azy_content_deserialize_json_string2)
228} 254}
229END_TEST 255END_TEST
230 256
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) 257START_TEST(_azy_content_deserialize_json_string3)
235{ 258{
236 Azy_Content *content; 259 Azy_Content *content;
@@ -239,6 +262,9 @@ START_TEST(_azy_content_deserialize_json_string3)
239 Eina_Value *ev; 262 Eina_Value *ev;
240 T002_String *ts; 263 T002_String *ts;
241 264
265 PRINT("_azy_content_deserialize_json_string3", "data test_string does not exist.",
266 "\n-- test_string = \"\",\n-- test_stringshare is ignored.");
267
242 content = azy_content_new(NULL); 268 content = azy_content_new(NULL);
243 ck_assert_msg(!!content, "Error while allocating content."); 269 ck_assert_msg(!!content, "Error while allocating content.");
244 270
@@ -264,6 +290,10 @@ START_TEST(_azy_content_deserialize_json_string4)
264 Eina_Bool r; 290 Eina_Bool r;
265 const char *s = ""; 291 const char *s = "";
266 292
293 PRINT("_azy_content_deserialize_json_string4",
294 "json is not a in valid format, equal to empty string.",
295 "azy_content_deserialize_json return an error.");
296
267 content = azy_content_new(NULL); 297 content = azy_content_new(NULL);
268 ck_assert_msg(!!content, "Error while allocating content."); 298 ck_assert_msg(!!content, "Error while allocating content.");
269 299
@@ -281,6 +311,9 @@ START_TEST(_azy_content_deserialize_json_string5)
281 const char *s = "{}"; 311 const char *s = "{}";
282 Eina_Value *ev; 312 Eina_Value *ev;
283 313
314 PRINT("_azy_content_deserialize_json_string5", "json data is empty, equal to {}.",
315 "azy_content_retval_get return NULL.");
316
284 content = azy_content_new(NULL); 317 content = azy_content_new(NULL);
285 ck_assert_msg(!!content, "Error while allocating content."); 318 ck_assert_msg(!!content, "Error while allocating content.");
286 319
@@ -300,6 +333,10 @@ START_TEST(_azy_content_deserialize_json_string6)
300 Eina_Bool r; 333 Eina_Bool r;
301 const char *s = "{\"test_string\":}"; 334 const char *s = "{\"test_string\":}";
302 335
336 PRINT("_azy_content_deserialize_json_string6",
337 "json is not in a valid format, value of data is not set.",
338 "azy_content_deserialize_json return an error.");
339
303 content = azy_content_new(NULL); 340 content = azy_content_new(NULL);
304 ck_assert_msg(!!content, "Error while allocating content."); 341 ck_assert_msg(!!content, "Error while allocating content.");
305 342
@@ -320,6 +357,10 @@ START_TEST(_azy_content_deserialize_json_array_string1)
320 *el2; 357 *el2;
321 Eina_Stringshare *data; 358 Eina_Stringshare *data;
322 359
360 PRINT("_azy_content_deserialize_json_array_string1", "correct array string.",
361 "\n-- eina_list_count = 2,\n-- first element = \"string1\","
362 "\n-- second element = \"string2\".");
363
323 content = azy_content_new(NULL); 364 content = azy_content_new(NULL);
324 ck_assert_msg(!!content, "Error while allocating content."); 365 ck_assert_msg(!!content, "Error while allocating content.");
325 366
@@ -341,19 +382,24 @@ START_TEST(_azy_content_deserialize_json_array_string1)
341} 382}
342END_TEST 383END_TEST
343 384
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) 385START_TEST(_azy_content_deserialize_json_array_string2)
348{ 386{
349 Azy_Content *content; 387 Azy_Content *content;
350 Eina_Bool r; 388 Eina_Bool r;
351 const char *s = "[\"string1\",2]"; 389 const char *s = "[\"string1\",2,\"string3\"]";
352 Eina_Value *ev; 390 Eina_Value *ev;
353 Eina_List *el = NULL, 391 Eina_List *el = NULL,
354 *el2; 392 *el2;
355 Eina_Stringshare *data; 393 Eina_Stringshare *data;
356 394
395 PRINT("_azy_content_deserialize_json_array_string2",
396 "array contain data with a different type (string and int).",
397 "\n-- eina_value must contain only one type, the reference type is the first "
398 "type found (here string),"
399 "\n-- data of type int is ignored,\n-- eina_list_count = 2,"
400 "\n-- first element = \"string1\","
401 "\n-- second element = \"string3\".");
402
357 content = azy_content_new(NULL); 403 content = azy_content_new(NULL);
358 ck_assert_msg(!!content, "Error while allocating content."); 404 ck_assert_msg(!!content, "Error while allocating content.");
359 405
@@ -368,7 +414,7 @@ START_TEST(_azy_content_deserialize_json_array_string2)
368 ck_assert_msg(!!el, "Error, value of el is NULL."); 414 ck_assert_msg(!!el, "Error, value of el is NULL.");
369 ck_assert_int_eq(eina_list_count(el), 2); 415 ck_assert_int_eq(eina_list_count(el), 2);
370 ck_assert_str_eq( (char *)eina_list_nth(el, 0), "string1"); 416 ck_assert_str_eq( (char *)eina_list_nth(el, 0), "string1");
371 ck_assert_str_eq( (char *)eina_list_nth(el, 1), ""); 417 ck_assert_str_eq( (char *)eina_list_nth(el, 1), "string3");
372 418
373 EINA_LIST_FOREACH(el, el2, data) eina_stringshare_del(data); 419 EINA_LIST_FOREACH(el, el2, data) eina_stringshare_del(data);
374 azy_content_free(content); 420 azy_content_free(content);
@@ -381,6 +427,10 @@ START_TEST(_azy_content_deserialize_json_array_string3)
381 Eina_Bool r; 427 Eina_Bool r;
382 const char *s = ""; 428 const char *s = "";
383 429
430 PRINT("_azy_content_deserialize_json_array_string3",
431 "json is not a in valid format, equal to empty string.",
432 "azy_content_deserialize_json return an error.");
433
384 content = azy_content_new(NULL); 434 content = azy_content_new(NULL);
385 ck_assert_msg(!!content, "Error while allocating content."); 435 ck_assert_msg(!!content, "Error while allocating content.");
386 436
@@ -399,6 +449,9 @@ START_TEST(_azy_content_deserialize_json_array_string4)
399 Eina_Value *ev; 449 Eina_Value *ev;
400 Eina_List *el = NULL; 450 Eina_List *el = NULL;
401 451
452 PRINT("_azy_content_deserialize_json_array_string4",
453 "array is empty.", "eina_list = NULL.");
454
402 content = azy_content_new(NULL); 455 content = azy_content_new(NULL);
403 ck_assert_msg(!!content, "Error while allocating content."); 456 ck_assert_msg(!!content, "Error while allocating content.");
404 457
@@ -424,6 +477,9 @@ START_TEST(_azy_content_deserialize_json_array_string5)
424 Eina_Value *ev; 477 Eina_Value *ev;
425 Eina_List *el = NULL; 478 Eina_List *el = NULL;
426 479
480 PRINT("_azy_content_deserialize_json_array_string5",
481 "json data is wrong, equal to {}.", "eina_list = NULL.");
482
427 content = azy_content_new(NULL); 483 content = azy_content_new(NULL);
428 ck_assert_msg(!!content, "Error while allocating content."); 484 ck_assert_msg(!!content, "Error while allocating content.");
429 485
@@ -447,6 +503,10 @@ START_TEST(_azy_content_deserialize_json_array_string6)
447 Eina_Bool r; 503 Eina_Bool r;
448 const char *s = "[\"string1\",]"; 504 const char *s = "[\"string1\",]";
449 505
506 PRINT("_azy_content_deserialize_json_array_string6",
507 "json is not in a valid format, value of one data is not set.",
508 "azy_content_deserialize_json return an error.");
509
450 content = azy_content_new(NULL); 510 content = azy_content_new(NULL);
451 ck_assert_msg(!!content, "Error while allocating content."); 511 ck_assert_msg(!!content, "Error while allocating content.");
452 512
@@ -489,6 +549,9 @@ START_TEST(_azy_content_deserialize_json_struct1)
489 T002_Server *ts; 549 T002_Server *ts;
490 T002_Computer *tc; 550 T002_Computer *tc;
491 551
552 PRINT("_azy_content_deserialize_json_struct1", "correct struct data.",
553 "all values are correct (int, double, boolean, string, array, struct).");
554
492 content = azy_content_new(NULL); 555 content = azy_content_new(NULL);
493 ck_assert_msg(!!content, "Error while allocating content."); 556 ck_assert_msg(!!content, "Error while allocating content.");
494 557
@@ -511,7 +574,7 @@ START_TEST(_azy_content_deserialize_json_struct1)
511 ck_assert_str_eq(ts->network->gateway, "192.168.4.1"); 574 ck_assert_str_eq(ts->network->gateway, "192.168.4.1");
512 ck_assert_str_eq(ts->network->netmask, "255.255.255.0"); 575 ck_assert_str_eq(ts->network->netmask, "255.255.255.0");
513 ck_assert_str_eq(ts->network->dns, "192.168.4.1"); 576 ck_assert_str_eq(ts->network->dns, "192.168.4.1");
514 ck_assert_msg(!!ts->computers, "Error while getting ts->network."); 577 ck_assert_msg(!!ts->computers, "Error while getting ts->computers.");
515 ck_assert_int_eq(eina_list_count(ts->computers), 2); 578 ck_assert_int_eq(eina_list_count(ts->computers), 2);
516 tc = eina_list_nth(ts->computers, 0); 579 tc = eina_list_nth(ts->computers, 0);
517 ck_assert_str_eq(tc->name, "sango"); 580 ck_assert_str_eq(tc->name, "sango");
@@ -532,6 +595,10 @@ START_TEST(_azy_content_deserialize_json_struct2)
532 Eina_Bool r; 595 Eina_Bool r;
533 const char *s = ""; 596 const char *s = "";
534 597
598 PRINT("_azy_content_deserialize_json_struct2",
599 "json is not a in valid format, equal to empty string.",
600 "azy_content_deserialize_json return an error.");
601
535 content = azy_content_new(NULL); 602 content = azy_content_new(NULL);
536 ck_assert_msg(!!content, "Error while allocating content."); 603 ck_assert_msg(!!content, "Error while allocating content.");
537 604
@@ -549,6 +616,9 @@ START_TEST(_azy_content_deserialize_json_struct3)
549 const char *s = "{}"; 616 const char *s = "{}";
550 Eina_Value *ev; 617 Eina_Value *ev;
551 618
619 PRINT("_azy_content_deserialize_json_struct3", "json data is empty, equal to {}.",
620 "azy_content_retval_get return NULL.");
621
552 content = azy_content_new(NULL); 622 content = azy_content_new(NULL);
553 ck_assert_msg(!!content, "Error while allocating content."); 623 ck_assert_msg(!!content, "Error while allocating content.");
554 624
@@ -570,6 +640,11 @@ START_TEST(_azy_content_deserialize_json_struct4)
570 Eina_Value *ev; 640 Eina_Value *ev;
571 T002_Server *ts; 641 T002_Server *ts;
572 642
643 PRINT("_azy_content_deserialize_json_struct4",
644 "json data is an invalid array equal to [].",
645 "all values are set (int = 0, double = 0, boolean = EINA_FALSE, string = \"\","
646 "array = [], struct = {}).");
647
573 content = azy_content_new(NULL); 648 content = azy_content_new(NULL);
574 ck_assert_msg(!!content, "Error while allocating content."); 649 ck_assert_msg(!!content, "Error while allocating content.");
575 650
@@ -580,8 +655,21 @@ START_TEST(_azy_content_deserialize_json_struct4)
580 ck_assert_msg(!!ev, "Error, azy_content_retval_get must return NULL."); 655 ck_assert_msg(!!ev, "Error, azy_content_retval_get must return NULL.");
581 656
582 r = azy_value_to_T002_Server(ev, &ts); 657 r = azy_value_to_T002_Server(ev, &ts);
583 ck_assert_msg(!r, "Error, azy_value_to_Array_string must return EINA_FALSE."); 658 ck_assert_msg(r, "Error while getting value of ts.");
584 ck_assert_msg(!ts, "Error, value of ts isn't NULL."); 659 ck_assert_msg(!!ts, "Error, value of ts is NULL.");
660 ck_assert_str_eq(ts->key, "");
661 ck_assert_int_eq(ts->initialize, EINA_FALSE);
662 ck_assert_int_eq(ts->connexions, 0);
663 ck_assert_str_eq(ts->hash, "");
664 ck_assert_double_eq(ts->volume, 0);
665 ck_assert_msg(!!ts->network, "Error while getting ts->network.");
666 ck_assert_str_eq(ts->network->ip, "");
667 ck_assert_str_eq(ts->network->gateway, "");
668 ck_assert_str_eq(ts->network->netmask, "");
669 ck_assert_str_eq(ts->network->dns, "");
670 ck_assert_msg(!ts->computers, "Error, ts->computers must be empty list.");
671 ck_assert_int_eq(eina_list_count(ts->computers), 0);
672 ck_assert_str_eq(ts->licence, "");
585 673
586 azy_content_free(content); 674 azy_content_free(content);
587} 675}
@@ -633,6 +721,10 @@ START_TEST(_azy_content_deserialize_json_struct5)
633 T002_Server *ts; 721 T002_Server *ts;
634 T002_Computer *tc; 722 T002_Computer *tc;
635 723
724 PRINT("_azy_content_deserialize_json_struct5", "data hash does not exist.",
725 "if a data does not exist in middle of json, this data must be init and the "
726 "next datas must be set to their values.");
727
636 content = azy_content_new(NULL); 728 content = azy_content_new(NULL);
637 ck_assert_msg(!!content, "Error while allocating content."); 729 ck_assert_msg(!!content, "Error while allocating content.");
638 730
@@ -655,7 +747,7 @@ START_TEST(_azy_content_deserialize_json_struct5)
655 ck_assert_str_eq(ts->network->gateway, "192.168.4.1"); 747 ck_assert_str_eq(ts->network->gateway, "192.168.4.1");
656 ck_assert_str_eq(ts->network->netmask, "255.255.255.0"); 748 ck_assert_str_eq(ts->network->netmask, "255.255.255.0");
657 ck_assert_str_eq(ts->network->dns, "192.168.4.1"); 749 ck_assert_str_eq(ts->network->dns, "192.168.4.1");
658 ck_assert_msg(!!ts->computers, "Error while getting ts->network."); 750 ck_assert_msg(!!ts->computers, "Error while getting ts->computers.");
659 ck_assert_int_eq(eina_list_count(ts->computers), 2); 751 ck_assert_int_eq(eina_list_count(ts->computers), 2);
660 tc = eina_list_nth(ts->computers, 0); 752 tc = eina_list_nth(ts->computers, 0);
661 ck_assert_str_eq(tc->name, "sango"); 753 ck_assert_str_eq(tc->name, "sango");