From: James Prestwood <prestwoj at gmail.com>
To: iwd at lists.01.org
Subject: [PATCH 7/8] unit: add arrays of objects test
Date: Wed, 05 Jan 2022 10:46:26 -0800 [thread overview]
Message-ID: <20220105184627.329505-7-prestwoj@gmail.com> (raw)
In-Reply-To: 20220105184627.329505-1-prestwoj@gmail.com
[-- Attachment #1: Type: text/plain, Size: 1827 bytes --]
---
unit/test-json.c | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/unit/test-json.c b/unit/test-json.c
index 1a7daaff..52e3f675 100644
--- a/unit/test-json.c
+++ b/unit/test-json.c
@@ -315,10 +315,12 @@ static void test_json_arrays(const void *data)
"\"int_array\":[-1, -2, -3, -4, -5, -6],"
"\"bool_array\":[true, false, true, false],"
"\"null_array\":[null, null, null, null],"
+ "\"obj_array\":[{}, {\"key\":\"value\", \"key2\":\"value2\"}],"
"\"mixed_array\":[1, -1, true, false, null]}";
struct json_iter iter;
- struct json_iter i_array, ui_array, b_array, n_array, m_array;
+ struct json_iter i_array, ui_array, b_array, n_array,
+ m_array, obj_array;
struct json_contents *c = json_contents_new(json, strlen(json));
json_iter_init(&iter, c);
@@ -328,6 +330,7 @@ static void test_json_arrays(const void *data)
JSON_MANDATORY("bool_array", JSON_ARRAY, &b_array),
JSON_MANDATORY("int_array", JSON_ARRAY, &i_array),
JSON_MANDATORY("uint_array", JSON_ARRAY, &ui_array),
+ JSON_MANDATORY("obj_array", JSON_ARRAY, &obj_array),
JSON_UNDEFINED));
count = 1;
@@ -394,6 +397,30 @@ static void test_json_arrays(const void *data)
count++;
}
+ count = 0;
+
+ while (json_iter_next(&obj_array)) {
+ struct json_iter object;
+
+ assert(json_iter_get_type(&obj_array) == JSON_OBJECT);
+ assert(json_iter_get_container(&obj_array, &object));
+
+ switch (count) {
+ case 0:
+ assert(json_iter_parse(&object, JSON_UNDEFINED));
+ break;
+ case 1:
+ assert(json_iter_parse(&object,
+ JSON_MANDATORY("key", JSON_STRING, NULL),
+ JSON_UNDEFINED));
+ break;
+ }
+
+ count++;
+ }
+
+ assert(count == 2);
+
json_contents_free(c);
}
--
2.31.1
reply other threads:[~2022-01-05 18:46 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220105184627.329505-7-prestwoj@gmail.com \
--to=unknown@example.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.