Code

t/: Use ck_assert() instead of assert() in all tests.
[sysdb.git] / t / unit / core / store_json_test.c
index 9dc157068183b49c2e2c4e1e74276bcccee9c064..b69573c45fde0afd0b90ab5db4402f225eb9ac00 100644 (file)
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "core/store.h"
-#include "libsysdb_test.h"
+#if HAVE_CONFIG_H
+#      include "config.h"
+#endif
 
-#include <assert.h>
+#include "core/store.h"
+#include "testutils.h"
 
 #include <check.h>
 #include <stdlib.h>
@@ -120,8 +122,7 @@ verify_json_output(sdb_strbuf_t *buf, const char *expected)
 
 struct {
        struct {
-               sdb_store_matcher_t *(*m)(sdb_store_expr_t *,
-                               sdb_store_expr_t *);
+               sdb_store_matcher_t *(*m)(sdb_store_expr_t *, sdb_store_expr_t *);
                int field;
                sdb_data_t value;
        } filter;
@@ -151,6 +152,9 @@ struct {
                                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": [], "
                                                "\"attributes\": ["
+                                                       "{\"name\": \"hostname\", \"value\": \"h1\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"update_interval\": \"0s\", \"backends\": []},"
                                                        "{\"name\": \"k3\", \"value\": 42, "
                                                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []}"
@@ -158,7 +162,12 @@ struct {
                                        "{\"name\": \"m2\", "
                                                "\"timeseries\": false, "
                                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                               "\"update_interval\": \"0s\", \"backends\": []}"
+                                               "\"update_interval\": \"0s\", \"backends\": [], "
+                                               "\"attributes\": ["
+                                                       "{\"name\": \"hostname\", \"value\": \"h1\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"update_interval\": \"0s\", \"backends\": []}"
+                                               "]}"
                                "]},"
                        "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
                                "\"update_interval\": \"0s\", \"backends\": [], "
@@ -166,16 +175,29 @@ struct {
                                        "{\"name\": \"m1\", "
                                                "\"timeseries\": false, "
                                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                               "\"update_interval\": \"0s\", \"backends\": []}"
+                                               "\"update_interval\": \"0s\", \"backends\": [], "
+                                               "\"attributes\": ["
+                                                       "{\"name\": \"hostname\", \"value\": \"h2\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"update_interval\": \"0s\", \"backends\": []}"
+                                               "]}"
                                "], "
                                "\"services\": ["
                                        "{\"name\": \"s1\", "
                                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                               "\"update_interval\": \"0s\", \"backends\": []},"
+                                               "\"update_interval\": \"0s\", \"backends\": [], "
+                                               "\"attributes\": ["
+                                                       "{\"name\": \"hostname\", \"value\": \"h2\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"update_interval\": \"0s\", \"backends\": []}"
+                                               "]},"
                                        "{\"name\": \"s2\", "
                                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": [], "
                                                "\"attributes\": ["
+                                                       "{\"name\": \"hostname\", \"value\": \"h2\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"update_interval\": \"0s\", \"backends\": []},"
                                                        "{\"name\": \"k1\", \"value\": 123, "
                                                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []},"
@@ -211,6 +233,9 @@ struct {
                                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": [], "
                                                "\"attributes\": ["
+                                                       "{\"name\": \"hostname\", \"value\": \"h2\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"update_interval\": \"0s\", \"backends\": []},"
                                                        "{\"name\": \"k1\", \"value\": 123, "
                                                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []}"
@@ -232,7 +257,12 @@ struct {
                                        "{\"name\": \"m2\", "
                                                "\"timeseries\": false, "
                                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                               "\"update_interval\": \"0s\", \"backends\": []}"
+                                               "\"update_interval\": \"0s\", \"backends\": [], "
+                                               "\"attributes\": ["
+                                                       "{\"name\": \"hostname\", \"value\": \"h1\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"update_interval\": \"0s\", \"backends\": []}"
+                                               "]}"
                                "]}"
                "]" },
        { { sdb_store_ge_matcher, SDB_FIELD_LAST_UPDATE,
@@ -255,11 +285,19 @@ struct {
                                "\"services\": ["
                                        "{\"name\": \"s1\", "
                                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                               "\"update_interval\": \"0s\", \"backends\": []},"
+                                               "\"update_interval\": \"0s\", \"backends\": [], "
+                                               "\"attributes\": ["
+                                                       "{\"name\": \"hostname\", \"value\": \"h2\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"update_interval\": \"0s\", \"backends\": []}"
+                                               "]},"
                                        "{\"name\": \"s2\", "
                                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": [], "
                                                "\"attributes\": ["
+                                                       "{\"name\": \"hostname\", \"value\": \"h2\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"update_interval\": \"0s\", \"backends\": []},"
                                                        "{\"name\": \"k1\", \"value\": 123, "
                                                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []},"
@@ -294,6 +332,9 @@ struct {
                                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": [], "
                                                "\"attributes\": ["
+                                                       "{\"name\": \"hostname\", \"value\": \"h2\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"update_interval\": \"0s\", \"backends\": []},"
                                                        "{\"name\": \"k1\", \"value\": 123, "
                                                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []}"
@@ -315,6 +356,9 @@ struct {
                                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": [], "
                                                "\"attributes\": ["
+                                                       "{\"name\": \"hostname\", \"value\": \"h1\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"update_interval\": \"0s\", \"backends\": []},"
                                                        "{\"name\": \"k3\", \"value\": 42, "
                                                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []}"
@@ -322,7 +366,12 @@ struct {
                                        "{\"name\": \"m2\", "
                                                "\"timeseries\": false, "
                                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                               "\"update_interval\": \"0s\", \"backends\": []}"
+                                               "\"update_interval\": \"0s\", \"backends\": [], "
+                                               "\"attributes\": ["
+                                                       "{\"name\": \"hostname\", \"value\": \"h1\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"update_interval\": \"0s\", \"backends\": []}"
+                                               "]}"
                                "]},"
                        "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
                                "\"update_interval\": \"0s\", \"backends\": [], "
@@ -330,7 +379,12 @@ struct {
                                        "{\"name\": \"m1\", "
                                                "\"timeseries\": false, "
                                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                               "\"update_interval\": \"0s\", \"backends\": []}"
+                                               "\"update_interval\": \"0s\", \"backends\": [], "
+                                               "\"attributes\": ["
+                                                       "{\"name\": \"hostname\", \"value\": \"h2\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"update_interval\": \"0s\", \"backends\": []}"
+                                               "]}"
                                "]}"
                "]" },
        { { NULL, 0, SDB_DATA_INIT },
@@ -367,7 +421,12 @@ struct {
                                        "{\"name\": \"m2\", "
                                                "\"timeseries\": false, "
                                                "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                               "\"update_interval\": \"0s\", \"backends\": []}"
+                                               "\"update_interval\": \"0s\", \"backends\": [], "
+                                               "\"attributes\": ["
+                                                       "{\"name\": \"hostname\", \"value\": \"h1\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"update_interval\": \"0s\", \"backends\": []}"
+                                               "]}"
                                "]}"
                "]" },
        { { sdb_store_lt_matcher, SDB_FIELD_LAST_UPDATE,
@@ -405,7 +464,7 @@ START_TEST(test_store_tojson)
        sdb_strbuf_clear(buf);
        f = sdb_store_json_formatter(buf,
                        store_tojson_data[_i].type, SDB_WANT_ARRAY);
-       assert(f);
+       ck_assert(f != NULL);
 
        status = sdb_store_scan(store_tojson_data[_i].type,
                        /* m = */ NULL, filter, store_tojson_data[_i].f, f);
@@ -422,19 +481,14 @@ START_TEST(test_store_tojson)
 }
 END_TEST
 
-Suite *
-core_store_json_suite(void)
+TEST_MAIN("core::store_json")
 {
-       Suite *s = suite_create("core::store_json");
-       TCase *tc;
-
-       tc = tcase_create("core");
+       TCase *tc = tcase_create("core");
        TC_ADD_LOOP_TEST(tc, store_tojson);
        tcase_add_unchecked_fixture(tc, populate, sdb_store_clear);
-       suite_add_tcase(s, tc);
-
-       return s;
-} /* core_store_json_suite */
+       ADD_TCASE(tc);
+}
+TEST_MAIN_END
 
 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */