test-json-parser.c revision 4e8e7a93628b4ed60aaaa47c6f72c1433f21e81d
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2012 Dovecot authors, see the included COPYING file */
5666a3d6a7ea89362b8d9e8b39b15424cd9d6388Timo Sirainenstatic const char json_input[] =
146f9076cd456ea1e9b3f8536456d9d3c962fadbStephan Bosch "\t\"key\"\t:\t\t\"string\","
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen " \"key2\" : 1234, \n"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen "\"key3\":true,"
8c909e451d14075c05d90382cf8eebc4e354f569Timo Sirainen "\"key4\":false,"
8c909e451d14075c05d90382cf8eebc4e354f569Timo Sirainen "\"key5\":null,"
8c909e451d14075c05d90382cf8eebc4e354f569Timo Sirainen "\"key6\": {},"
573f0491a5733fe21fa062a455acb4790b4e0499Timo Sirainen "\"key7\": {"
573f0491a5733fe21fa062a455acb4790b4e0499Timo Sirainen " \"sub1\":\"value\""
3ed2d0f6b5e67e2663d44489d9da3176823789a8Timo Sirainen "\"key8\": {"
65f8fb656051f1059f7b5a2da9c5555adcc30439Timo Sirainen " \"sub2\":-12.456,\n"
1a5573ebc32fae2fe576ec544e1781323c1db609Timo Sirainen " \"sub3\":12.456e9,\n"
1a5573ebc32fae2fe576ec544e1781323c1db609Timo Sirainen " \"sub4\":0.456e-789"
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen "\"key9\": \"\\\\\\\"\\b\\f\\n\\r\\t\\u0001\uffff\""
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenstatic struct {
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen { JSON_TYPE_STRING, "\\\"\b\f\n\r\t\001\xef\xbf\xbf" }
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenstatic void test_json_parser_success(bool full_size)
e5fd6dfd0a492e4708d4dbb7971d7fc5d7b8fd85Timo Sirainen unsigned int i, pos, json_input_len = strlen(json_input);
dfaefeabae939803ceb8c503101e86b5496541d1Timo Sirainen input = test_istream_create_data(json_input, json_input_len);
d46a1e3f999dda802dc5137e883adcd7a6629cd3Timo Sirainen while ((ret = json_parse_next(parser, &type, &value)) > 0) {
d1e843e77f4760e303c53d9fce10123fc8d230a1Timo Sirainen test_assert(null_strcmp(json_output[pos].value, value) == 0);
08e9fd42eb8007e1f9db62c088eef74f906114a5Josef 'Jeff' Sipek test_assert(json_parse_next(parser, &type, &value) == -1);