test/json.c

changeset 44
3bac2715ccb9
parent 43
73c1ced3a620
child 46
96e139ab57f2
--- a/test/json.c	Sun Jan 04 18:09:59 2026 +0100
+++ b/test/json.c	Mon Jan 05 21:37:39 2026 +0100
@@ -397,7 +397,7 @@
         
         CX_TEST_ASSERT(obj);
         CX_TEST_ASSERT(!cx_strcmp(obj->test, "hello world"));
-        CX_TEST_ASSERT(obj->test2List);
+        CX_TEST_ASSERT(obj->test2List != NULL);
         CX_TEST_ASSERT(cxListSize(obj->test2List) == 2);
         
         Test2 *elm0 = cxListAt(obj->test2List, 0);
@@ -415,3 +415,54 @@
         free(obj);
     }
 }
+
+CX_TEST(testJsonToObjectWithEmptyArray) {
+    const char *jsonStr =
+        "{"
+        "\"test\":\"hello world 2\","
+        "\"test2List\":[ ]"
+        "}";
+    
+    CxJsonValue *json;
+    cxJsonFromString(NULL, jsonStr, &json);
+    
+    CX_TEST_DO {
+        Test5 *obj = dbuJsonToObject(test5_class, NULL, json);
+        
+        CX_TEST_ASSERT(obj);
+        CX_TEST_ASSERT(!cx_strcmp(obj->test, "hello world 2"));
+        CX_TEST_ASSERT(obj->test2List == NULL || cxListSize(obj->test2List) == 0);
+        
+        free(obj);
+    }
+}
+
+CX_TEST(testJsonToObjectWithNullArray) {
+    const char *jsonStr =
+        "{"
+        "\"test\":\"hello world 3\","
+        "\"test2List\":[ null, null, null ]"
+        "}";
+    
+    CxJsonValue *json;
+    cxJsonFromString(NULL, jsonStr, &json);
+    
+    CX_TEST_DO {
+        Test5 *obj = dbuJsonToObject(test5_class, NULL, json);
+        
+        CX_TEST_ASSERT(obj);
+        CX_TEST_ASSERT(!cx_strcmp(obj->test, "hello world 3"));
+        CX_TEST_ASSERT(obj->test2List != NULL);
+        CX_TEST_ASSERT(cxListSize(obj->test2List) == 3);
+        
+        Test2 *elm0 = cxListAt(obj->test2List, 0);
+        Test2 *elm1 = cxListAt(obj->test2List, 1);
+        Test2 *elm2 = cxListAt(obj->test2List, 2);
+        
+        CX_TEST_ASSERT(elm0 == NULL);
+        CX_TEST_ASSERT(elm1 == NULL);
+        CX_TEST_ASSERT(elm2 == NULL);
+        
+        free(obj);
+    }
+}

mercurial