Deleted Added
full compact
test_generate.c (275223) test_generate.c (279549)
1/* Copyright (c) 2013, Vsevolod Stakhov
2 * All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright

--- 16 unchanged lines hidden (view full) ---

25#include <errno.h>
26#include <assert.h>
27#include "ucl.h"
28
29int
30main (int argc, char **argv)
31{
32 ucl_object_t *obj, *cur, *ar, *ref;
1/* Copyright (c) 2013, Vsevolod Stakhov
2 * All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright

--- 16 unchanged lines hidden (view full) ---

25#include <errno.h>
26#include <assert.h>
27#include "ucl.h"
28
29int
30main (int argc, char **argv)
31{
32 ucl_object_t *obj, *cur, *ar, *ref;
33 const ucl_object_t *found;
33 ucl_object_iter_t it;
34 const ucl_object_t *found, *it_obj;
34 FILE *out;
35 unsigned char *emitted;
36 const char *fname_out = NULL;
37 int ret = 0;
38
39 switch (argc) {
40 case 2:
41 fname_out = argv[1];

--- 12 unchanged lines hidden (view full) ---

54 }
55
56 obj = ucl_object_typed_new (UCL_OBJECT);
57
58 /* Keys replacing */
59 cur = ucl_object_fromstring_common ("value1", 0, UCL_STRING_TRIM);
60 ucl_object_insert_key (obj, cur, "key0", 0, false);
61 cur = ucl_object_fromdouble (0.1);
35 FILE *out;
36 unsigned char *emitted;
37 const char *fname_out = NULL;
38 int ret = 0;
39
40 switch (argc) {
41 case 2:
42 fname_out = argv[1];

--- 12 unchanged lines hidden (view full) ---

55 }
56
57 obj = ucl_object_typed_new (UCL_OBJECT);
58
59 /* Keys replacing */
60 cur = ucl_object_fromstring_common ("value1", 0, UCL_STRING_TRIM);
61 ucl_object_insert_key (obj, cur, "key0", 0, false);
62 cur = ucl_object_fromdouble (0.1);
62 ucl_object_replace_key (obj, cur, "key0", 0, false);
63 assert (ucl_object_replace_key (obj, cur, "key0", 0, false));
63
64 /* Create some strings */
65 cur = ucl_object_fromstring_common (" test string ", 0, UCL_STRING_TRIM);
66 ucl_object_insert_key (obj, cur, "key1", 0, false);
67 cur = ucl_object_fromstring_common (" test \nstring\n ", 0, UCL_STRING_TRIM | UCL_STRING_ESCAPE);
68 ucl_object_insert_key (obj, cur, "key2", 0, false);
69 cur = ucl_object_fromstring_common (" test string \n", 0, 0);
70 ucl_object_insert_key (obj, cur, "key3", 0, false);

--- 63 unchanged lines hidden (view full) ---

134 assert (found != NULL && ucl_object_toint (found) == 10);
135 /* No such index */
136 found = ucl_lookup_path (obj, ".key4.3");
137 assert (found == NULL);
138 /* No such key */
139 found = ucl_lookup_path (obj, "key9..key1");
140 assert (found == NULL);
141
64
65 /* Create some strings */
66 cur = ucl_object_fromstring_common (" test string ", 0, UCL_STRING_TRIM);
67 ucl_object_insert_key (obj, cur, "key1", 0, false);
68 cur = ucl_object_fromstring_common (" test \nstring\n ", 0, UCL_STRING_TRIM | UCL_STRING_ESCAPE);
69 ucl_object_insert_key (obj, cur, "key2", 0, false);
70 cur = ucl_object_fromstring_common (" test string \n", 0, 0);
71 ucl_object_insert_key (obj, cur, "key3", 0, false);

--- 63 unchanged lines hidden (view full) ---

135 assert (found != NULL && ucl_object_toint (found) == 10);
136 /* No such index */
137 found = ucl_lookup_path (obj, ".key4.3");
138 assert (found == NULL);
139 /* No such key */
140 found = ucl_lookup_path (obj, "key9..key1");
141 assert (found == NULL);
142
143 /* Test iteration */
144 it = ucl_object_iterate_new (obj);
145 it_obj = ucl_object_iterate_safe (it, true);
146 /* key0 = 0.1 */
147 assert (ucl_object_type (it_obj) == UCL_FLOAT);
148 it_obj = ucl_object_iterate_safe (it, true);
149 /* key1 = "" */
150 assert (ucl_object_type (it_obj) == UCL_STRING);
151 it_obj = ucl_object_iterate_safe (it, true);
152 /* key2 = "" */
153 assert (ucl_object_type (it_obj) == UCL_STRING);
154 it_obj = ucl_object_iterate_safe (it, true);
155 /* key3 = "" */
156 assert (ucl_object_type (it_obj) == UCL_STRING);
157 it_obj = ucl_object_iterate_safe (it, true);
158 /* key4 = ([float, int, float], boolean) */
159 ucl_object_iterate_reset (it, it_obj);
160 it_obj = ucl_object_iterate_safe (it, true);
161 assert (ucl_object_type (it_obj) == UCL_FLOAT);
162 it_obj = ucl_object_iterate_safe (it, true);
163 assert (ucl_object_type (it_obj) == UCL_INT);
164 it_obj = ucl_object_iterate_safe (it, true);
165 assert (ucl_object_type (it_obj) == UCL_FLOAT);
166 it_obj = ucl_object_iterate_safe (it, true);
167 assert (ucl_object_type (it_obj) == UCL_BOOLEAN);
168 ucl_object_iterate_free (it);
169
142 emitted = ucl_object_emit (obj, UCL_EMIT_CONFIG);
143
144 fprintf (out, "%s\n", emitted);
145 ucl_object_unref (obj);
146
147 if (emitted != NULL) {
148 free (emitted);
149 }
150 fclose (out);
151
152 /* Ref should still be accessible */
153 ref->value.iv = 100500;
154 ucl_object_unref (ref);
155
156 return ret;
157}
170 emitted = ucl_object_emit (obj, UCL_EMIT_CONFIG);
171
172 fprintf (out, "%s\n", emitted);
173 ucl_object_unref (obj);
174
175 if (emitted != NULL) {
176 free (emitted);
177 }
178 fclose (out);
179
180 /* Ref should still be accessible */
181 ref->value.iv = 100500;
182 ucl_object_unref (ref);
183
184 return ret;
185}