dff1b53a7fb28a5bb32fc6c53d2c71462a44a993
1 /*
2 * SysDB - t/unit/core/timeseries_test.c
3 * Copyright (C) 2016 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/timeseries.h"
33 #include "testutils.h"
35 #include <check.h>
37 #define TS "1970-01-01 00:00:00 +0000"
38 #define V "0.000000"
40 START_TEST(timeseries)
41 {
42 const char * const data_names[] = {"abc", "xyz"};
43 sdb_timeseries_t *ts = sdb_timeseries_create(2, data_names, 2);
44 sdb_strbuf_t *buf = sdb_strbuf_create(0);
45 int test;
47 const char *expected =
48 "{\"start\": \""TS"\", \"end\": \""TS"\", \"data\": {"
49 "\"abc\": [{\"timestamp\": \""TS"\", \"value\": \""V"\"},"
50 "{\"timestamp\": \""TS"\", \"value\": \""V"\"}],"
51 "\"xyz\": [{\"timestamp\": \""TS"\", \"value\": \""V"\"},"
52 "{\"timestamp\": \""TS"\", \"value\": \""V"\"}]"
53 "}}";
55 fail_unless(ts != NULL,
56 "sdb_timeseries_create(2, {\"abc\", \"xyz\"}, 3) = NULL; expected: <ts>");
58 test = sdb_timeseries_tojson(ts, buf);
59 fail_unless(test == 0,
60 "sdb_timeseries_tojson(<ts>, <buf>) = %d; expected: 0", test);
61 sdb_diff_strings("sdb_timeseries_tojson(<ts>, <buf>) returned unexpected JSON",
62 sdb_strbuf_string(buf), expected);
64 sdb_timeseries_destroy(ts);
65 sdb_strbuf_destroy(buf);
66 }
67 END_TEST
69 TEST_MAIN("core::timeseries")
70 {
71 TCase *tc = tcase_create("core");
72 tcase_add_test(tc, timeseries);
73 ADD_TCASE(tc);
74 }
75 TEST_MAIN_END
77 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */