2 * Copyright (c) 2009, 2010 Petri Lehtinen <petri@digip.org>
3 * Copyright (c) 2010 Graeme Smecher <graeme.smecher@mail.mcgill.ca>
5 * Jansson is free software; you can redistribute it and/or modify
6 * it under the terms of the MIT license. See LICENSE for details.
24 * Simple, valid json_pack cases
28 rv = json_unpack(json_true(), NULL, "b", &i1);
30 fail("json_unpack boolean failed");
33 rv = json_unpack(json_false(), NULL, "b", &i1);
35 fail("json_unpack boolean failed");
38 rv = json_unpack(json_null(), NULL, "n");
40 fail("json_unpack null failed");
44 rv = json_unpack(j, NULL, "i", &i1);
46 fail("json_unpack integer failed");
51 rv = json_unpack(j, NULL, "f", &f);
53 fail("json_unpack real failed");
57 j = json_string("foo");
58 rv = json_unpack(j, NULL, "s", &s);
59 if(rv || strcmp(s, "foo"))
60 fail("json_unpack string failed");
65 rv = json_unpack(j, NULL, "{}");
67 fail("json_unpack empty object failed");
72 rv = json_unpack(j, NULL, "[]");
74 fail("json_unpack empty list failed");
77 /* non-incref'd object */
79 rv = json_unpack(j, NULL, "o", &j2);
80 if(j2 != j || j->refcount != (ssize_t)1)
81 fail("json_unpack object failed");
86 rv = json_unpack(j, NULL, "O", &j2);
87 if(j2 != j || j->refcount != (ssize_t)2)
88 fail("json_unpack object failed");
93 j = json_pack(NULL, "{s:i}", "foo", 1);
94 rv = json_unpack(j, NULL, "{s:i}", "foo", &i1);
96 fail("json_unpack simple object failed");
100 j = json_pack(NULL, "[iii]", 1, 2, 3);
101 rv = json_unpack(j, NULL, "[i,i,i]", &i1, &i2, &i3);
102 if(rv || i1 != 1 || i2 != 2 || i3 != 3)
103 fail("json_unpack simple array failed");
109 /* vim: ts=4:expandtab:sw=4