| 136 CX_TEST_ASSERT(cxJsonIsString(object)); |
136 CX_TEST_ASSERT(cxJsonIsString(object)); |
| 137 CX_TEST_ASSERT(0 == cx_strcmp( |
137 CX_TEST_ASSERT(0 == cx_strcmp( |
| 138 cxJsonAsCxString(object), |
138 cxJsonAsCxString(object), |
| 139 CX_STR("{\n\t\"object\":null\n}")) |
139 CX_STR("{\n\t\"object\":null\n}")) |
| 140 ); |
140 ); |
| |
141 cxJsonValueFree(obj); |
| |
142 } |
| |
143 cxJsonDestroy(&json); |
| |
144 } |
| |
145 |
| |
146 CX_TEST(test_json_escaped_unicode_strings) { |
| |
147 cxstring text = cx_str( |
| |
148 "{\n" |
| |
149 "\"ascii\":\"\\u0041\\u0053\\u0043\\u0049\\u0049\",\n" |
| |
150 "\"unicode\":\"\\u00df\\u00DF\",\n" |
| |
151 "\"mixed\":\"mixed ä ö \\u00e4 \\u00f6\",\n" |
| |
152 "\"wide\":\"\\u03a3\\u29b0\"" |
| |
153 "}" |
| |
154 ); |
| |
155 |
| |
156 CxJson json; |
| |
157 cxJsonInit(&json, NULL); |
| |
158 CX_TEST_DO { |
| |
159 cxJsonFill(&json, text); |
| |
160 CxJsonValue *obj; |
| |
161 CxJsonStatus result = cxJsonNext(&json, &obj); |
| |
162 CX_TEST_ASSERT(result == CX_JSON_NO_ERROR); |
| |
163 CX_TEST_ASSERT(cxJsonIsObject(obj)); |
| |
164 |
| |
165 CxJsonValue *ascii = cxJsonObjGet(obj, "ascii"); |
| |
166 CX_TEST_ASSERT(cxJsonIsString(ascii)); |
| |
167 CX_TEST_ASSERT(0 == cx_strcmp( |
| |
168 cxJsonAsCxString(ascii), |
| |
169 CX_STR("ASCII")) |
| |
170 ); |
| |
171 |
| |
172 CxJsonValue *unicode = cxJsonObjGet(obj, "unicode"); |
| |
173 CX_TEST_ASSERT(cxJsonIsString(unicode)); |
| |
174 CX_TEST_ASSERT(0 == cx_strcmp( |
| |
175 cxJsonAsCxString(unicode), |
| |
176 CX_STR("ßß")) |
| |
177 ); |
| |
178 |
| |
179 CxJsonValue *mixed = cxJsonObjGet(obj, "mixed"); |
| |
180 CX_TEST_ASSERT(cxJsonIsString(mixed)); |
| |
181 CX_TEST_ASSERT(0 == cx_strcmp( |
| |
182 cxJsonAsCxString(mixed), |
| |
183 CX_STR("mixed ä ö ä ö")) |
| |
184 ); |
| |
185 |
| |
186 CxJsonValue *wide = cxJsonObjGet(obj, "wide"); |
| |
187 CX_TEST_ASSERT(cxJsonIsString(wide)); |
| |
188 CX_TEST_ASSERT(0 == cx_strcmp( |
| |
189 cxJsonAsCxString(wide), |
| |
190 CX_STR("\u03a3\u29b0")) |
| |
191 ); |
| |
192 |
| 141 cxJsonValueFree(obj); |
193 cxJsonValueFree(obj); |
| 142 } |
194 } |
| 143 cxJsonDestroy(&json); |
195 cxJsonDestroy(&json); |
| 144 } |
196 } |
| 145 |
197 |
| 1040 CxTestSuite *suite = cx_test_suite_new("json"); |
1092 CxTestSuite *suite = cx_test_suite_new("json"); |
| 1041 |
1093 |
| 1042 cx_test_register(suite, test_json_init_default); |
1094 cx_test_register(suite, test_json_init_default); |
| 1043 cx_test_register(suite, test_json_simple_object); |
1095 cx_test_register(suite, test_json_simple_object); |
| 1044 cx_test_register(suite, test_json_escaped_strings); |
1096 cx_test_register(suite, test_json_escaped_strings); |
| |
1097 cx_test_register(suite, test_json_escaped_unicode_strings); |
| 1045 cx_test_register(suite, test_json_escaped_end_of_string); |
1098 cx_test_register(suite, test_json_escaped_end_of_string); |
| 1046 cx_test_register(suite, test_json_object_incomplete_token); |
1099 cx_test_register(suite, test_json_object_incomplete_token); |
| 1047 cx_test_register(suite, test_json_token_wrongly_completed); |
1100 cx_test_register(suite, test_json_token_wrongly_completed); |
| 1048 cx_test_register(suite, test_json_object_error); |
1101 cx_test_register(suite, test_json_object_error); |
| 1049 cx_test_register(suite, test_json_subsequent_fill); |
1102 cx_test_register(suite, test_json_subsequent_fill); |