clang-format the files

This commit is contained in:
dota17
2020-03-28 10:25:00 +08:00
parent c117d8a8a8
commit 8b162c4b89
54 changed files with 2860 additions and 2713 deletions

View File

@@ -1,8 +1,8 @@
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <assert.h>
#include "json.h"
#include "json_tokener.h"
@@ -106,7 +106,7 @@ static void test_basic_parse()
single_basic_parse("{\"FoO\" : -12.3E512}", 0);
single_basic_parse("{\"FoO\" : -12.3e512}", 0);
single_basic_parse("{\"FoO\" : -12.3E51.2}", 0); /* non-sensical, returns null */
single_basic_parse("{\"FoO\" : -12.3E51.2}", 0); /* non-sensical, returns null */
single_basic_parse("{\"FoO\" : -12.3E512E12}", 0); /* non-sensical, returns null */
single_basic_parse("[\"\\n\"]", 0);
single_basic_parse("[\"\\nabc\\n\"]", 0);
@@ -119,7 +119,9 @@ static void test_basic_parse()
single_basic_parse("{ \'foo\': \'bar\' }", 0);
single_basic_parse("{ \"foo\": \"bar\", \"baz\": null, \"bool0\": true }", 0);
single_basic_parse("{ \"foo\": [null, \"foo\"] }", 0);
single_basic_parse("{ \"abc\": 12, \"foo\": \"bar\", \"bool0\": false, \"bool1\": true, \"arr\": [ 1, 2, 3, null, 5 ] }", 0);
single_basic_parse("{ \"abc\": 12, \"foo\": \"bar\", \"bool0\": false, \"bool1\": true, "
"\"arr\": [ 1, 2, 3, null, 5 ] }",
0);
single_basic_parse("{ \"abc\": \"blue\nred\\ngreen\" }", 0);
// Clear serializer for these tests so we see the actual parsed value.
@@ -130,7 +132,7 @@ static void test_basic_parse()
single_basic_parse("[0e+-1]", 1);
single_basic_parse("\"hello world!\"", 1);
// uint64/int64 range test
// uint64/int64 range test
single_basic_parse("[9223372036854775806]", 1);
single_basic_parse("[9223372036854775807]", 1);
single_basic_parse("[9223372036854775808]", 1);
@@ -147,8 +149,8 @@ static void test_utf8_parse()
// json_tokener_parse doesn't support checking for byte order marks.
// It's the responsibility of the caller to detect and skip a BOM.
// Both of these checks return null.
char utf8_bom[] = { 0xEF, 0xBB, 0xBF, 0x00 };
char utf8_bom_and_chars[] = { 0xEF, 0xBB, 0xBF, '{', '}', 0x00 };
char utf8_bom[] = {0xEF, 0xBB, 0xBF, 0x00};
char utf8_bom_and_chars[] = {0xEF, 0xBB, 0xBF, '{', '}', 0x00};
single_basic_parse(utf8_bom, 0);
single_basic_parse(utf8_bom_and_chars, 0);
}
@@ -161,10 +163,8 @@ static void do_clear_serializer(json_object *jso)
json_c_visit(jso, 0, clear_serializer, NULL);
}
static int clear_serializer(json_object *jso, int flags,
json_object *parent_jso,
const char *jso_key,
size_t *jso_index, void *userarg)
static int clear_serializer(json_object *jso, int flags, json_object *parent_jso,
const char *jso_key, size_t *jso_index, void *userarg)
{
if (jso)
json_object_set_serializer(jso, NULL, NULL, NULL);
@@ -177,24 +177,25 @@ static void test_verbose_parse()
enum json_tokener_error error = json_tokener_success;
new_obj = json_tokener_parse_verbose("{ foo }", &error);
assert (error == json_tokener_error_parse_object_key_name);
assert (new_obj == NULL);
assert(error == json_tokener_error_parse_object_key_name);
assert(new_obj == NULL);
new_obj = json_tokener_parse("{ foo }");
assert (new_obj == NULL);
assert(new_obj == NULL);
new_obj = json_tokener_parse("foo");
assert (new_obj == NULL);
assert(new_obj == NULL);
new_obj = json_tokener_parse_verbose("foo", &error);
assert (new_obj == NULL);
assert(new_obj == NULL);
/* b/c the string starts with 'f' parsing return a boolean error */
assert (error == json_tokener_error_parse_boolean);
assert(error == json_tokener_error_parse_boolean);
puts("json_tokener_parse_verbose() OK");
}
struct incremental_step {
struct incremental_step
{
const char *string_to_parse;
int length;
int char_offset;
@@ -202,205 +203,205 @@ struct incremental_step {
int reset_tokener;
} incremental_steps[] = {
/* Check that full json messages can be parsed, both w/ and w/o a reset */
{ "{ \"foo\": 123 }", -1, -1, json_tokener_success, 0 },
{ "{ \"foo\": 456 }", -1, -1, json_tokener_success, 1 },
{ "{ \"foo\": 789 }", -1, -1, json_tokener_success, 1 },
/* Check that full json messages can be parsed, both w/ and w/o a reset */
{"{ \"foo\": 123 }", -1, -1, json_tokener_success, 0},
{"{ \"foo\": 456 }", -1, -1, json_tokener_success, 1},
{"{ \"foo\": 789 }", -1, -1, json_tokener_success, 1},
/* Check the comment parse*/
{ "/* hello */{ \"foo\"", -1, -1, json_tokener_continue, 0 },
{ "/* hello */:/* hello */", -1, -1, json_tokener_continue, 0 },
{ "\"bar\"/* hello */", -1, -1, json_tokener_continue, 0 },
{ "}/* hello */", -1, -1, json_tokener_success, 1 },
{ "/ hello ", -1, 1, json_tokener_error_parse_comment, 1 },
{ "/* hello\"foo\"", -1, -1, json_tokener_continue, 1 },
{ "/* hello*\"foo\"", -1, -1, json_tokener_continue, 1 },
{ "// hello\"foo\"", -1, -1, json_tokener_continue, 1 },
/* Check the comment parse*/
{"/* hello */{ \"foo\"", -1, -1, json_tokener_continue, 0},
{"/* hello */:/* hello */", -1, -1, json_tokener_continue, 0},
{"\"bar\"/* hello */", -1, -1, json_tokener_continue, 0},
{"}/* hello */", -1, -1, json_tokener_success, 1},
{"/ hello ", -1, 1, json_tokener_error_parse_comment, 1},
{"/* hello\"foo\"", -1, -1, json_tokener_continue, 1},
{"/* hello*\"foo\"", -1, -1, json_tokener_continue, 1},
{"// hello\"foo\"", -1, -1, json_tokener_continue, 1},
/* Check a basic incremental parse */
{ "{ \"foo", -1, -1, json_tokener_continue, 0 },
{ "\": {\"bar", -1, -1, json_tokener_continue, 0 },
{ "\":13}}", -1, -1, json_tokener_success, 1 },
/* Check a basic incremental parse */
{"{ \"foo", -1, -1, json_tokener_continue, 0},
{"\": {\"bar", -1, -1, json_tokener_continue, 0},
{"\":13}}", -1, -1, json_tokener_success, 1},
/* Check that json_tokener_reset actually resets */
{ "{ \"foo", -1, -1, json_tokener_continue, 1 },
{ ": \"bar\"}", -1, 0, json_tokener_error_parse_unexpected, 1 },
/* Check that json_tokener_reset actually resets */
{"{ \"foo", -1, -1, json_tokener_continue, 1},
{": \"bar\"}", -1, 0, json_tokener_error_parse_unexpected, 1},
/* Check incremental parsing with trailing characters */
{ "{ \"foo", -1, -1, json_tokener_continue, 0 },
{ "\": {\"bar", -1, -1, json_tokener_continue, 0 },
{ "\":13}}XXXX", 10, 6, json_tokener_success, 0 },
{ "XXXX", 4, 0, json_tokener_error_parse_unexpected, 1 },
/* Check incremental parsing with trailing characters */
{"{ \"foo", -1, -1, json_tokener_continue, 0},
{"\": {\"bar", -1, -1, json_tokener_continue, 0},
{"\":13}}XXXX", 10, 6, json_tokener_success, 0},
{"XXXX", 4, 0, json_tokener_error_parse_unexpected, 1},
/* Check that trailing characters can change w/o a reset */
{ "{\"x\": 123 }\"X\"", -1, 11, json_tokener_success, 0 },
{ "\"Y\"", -1, -1, json_tokener_success, 1 },
/* Check that trailing characters can change w/o a reset */
{"{\"x\": 123 }\"X\"", -1, 11, json_tokener_success, 0},
{"\"Y\"", -1, -1, json_tokener_success, 1},
/* To stop parsing a number we need to reach a non-digit, e.g. a \0 */
{ "1", 1, 1, json_tokener_continue, 0 },
/* This should parse as the number 12, since it continues the "1" */
{ "2", 2, 1, json_tokener_success, 0 },
{ "12{", 3, 2, json_tokener_success, 1 },
/* Parse number in strict model */
{ "[02]", -1, 3, json_tokener_error_parse_number, 3 },
/* To stop parsing a number we need to reach a non-digit, e.g. a \0 */
{"1", 1, 1, json_tokener_continue, 0},
/* This should parse as the number 12, since it continues the "1" */
{"2", 2, 1, json_tokener_success, 0},
{"12{", 3, 2, json_tokener_success, 1},
/* Parse number in strict model */
{"[02]", -1, 3, json_tokener_error_parse_number, 3},
/* Similar tests for other kinds of objects: */
/* These could all return success immediately, since regardless of
/* Similar tests for other kinds of objects: */
/* These could all return success immediately, since regardless of
what follows the false/true/null token we *will* return a json object,
but it currently doesn't work that way. hmm... */
{ "false", 5, 5, json_tokener_continue, 1 },
{ "false", 6, 5, json_tokener_success, 1 },
{ "true", 4, 4, json_tokener_continue, 1 },
{ "true", 5, 4, json_tokener_success, 1 },
{ "null", 4, 4, json_tokener_continue, 1 },
{ "null", 5, 4, json_tokener_success, 1 },
{"false", 5, 5, json_tokener_continue, 1},
{"false", 6, 5, json_tokener_success, 1},
{"true", 4, 4, json_tokener_continue, 1},
{"true", 5, 4, json_tokener_success, 1},
{"null", 4, 4, json_tokener_continue, 1},
{"null", 5, 4, json_tokener_success, 1},
{ "Infinity", 9, 8, json_tokener_success, 1 },
{ "infinity", 9, 8, json_tokener_success, 1 },
{ "-infinity", 10, 9, json_tokener_success, 1 },
{ "infinity", 9, 0, json_tokener_error_parse_unexpected, 3 },
{ "-infinity", 10, 1, json_tokener_error_parse_unexpected, 3 },
{"Infinity", 9, 8, json_tokener_success, 1},
{"infinity", 9, 8, json_tokener_success, 1},
{"-infinity", 10, 9, json_tokener_success, 1},
{"infinity", 9, 0, json_tokener_error_parse_unexpected, 3},
{"-infinity", 10, 1, json_tokener_error_parse_unexpected, 3},
{ "inf", 3, 3, json_tokener_continue, 0 },
{ "inity", 6, 5, json_tokener_success, 1 },
{ "-inf", 4, 4, json_tokener_continue, 0 },
{ "inity", 6, 5, json_tokener_success, 1 },
{"inf", 3, 3, json_tokener_continue, 0},
{"inity", 6, 5, json_tokener_success, 1},
{"-inf", 4, 4, json_tokener_continue, 0},
{"inity", 6, 5, json_tokener_success, 1},
{ "i", 1, 1, json_tokener_continue, 0 },
{ "n", 1, 1, json_tokener_continue, 0 },
{ "f", 1, 1, json_tokener_continue, 0 },
{ "i", 1, 1, json_tokener_continue, 0 },
{ "n", 1, 1, json_tokener_continue, 0 },
{ "i", 1, 1, json_tokener_continue, 0 },
{ "t", 1, 1, json_tokener_continue, 0 },
{ "y", 1, 1, json_tokener_continue, 0 },
{ "", 1, 0, json_tokener_success, 1 },
{"i", 1, 1, json_tokener_continue, 0},
{"n", 1, 1, json_tokener_continue, 0},
{"f", 1, 1, json_tokener_continue, 0},
{"i", 1, 1, json_tokener_continue, 0},
{"n", 1, 1, json_tokener_continue, 0},
{"i", 1, 1, json_tokener_continue, 0},
{"t", 1, 1, json_tokener_continue, 0},
{"y", 1, 1, json_tokener_continue, 0},
{"", 1, 0, json_tokener_success, 1},
{ "-", 1, 1, json_tokener_continue, 0 },
{ "inf", 3, 3, json_tokener_continue, 0 },
{ "ini", 3, 3, json_tokener_continue, 0 },
{ "ty", 3, 2, json_tokener_success, 1 },
{"-", 1, 1, json_tokener_continue, 0},
{"inf", 3, 3, json_tokener_continue, 0},
{"ini", 3, 3, json_tokener_continue, 0},
{"ty", 3, 2, json_tokener_success, 1},
{ "-", 1, 1, json_tokener_continue, 0 },
{ "i", 1, 1, json_tokener_continue, 0 },
{ "nfini", 5, 5, json_tokener_continue, 0 },
{ "ty", 3, 2, json_tokener_success, 1 },
{"-", 1, 1, json_tokener_continue, 0},
{"i", 1, 1, json_tokener_continue, 0},
{"nfini", 5, 5, json_tokener_continue, 0},
{"ty", 3, 2, json_tokener_success, 1},
{ "-i", 2, 2, json_tokener_continue, 0 },
{ "nfinity", 8, 7, json_tokener_success, 1 },
{"-i", 2, 2, json_tokener_continue, 0},
{"nfinity", 8, 7, json_tokener_success, 1},
{ "InfinityX", 10, 8, json_tokener_success, 0 },
{ "X", 1, 0, json_tokener_error_parse_unexpected, 1 },
{"InfinityX", 10, 8, json_tokener_success, 0},
{"X", 1, 0, json_tokener_error_parse_unexpected, 1},
{ "Infinity1234", 13, 8, json_tokener_success, 0 },
{ "1234", 5, 4, json_tokener_success, 1 },
{"Infinity1234", 13, 8, json_tokener_success, 0},
{"1234", 5, 4, json_tokener_success, 1},
{ "Infinity9999", 8, 8, json_tokener_continue, 0 },
{"Infinity9999", 8, 8, json_tokener_continue, 0},
/* returns the Infinity loaded up by the previous call: */
{ "1234", 5, 0, json_tokener_success, 0 },
{ "1234", 5, 4, json_tokener_success, 1 },
/* returns the Infinity loaded up by the previous call: */
{"1234", 5, 0, json_tokener_success, 0},
{"1234", 5, 4, json_tokener_success, 1},
/* offset=1 because "n" is the start of "null". hmm... */
{ "noodle", 7, 1, json_tokener_error_parse_null, 1 },
/* offset=2 because "na" is the start of "nan". hmm... */
{ "naodle", 7, 2, json_tokener_error_parse_null, 1 },
/* offset=2 because "tr" is the start of "true". hmm... */
{ "track", 6, 2, json_tokener_error_parse_boolean, 1 },
{ "fail", 5, 2, json_tokener_error_parse_boolean, 1 },
/* offset=1 because "n" is the start of "null". hmm... */
{"noodle", 7, 1, json_tokener_error_parse_null, 1},
/* offset=2 because "na" is the start of "nan". hmm... */
{"naodle", 7, 2, json_tokener_error_parse_null, 1},
/* offset=2 because "tr" is the start of "true". hmm... */
{"track", 6, 2, json_tokener_error_parse_boolean, 1},
{"fail", 5, 2, json_tokener_error_parse_boolean, 1},
/* Although they may initially look like they should fail,
/* Although they may initially look like they should fail,
* the next few tests check that parsing multiple sequential
* json objects in the input works as expected
*/
{ "null123", 9, 4, json_tokener_success, 0 },
{ &"null123"[4], 4, 3, json_tokener_success, 1 },
{ "nullx", 5, 4, json_tokener_success, 0 },
{ &"nullx"[4], 2, 0, json_tokener_error_parse_unexpected, 1 },
{ "{\"a\":1}{\"b\":2}",15, 7, json_tokener_success, 0 },
{ &"{\"a\":1}{\"b\":2}"[7],
8, 7, json_tokener_success, 1 },
{"null123", 9, 4, json_tokener_success, 0},
{&"null123"[4], 4, 3, json_tokener_success, 1},
{"nullx", 5, 4, json_tokener_success, 0},
{&"nullx"[4], 2, 0, json_tokener_error_parse_unexpected, 1},
{"{\"a\":1}{\"b\":2}", 15, 7, json_tokener_success, 0},
{&"{\"a\":1}{\"b\":2}"[7], 8, 7, json_tokener_success, 1},
/* Some bad formatting. Check we get the correct error status */
{ "2015-01-15", 10, 4, json_tokener_error_parse_number, 1 },
/* Some bad formatting. Check we get the correct error status */
{"2015-01-15", 10, 4, json_tokener_error_parse_number, 1},
/* Strings have a well defined end point, so we can stop at the quote */
{ "\"blue\"", -1, -1, json_tokener_success, 0 },
/* Strings have a well defined end point, so we can stop at the quote */
{"\"blue\"", -1, -1, json_tokener_success, 0},
/* Check each of the escape sequences defined by the spec */
{ "\"\\\"\"", -1, -1, json_tokener_success, 0 },
{ "\"\\\\\"", -1, -1, json_tokener_success, 0 },
{ "\"\\b\"", -1, -1, json_tokener_success, 0 },
{ "\"\\f\"", -1, -1, json_tokener_success, 0 },
{ "\"\\n\"", -1, -1, json_tokener_success, 0 },
{ "\"\\r\"", -1, -1, json_tokener_success, 0 },
{ "\"\\t\"", -1, -1, json_tokener_success, 0 },
{ "\"\\/\"", -1, -1, json_tokener_success, 0 },
// Escaping a forward slash is optional
{ "\"/\"", -1, -1, json_tokener_success, 0 },
/* Check wrong escape sequences */
{ "\"\\a\"", -1, 2, json_tokener_error_parse_string, 1 },
/* Check each of the escape sequences defined by the spec */
{"\"\\\"\"", -1, -1, json_tokener_success, 0},
{"\"\\\\\"", -1, -1, json_tokener_success, 0},
{"\"\\b\"", -1, -1, json_tokener_success, 0},
{"\"\\f\"", -1, -1, json_tokener_success, 0},
{"\"\\n\"", -1, -1, json_tokener_success, 0},
{"\"\\r\"", -1, -1, json_tokener_success, 0},
{"\"\\t\"", -1, -1, json_tokener_success, 0},
{"\"\\/\"", -1, -1, json_tokener_success, 0},
// Escaping a forward slash is optional
{"\"/\"", -1, -1, json_tokener_success, 0},
/* Check wrong escape sequences */
{"\"\\a\"", -1, 2, json_tokener_error_parse_string, 1},
/* Check '\'' in strict model */
{ "\'foo\'", -1, 0, json_tokener_error_parse_unexpected, 3 },
/* Check '\'' in strict model */
{"\'foo\'", -1, 0, json_tokener_error_parse_unexpected, 3},
/* Parse array/object */
{ "[1,2,3]", -1, -1, json_tokener_success, 0 },
{ "[1,2,3}", -1, 6, json_tokener_error_parse_array, 1 },
{ "{\"a\"}", -1, 4, json_tokener_error_parse_object_key_sep, 1 },
{ "{\"a\":1]", -1, 6, json_tokener_error_parse_object_value_sep, 1 },
{ "{\"a\"::1}", -1, 5, json_tokener_error_parse_unexpected, 1 },
{ "{\"a\":}", -1, 5, json_tokener_error_parse_unexpected, 1 },
{ "{\"a\":1,\"a\":2}",-1, -1, json_tokener_success, 1 },
{ "\"a\":1}", -1, 3, json_tokener_success, 1 },
{ "{\"a\":1", -1, -1, json_tokener_continue, 1 },
{ "[,]", -1, 1, json_tokener_error_parse_unexpected, 1 },
{ "[,1]", -1, 1, json_tokener_error_parse_unexpected, 1 },
/* Parse array/object */
{"[1,2,3]", -1, -1, json_tokener_success, 0},
{"[1,2,3}", -1, 6, json_tokener_error_parse_array, 1},
{"{\"a\"}", -1, 4, json_tokener_error_parse_object_key_sep, 1},
{"{\"a\":1]", -1, 6, json_tokener_error_parse_object_value_sep, 1},
{"{\"a\"::1}", -1, 5, json_tokener_error_parse_unexpected, 1},
{"{\"a\":}", -1, 5, json_tokener_error_parse_unexpected, 1},
{"{\"a\":1,\"a\":2}", -1, -1, json_tokener_success, 1},
{"\"a\":1}", -1, 3, json_tokener_success, 1},
{"{\"a\":1", -1, -1, json_tokener_continue, 1},
{"[,]", -1, 1, json_tokener_error_parse_unexpected, 1},
{"[,1]", -1, 1, json_tokener_error_parse_unexpected, 1},
/* This behaviour doesn't entirely follow the json spec, but until we have
/* This behaviour doesn't entirely follow the json spec, but until we have
* a way to specify how strict to be we follow Postel's Law and be liberal
* in what we accept (up to a point).
*/
{ "[1,2,3,]", -1, -1, json_tokener_success, 0 },
{ "[1,2,,3,]", -1, 5, json_tokener_error_parse_unexpected, 0 },
{"[1,2,3,]", -1, -1, json_tokener_success, 0},
{"[1,2,,3,]", -1, 5, json_tokener_error_parse_unexpected, 0},
{ "[1,2,3,]", -1, 7, json_tokener_error_parse_unexpected, 3 },
{ "{\"a\":1,}", -1, 7, json_tokener_error_parse_unexpected, 3 },
{"[1,2,3,]", -1, 7, json_tokener_error_parse_unexpected, 3},
{"{\"a\":1,}", -1, 7, json_tokener_error_parse_unexpected, 3},
// utf-8 test
// acsll encoding
{ "\x22\x31\x32\x33\x61\x73\x63\x24\x25\x26\x22",-1, -1, json_tokener_success, 5 },
{ "\x22\x31\x32\x33\x61\x73\x63\x24\x25\x26\x22",-1, -1, json_tokener_success, 1 },
// utf-8 encoding
{ "\x22\xe4\xb8\x96\xe7\x95\x8c\x22",-1, -1, json_tokener_success, 5 },
{ "\x22\xe4\xb8",-1, 3, json_tokener_error_parse_utf8_string, 4 },
{ "\x96\xe7\x95\x8c\x22",-1, 0, json_tokener_error_parse_utf8_string, 5 },
{ "\x22\xe4\xb8\x96\xe7\x95\x8c\x22",-1, -1, json_tokener_success, 1 },
{ "\x22\xcf\x80\xcf\x86\x22",-1, -1, json_tokener_success, 5 },
{ "\x22\xf0\xa5\x91\x95\x22",-1, -1, json_tokener_success, 5 },
// wrong utf-8 encoding
{ "\x22\xe6\x9d\x4e\x22",-1, 3, json_tokener_error_parse_utf8_string, 5 },
{ "\x22\xe6\x9d\x4e\x22",-1, 5, json_tokener_success, 1 },
// GBK encoding
{ "\x22\xc0\xee\xc5\xf4\x22",-1, 2, json_tokener_error_parse_utf8_string, 5 },
{ "\x22\xc0\xee\xc5\xf4\x22",-1, 6, json_tokener_success, 1 },
// char after space
{ "\x20\x20\x22\xe4\xb8\x96\x22",-1, -1, json_tokener_success, 5 },
{ "\x20\x20\x81\x22\xe4\xb8\x96\x22",-1, 2, json_tokener_error_parse_utf8_string, 5 },
{ "\x5b\x20\x81\x31\x5d",-1, 2, json_tokener_error_parse_utf8_string, 5 },
// char in state inf
{ "\x49\x6e\x66\x69\x6e\x69\x74\x79",9, 8, json_tokener_success, 1 },
{ "\x49\x6e\x66\x81\x6e\x69\x74\x79",-1, 3, json_tokener_error_parse_utf8_string, 5 },
// char in escape unicode
{ "\x22\x5c\x75\x64\x38\x35\x35\x5c\x75\x64\x63\x35\x35\x22",15, 14, json_tokener_success, 5 },
{ "\x22\x5c\x75\x64\x38\x35\x35\xc0\x75\x64\x63\x35\x35\x22",-1, 8, json_tokener_error_parse_utf8_string, 5 },
{ "\x22\x5c\x75\x64\x30\x30\x33\x31\xc0\x22",-1, 9, json_tokener_error_parse_utf8_string, 5 },
// char in number
{ "\x31\x31\x81\x31\x31",-1, 2, json_tokener_error_parse_utf8_string, 5 },
// char in object
{ "\x7b\x22\x31\x81\x22\x3a\x31\x7d",-1, 3, json_tokener_error_parse_utf8_string, 5 },
// utf-8 test
// acsll encoding
{"\x22\x31\x32\x33\x61\x73\x63\x24\x25\x26\x22", -1, -1, json_tokener_success, 5},
{"\x22\x31\x32\x33\x61\x73\x63\x24\x25\x26\x22", -1, -1, json_tokener_success, 1},
// utf-8 encoding
{"\x22\xe4\xb8\x96\xe7\x95\x8c\x22", -1, -1, json_tokener_success, 5},
{"\x22\xe4\xb8", -1, 3, json_tokener_error_parse_utf8_string, 4},
{"\x96\xe7\x95\x8c\x22", -1, 0, json_tokener_error_parse_utf8_string, 5},
{"\x22\xe4\xb8\x96\xe7\x95\x8c\x22", -1, -1, json_tokener_success, 1},
{"\x22\xcf\x80\xcf\x86\x22", -1, -1, json_tokener_success, 5},
{"\x22\xf0\xa5\x91\x95\x22", -1, -1, json_tokener_success, 5},
// wrong utf-8 encoding
{"\x22\xe6\x9d\x4e\x22", -1, 3, json_tokener_error_parse_utf8_string, 5},
{"\x22\xe6\x9d\x4e\x22", -1, 5, json_tokener_success, 1},
// GBK encoding
{"\x22\xc0\xee\xc5\xf4\x22", -1, 2, json_tokener_error_parse_utf8_string, 5},
{"\x22\xc0\xee\xc5\xf4\x22", -1, 6, json_tokener_success, 1},
// char after space
{"\x20\x20\x22\xe4\xb8\x96\x22", -1, -1, json_tokener_success, 5},
{"\x20\x20\x81\x22\xe4\xb8\x96\x22", -1, 2, json_tokener_error_parse_utf8_string, 5},
{"\x5b\x20\x81\x31\x5d", -1, 2, json_tokener_error_parse_utf8_string, 5},
// char in state inf
{"\x49\x6e\x66\x69\x6e\x69\x74\x79", 9, 8, json_tokener_success, 1},
{"\x49\x6e\x66\x81\x6e\x69\x74\x79", -1, 3, json_tokener_error_parse_utf8_string, 5},
// char in escape unicode
{"\x22\x5c\x75\x64\x38\x35\x35\x5c\x75\x64\x63\x35\x35\x22", 15, 14, json_tokener_success, 5},
{"\x22\x5c\x75\x64\x38\x35\x35\xc0\x75\x64\x63\x35\x35\x22", -1, 8,
json_tokener_error_parse_utf8_string, 5},
{"\x22\x5c\x75\x64\x30\x30\x33\x31\xc0\x22", -1, 9, json_tokener_error_parse_utf8_string, 5},
// char in number
{"\x31\x31\x81\x31\x31", -1, 2, json_tokener_error_parse_utf8_string, 5},
// char in object
{"\x7b\x22\x31\x81\x22\x3a\x31\x7d", -1, 3, json_tokener_error_parse_utf8_string, 5},
{ NULL, -1, -1, json_tokener_success, 0 },
{NULL, -1, -1, json_tokener_success, 0},
};
static void test_incremental_parse()
@@ -422,7 +423,8 @@ static void test_incremental_parse()
string_to_parse = "{ \"foo"; /* } */
printf("json_tokener_parse(%s) ... ", string_to_parse);
new_obj = json_tokener_parse(string_to_parse);
if (new_obj == NULL) puts("got error as expected");
if (new_obj == NULL)
puts("got error as expected");
/* test incremental parsing in various forms */
tok = json_tokener_new();
@@ -434,19 +436,19 @@ static void test_incremental_parse()
size_t expected_char_offset;
if (step->reset_tokener & 2)
{
if (step->reset_tokener & 4)
json_tokener_set_flags(tok, 3);
else
json_tokener_set_flags(tok, JSON_TOKENER_STRICT);
}
{
if (step->reset_tokener & 4)
json_tokener_set_flags(tok, 3);
else
json_tokener_set_flags(tok, JSON_TOKENER_STRICT);
}
else
{
if (step->reset_tokener & 4)
json_tokener_set_flags(tok, JSON_TOKENER_VALIDATE_UTF8);
else
json_tokener_set_flags(tok, 0);
}
{
if (step->reset_tokener & 4)
json_tokener_set_flags(tok, JSON_TOKENER_VALIDATE_UTF8);
else
json_tokener_set_flags(tok, 0);
}
if (length == -1)
length = strlen(step->string_to_parse);
@@ -455,8 +457,8 @@ static void test_incremental_parse()
else
expected_char_offset = step->char_offset;
printf("json_tokener_parse_ex(tok, %-12s, %3d) ... ",
step->string_to_parse, length);
printf("json_tokener_parse_ex(tok, %-12s, %3d) ... ", step->string_to_parse,
length);
new_obj = json_tokener_parse_ex(tok, step->string_to_parse, length);
jerr = json_tokener_get_error(tok);
@@ -470,8 +472,7 @@ static void test_incremental_parse()
json_tokener_error_desc(jerr));
else if (json_tokener_get_parse_end(tok) != expected_char_offset)
printf("ERROR: wrong char_offset %zu != expected %zu\n",
json_tokener_get_parse_end(tok),
expected_char_offset);
json_tokener_get_parse_end(tok), expected_char_offset);
else
{
printf("OK: got correct error: %s\n",
@@ -482,19 +483,17 @@ static void test_incremental_parse()
else
{
if (new_obj == NULL &&
!(step->length >= 4 &&
strncmp(step->string_to_parse, "null", 4) == 0))
!(step->length >= 4 && strncmp(step->string_to_parse, "null", 4) == 0))
printf("ERROR: expected valid object, instead: %s\n",
json_tokener_error_desc(jerr));
else if (json_tokener_get_parse_end(tok) != expected_char_offset)
printf("ERROR: wrong char_offset %zu != expected %zu\n",
json_tokener_get_parse_end(tok),
expected_char_offset);
json_tokener_get_parse_end(tok), expected_char_offset);
else
{
printf("OK: got object of type [%s]: %s\n",
json_type_to_name(json_object_get_type(new_obj)),
json_object_to_json_string(new_obj));
json_type_to_name(json_object_get_type(new_obj)),
json_object_to_json_string(new_obj));
this_step_ok = 1;
}
}