Merge branch '2.2'
[profile/ivi/jansson.git] / test / suites / api / test_unpack.c
index b7935a8..b259b5f 100644 (file)
@@ -11,7 +11,7 @@
 #include <stdio.h>
 #include "util.h"
 
-int main()
+static void run_tests()
 {
     json_t *j, *j2;
     int i1, i2, i3;
@@ -122,6 +122,13 @@ int main()
         fail("json_unpack simple array failed");
     json_decref(j);
 
+    /* object with many items & strict checking */
+    j = json_pack("{s:i, s:i, s:i}", "a", 1, "b", 2, "c", 3);
+    rv = json_unpack(j, "{s:i, s:i, s:i}", "a", &i1, "b", &i2, "c", &i3);
+    if(rv || i1 != 1 || i2 != 2 || i3 != 3)
+        fail("json_unpack object with many items failed");
+    json_decref(j);
+
     /*
      * Invalid cases
      */
@@ -134,6 +141,7 @@ int main()
     if(!json_unpack_ex(NULL, &error, 0, "[i]"))
         fail("json_unpack succeeded with NULL root");
     check_error("NULL root value", "<root>", -1, -1, 0);
+    json_decref(j);
 
     /* mismatched open/close array/object */
     j = json_pack("[]");
@@ -167,11 +175,13 @@ int main()
     if(!json_unpack_ex(j, &error, 0, "[i]a", &i1))
         fail("json_unpack failed to catch garbage after format string");
     check_error("Garbage after format string", "<format>", 1, 4, 4);
+    json_decref(j);
 
     j = json_integer(12345);
     if(!json_unpack_ex(j, &error, 0, "ia", &i1))
         fail("json_unpack failed to catch garbage after format string");
     check_error("Garbage after format string", "<format>", 1, 2, 2);
+    json_decref(j);
 
     /* NULL format string */
     j = json_pack("[]");
@@ -282,7 +292,7 @@ int main()
     /* Unpack the same item twice */
     j = json_pack("{s:s, s:i}", "foo", "bar", "baz", 42);
     if(!json_unpack_ex(j, &error, 0, "{s:s,s:s!}", "foo", &s, "foo", &s))
-       fail("json_unpack object with strict validation failed");
+        fail("json_unpack object with strict validation failed");
     check_error("1 object item(s) left unpacked", "<validation>", 1, 10, 10);
     json_decref(j);
 
@@ -326,6 +336,4 @@ int main()
         fail("json_unpack nested array with strict validation failed");
     check_error("1 array item(s) left unpacked", "<validation>", 1, 5, 5);
     json_decref(j);
-
-    return 0;
 }