]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Test if JSON parser fails on invalid input
authorJán Tomko <jtomko@redhat.com>
Mon, 14 Oct 2013 13:37:06 +0000 (15:37 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 20 Nov 2013 11:32:15 +0000 (12:32 +0100)
tests/jsontest.c

index 6add816bf053b5af9c4f270e55b3a2ea95cce397..73d8b0290f26f0e3a8a81498703a358a76dca563 100644 (file)
@@ -145,6 +145,10 @@ mymain(void)
 #define DO_TEST_PARSE(name, doc)                \
     DO_TEST_FULL(name, FromString, doc, NULL, true)
 
+#define DO_TEST_PARSE_FAIL(name, doc)           \
+    DO_TEST_FULL(name, FromString, doc, NULL, false)
+
+
     DO_TEST_PARSE("Simple", "{\"return\": {}, \"id\": \"libvirt-1\"}");
     DO_TEST_PARSE("NotSoSimple", "{\"QMP\": {\"version\": {\"qemu\":"
             "{\"micro\": 91, \"minor\": 13, \"major\": 0},"
@@ -188,6 +192,22 @@ mymain(void)
     DO_TEST_FULL("add and remove", AddRemove,
                  "[ 1 ]", NULL, false);
 
+
+    DO_TEST_PARSE("almost nothing", "[]");
+    DO_TEST_PARSE_FAIL("nothing", "");
+
+    DO_TEST_PARSE("number without garbage", "[ 234545 ]");
+    DO_TEST_PARSE_FAIL("number with garbage", "[ 2345b45 ]");
+
+    DO_TEST_PARSE("float without garbage", "[ 0.0314159e+100 ]");
+    DO_TEST_PARSE_FAIL("float with garbage", "[ 0.0314159ee+100 ]");
+
+    DO_TEST_PARSE("string", "[ \"The meaning of life\" ]");
+
+    DO_TEST_PARSE_FAIL("object with numeric keys", "{ 1:1, 2:1, 3:2 }");
+    DO_TEST_PARSE_FAIL("array of an object with an array as a key",
+                       "[ {[\"key1\", \"key2\"]: \"value\"} ]");
+
     return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 }