2 * Copyright (c) 2009 Petri Lehtinen <petri@digip.org>
4 * Jansson is free software; you can redistribute it and/or modify
5 * it under the terms of the MIT license. See LICENSE for details.
13 json_t *array, *five, *seven, *value;
17 five = json_integer(5);
18 seven = json_integer(7);
21 fail("unable to create array");
23 fail("unable to create integer");
25 fail("unable to create integer");
27 if(json_array_size(array) != 0)
28 fail("empty array has nonzero size");
30 if(!json_array_append(array, NULL))
31 fail("able to append NULL");
33 if(json_array_append(array, five))
34 fail("unable to append");
36 if(json_array_size(array) != 1)
37 fail("wrong array size");
39 value = json_array_get(array, 0);
41 fail("unable to get item");
43 fail("got wrong value");
45 if(json_array_append(array, seven))
46 fail("unable to append value");
48 if(json_array_size(array) != 2)
49 fail("wrong array size");
51 value = json_array_get(array, 1);
53 fail("unable to get item");
55 fail("got wrong value");
57 if(json_array_set(array, 0, seven))
58 fail("unable to set value");
60 if(!json_array_set(array, 0, NULL))
61 fail("able to set NULL");
63 if(json_array_size(array) != 2)
64 fail("wrong array size");
66 value = json_array_get(array, 0);
68 fail("unable to get item");
70 fail("got wrong value");
72 if(json_array_get(array, 2) != NULL)
73 fail("able to get value out of bounds");
75 if(!json_array_set(array, 2, seven))
76 fail("able to set value out of bounds");
78 for(i = 2; i < 30; i++) {
79 if(json_array_append(array, seven))
80 fail("unable to append value");
82 if(json_array_size(array) != i + 1)
83 fail("wrong array size");
86 for(i = 0; i < 30; i++) {
87 value = json_array_get(array, i);
89 fail("unable to get item");
91 fail("got wrong value");
94 if(json_array_set_new(array, 15, json_integer(123)))
95 fail("unable to set new value");
97 value = json_array_get(array, 15);
98 if(!json_is_integer(value) || json_integer_value(value) != 123)
99 fail("json_array_set_new works incorrectly");
101 if(!json_array_set_new(array, 15, NULL))
102 fail("able to set_new NULL value");
104 if(json_array_append_new(array, json_integer(321)))
105 fail("unable to append new value");
107 value = json_array_get(array, json_array_size(array) - 1);
108 if(!json_is_integer(value) || json_integer_value(value) != 321)
109 fail("json_array_append_new works incorrectly");
111 if(!json_array_append_new(array, NULL))
112 fail("able to append_new NULL value");