aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2019-10-19 20:35:28 +0300
committerPetri Lehtinen <petri@digip.org>2019-10-21 08:56:03 +0300
commita8f5fa5f5a2b7613aa2aa27b4a4df83b5a0ecd1b (patch)
tree366ad4f7e39808675d35d9c941fd51a8c86b0bda /test
parent7c0297abe8f4fb4aafd642c3130628185dc78978 (diff)
downloadjansson-a8f5fa5f5a2b7613aa2aa27b4a4df83b5a0ecd1b.zip
jansson-a8f5fa5f5a2b7613aa2aa27b4a4df83b5a0ecd1b.tar.gz
jansson-a8f5fa5f5a2b7613aa2aa27b4a4df83b5a0ecd1b.tar.bz2
Tweak clang-format configuration a bit
Set ColumnLimit to 90, remove AllowShortCaseLabelsOnASingleLine.
Diffstat (limited to 'test')
-rw-r--r--test/bin/json_process.c14
-rw-r--r--test/suites/api/test_array.c4
-rw-r--r--test/suites/api/test_chaos.c55
-rw-r--r--test/suites/api/test_dump.c20
-rw-r--r--test/suites/api/test_dump_callback.c3
-rw-r--r--test/suites/api/test_equal.c31
-rw-r--r--test/suites/api/test_load.c13
-rw-r--r--test/suites/api/test_load_callback.c3
-rw-r--r--test/suites/api/test_memory_funcs.c7
-rw-r--r--test/suites/api/test_object.c63
-rw-r--r--test/suites/api/test_pack.c110
-rw-r--r--test/suites/api/test_unpack.c119
-rw-r--r--test/suites/api/test_version.c3
-rw-r--r--test/suites/api/util.h104
14 files changed, 249 insertions, 300 deletions
diff --git a/test/bin/json_process.c b/test/bin/json_process.c
index b1f0775..f7f46d0 100644
--- a/test/bin/json_process.c
+++ b/test/bin/json_process.c
@@ -191,8 +191,7 @@ int use_conf(char *test_path) {
flags |= JSON_SORT_KEYS;
if (conf.precision < 0 || conf.precision > 31) {
- fprintf(stderr, "invalid value for JSON_REAL_PRECISION: %d\n",
- conf.precision);
+ fprintf(stderr, "invalid value for JSON_REAL_PRECISION: %d\n", conf.precision);
fclose(infile);
return 2;
}
@@ -213,8 +212,8 @@ int use_conf(char *test_path) {
fclose(infile);
if (!json) {
- sprintf(errstr, "%d %d %d\n%s\n", error.line, error.column,
- error.position, error.text);
+ sprintf(errstr, "%d %d %d\n%s\n", error.line, error.column, error.position,
+ error.text);
ret = cmpfile(errstr, test_path, "error");
return ret;
@@ -278,8 +277,7 @@ int use_env() {
precision = getenv_int("JSON_REAL_PRECISION");
if (precision < 0 || precision > 31) {
- fprintf(stderr, "invalid value for JSON_REAL_PRECISION: %d\n",
- precision);
+ fprintf(stderr, "invalid value for JSON_REAL_PRECISION: %d\n", precision);
return 2;
}
@@ -320,8 +318,8 @@ int use_env() {
json = json_loadf(stdin, 0, &error);
if (!json) {
- fprintf(stderr, "%d %d %d\n%s\n", error.line, error.column,
- error.position, error.text);
+ fprintf(stderr, "%d %d %d\n%s\n", error.line, error.column, error.position,
+ error.text);
return 1;
}
diff --git a/test/suites/api/test_array.c b/test/suites/api/test_array.c
index bb89c4b..e5d9d1a 100644
--- a/test/suites/api/test_array.c
+++ b/test/suites/api/test_array.c
@@ -387,9 +387,7 @@ static void test_array_foreach() {
array1 = json_pack("[sisisi]", "foo", 1, "bar", 2, "baz", 3);
array2 = json_array();
- json_array_foreach(array1, index, value) {
- json_array_append(array2, value);
- }
+ json_array_foreach(array1, index, value) { json_array_append(array2, value); }
if (!json_equal(array1, array2))
fail("json_array_foreach failed to iterate all elements");
diff --git a/test/suites/api/test_chaos.c b/test/suites/api/test_chaos.c
index 6c1878e..8687243 100644
--- a/test/suites/api/test_chaos.c
+++ b/test/suites/api/test_chaos.c
@@ -23,19 +23,19 @@ void *chaos_malloc(size_t size) {
void chaos_free(void *obj) { free(obj); }
/* Test all potential allocation failures. */
-#define chaos_loop(condition, code, cleanup) \
- { \
- chaos_pos = chaos_fail = 0; \
- while (condition) { \
- if (chaos_fail > CHAOS_MAX_FAILURE) \
- fail("too many chaos failures"); \
- code chaos_pos = 0; \
- chaos_fail++; \
- } \
- cleanup \
+#define chaos_loop(condition, code, cleanup) \
+ { \
+ chaos_pos = chaos_fail = 0; \
+ while (condition) { \
+ if (chaos_fail > CHAOS_MAX_FAILURE) \
+ fail("too many chaos failures"); \
+ code chaos_pos = 0; \
+ chaos_fail++; \
+ } \
+ cleanup \
}
-#define chaos_loop_new_value(json, initcall) \
+#define chaos_loop_new_value(json, initcall) \
chaos_loop(!json, json = initcall;, json_decref(json); json = NULL;)
int test_unpack() {
@@ -43,14 +43,12 @@ int test_unpack() {
int v1;
int v2;
json_error_t error;
- json_t *root =
- json_pack("{s:i, s:i, s:i, s:i}", "n1", 1, "n2", 2, "n3", 3, "n4", 4);
+ json_t *root = json_pack("{s:i, s:i, s:i, s:i}", "n1", 1, "n2", 2, "n3", 3, "n4", 4);
if (!root)
return -1;
- if (!json_unpack_ex(root, &error, JSON_STRICT, "{s:i, s:i}", "n1", &v1,
- "n2", &v2))
+ if (!json_unpack_ex(root, &error, JSON_STRICT, "{s:i, s:i}", "n1", &v1, "n2", &v2))
fail("Unexpected success");
if (json_error_code(&error) != json_error_end_of_input_expected) {
@@ -96,8 +94,7 @@ static void test_chaos() {
json_t *intnum = json_integer(1);
json_t *dblnum = json_real(0.5);
char *dumptxt = NULL;
- json_t *dumpobj =
- json_pack("{s:[iiis], s:s}", "key1", 1, 2, 3, "txt", "key2", "v2");
+ json_t *dumpobj = json_pack("{s:[iiis], s:s}", "key1", 1, 2, 3, "txt", "key2", "v2");
int keyno;
if (!obj || !arr1 || !arr2 || !txt || !intnum || !dblnum || !dumpobj)
@@ -112,22 +109,20 @@ static void test_chaos() {
chaos_loop_new_value(json, json_pack("[s*,s*]", "v1", "v2"));
chaos_loop_new_value(json, json_pack("o", json_incref(txt)));
chaos_loop_new_value(json, json_pack("O", txt));
- chaos_loop_new_value(json,
- json_pack("s++", "a", "long string to force realloc",
- "another long string to force yet another "
- "reallocation of the string because "
- "that's what we are testing."));
+ chaos_loop_new_value(json, json_pack("s++", "a", "long string to force realloc",
+ "another long string to force yet another "
+ "reallocation of the string because "
+ "that's what we are testing."));
chaos_loop(test_unpack(), , );
- chaos_loop(
- json_dump_callback(dumpobj, dump_chaos_callback, NULL, JSON_INDENT(1)),
- , );
+ chaos_loop(json_dump_callback(dumpobj, dump_chaos_callback, NULL, JSON_INDENT(1)),
+ , );
chaos_loop(json_dump_callback(dumpobj, dump_chaos_callback, NULL,
JSON_INDENT(1) | JSON_SORT_KEYS),
, );
- chaos_loop(!dumptxt, dumptxt = json_dumps(dumpobj, JSON_COMPACT);
- , free(dumptxt); dumptxt = NULL;);
+ chaos_loop(!dumptxt, dumptxt = json_dumps(dumpobj, JSON_COMPACT);, free(dumptxt);
+ dumptxt = NULL;);
chaos_loop_new_value(json, json_copy(obj));
chaos_loop_new_value(json, json_deep_copy(obj));
@@ -141,8 +136,7 @@ static void test_chaos() {
#define JSON_LOAD_TXT "{\"n\":[1,2,3,4,5,6,7,8,9,10]}"
chaos_loop_new_value(json, json_loads(JSON_LOAD_TXT, 0, NULL));
- chaos_loop_new_value(
- json, json_loadb(JSON_LOAD_TXT, strlen(JSON_LOAD_TXT), 0, NULL));
+ chaos_loop_new_value(json, json_loadb(JSON_LOAD_TXT, strlen(JSON_LOAD_TXT), 0, NULL));
chaos_loop_new_value(json, json_sprintf("%s", "string"));
@@ -152,8 +146,7 @@ static void test_chaos() {
char testkey[10];
snprintf(testkey, sizeof(testkey), "test%d", keyno);
- chaos_loop(json_object_set_new_nocheck(obj, testkey, json_object()),
- , );
+ chaos_loop(json_object_set_new_nocheck(obj, testkey, json_object()), , );
#endif
chaos_loop(json_array_append_new(arr1, json_null()), , );
chaos_loop(json_array_insert_new(arr2, 0, json_null()), , );
diff --git a/test/suites/api/test_dump.c b/test/suites/api/test_dump.c
index de90dc6..e8cb519 100644
--- a/test/suites/api/test_dump.c
+++ b/test/suites/api/test_dump.c
@@ -42,8 +42,7 @@ static void encode_null() {
/* Don't test json_dump_file to avoid creating a file */
- if (json_dump_callback(NULL, encode_null_callback, NULL, JSON_ENCODE_ANY) !=
- -1)
+ if (json_dump_callback(NULL, encode_null_callback, NULL, JSON_ENCODE_ANY) != -1)
fail("json_dump_callback didn't fail for NULL");
}
@@ -176,20 +175,17 @@ static void escape_slashes() {
char *result;
json = json_object();
- json_object_set_new(json, "url",
- json_string("https://github.com/akheron/jansson"));
+ json_object_set_new(json, "url", json_string("https://github.com/akheron/jansson"));
result = json_dumps(json, 0);
- if (!result ||
- strcmp(result, "{\"url\": \"https://github.com/akheron/jansson\"}"))
+ if (!result || strcmp(result, "{\"url\": \"https://github.com/akheron/jansson\"}"))
fail("json_dumps failed to not escape slashes");
free(result);
result = json_dumps(json, JSON_ESCAPE_SLASH);
if (!result ||
- strcmp(result,
- "{\"url\": \"https:\\/\\/github.com\\/akheron\\/jansson\"}"))
+ strcmp(result, "{\"url\": \"https:\\/\\/github.com\\/akheron\\/jansson\"}"))
fail("json_dumps failed to escape slashes");
free(result);
@@ -275,8 +271,8 @@ static void dumpfd() {
}
static void embed() {
- static const char *plains[] = {"{\"bar\":[],\"foo\":{}}", "[[],{}]", "{}",
- "[]", NULL};
+ static const char *plains[] = {"{\"bar\":[],\"foo\":{}}", "[[],{}]", "{}", "[]",
+ NULL};
size_t i;
@@ -290,8 +286,8 @@ static void embed() {
psize = strlen(plain) - 2;
embed = calloc(1, psize);
parse = json_loads(plain, 0, NULL);
- esize = json_dumpb(parse, embed, psize,
- JSON_COMPACT | JSON_SORT_KEYS | JSON_EMBED);
+ esize =
+ json_dumpb(parse, embed, psize, JSON_COMPACT | JSON_SORT_KEYS | JSON_EMBED);
json_decref(parse);
if (esize != psize)
fail("json_dumpb(JSON_EMBED) returned an invalid size");
diff --git a/test/suites/api/test_dump_callback.c b/test/suites/api/test_dump_callback.c
index 77e9a50..80ea008 100644
--- a/test/suites/api/test_dump_callback.c
+++ b/test/suites/api/test_dump_callback.c
@@ -29,8 +29,7 @@ static int my_writer(const char *buffer, size_t len, void *data) {
static void run_tests() {
struct my_sink s;
json_t *json;
- const char str[] =
- "[\"A\", {\"B\": \"C\", \"e\": false}, 1, null, \"foo\"]";
+ const char str[] = "[\"A\", {\"B\": \"C\", \"e\": false}, 1, null, \"foo\"]";
char *dumped_to_string;
json = json_loads(str, 0, NULL);
diff --git a/test/suites/api/test_equal.c b/test/suites/api/test_equal.c
index 9bcd392..d068b7b 100644
--- a/test/suites/api/test_equal.c
+++ b/test/suites/api/test_equal.c
@@ -157,18 +157,17 @@ static void test_equal_object() {
static void test_equal_complex() {
json_t *value1, *value2, *value3;
- const char *complex_json =
- "{"
- " \"integer\": 1, "
- " \"real\": 3.141592, "
- " \"string\": \"foobar\", "
- " \"true\": true, "
- " \"object\": {"
- " \"array-in-object\": [1,true,\"foo\",{}],"
- " \"object-in-object\": {\"foo\": \"bar\"}"
- " },"
- " \"array\": [\"foo\", false, null, 1.234]"
- "}";
+ const char *complex_json = "{"
+ " \"integer\": 1, "
+ " \"real\": 3.141592, "
+ " \"string\": \"foobar\", "
+ " \"true\": true, "
+ " \"object\": {"
+ " \"array-in-object\": [1,true,\"foo\",{}],"
+ " \"object-in-object\": {\"foo\": \"bar\"}"
+ " },"
+ " \"array\": [\"foo\", false, null, 1.234]"
+ "}";
value1 = json_loads(complex_json, 0, NULL);
value2 = json_loads(complex_json, 0, NULL);
@@ -179,14 +178,14 @@ static void test_equal_complex() {
fail("json_equal fails for two equal objects");
json_array_set_new(
- json_object_get(json_object_get(value2, "object"), "array-in-object"),
- 1, json_false());
+ json_object_get(json_object_get(value2, "object"), "array-in-object"), 1,
+ json_false());
if (json_equal(value1, value2))
fail("json_equal fails for two inequal objects");
json_object_set_new(
- json_object_get(json_object_get(value3, "object"), "object-in-object"),
- "foo", json_string("baz"));
+ json_object_get(json_object_get(value3, "object"), "object-in-object"), "foo",
+ json_string("baz"));
if (json_equal(value1, value3))
fail("json_equal fails for two inequal objects");
diff --git a/test/suites/api/test_load.c b/test/suites/api/test_load.c
index 8eaf355..1c64b0c 100644
--- a/test/suites/api/test_load.c
+++ b/test/suites/api/test_load.c
@@ -29,8 +29,7 @@ static void file_not_found() {
*pos = '\0';
- if (strcmp(error.text, "unable to open /path/to/nonexistent/file.json") !=
- 0)
+ if (strcmp(error.text, "unable to open /path/to/nonexistent/file.json") != 0)
fail("json_load_file returned an invalid error message");
if (json_error_code(&error) != json_error_cannot_open_file)
fail("json_load_file returned an invalid error code");
@@ -71,8 +70,8 @@ static void disable_eof_check() {
if (json_loads(text, 0, &error))
fail("json_loads did not detect garbage after JSON text");
- check_error(json_error_end_of_input_expected,
- "end of file expected near 'garbage'", "<string>", 1, 18, 18);
+ check_error(json_error_end_of_input_expected, "end of file expected near 'garbage'",
+ "<string>", 1, 18, 18);
json = json_loads(text, JSON_DISABLE_EOF_CHECK, &error);
if (!json)
@@ -127,10 +126,8 @@ static void decode_int_as_real() {
imprecise = "9007199254740993";
expected = 9007199254740992ll;
- json = json_loads(imprecise, JSON_DECODE_INT_AS_REAL | JSON_DECODE_ANY,
- &error);
- if (!json || !json_is_real(json) ||
- expected != (json_int_t)json_real_value(json))
+ json = json_loads(imprecise, JSON_DECODE_INT_AS_REAL | JSON_DECODE_ANY, &error);
+ if (!json || !json_is_real(json) || expected != (json_int_t)json_real_value(json))
fail("json_load decode int as real failed - expected imprecision");
json_decref(json);
#endif
diff --git a/test/suites/api/test_load_callback.c b/test/suites/api/test_load_callback.c
index 1e27601..b292fcf 100644
--- a/test/suites/api/test_load_callback.c
+++ b/test/suites/api/test_load_callback.c
@@ -16,8 +16,7 @@ struct my_source {
size_t cap;
};
-static const char my_str[] =
- "[\"A\", {\"B\": \"C\", \"e\": false}, 1, null, \"foo\"]";
+static const char my_str[] = "[\"A\", {\"B\": \"C\", \"e\": false}, 1, null, \"foo\"]";
static size_t greedy_reader(void *buf, size_t buflen, void *arg) {
struct my_source *s = arg;
diff --git a/test/suites/api/test_memory_funcs.c b/test/suites/api/test_memory_funcs.c
index 9fc34fc..4fd6166 100644
--- a/test/suites/api/test_memory_funcs.c
+++ b/test/suites/api/test_memory_funcs.c
@@ -11,8 +11,8 @@ static size_t malloc_used = 0;
static void create_and_free_complex_object() {
json_t *obj;
- obj = json_pack("{s:i,s:n,s:b,s:b,s:{s:s},s:[i,i,i]}", "foo", 42, "bar",
- "baz", 1, "qux", 0, "alice", "bar", "baz", "bob", 9, 8, 7);
+ obj = json_pack("{s:i,s:n,s:b,s:b,s:{s:s},s:[i,i,i]}", "foo", 42, "bar", "baz", 1,
+ "qux", 0, "alice", "bar", "baz", "bob", 9, 8, 7);
json_decref(obj);
}
@@ -48,8 +48,7 @@ static void test_simple() {
json_get_alloc_funcs(&mfunc, &ffunc);
create_and_free_complex_object();
- if (malloc_called != 1 || free_called != 1 || mfunc != my_malloc ||
- ffunc != my_free)
+ if (malloc_called != 1 || free_called != 1 || mfunc != my_malloc || ffunc != my_free)
fail("Custom allocation failed");
}
diff --git a/test/suites/api/test_object.c b/test/suites/api/test_object.c
index 033db21..331edf2 100644
--- a/test/suites/api/test_object.c
+++ b/test/suites/api/test_object.c
@@ -20,10 +20,9 @@ static void test_clear() {
if (!ten)
fail("unable to create integer");
- if (json_object_set(object, "a", ten) ||
- json_object_set(object, "b", ten) ||
- json_object_set(object, "c", ten) ||
- json_object_set(object, "d", ten) || json_object_set(object, "e", ten))
+ if (json_object_set(object, "a", ten) || json_object_set(object, "b", ten) ||
+ json_object_set(object, "c", ten) || json_object_set(object, "d", ten) ||
+ json_object_set(object, "e", ten))
fail("unable to set value");
if (json_object_size(object) != 5)
@@ -76,10 +75,8 @@ static void test_update() {
if (json_object_size(object) != 5)
fail("invalid size after update");
- if (json_object_get(object, "a") != ten ||
- json_object_get(object, "b") != ten ||
- json_object_get(object, "c") != ten ||
- json_object_get(object, "d") != ten ||
+ if (json_object_get(object, "a") != ten || json_object_get(object, "b") != ten ||
+ json_object_get(object, "c") != ten || json_object_get(object, "d") != ten ||
json_object_get(object, "e") != ten)
fail("update works incorrectly");
@@ -91,10 +88,8 @@ static void test_update() {
if (json_object_size(object) != 5)
fail("invalid size after update");
- if (json_object_get(object, "a") != ten ||
- json_object_get(object, "b") != ten ||
- json_object_get(object, "c") != ten ||
- json_object_get(object, "d") != ten ||
+ if (json_object_get(object, "a") != ten || json_object_get(object, "b") != ten ||
+ json_object_get(object, "c") != ten || json_object_get(object, "d") != ten ||
json_object_get(object, "e") != ten)
fail("update works incorrectly");
@@ -104,10 +99,9 @@ static void test_update() {
if (json_object_clear(other))
fail("clear failed");
- if (json_object_set(other, "a", nine) ||
- json_object_set(other, "b", nine) ||
- json_object_set(other, "f", nine) ||
- json_object_set(other, "g", nine) || json_object_set(other, "h", nine))
+ if (json_object_set(other, "a", nine) || json_object_set(other, "b", nine) ||
+ json_object_set(other, "f", nine) || json_object_set(other, "g", nine) ||
+ json_object_set(other, "h", nine))
fail("unable to set value");
if (json_object_update(object, other))
@@ -116,10 +110,8 @@ static void test_update() {
if (json_object_size(object) != 8)
fail("invalid size after update");
- if (json_object_get(object, "a") != nine ||
- json_object_get(object, "b") != nine ||
- json_object_get(object, "f") != nine ||
- json_object_get(object, "g") != nine ||
+ if (json_object_get(object, "a") != nine || json_object_get(object, "b") != nine ||
+ json_object_get(object, "f") != nine || json_object_get(object, "g") != nine ||
json_object_get(object, "h") != nine)
fail("update works incorrectly");
@@ -301,8 +293,7 @@ static void test_recursive_updates() {
if (!json_object_get(object, "foo"))
fail("json_object_update_recursive removed existing key");
- if (json_integer_value(
- json_object_get(json_object_get(object, "bar"), "baz")) != 3)
+ if (json_integer_value(json_object_get(json_object_get(object, "bar"), "baz")) != 3)
fail("json_object_update_recursive failed to update nested value");
barAfter = json_object_get(object, "bar");
@@ -318,14 +309,14 @@ static void test_recursive_updates() {
/* check circular reference */
object = json_pack("{s{s{s{si}}}}", "foo", "bar", "baz", "xxx", 2);
other = json_pack("{s{s{si}}}", "foo", "bar", "baz", 2);
- json_object_set(json_object_get(json_object_get(other, "foo"), "bar"),
- "baz", json_object_get(other, "foo"));
+ json_object_set(json_object_get(json_object_get(other, "foo"), "bar"), "baz",
+ json_object_get(other, "foo"));
if (!json_object_update_recursive(object, other))
fail("json_object_update_recursive update a circular reference!");
- json_object_set_new(json_object_get(json_object_get(other, "foo"), "bar"),
- "baz", json_integer(1));
+ json_object_set_new(json_object_get(json_object_get(other, "foo"), "bar"), "baz",
+ json_integer(1));
if (json_object_update_recursive(object, other))
fail("json_object_update_recursive failed!");
@@ -347,8 +338,7 @@ static void test_circular() {
fail("able to set self");
/* create circular references */
- if (json_object_set(object1, "a", object2) ||
- json_object_set(object2, "a", object1))
+ if (json_object_set(object1, "a", object2) || json_object_set(object2, "a", object1))
fail("unable to set value");
/* circularity is detected when dumping */
@@ -418,8 +408,8 @@ static void test_iterators() {
if (json_object_iter_next(object, NULL))
fail("able to increment a NULL iterator");
- if (json_object_set(object, "a", foo) ||
- json_object_set(object, "b", bar) || json_object_set(object, "c", baz))
+ if (json_object_set(object, "a", foo) || json_object_set(object, "b", bar) ||
+ json_object_set(object, "c", baz))
fail("unable to populate object");
iter = json_object_iter(object);
@@ -518,8 +508,7 @@ static void test_misc() {
fail("got different value than what was added");
/* "a", "lp" and "px" collide in a five-bucket hashtable */
- if (json_object_set(object, "b", string) ||
- json_object_set(object, "lp", string) ||
+ if (json_object_set(object, "b", string) || json_object_set(object, "lp", string) ||
json_object_set(object, "px", string))
fail("unable to set value");
@@ -630,8 +619,7 @@ static void test_object_foreach() {
object1 = json_pack("{sisisi}", "foo", 1, "bar", 2, "baz", 3);
object2 = json_object();
- json_object_foreach(object1, key, value)
- json_object_set(object2, key, value);
+ json_object_foreach(object1, key, value) json_object_set(object2, key, value);
if (!json_equal(object1, object2))
fail("json_object_foreach failed to iterate all key-value pairs");
@@ -647,9 +635,7 @@ static void test_object_foreach_safe() {
object = json_pack("{sisisi}", "foo", 1, "bar", 2, "baz", 3);
- json_object_foreach_safe(object, tmp, key, value) {
- json_object_del(object, key);
- }
+ json_object_foreach_safe(object, tmp, key, value) { json_object_del(object, key); }
if (json_object_size(object) != 0)
fail("json_object_foreach_safe failed to iterate all key-value pairs");
@@ -762,8 +748,7 @@ static void test_bad_args(void) {
if (json_object_iter_next(obj, NULL) != NULL)
fail("json_object_iter_next with NULL iter returned non-NULL");
if (json_object_iter_next(num, iter) != NULL)
- fail(
- "json_object_iter_next with non-object argument returned non-NULL");
+ fail("json_object_iter_next with non-object argument returned non-NULL");
if (json_object_iter_key(NULL) != NULL)
fail("json_object_iter_key with NULL iter returned non-NULL");
diff --git a/test/suites/api/test_pack.c b/test/suites/api/test_pack.c
index dd510a4..865f60b 100644
--- a/test/suites/api/test_pack.c
+++ b/test/suites/api/test_pack.c
@@ -31,18 +31,18 @@ static void test_inifity() {
if (json_pack_ex(&error, 0, "f", INFINITY))
fail("json_pack infinity incorrectly succeeded");
- check_error(json_error_numeric_overflow, "Invalid floating point value",
- "<args>", 1, 1, 1);
+ check_error(json_error_numeric_overflow, "Invalid floating point value", "<args>", 1,
+ 1, 1);
if (json_pack_ex(&error, 0, "[f]", INFINITY))
fail("json_pack infinity array element incorrectly succeeded");
- check_error(json_error_numeric_overflow, "Invalid floating point value",
- "<args>", 1, 2, 2);
+ check_error(json_error_numeric_overflow, "Invalid floating point value", "<args>", 1,
+ 2, 2);
if (json_pack_ex(&error, 0, "{s:f}", "key", INFINITY))
fail("json_pack infinity object value incorrectly succeeded");
- check_error(json_error_numeric_overflow, "Invalid floating point value",
- "<args>", 1, 4, 4);
+ check_error(json_error_numeric_overflow, "Invalid floating point value", "<args>", 1,
+ 4, 4);
#ifdef _MSC_VER
#pragma warning(pop)
@@ -300,8 +300,8 @@ static void run_tests() {
if (json_pack_ex(&error, 0, "{s:i*}", "a", 1))
fail("json_pack object optional invalid incorrectly succeeded");
- check_error(json_error_invalid_format, "Expected format 's', got '*'",
- "<format>", 1, 5, 5);
+ check_error(json_error_invalid_format, "Expected format 's', got '*'", "<format>", 1,
+ 5, 5);
value = json_pack("{s:s*,s:o*,s:O*}", "a", NULL, "b", NULL, "c", NULL);
if (!json_is_object(value) || json_object_size(value) != 0)
@@ -342,8 +342,8 @@ static void run_tests() {
if (json_pack_ex(&error, 0, "[i*]", 1))
fail("json_pack array optional invalid incorrectly succeeded");
- check_error(json_error_invalid_format, "Unexpected format character '*'",
- "<format>", 1, 3, 3);
+ check_error(json_error_invalid_format, "Unexpected format character '*'", "<format>",
+ 1, 3, 3);
value = json_pack("[**]", NULL);
if (value)
@@ -357,18 +357,18 @@ static void run_tests() {
/* Invalid float values */
if (json_pack_ex(&error, 0, "f", NAN))
fail("json_pack NAN incorrectly succeeded");
- check_error(json_error_numeric_overflow, "Invalid floating point value",
- "<args>", 1, 1, 1);
+ check_error(json_error_numeric_overflow, "Invalid floating point value", "<args>", 1,
+ 1, 1);
if (json_pack_ex(&error, 0, "[f]", NAN))
fail("json_pack NAN array element incorrectly succeeded");
- check_error(json_error_numeric_overflow, "Invalid floating point value",
- "<args>", 1, 2, 2);
+ check_error(json_error_numeric_overflow, "Invalid floating point value", "<args>", 1,
+ 2, 2);
if (json_pack_ex(&error, 0, "{s:f}", "key", NAN))
fail("json_pack NAN object value incorrectly succeeded");
- check_error(json_error_numeric_overflow, "Invalid floating point value",
- "<args>", 1, 4, 4);
+ check_error(json_error_numeric_overflow, "Invalid floating point value", "<args>", 1,
+ 4, 4);
#endif
#ifdef INFINITY
@@ -400,42 +400,42 @@ static void run_tests() {
/* newline in format string */
if (json_pack_ex(&error, 0, "{\n\n1"))
fail("json_pack failed to catch invalid format '1'");
- check_error(json_error_invalid_format, "Expected format 's', got '1'",
- "<format>", 3, 1, 4);
+ check_error(json_error_invalid_format, "Expected format 's', got '1'", "<format>", 3,
+ 1, 4);
/* mismatched open/close array/object */
if (json_pack_ex(&error, 0, "[}"))
fail("json_pack failed to catch mismatched '}'");
- check_error(json_error_invalid_format, "Unexpected format character '}'",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Unexpected format character '}'", "<format>",
+ 1, 2, 2);
if (json_pack_ex(&error, 0, "{]"))
fail("json_pack failed to catch mismatched ']'");
- check_error(json_error_invalid_format, "Expected format 's', got ']'",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Expected format 's', got ']'", "<format>", 1,
+ 2, 2);
/* missing close array */
if (json_pack_ex(&error, 0, "["))
fail("json_pack failed to catch missing ']'");
- check_error(json_error_invalid_format, "Unexpected end of format string",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Unexpected end of format string", "<format>",
+ 1, 2, 2);
/* missing close object */
if (json_pack_ex(&error, 0, "{"))
fail("json_pack failed to catch missing '}'");
- check_error(json_error_invalid_format, "Unexpected end of format string",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Unexpected end of format string", "<format>",
+ 1, 2, 2);
/* garbage after format string */
if (json_pack_ex(&error, 0, "[i]a", 42))
fail("json_pack failed to catch garbage after format string");
- check_error(json_error_invalid_format, "Garbage after format string",
- "<format>", 1, 4, 4);
+ check_error(json_error_invalid_format, "Garbage after format string", "<format>", 1,
+ 4, 4);
if (json_pack_ex(&error, 0, "ia", 42))
fail("json_pack failed to catch garbage after format string");
- check_error(json_error_invalid_format, "Garbage after format string",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Garbage after format string", "<format>", 1,
+ 2, 2);
/* NULL string */
if (json_pack_ex(&error, 0, "s", NULL))
@@ -445,20 +445,20 @@ static void run_tests() {
/* + on its own */
if (json_pack_ex(&error, 0, "+", NULL))
fail("json_pack failed to a lone +");
- check_error(json_error_invalid_format, "Unexpected format character '+'",
- "<format>", 1, 1, 1);
+ check_error(json_error_invalid_format, "Unexpected format character '+'", "<format>",
+ 1, 1, 1);
/* Empty format */
if (json_pack_ex(&error, 0, ""))
fail("json_pack failed to catch empty format string");
- check_error(json_error_invalid_argument, "NULL or empty format string",
- "<format>", -1, -1, 0);
+ check_error(json_error_invalid_argument, "NULL or empty format string", "<format>",
+ -1, -1, 0);
/* NULL format */
if (json_pack_ex(&error, 0, NULL))
fail("json_pack failed to catch NULL format string");
- check_error(json_error_invalid_argument, "NULL or empty format string",
- "<format>", -1, -1, 0);
+ check_error(json_error_invalid_argument, "NULL or empty format string", "<format>",
+ -1, -1, 0);
/* NULL key */
if (json_pack_ex(&error, 0, "{s:i}", NULL, 1))
@@ -467,8 +467,7 @@ static void run_tests() {
/* NULL value followed by object still steals the object's ref */
value = json_incref(json_object());
- if (json_pack_ex(&error, 0, "{s:s,s:o}", "badnull", NULL, "dontleak",
- value))
+ if (json_pack_ex(&error, 0, "{s:s,s:o}", "badnull", NULL, "dontleak", value))
fail("json_pack failed to catch NULL value");
check_error(json_error_null_value, "NULL string", "<args>", 1, 4, 4);
if (value->refcount != (size_t)1)
@@ -478,52 +477,47 @@ static void run_tests() {
/* More complicated checks for row/columns */
if (json_pack_ex(&error, 0, "{ {}: s }", "foo"))
fail("json_pack failed to catch object as key");
- check_error(json_error_invalid_format, "Expected format 's', got '{'",
- "<format>", 1, 3, 3);
+ check_error(json_error_invalid_format, "Expected format 's', got '{'", "<format>", 1,
+ 3, 3);
/* Complex object */
if (json_pack_ex(&error, 0, "{ s: {}, s:[ii{} }", "foo", "bar", 12, 13))
fail("json_pack failed to catch missing ]");
- check_error(json_error_invalid_format, "Unexpected format character '}'",
- "<format>", 1, 19, 19);
+ check_error(json_error_invalid_format, "Unexpected format character '}'", "<format>",
+ 1, 19, 19);
/* Complex array */
if (json_pack_ex(&error, 0, "[[[[[ [[[[[ [[[[ }]]]] ]]]] ]]]]]"))
fail("json_pack failed to catch extra }");
- check_error(json_error_invalid_format, "Unexpected format character '}'",
- "<format>", 1, 21, 21);
+ check_error(json_error_invalid_format, "Unexpected format character '}'", "<format>",
+ 1, 21, 21);
/* Invalid UTF-8 in object key */
if (json_pack_ex(&error, 0, "{s:i}", "\xff\xff", 42))
fail("json_pack failed to catch invalid UTF-8 in an object key");
- check_error(json_error_invalid_utf8, "Invalid UTF-8 object key", "<args>",
- 1, 2, 2);
+ check_error(json_error_invalid_utf8, "Invalid UTF-8 object key", "<args>", 1, 2, 2);
/* Invalid UTF-8 in a string */
if (json_pack_ex(&error, 0, "{s:s}", "foo", "\xff\xff"))
fail("json_pack failed to catch invalid UTF-8 in a string");
- check_error(json_error_invalid_utf8, "Invalid UTF-8 string", "<args>", 1, 4,
- 4);
+ check_error(json_error_invalid_utf8, "Invalid UTF-8 string", "<args>", 1, 4, 4);
/* Invalid UTF-8 in an optional '?' string */
if (json_pack_ex(&error, 0, "{s:s?}", "foo", "\xff\xff"))
fail("json_pack failed to catch invalid UTF-8 in an optional '?' "
"string");
- check_error(json_error_invalid_utf8, "Invalid UTF-8 string", "<args>", 1, 5,
- 5);
+ check_error(json_error_invalid_utf8, "Invalid UTF-8 string", "<args>", 1, 5, 5);
/* Invalid UTF-8 in an optional '*' string */
if (json_pack_ex(&error, 0, "{s:s*}", "foo", "\xff\xff"))
fail("json_pack failed to catch invalid UTF-8 in an optional '*' "
"string");
- check_error(json_error_invalid_utf8, "Invalid UTF-8 string", "<args>", 1, 5,
- 5);
+ check_error(json_error_invalid_utf8, "Invalid UTF-8 string", "<args>", 1, 5, 5);
/* Invalid UTF-8 in a concatenated key */
if (json_pack_ex(&error, 0, "{s+:i}", "\xff\xff", "concat", 42))
fail("json_pack failed to catch invalid UTF-8 in an object key");
- check_error(json_error_invalid_utf8, "Invalid UTF-8 object key", "<args>",
- 1, 3, 3);
+ check_error(json_error_invalid_utf8, "Invalid UTF-8 object key", "<args>", 1, 3, 3);
if (json_pack_ex(&error, 0, "{s:o}", "foo", NULL))
fail("json_pack failed to catch nullable object");
@@ -539,13 +533,13 @@ static void run_tests() {
if (json_pack_ex(&error, 0, "[1s", "Hi"))
fail("json_pack failed to catch invalid format");
- check_error(json_error_invalid_format, "Unexpected format character '1'",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Unexpected format character '1'", "<format>",
+ 1, 2, 2);
if (json_pack_ex(&error, 0, "[1s+", "Hi", "ya"))
fail("json_pack failed to catch invalid format");
- check_error(json_error_invalid_format, "Unexpected format character '1'",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Unexpected format character '1'", "<format>",
+ 1, 2, 2);
if (json_pack_ex(&error, 0, "[so]", NULL, json_object()))
fail("json_pack failed to catch NULL value");
diff --git a/test/suites/api/test_unpack.c b/test/suites/api/test_unpack.c
index df5a856..139ec6f 100644
--- a/test/suites/api/test_unpack.c
+++ b/test/suites/api/test_unpack.c
@@ -143,8 +143,8 @@ static void run_tests() {
j = json_integer(42);
if (!json_unpack_ex(j, &error, 0, "z"))
fail("json_unpack succeeded with invalid format character");
- check_error(json_error_invalid_format, "Unexpected format character 'z'",
- "<format>", 1, 1, 1);
+ check_error(json_error_invalid_format, "Unexpected format character 'z'", "<format>",
+ 1, 1, 1);
if (!json_unpack_ex(NULL, &error, 0, "[i]"))
fail("json_unpack succeeded with NULL root");
@@ -155,62 +155,61 @@ static void run_tests() {
j = json_pack("[]");
if (!json_unpack_ex(j, &error, 0, "[}"))
fail("json_unpack failed to catch mismatched ']'");
- check_error(json_error_invalid_format, "Unexpected format character '}'",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Unexpected format character '}'", "<format>",
+ 1, 2, 2);
json_decref(j);
j = json_pack("{}");
if (!json_unpack_ex(j, &error, 0, "{]"))
fail("json_unpack failed to catch mismatched '}'");
- check_error(json_error_invalid_format, "Expected format 's', got ']'",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Expected format 's', got ']'", "<format>", 1,
+ 2, 2);
json_decref(j);
/* missing close array */
j = json_pack("[]");
if (!json_unpack_ex(j, &error, 0, "["))
fail("json_unpack failed to catch missing ']'");
- check_error(json_error_invalid_format, "Unexpected end of format string",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Unexpected end of format string", "<format>",
+ 1, 2, 2);
json_decref(j);
/* missing close object */
j = json_pack("{}");
if (!json_unpack_ex(j, &error, 0, "{"))
fail("json_unpack failed to catch missing '}'");
- check_error(json_error_invalid_format, "Unexpected end of format string",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Unexpected end of format string", "<format>",
+ 1, 2, 2);
json_decref(j);
/* garbage after format string */
j = json_pack("[i]", 42);
if (!json_unpack_ex(j, &error, 0, "[i]a", &i1))
fail("json_unpack failed to catch garbage after format string");
- check_error(json_error_invalid_format, "Garbage after format string",
- "<format>", 1, 4, 4);
+ check_error(json_error_invalid_format, "Garbage after format string", "<format>", 1,
+ 4, 4);
json_decref(j);
j = json_integer(12345);
if (!json_unpack_ex(j, &error, 0, "ia", &i1))
fail("json_unpack failed to catch garbage after format string");
- check_error(json_error_invalid_format, "Garbage after format string",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Garbage after format string", "<format>", 1,
+ 2, 2);
json_decref(j);
/* NULL format string */
j = json_pack("[]");
if (!json_unpack_ex(j, &error, 0, NULL))
fail("json_unpack failed to catch null format string");
- check_error(json_error_invalid_argument, "NULL or empty format string",
- "<format>", -1, -1, 0);
+ check_error(json_error_invalid_argument, "NULL or empty format string", "<format>",
+ -1, -1, 0);
json_decref(j);
/* NULL string pointer */
j = json_string("foobie");
if (!json_unpack_ex(j, &error, 0, "s", NULL))
fail("json_unpack failed to catch null string pointer");
- check_error(json_error_null_value, "NULL string argument", "<args>", 1, 1,
- 1);
+ check_error(json_error_null_value, "NULL string argument", "<args>", 1, 1, 1);
json_decref(j);
/* invalid types */
@@ -218,13 +217,13 @@ static void run_tests() {
j2 = json_string("foo");
if (!json_unpack_ex(j, &error, 0, "s"))
fail("json_unpack failed to catch invalid type");
- check_error(json_error_wrong_type, "Expected string, got integer",
- "<validation>", 1, 1, 1);
+ check_error(json_error_wrong_type, "Expected string, got integer", "<validation>", 1,
+ 1, 1);
if (!json_unpack_ex(j, &error, 0, "n"))
fail("json_unpack failed to catch invalid type");
- check_error(json_error_wrong_type, "Expected null, got integer",
- "<validation>", 1, 1, 1);
+ check_error(json_error_wrong_type, "Expected null, got integer", "<validation>", 1, 1,
+ 1);
if (!json_unpack_ex(j, &error, 0, "b"))
fail("json_unpack failed to catch invalid type");
@@ -233,18 +232,18 @@ static void run_tests() {
if (!json_unpack_ex(j2, &error, 0, "i"))
fail("json_unpack failed to catch invalid type");
- check_error(json_error_wrong_type, "Expected integer, got string",
- "<validation>", 1, 1, 1);
+ check_error(json_error_wrong_type, "Expected integer, got string", "<validation>", 1,
+ 1, 1);
if (!json_unpack_ex(j2, &error, 0, "I"))
fail("json_unpack failed to catch invalid type");
- check_error(json_error_wrong_type, "Expected integer, got string",
- "<validation>", 1, 1, 1);
+ check_error(json_error_wrong_type, "Expected integer, got string", "<validation>", 1,
+ 1, 1);
if (!json_unpack_ex(j, &error, 0, "f"))
fail("json_unpack failed to catch invalid type");
- check_error(json_error_wrong_type, "Expected real, got integer",
- "<validation>", 1, 1, 1);
+ check_error(json_error_wrong_type, "Expected real, got integer", "<validation>", 1, 1,
+ 1);
if (!json_unpack_ex(j2, &error, 0, "F"))
fail("json_unpack failed to catch invalid type");
@@ -253,13 +252,13 @@ static void run_tests() {
if (!json_unpack_ex(j, &error, 0, "[i]"))
fail("json_unpack failed to catch invalid type");
- check_error(json_error_wrong_type, "Expected array, got integer",
- "<validation>", 1, 1, 1);
+ check_error(json_error_wrong_type, "Expected array, got integer", "<validation>", 1,
+ 1, 1);
if (!json_unpack_ex(j, &error, 0, "{si}", "foo"))
fail("json_unpack failed to catch invalid type");
- check_error(json_error_wrong_type, "Expected object, got integer",
- "<validation>", 1, 1, 1);
+ check_error(json_error_wrong_type, "Expected object, got integer", "<validation>", 1,
+ 1, 1);
json_decref(j);
json_decref(j2);
@@ -283,8 +282,8 @@ static void run_tests() {
j = json_pack("{si}", "foo", 42);
if (!json_unpack_ex(j, &error, 0, "{si}", "baz", &i1))
fail("json_unpack failed to catch null string pointer");
- check_error(json_error_item_not_found, "Object item not found: baz",
- "<validation>", 1, 3, 3);
+ check_error(json_error_item_not_found, "Object item not found: baz", "<validation>",
+ 1, 3, 3);
json_decref(j);
/*
@@ -300,16 +299,16 @@ static void run_tests() {
j = json_pack("[iii]", 1, 2, 3);
if (!json_unpack_ex(j, &error, 0, "[ii!]", &i1, &i2))
fail("json_unpack array with strict validation failed");
- check_error(json_error_end_of_input_expected,
- "1 array item(s) left unpacked", "<validation>", 1, 5, 5);
+ check_error(json_error_end_of_input_expected, "1 array item(s) left unpacked",
+ "<validation>", 1, 5, 5);
json_decref(j);
/* Like above, but with JSON_STRICT instead of '!' format */
j = json_pack("[iii]", 1, 2, 3);
if (!json_unpack_ex(j, &error, JSON_STRICT, "[ii]", &i1, &i2))
fail("json_unpack array with strict validation failed");
- check_error(json_error_end_of_input_expected,
- "1 array item(s) left unpacked", "<validation>", 1, 4, 4);
+ check_error(json_error_end_of_input_expected, "1 array item(s) left unpacked",
+ "<validation>", 1, 4, 4);
json_decref(j);
j = json_pack("{s:s, s:i}", "foo", "bar", "baz", 42);
@@ -323,17 +322,16 @@ static void run_tests() {
if (!json_unpack_ex(j, &error, 0, "{s:s,s:s!}", "foo", &s, "foo", &s))
fail("json_unpack object with strict validation failed");
{
- const char *possible_errors[] = {
- "2 object item(s) left unpacked: baz, quux",
- "2 object item(s) left unpacked: quux, baz"};
- check_errors(json_error_end_of_input_expected, possible_errors, 2,
- "<validation>", 1, 10, 10);
+ const char *possible_errors[] = {"2 object item(s) left unpacked: baz, quux",
+ "2 object item(s) left unpacked: quux, baz"};
+ check_errors(json_error_end_of_input_expected, possible_errors, 2, "<validation>",
+ 1, 10, 10);
}
json_decref(j);
j = json_pack("[i,{s:i,s:n},[i,i]]", 1, "foo", 2, "bar", 3, 4);
- if (json_unpack_ex(j, NULL, JSON_STRICT | JSON_VALIDATE_ONLY,
- "[i{sisn}[ii]]", "foo", "bar"))
+ if (json_unpack_ex(j, NULL, JSON_STRICT | JSON_VALIDATE_ONLY, "[i{sisn}[ii]]", "foo",
+ "bar"))
fail("json_unpack complex value with strict validation failed");
json_decref(j);
@@ -341,41 +339,41 @@ static void run_tests() {
j = json_pack("[ii]", 1, 2);
if (!json_unpack_ex(j, &error, 0, "[i!i]", &i1, &i2))
fail("json_unpack failed to catch ! in the middle of an array");
- check_error(json_error_invalid_format, "Expected ']' after '!', got 'i'",
- "<format>", 1, 4, 4);
+ check_error(json_error_invalid_format, "Expected ']' after '!', got 'i'", "<format>",
+ 1, 4, 4);
if (!json_unpack_ex(j, &error, 0, "[i*i]", &i1, &i2))
fail("json_unpack failed to catch * in the middle of an array");
- check_error(json_error_invalid_format, "Expected ']' after '*', got 'i'",
- "<format>", 1, 4, 4);
+ check_error(json_error_invalid_format, "Expected ']' after '*', got 'i'", "<format>",
+ 1, 4, 4);
json_decref(j);
j = json_pack("{sssi}", "foo", "bar", "baz", 42);
if (!json_unpack_ex(j, &error, 0, "{ss!si}", "foo", &s, "baz", &i1))
fail("json_unpack failed to catch ! in the middle of an object");
- check_error(json_error_invalid_format, "Expected '}' after '!', got 's'",
- "<format>", 1, 5, 5);
+ check_error(json_error_invalid_format, "Expected '}' after '!', got 's'", "<format>",
+ 1, 5, 5);
if (!json_unpack_ex(j, &error, 0, "{ss*si}", "foo", &s, "baz", &i1))
fail("json_unpack failed to catch ! in the middle of an object");
- check_error(json_error_invalid_format, "Expected '}' after '*', got 's'",
- "<format>", 1, 5, 5);
+ check_error(json_error_invalid_format, "Expected '}' after '*', got 's'", "<format>",
+ 1, 5, 5);
json_decref(j);
/* Error in nested object */
j = json_pack("{s{snsn}}", "foo", "bar", "baz");
if (!json_unpack_ex(j, &error, 0, "{s{sn!}}", "foo", "bar"))
fail("json_unpack nested object with strict validation failed");
- check_error(json_error_end_of_input_expected,
- "1 object item(s) left unpacked: baz", "<validation>", 1, 7, 7);
+ check_error(json_error_end_of_input_expected, "1 object item(s) left unpacked: baz",
+ "<validation>", 1, 7, 7);
json_decref(j);
/* Error in nested array */
j = json_pack("[[ii]]", 1, 2);
if (!json_unpack_ex(j, &error, 0, "[[i!]]", &i1))
fail("json_unpack nested array with strict validation failed");
- check_error(json_error_end_of_input_expected,
- "1 array item(s) left unpacked", "<validation>", 1, 5, 5);
+ check_error(json_error_end_of_input_expected, "1 array item(s) left unpacked",
+ "<validation>", 1, 5, 5);
json_decref(j);
/* Optional values */
@@ -397,8 +395,7 @@ static void run_tests() {
j = json_object();
i1 = i2 = i3 = 0;
- if (json_unpack(j, "{s?[ii]s?{s{si}}}", "foo", &i1, &i2, "bar", "baz",
- "quux", &i3))
+ if (json_unpack(j, "{s?[ii]s?{s{si}}}", "foo", &i1, &i2, "bar", "baz", "quux", &i3))
fail("json_unpack failed for complex optional values");
if (i1 != 0 || i2 != 0 || i3 != 0)
fail("json_unpack unexpectedly unpacked something");
@@ -428,7 +425,7 @@ static void run_tests() {
if (!json_unpack_ex(j, &error, 0, "{sis?i!}", "foo", &i1, "bar", &i2))
fail("json_unpack failed for optional values with strict mode and "
"compensation");
- check_error(json_error_end_of_input_expected,
- "1 object item(s) left unpacked: baz", "<validation>", 1, 8, 8);
+ check_error(json_error_end_of_input_expected, "1 object item(s) left unpacked: baz",
+ "<validation>", 1, 8, 8);
json_decref(j);
}
diff --git a/test/suites/api/test_version.c b/test/suites/api/test_version.c
index 5083157..05e0e96 100644
--- a/test/suites/api/test_version.c
+++ b/test/suites/api/test_version.c
@@ -26,8 +26,7 @@ static void test_version_cmp() {
}
if (JANSSON_MINOR_VERSION) {
- if (jansson_version_cmp(JANSSON_MAJOR_VERSION,
- JANSSON_MINOR_VERSION - 1,
+ if (jansson_version_cmp(JANSSON_MAJOR_VERSION, JANSSON_MINOR_VERSION - 1,
JANSSON_MICRO_VERSION) <= 0) {
fail("jansson_version_cmp less than check failed");
}
diff --git a/test/suites/api/util.h b/test/suites/api/util.h
index cf8a4dd..d964c49 100644
--- a/test/suites/api/util.h
+++ b/test/suites/api/util.h
@@ -22,66 +22,62 @@
#define failhdr fprintf(stderr, "%s:%d: ", __FILE__, __LINE__)
-#define fail(msg) \
- do { \
- failhdr; \
- fprintf(stderr, "%s\n", msg); \
- exit(1); \
+#define fail(msg) \
+ do { \
+ failhdr; \
+ fprintf(stderr, "%s\n", msg); \
+ exit(1); \
} while (0)
/* Assumes json_error_t error */
-#define check_errors(code_, texts_, num_, source_, line_, column_, position_) \
- do { \
- int i_, found_ = 0; \
- if (json_error_code(&error) != code_) { \
- failhdr; \
- fprintf(stderr, "code: %d != %d\n", json_error_code(&error), \
- code_); \
- exit(1); \
- } \
- for (i_ = 0; i_ < num_; i_++) { \
- if (strcmp(error.text, texts_[i_]) == 0) { \
- found_ = 1; \
- break; \
- } \
- } \
- if (!found_) { \
- failhdr; \
- if (num_ == 1) { \
- fprintf(stderr, "text: \"%s\" != \"%s\"\n", error.text, \
- texts_[0]); \
- } else { \
- fprintf(stderr, "text: \"%s\" does not match\n", error.text); \
- } \
- exit(1); \
- } \
- if (strcmp(error.source, source_) != 0) { \
- failhdr; \
- \
- fprintf(stderr, "source: \"%s\" != \"%s\"\n", error.source, \
- source_); \
- exit(1); \
- } \
- if (error.line != line_) { \
- failhdr; \
- fprintf(stderr, "line: %d != %d\n", error.line, line_); \
- exit(1); \
- } \
- if (error.column != column_) { \
- failhdr; \
- fprintf(stderr, "column: %d != %d\n", error.column, column_); \
- exit(1); \
- } \
- if (error.position != position_) { \
- failhdr; \
- fprintf(stderr, "position: %d != %d\n", error.position, \
- position_); \
- exit(1); \
- } \
+#define check_errors(code_, texts_, num_, source_, line_, column_, position_) \
+ do { \
+ int i_, found_ = 0; \
+ if (json_error_code(&error) != code_) { \
+ failhdr; \
+ fprintf(stderr, "code: %d != %d\n", json_error_code(&error), code_); \
+ exit(1); \
+ } \
+ for (i_ = 0; i_ < num_; i_++) { \
+ if (strcmp(error.text, texts_[i_]) == 0) { \
+ found_ = 1; \
+ break; \
+ } \
+ } \
+ if (!found_) { \
+ failhdr; \
+ if (num_ == 1) { \
+ fprintf(stderr, "text: \"%s\" != \"%s\"\n", error.text, texts_[0]); \
+ } else { \
+ fprintf(stderr, "text: \"%s\" does not match\n", error.text); \
+ } \
+ exit(1); \
+ } \
+ if (strcmp(error.source, source_) != 0) { \
+ failhdr; \
+ \
+ fprintf(stderr, "source: \"%s\" != \"%s\"\n", error.source, source_); \
+ exit(1); \
+ } \
+ if (error.line != line_) { \
+ failhdr; \
+ fprintf(stderr, "line: %d != %d\n", error.line, line_); \
+ exit(1); \
+ } \
+ if (error.column != column_) { \
+ failhdr; \
+ fprintf(stderr, "column: %d != %d\n", error.column, column_); \
+ exit(1); \
+ } \
+ if (error.position != position_) { \
+ failhdr; \
+ fprintf(stderr, "position: %d != %d\n", error.position, position_); \
+ exit(1); \
+ } \
} while (0)
/* Assumes json_error_t error */
-#define check_error(code_, text_, source_, line_, column_, position_) \
+#define check_error(code_, text_, source_, line_, column_, position_) \
check_errors(code_, &text_, 1, source_, line_, column_, position_)
static void run_tests();