d887c439f0bddbb4c21572402d27e9d490245d24
1 /*
2 * SysDB - t/unit/core/store_json_test.c
3 * Copyright (C) 2014 Sebastian 'tokkee' Harl <sh@tokkee.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
28 #if HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include "core/plugin.h"
33 #include "core/store.h"
34 #include "testutils.h"
36 #include <check.h>
37 #include <stdlib.h>
39 /* Make SDB_INTERVAL_SECOND a constant initializer. */
40 #undef SDB_INTERVAL_SECOND
41 #define SDB_INTERVAL_SECOND 1000000000L
43 static sdb_store_t *store;
45 static void
46 populate(void)
47 {
48 sdb_data_t datum;
50 store = sdb_store_create();
51 ck_assert(store != NULL);
53 sdb_store_host(store, "h1", 1 * SDB_INTERVAL_SECOND);
54 sdb_store_host(store, "h2", 3 * SDB_INTERVAL_SECOND);
56 datum.type = SDB_TYPE_STRING;
57 datum.data.string = "v1";
58 sdb_store_attribute(store, "h1", "k1", &datum, 1 * SDB_INTERVAL_SECOND);
59 datum.data.string = "v2";
60 sdb_store_attribute(store, "h1", "k2", &datum, 2 * SDB_INTERVAL_SECOND);
61 datum.data.string = "v3";
62 sdb_store_attribute(store, "h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
64 /* make sure that older updates don't overwrite existing values */
65 datum.data.string = "fail";
66 sdb_store_attribute(store, "h1", "k2", &datum, 1 * SDB_INTERVAL_SECOND);
67 sdb_store_attribute(store, "h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
69 sdb_store_metric(store, "h1", "m1", /* store */ NULL, 2 * SDB_INTERVAL_SECOND);
70 sdb_store_metric(store, "h1", "m2", /* store */ NULL, 1 * SDB_INTERVAL_SECOND);
71 sdb_store_metric(store, "h2", "m1", /* store */ NULL, 1 * SDB_INTERVAL_SECOND);
73 sdb_store_service(store, "h2", "s1", 1 * SDB_INTERVAL_SECOND);
74 sdb_store_service(store, "h2", "s2", 2 * SDB_INTERVAL_SECOND);
76 datum.type = SDB_TYPE_INTEGER;
77 datum.data.integer = 42;
78 sdb_store_metric_attr(store, "h1", "m1", "k3",
79 &datum, 2 * SDB_INTERVAL_SECOND);
81 datum.data.integer = 123;
82 sdb_store_service_attr(store, "h2", "s2", "k1",
83 &datum, 2 * SDB_INTERVAL_SECOND);
84 datum.data.integer = 4711;
85 sdb_store_service_attr(store, "h2", "s2", "k2",
86 &datum, 1 * SDB_INTERVAL_SECOND);
88 /* don't overwrite k1 */
89 datum.data.integer = 666;
90 sdb_store_service_attr(store, "h2", "s2", "k1",
91 &datum, 2 * SDB_INTERVAL_SECOND);
92 } /* populate */
94 static void
95 turndown(void)
96 {
97 sdb_object_deref(SDB_OBJ(store));
98 store = NULL;
99 } /* turndown */
101 static int
102 scan_tojson(sdb_store_obj_t *obj,
103 sdb_store_matcher_t __attribute__((unused)) *filter,
104 void *user_data)
105 {
106 sdb_store_json_formatter_t *f = user_data;
107 return sdb_store_json_emit(f, obj);
108 } /* scan_tojson */
110 static int
111 scan_tojson_full(sdb_store_obj_t *obj, sdb_store_matcher_t *filter,
112 void *user_data)
113 {
114 sdb_store_json_formatter_t *f = user_data;
115 return sdb_store_json_emit_full(f, obj, filter);
116 } /* scan_tojson_full */
118 static void
119 verify_json_output(sdb_strbuf_t *buf, const char *expected)
120 {
121 const char *got = sdb_strbuf_string(buf);
122 size_t len1 = strlen(got);
123 size_t len2 = strlen(expected);
125 size_t i;
126 int pos = -1;
128 if (len1 != len2)
129 pos = (int)SDB_MIN(len1, len2);
131 for (i = 0; i < SDB_MIN(len1, len2); ++i) {
132 if (got[i] != expected[i]) {
133 pos = (int)i;
134 break;
135 }
136 }
138 fail_unless(pos == -1,
139 "Serializing hosts to JSON returned unexpected result\n"
140 " got: %s\n %*s\n expected: %s",
141 got, pos + 1, "^", expected);
142 } /* verify_json_output */
144 struct {
145 struct {
146 sdb_store_matcher_t *(*m)(sdb_store_expr_t *, sdb_store_expr_t *);
147 int field;
148 sdb_data_t value;
149 } filter;
150 int type;
151 int (*f)(sdb_store_obj_t *, sdb_store_matcher_t *, void *);
152 const char *expected;
153 } store_tojson_data[] = {
154 { { NULL, 0, SDB_DATA_INIT },
155 SDB_HOST, scan_tojson_full,
156 "["
157 "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", "
158 "\"update_interval\": \"0s\", \"backends\": [], "
159 "\"attributes\": ["
160 "{\"name\": \"k1\", \"value\": \"v1\", "
161 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
162 "\"update_interval\": \"0s\", \"backends\": []},"
163 "{\"name\": \"k2\", \"value\": \"v2\", "
164 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
165 "\"update_interval\": \"0s\", \"backends\": []},"
166 "{\"name\": \"k3\", \"value\": \"v3\", "
167 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
168 "\"update_interval\": \"0s\", \"backends\": []}"
169 "], "
170 "\"metrics\": ["
171 "{\"name\": \"m1\", "
172 "\"timeseries\": false, "
173 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
174 "\"update_interval\": \"0s\", \"backends\": [], "
175 "\"attributes\": ["
176 "{\"name\": \"hostname\", \"value\": \"h1\", "
177 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
178 "\"update_interval\": \"0s\", \"backends\": []},"
179 "{\"name\": \"k3\", \"value\": 42, "
180 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
181 "\"update_interval\": \"0s\", \"backends\": []}"
182 "]},"
183 "{\"name\": \"m2\", "
184 "\"timeseries\": false, "
185 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
186 "\"update_interval\": \"0s\", \"backends\": [], "
187 "\"attributes\": ["
188 "{\"name\": \"hostname\", \"value\": \"h1\", "
189 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
190 "\"update_interval\": \"0s\", \"backends\": []}"
191 "]}"
192 "]},"
193 "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
194 "\"update_interval\": \"0s\", \"backends\": [], "
195 "\"metrics\": ["
196 "{\"name\": \"m1\", "
197 "\"timeseries\": false, "
198 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
199 "\"update_interval\": \"0s\", \"backends\": [], "
200 "\"attributes\": ["
201 "{\"name\": \"hostname\", \"value\": \"h2\", "
202 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
203 "\"update_interval\": \"0s\", \"backends\": []}"
204 "]}"
205 "], "
206 "\"services\": ["
207 "{\"name\": \"s1\", "
208 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
209 "\"update_interval\": \"0s\", \"backends\": [], "
210 "\"attributes\": ["
211 "{\"name\": \"hostname\", \"value\": \"h2\", "
212 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
213 "\"update_interval\": \"0s\", \"backends\": []}"
214 "]},"
215 "{\"name\": \"s2\", "
216 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
217 "\"update_interval\": \"0s\", \"backends\": [], "
218 "\"attributes\": ["
219 "{\"name\": \"hostname\", \"value\": \"h2\", "
220 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
221 "\"update_interval\": \"0s\", \"backends\": []},"
222 "{\"name\": \"k1\", \"value\": 123, "
223 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
224 "\"update_interval\": \"0s\", \"backends\": []},"
225 "{\"name\": \"k2\", \"value\": 4711, "
226 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
227 "\"update_interval\": \"0s\", \"backends\": []}"
228 "]}"
229 "]}"
230 "]" },
231 { { NULL, 0, SDB_DATA_INIT },
232 SDB_HOST, scan_tojson,
233 "["
234 "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", "
235 "\"update_interval\": \"0s\", \"backends\": []},"
236 "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
237 "\"update_interval\": \"0s\", \"backends\": []}"
238 "]" },
239 { { sdb_store_eq_matcher, SDB_FIELD_NAME,
240 { SDB_TYPE_STRING, { .string = "h1" } } },
241 SDB_HOST, scan_tojson_full,
242 "["
243 "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", "
244 "\"update_interval\": \"0s\", \"backends\": []}"
245 "]" },
246 { { sdb_store_gt_matcher, SDB_FIELD_LAST_UPDATE,
247 { SDB_TYPE_DATETIME, { .datetime = 1 * SDB_INTERVAL_SECOND } } },
248 SDB_HOST, scan_tojson_full,
249 "["
250 "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
251 "\"update_interval\": \"0s\", \"backends\": [], "
252 "\"services\": ["
253 "{\"name\": \"s2\", "
254 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
255 "\"update_interval\": \"0s\", \"backends\": [], "
256 "\"attributes\": ["
257 "{\"name\": \"hostname\", \"value\": \"h2\", "
258 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
259 "\"update_interval\": \"0s\", \"backends\": []},"
260 "{\"name\": \"k1\", \"value\": 123, "
261 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
262 "\"update_interval\": \"0s\", \"backends\": []}"
263 "]}"
264 "]}"
265 "]" },
266 { { sdb_store_le_matcher, SDB_FIELD_LAST_UPDATE,
267 { SDB_TYPE_DATETIME, { .datetime = 1 * SDB_INTERVAL_SECOND } } },
268 SDB_HOST, scan_tojson_full,
269 "["
270 "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", "
271 "\"update_interval\": \"0s\", \"backends\": [], "
272 "\"attributes\": ["
273 "{\"name\": \"k1\", \"value\": \"v1\", "
274 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
275 "\"update_interval\": \"0s\", \"backends\": []}"
276 "], "
277 "\"metrics\": ["
278 "{\"name\": \"m2\", "
279 "\"timeseries\": false, "
280 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
281 "\"update_interval\": \"0s\", \"backends\": [], "
282 "\"attributes\": ["
283 "{\"name\": \"hostname\", \"value\": \"h1\", "
284 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
285 "\"update_interval\": \"0s\", \"backends\": []}"
286 "]}"
287 "]}"
288 "]" },
289 { { sdb_store_ge_matcher, SDB_FIELD_LAST_UPDATE,
290 { SDB_TYPE_DATETIME, { .datetime = 3 * SDB_INTERVAL_SECOND } } },
291 SDB_HOST, scan_tojson_full,
292 "["
293 "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
294 "\"update_interval\": \"0s\", \"backends\": []}"
295 "]" },
296 { { sdb_store_lt_matcher, SDB_FIELD_LAST_UPDATE,
297 { SDB_TYPE_DATETIME, { .datetime = 0 } } },
298 SDB_HOST, scan_tojson_full,
299 "[]" },
301 { { NULL, 0, SDB_DATA_INIT },
302 SDB_SERVICE, scan_tojson_full,
303 "["
304 "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
305 "\"update_interval\": \"0s\", \"backends\": [], "
306 "\"services\": ["
307 "{\"name\": \"s1\", "
308 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
309 "\"update_interval\": \"0s\", \"backends\": [], "
310 "\"attributes\": ["
311 "{\"name\": \"hostname\", \"value\": \"h2\", "
312 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
313 "\"update_interval\": \"0s\", \"backends\": []}"
314 "]},"
315 "{\"name\": \"s2\", "
316 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
317 "\"update_interval\": \"0s\", \"backends\": [], "
318 "\"attributes\": ["
319 "{\"name\": \"hostname\", \"value\": \"h2\", "
320 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
321 "\"update_interval\": \"0s\", \"backends\": []},"
322 "{\"name\": \"k1\", \"value\": 123, "
323 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
324 "\"update_interval\": \"0s\", \"backends\": []},"
325 "{\"name\": \"k2\", \"value\": 4711, "
326 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
327 "\"update_interval\": \"0s\", \"backends\": []}"
328 "]}"
329 "]}"
330 "]" },
331 { { NULL, 0, SDB_DATA_INIT },
332 SDB_SERVICE, scan_tojson,
333 "["
334 "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
335 "\"update_interval\": \"0s\", \"backends\": [], "
336 "\"services\": ["
337 "{\"name\": \"s1\", "
338 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
339 "\"update_interval\": \"0s\", \"backends\": []},"
340 "{\"name\": \"s2\", "
341 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
342 "\"update_interval\": \"0s\", \"backends\": []}"
343 "]}"
344 "]" },
345 { { sdb_store_gt_matcher, SDB_FIELD_LAST_UPDATE,
346 { SDB_TYPE_DATETIME, { .datetime = 1 * SDB_INTERVAL_SECOND } } },
347 SDB_SERVICE, scan_tojson_full,
348 "["
349 "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
350 "\"update_interval\": \"0s\", \"backends\": [], "
351 "\"services\": ["
352 "{\"name\": \"s2\", "
353 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
354 "\"update_interval\": \"0s\", \"backends\": [], "
355 "\"attributes\": ["
356 "{\"name\": \"hostname\", \"value\": \"h2\", "
357 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
358 "\"update_interval\": \"0s\", \"backends\": []},"
359 "{\"name\": \"k1\", \"value\": 123, "
360 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
361 "\"update_interval\": \"0s\", \"backends\": []}"
362 "]}"
363 "]}"
364 "]" },
365 { { sdb_store_lt_matcher, SDB_FIELD_LAST_UPDATE,
366 { SDB_TYPE_DATETIME, { .datetime = 0 } } },
367 SDB_SERVICE, scan_tojson_full,
368 "[]" },
369 { { NULL, 0, SDB_DATA_INIT },
370 SDB_METRIC, scan_tojson_full,
371 "["
372 "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", "
373 "\"update_interval\": \"0s\", \"backends\": [], "
374 "\"metrics\": ["
375 "{\"name\": \"m1\", "
376 "\"timeseries\": false, "
377 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
378 "\"update_interval\": \"0s\", \"backends\": [], "
379 "\"attributes\": ["
380 "{\"name\": \"hostname\", \"value\": \"h1\", "
381 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
382 "\"update_interval\": \"0s\", \"backends\": []},"
383 "{\"name\": \"k3\", \"value\": 42, "
384 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
385 "\"update_interval\": \"0s\", \"backends\": []}"
386 "]},"
387 "{\"name\": \"m2\", "
388 "\"timeseries\": false, "
389 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
390 "\"update_interval\": \"0s\", \"backends\": [], "
391 "\"attributes\": ["
392 "{\"name\": \"hostname\", \"value\": \"h1\", "
393 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
394 "\"update_interval\": \"0s\", \"backends\": []}"
395 "]}"
396 "]},"
397 "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
398 "\"update_interval\": \"0s\", \"backends\": [], "
399 "\"metrics\": ["
400 "{\"name\": \"m1\", "
401 "\"timeseries\": false, "
402 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
403 "\"update_interval\": \"0s\", \"backends\": [], "
404 "\"attributes\": ["
405 "{\"name\": \"hostname\", \"value\": \"h2\", "
406 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
407 "\"update_interval\": \"0s\", \"backends\": []}"
408 "]}"
409 "]}"
410 "]" },
411 { { NULL, 0, SDB_DATA_INIT },
412 SDB_METRIC, scan_tojson,
413 "["
414 "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", "
415 "\"update_interval\": \"0s\", \"backends\": [], "
416 "\"metrics\": ["
417 "{\"name\": \"m1\", "
418 "\"timeseries\": false, "
419 "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
420 "\"update_interval\": \"0s\", \"backends\": []},"
421 "{\"name\": \"m2\", "
422 "\"timeseries\": false, "
423 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
424 "\"update_interval\": \"0s\", \"backends\": []}"
425 "]},"
426 "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
427 "\"update_interval\": \"0s\", \"backends\": [], "
428 "\"metrics\": ["
429 "{\"name\": \"m1\", "
430 "\"timeseries\": false, "
431 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
432 "\"update_interval\": \"0s\", \"backends\": []}"
433 "]}"
434 "]" },
435 { { sdb_store_le_matcher, SDB_FIELD_LAST_UPDATE,
436 { SDB_TYPE_DATETIME, { .datetime = 1 * SDB_INTERVAL_SECOND } } },
437 SDB_METRIC, scan_tojson_full,
438 "["
439 "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", "
440 "\"update_interval\": \"0s\", \"backends\": [], "
441 "\"metrics\": ["
442 "{\"name\": \"m2\", "
443 "\"timeseries\": false, "
444 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
445 "\"update_interval\": \"0s\", \"backends\": [], "
446 "\"attributes\": ["
447 "{\"name\": \"hostname\", \"value\": \"h1\", "
448 "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
449 "\"update_interval\": \"0s\", \"backends\": []}"
450 "]}"
451 "]}"
452 "]" },
453 { { sdb_store_lt_matcher, SDB_FIELD_LAST_UPDATE,
454 { SDB_TYPE_DATETIME, { .datetime = 0 } } },
455 SDB_METRIC, scan_tojson_full,
456 "[]" },
457 };
459 START_TEST(test_store_tojson)
460 {
461 sdb_strbuf_t *buf = sdb_strbuf_create(0);
462 sdb_store_matcher_t *filter = NULL;
463 sdb_store_json_formatter_t *f;
464 int status;
466 if (store_tojson_data[_i].filter.m) {
467 sdb_store_expr_t *field;
468 sdb_store_expr_t *value;
470 field = sdb_store_expr_fieldvalue(store_tojson_data[_i].filter.field);
471 fail_unless(field != NULL,
472 "INTERNAL ERROR: sdb_store_expr_fieldvalue() = NULL");
473 value = sdb_store_expr_constvalue(&store_tojson_data[_i].filter.value);
474 fail_unless(value != NULL,
475 "INTERNAL ERROR: sdb_store_expr_constvalue() = NULL");
477 filter = store_tojson_data[_i].filter.m(field, value);
478 fail_unless(filter != NULL,
479 "INTERNAL ERROR: sdb_store_*_matcher() = NULL");
481 sdb_object_deref(SDB_OBJ(field));
482 sdb_object_deref(SDB_OBJ(value));
483 }
485 sdb_strbuf_clear(buf);
486 f = sdb_store_json_formatter(buf,
487 store_tojson_data[_i].type, SDB_WANT_ARRAY);
488 ck_assert(f != NULL);
490 status = sdb_store_scan(store, store_tojson_data[_i].type,
491 /* m = */ NULL, filter, store_tojson_data[_i].f, f);
492 fail_unless(status == 0,
493 "sdb_store_scan(HOST, ..., tojson) = %d; expected: 0",
494 status);
495 sdb_store_json_finish(f);
497 verify_json_output(buf, store_tojson_data[_i].expected);
499 sdb_object_deref(SDB_OBJ(filter));
500 sdb_object_deref(SDB_OBJ(f));
501 sdb_strbuf_destroy(buf);
502 }
503 END_TEST
505 TEST_MAIN("core::store_json")
506 {
507 TCase *tc = tcase_create("core");
508 tcase_add_unchecked_fixture(tc, populate, turndown);
509 TC_ADD_LOOP_TEST(tc, store_tojson);
510 ADD_TCASE(tc);
511 }
512 TEST_MAIN_END
514 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */