Wireless Daemon for Linux
 help / color / mirror / Atom feed
From: James Prestwood <prestwoj at gmail.com>
To: iwd at lists.01.org
Subject: [PATCH 2/5] unit: add strings to several json iteration tests
Date: Thu, 06 Jan 2022 14:42:13 -0800	[thread overview]
Message-ID: <20220106224216.569171-2-prestwoj@gmail.com> (raw)
In-Reply-To: 20220106224216.569171-1-prestwoj@gmail.com

[-- Attachment #1: Type: text/plain, Size: 3206 bytes --]

---
 unit/test-json.c | 43 ++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 38 insertions(+), 5 deletions(-)

diff --git a/unit/test-json.c b/unit/test-json.c
index d160f6b7..fb87987d 100644
--- a/unit/test-json.c
+++ b/unit/test-json.c
@@ -315,7 +315,7 @@ static void test_json_arrays(const void *data)
 			"\"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]}";
+			"\"mixed_array\":[1, -1, true, false, null, \"string\"]}";
 
 	struct json_iter iter;
 	struct json_iter i_array, ui_array, b_array, n_array,
@@ -372,25 +372,34 @@ static void test_json_arrays(const void *data)
 	count = 0;
 
 	while (json_iter_next(&m_array)) {
-		assert(json_iter_get_type(&m_array) == JSON_PRIMITIVE);
+		_auto_(l_free) char *str = NULL;
 
 		switch (count) {
 		case 0:
+			assert(json_iter_get_type(&m_array) == JSON_PRIMITIVE);
 			assert(json_iter_get_uint(&m_array, &ui));
 			assert(ui == 1);
 			break;
 		case 1:
+			assert(json_iter_get_type(&m_array) == JSON_PRIMITIVE);
 			assert(json_iter_get_int(&m_array, &i));
 			assert(i == -1);
 			break;
 		case 2:
 		case 3:
+			assert(json_iter_get_type(&m_array) == JSON_PRIMITIVE);
 			assert(json_iter_get_boolean(&m_array, &b));
 			assert(b == count % 2 ? false : true);
 			break;
 		case 4:
+			assert(json_iter_get_type(&m_array) == JSON_PRIMITIVE);
 			assert(json_iter_get_null(&m_array));
 			break;
+		case 5:
+			assert(json_iter_get_type(&m_array) == JSON_STRING);
+			assert(json_iter_get_string(&m_array, &str));
+			assert(!strcmp(str, "string"));
+			break;
 		}
 
 		count++;
@@ -425,7 +434,7 @@ static void test_json_arrays(const void *data)
 
 static void test_json_nested_arrays(const void *data)
 {
-	char json[] = "{\"array\":[[], {}, [1, 2], {\"key\":\"value\"}]}";
+	char json[] = "{\"array\":[[], {}, [1, 2], {\"key\":\"value\"}, [\"one\",\"two\"]]}";
 	int count = 0;
 	struct json_iter iter;
 	struct json_iter array;
@@ -442,8 +451,29 @@ static void test_json_nested_arrays(const void *data)
 
 		assert(json_iter_get_container(&array, &inner));
 
-		while (json_iter_next(&inner))
+		while (json_iter_next(&inner)) {
+			_auto_(l_free) char *str = NULL;
+
+			switch (count) {
+			case 0:
+			case 1:
+				assert(false);
+				break;
+			case 4:
+				assert(json_iter_get_type(&inner) ==
+							JSON_STRING);
+				assert(json_iter_get_string(&inner, &str));
+
+				if (count2 == 0)
+					assert(!strcmp("one", str));
+				else
+					assert(!strcmp("two", str));
+
+				break;
+			}
+
 			count2++;
+		}
 
 		/*
 		 * TODO: add checks for object iteration. Currently these will
@@ -456,6 +486,9 @@ static void test_json_nested_arrays(const void *data)
 		case 2:
 			assert(count2 == 2);
 			break;
+		case 4:
+			assert(count2 == 2);
+			break;
 		default:
 			break;
 		}
@@ -463,7 +496,7 @@ static void test_json_nested_arrays(const void *data)
 		count++;
 	}
 
-	assert(count == 4);
+	assert(count == 5);
 
 	json_contents_free(c);
 }
-- 
2.31.1

                 reply	other threads:[~2022-01-06 22:42 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=20220106224216.569171-2-prestwoj@gmail.com \
    --to=iwd@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox