Add _nocheck functions
[jansson.git] / test / suites / api / test_object.c
index 57650e8..7e9ada8 100644 (file)
@@ -167,6 +167,44 @@ static void test_circular()
     json_decref(object1);
 }
 
+static void test_set_nocheck()
+{
+    json_t *object, *string;
+
+    object = json_object();
+    string = json_string("bar");
+
+    if(!object)
+        fail("unable to create object");
+    if(!string)
+        fail("unable to create string");
+
+    if(json_object_set_nocheck(object, "foo", string))
+        fail("json_object_set_nocheck failed");
+    if(json_object_get(object, "foo") != string)
+        fail("json_object_get after json_object_set_nocheck failed");
+
+    /* invalid UTF-8 in key */
+    if(json_object_set_nocheck(object, "a\xefz", string))
+        fail("json_object_set_nocheck failed for invalid UTF-8");
+    if(json_object_get(object, "a\xefz") != string)
+        fail("json_object_get after json_object_set_nocheck failed");
+
+    if(json_object_set_new_nocheck(object, "bax", json_integer(123)))
+        fail("json_object_set_new_nocheck failed");
+    if(json_integer_value(json_object_get(object, "bax")) != 123)
+        fail("json_object_get after json_object_set_new_nocheck failed");
+
+    /* invalid UTF-8 in key */
+    if(json_object_set_new_nocheck(object, "asdf\xfe", json_integer(321)))
+        fail("json_object_set_new_nocheck failed for invalid UTF-8");
+    if(json_integer_value(json_object_get(object, "asdf\xfe")) != 321)
+        fail("json_object_get after json_object_set_new_nocheck failed");
+
+    json_decref(string);
+    json_decref(object);
+}
+
 static void test_misc()
 {
     json_t *object, *string, *other_string, *value;
@@ -293,6 +331,7 @@ int main()
     test_clear();
     test_update();
     test_circular();
+    test_set_nocheck();
 
     return 0;
 }