test-json-parser.c revision cd62b999690796343670d626aedf35d413c345f9
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen/* Copyright (c) 2013 Dovecot authors, see the included COPYING file */
b1f37113a5760bee842c5a7678bb5fa6f5bd8b60Timo Sirainenstatic const char json_input[] =
94d8e51119003d2bc5a100c663f90141f297385dTimo Sirainen "\t\"key\"\t:\t\t\"string\","
e28fa207d1a097fa6e4a867f74ee0761472ef1ceTimo Sirainen " \"key2\" : 1234, \n"
37847ec8eaec9ad55c9df10ae109efe7b37ac573Timo Sirainen "\"key3\":true,"
ef50336eefcb9ba99f73c6af37420eaf8857a39bTimo Sirainen "\"key4\":false,"
13d98ffa534f2e7d04a832c9d0153fc9c568b878Timo Sirainen "\"skip1\": \"jsifjaisfjiasji\","
13d98ffa534f2e7d04a832c9d0153fc9c568b878Timo Sirainen "\"skip2\": { \"x\":{ \"y\":123}, \"z\":[5,[6],{\"k\":0},3]},"
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen "\"key5\":null,"
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen "\"key6\": {},"
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen "\"key7\": {"
dc5606fb66d30a659459446b6ca1a8b4f1146052Timo Sirainen " \"sub1\":\"value\""
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen "\"key8\": {"
5694eeb99b69dea8033ca77ad69743c6b4871370Timo Sirainen " \"sub2\":-12.456,\n"
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen " \"sub3\":12.456e9,\n"
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen " \"sub4\":0.456e-789"
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen "\"key9\": \"foo\\\\\\\"\\b\\f\\n\\r\\t\\u0001\uffff\","
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen "\"key10\": \"foo\\\\\\\"\\b\\f\\n\\r\\t\\u0001\uffff\","
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen "\"key11\": [],"
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen "\"key12\": [ \"foo\" , 5.24,[true],{\"aobj\":[]}]"
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenstatic struct {
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen { JSON_TYPE_STRING, "foo\\\"\b\f\n\r\t\001\xef\xbf\xbf" },
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen { TYPE_STREAM, "foo\\\"\b\f\n\r\t\001\xef\xbf\xbf" },
a24519c36d5f8fa22f58b2c693ba547e8d175a54Timo Sirainenstream_read_value(struct istream **input, const char **value_r)
a24519c36d5f8fa22f58b2c693ba547e8d175a54Timo Sirainen const unsigned char *data;
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainenstatic void test_json_parser_success(bool full_size)
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen unsigned int i, pos, json_input_len = strlen(json_input);
2649b237dd4690575e75a30b2bf3b39ebd37b835Timo Sirainen test_begin(full_size ? "json parser" : "json parser (nonblocking)");
63e207529879438e9f4412d97cdc34bdc82a3702Timo Sirainen input = test_istream_create_data(json_input, json_input_len);
2649b237dd4690575e75a30b2bf3b39ebd37b835Timo Sirainen if (json_output[pos].type == (enum json_type)TYPE_SKIP) {
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen } else if (json_output[pos].type != (enum json_type)TYPE_STREAM) {
2a6dcd984104fed84bed8795ccdfabb20e41ce52Timo Sirainen test_assert(null_strcmp(json_output[pos].value, value) == 0);
2a6dcd984104fed84bed8795ccdfabb20e41ce52Timo Sirainen test_assert(json_parse_next(parser, &type, &value) == -1);