tests/test_json.c

changeset 1152
e4af44b488bc
parent 1149
df5665de7344
child 1154
afd12f31d28a
equal deleted inserted replaced
1151:60113356a7de 1152:e4af44b488bc
147 cxstring text = cx_str( 147 cxstring text = cx_str(
148 "{\n" 148 "{\n"
149 "\"ascii\":\"\\u0041\\u0053\\u0043\\u0049\\u0049\",\n" 149 "\"ascii\":\"\\u0041\\u0053\\u0043\\u0049\\u0049\",\n"
150 "\"unicode\":\"\\u00df\\u00DF\",\n" 150 "\"unicode\":\"\\u00df\\u00DF\",\n"
151 "\"mixed\":\"mixed ä ö \\u00e4 \\u00f6\",\n" 151 "\"mixed\":\"mixed ä ö \\u00e4 \\u00f6\",\n"
152 "\"wide\":\"\\u03a3\\u29b0\"" 152 "\"wide\":\"\\u03a3\\u29b0\",\n"
153 "\"surrogatepair1\":\"\\ud83e\\udff5\",\n"
154 "\"surrogatepair2\":\"test\\ud83e\\udff1AA\"\n,"
155 "\"mixed2\":\"123\\u03a3\\ud83e\\udfc5\\u00df\""
153 "}" 156 "}"
154 ); 157 );
155 158
156 CxJson json; 159 CxJson json;
157 cxJsonInit(&json, NULL); 160 cxJsonInit(&json, NULL);
186 CxJsonValue *wide = cxJsonObjGet(obj, "wide"); 189 CxJsonValue *wide = cxJsonObjGet(obj, "wide");
187 CX_TEST_ASSERT(cxJsonIsString(wide)); 190 CX_TEST_ASSERT(cxJsonIsString(wide));
188 CX_TEST_ASSERT(0 == cx_strcmp( 191 CX_TEST_ASSERT(0 == cx_strcmp(
189 cxJsonAsCxString(wide), 192 cxJsonAsCxString(wide),
190 CX_STR("\u03a3\u29b0")) 193 CX_STR("\u03a3\u29b0"))
194 );
195
196 CxJsonValue *surrogatepair1 = cxJsonObjGet(obj, "surrogatepair1");
197 CX_TEST_ASSERT(cxJsonIsString(surrogatepair1));
198 CX_TEST_ASSERT(0 == cx_strcmp(
199 cxJsonAsCxString(surrogatepair1),
200 CX_STR("\xf0\x9f\xaf\xb5"))
201 );
202
203 CxJsonValue *surrogatepair2 = cxJsonObjGet(obj, "surrogatepair2");
204 CX_TEST_ASSERT(cxJsonIsString(surrogatepair2));
205 CX_TEST_ASSERT(0 == cx_strcmp(
206 cxJsonAsCxString(surrogatepair2),
207 CX_STR("test\xf0\x9f\xaf\xb1" "AA"))
208 );
209
210 CxJsonValue *mixed2 = cxJsonObjGet(obj, "mixed2");
211 CX_TEST_ASSERT(cxJsonIsString(mixed2));
212 CX_TEST_ASSERT(0 == cx_strcmp(
213 cxJsonAsCxString(mixed2),
214 CX_STR("123\u03a3\xf0\x9f\xaf\x85ß"))
191 ); 215 );
192 216
193 cxJsonValueFree(obj); 217 cxJsonValueFree(obj);
194 } 218 }
195 cxJsonDestroy(&json); 219 cxJsonDestroy(&json);

mercurial