tests/test_json.c

changeset 941
9077724b75a0
parent 939
0bb7258366a0
child 946
b428424c0214
--- a/tests/test_json.c	Sun Oct 20 12:30:30 2024 +0200
+++ b/tests/test_json.c	Tue Oct 22 12:16:16 2024 +0200
@@ -148,11 +148,48 @@
     }
 }
 
+CX_TEST(test_json_object_error) {
+    cxstring text0 = cx_str(
+            "{\n"
+            "\t\"message\":\"success\",\n"
+            "\t\"data\":{\n"
+            "\t\t\"obj\":{\n"
+            "\t\t\t\"array\": [1, 2, 3, ?syntaxerror? ]\n"
+            "\t\t\"}\n"
+            "\t},\n"
+            "\t\"timestamp\":1729348561,\n"
+            "}"
+    );
+    cxstring text1 = cx_str("{ \"string\" }");
+    cxstring text2 = cx_str("{ \"a\" : }");
+    cxstring text3 = cx_str("{ \"a\" : \"b\" ]");
+    cxstring text4 = cx_str("{ \"name\": \"value\" ]");
+    
+    cxstring tests[] = { text0, text1, text2, text3, text4 };
+    
+    CX_TEST_DO {
+        int result;
+        CxJson json;
+        CxJsonValue *obj = NULL;
+        
+        for(int i=0;i<5;i++) {
+            cxJsonInit(&json);
+            cxJsonFill(&json, tests[i].ptr, tests[i].length);
+            result = cxJsonNext(&json, &obj);
+
+            CX_TEST_ASSERT(result == -1);
+            CX_TEST_ASSERT(obj == NULL);
+            cxJsonDestroy(&json);
+        }
+    }
+}
+
 CxTestSuite *cx_test_suite_json(void) {
     CxTestSuite *suite = cx_test_suite_new("json");
 
     cx_test_register(suite, test_json_simple_object);
     cx_test_register(suite, test_json_object_incomplete_token);
+    cx_test_register(suite, test_json_object_error);
 
     return suite;
 }

mercurial