[systemd-devel] [PATCH 3/5] test/test-json: Tests for the JSON parser and the tokenizer bugfix

Pavel Odvody podvody at redhat.com
Thu May 7 08:47:30 PDT 2015


Signed-off-by: Pavel Odvody <podvody at redhat.com>
---
 src/test/test-json.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/test/test-json.c b/src/test/test-json.c
index 24dc700..745eeb0 100644
--- a/src/test/test-json.c
+++ b/src/test/test-json.c
@@ -72,6 +72,17 @@ static void test_one(const char *data, ...) {
         va_end(ap);
 }
 
+static void test_file(const char *data) {
+        json_variant *v = NULL;
+        int r = json_parse(data, &v);
+
+        assert_se(r == 0);
+        assert_se(v != NULL);
+        assert_se(v->type == JSON_VARIANT_OBJECT);
+
+        json_variant_unref(v);
+}
+
 int main(int argc, char *argv[]) {
 
         test_one("x", -EINVAL);
@@ -102,5 +113,10 @@ int main(int argc, char *argv[]) {
         test_one("\"\\udc00\\udc00\"", -EINVAL);
         test_one("\"\\ud801\\udc37\"", JSON_STRING, "\xf0\x90\x90\xb7", JSON_END);
 
+        test_one("[1, 2]", JSON_ARRAY_OPEN, JSON_INTEGER, 1, JSON_COMMA, JSON_INTEGER, 2, JSON_ARRAY_CLOSE, JSON_END);
+
+        test_file("{\"k\": \"v\", \"foo\": [1, 2, 3], \"bar\": {\"zap\": null}}");
+        test_file("{\"mutant\": [1, null, \"1\", {\"1\": [1, \"1\"]}], \"blah\": 1.27}");
+
         return 0;
 }
-- 
2.1.0

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20150507/cb71088e/attachment.sig>


More information about the systemd-devel mailing list