Code

Drop sdb_store_get_host() from tests.
[sysdb.git] / t / unit / core / store_test.c
index d132508537a76789ca3e9effe2240473ff8f5e88..6d528dede366fe9bce639e9e6eb10eba4cb7a268 100644 (file)
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#if HAVE_CONFIG_H
+#      include "config.h"
+#endif
+
+#include "core/plugin.h"
 #include "core/store.h"
 #include "core/store-private.h"
-#include "libsysdb_test.h"
+#include "testutils.h"
 
 #include <check.h>
 #include <string.h>
+#include <strings.h>
+
+static void
+init(void)
+{
+       sdb_store_init();
+}
 
 static void
 populate(void)
 {
        sdb_data_t datum;
 
-       sdb_store_host("h1", 1);
-       sdb_store_host("h2", 3);
+       sdb_plugin_store_host("h1", 1);
+       sdb_plugin_store_host("h2", 3);
 
        datum.type = SDB_TYPE_STRING;
        datum.data.string = "v1";
-       sdb_store_attribute("h1", "k1", &datum, 1);
+       sdb_plugin_store_attribute("h1", "k1", &datum, 1);
        datum.data.string = "v2";
-       sdb_store_attribute("h1", "k2", &datum, 2);
+       sdb_plugin_store_attribute("h1", "k2", &datum, 2);
        datum.data.string = "v3";
-       sdb_store_attribute("h1", "k3", &datum, 2);
+       sdb_plugin_store_attribute("h1", "k3", &datum, 2);
 
        /* make sure that older updates don't overwrite existing values */
        datum.data.string = "fail";
-       sdb_store_attribute("h1", "k2", &datum, 1);
-       sdb_store_attribute("h1", "k3", &datum, 2);
+       sdb_plugin_store_attribute("h1", "k2", &datum, 1);
+       sdb_plugin_store_attribute("h1", "k3", &datum, 2);
 
-       sdb_store_metric("h1", "m1", /* store */ NULL, 2);
-       sdb_store_metric("h1", "m2", /* store */ NULL, 1);
-       sdb_store_metric("h2", "m1", /* store */ NULL, 1);
+       sdb_plugin_store_metric("h1", "m1", /* store */ NULL, 2);
+       sdb_plugin_store_metric("h1", "m2", /* store */ NULL, 1);
+       sdb_plugin_store_metric("h2", "m1", /* store */ NULL, 1);
 
-       sdb_store_service("h2", "s1", 1);
-       sdb_store_service("h2", "s2", 2);
+       sdb_plugin_store_service("h2", "s1", 1);
+       sdb_plugin_store_service("h2", "s2", 2);
 
        datum.type = SDB_TYPE_INTEGER;
        datum.data.integer = 42;
-       sdb_store_metric_attr("h1", "m1", "k3", &datum, 2);
+       sdb_plugin_store_metric_attribute("h1", "m1", "k3", &datum, 2);
 
        datum.data.integer = 123;
-       sdb_store_service_attr("h2", "s2", "k1", &datum, 2);
+       sdb_plugin_store_service_attribute("h2", "s2", "k1", &datum, 2);
        datum.data.integer = 4711;
-       sdb_store_service_attr("h2", "s2", "k2", &datum, 1);
+       sdb_plugin_store_service_attribute("h2", "s2", "k2", &datum, 1);
 
        /* don't overwrite k1 */
        datum.data.integer = 666;
-       sdb_store_service_attr("h2", "s2", "k1", &datum, 2);
+       sdb_plugin_store_service_attribute("h2", "s2", "k1", &datum, 2);
 } /* populate */
 
 START_TEST(test_store_host)
@@ -92,7 +104,7 @@ START_TEST(test_store_host)
 
        struct {
                const char *name;
-               _Bool       has;
+               bool        have;
        } golden_hosts[] = {
                { "a", 1 == 1 },
                { "b", 1 == 1 },
@@ -105,21 +117,23 @@ START_TEST(test_store_host)
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
                int status;
 
-               status = sdb_store_host(golden_data[i].name,
+               status = sdb_plugin_store_host(golden_data[i].name,
                                golden_data[i].last_update);
                fail_unless(status == golden_data[i].expected,
-                               "sdb_store_host(%s, %d) = %d; expected: %d",
+                               "sdb_plugin_store_host(%s, %d) = %d; expected: %d",
                                golden_data[i].name, (int)golden_data[i].last_update,
                                status, golden_data[i].expected);
        }
 
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_hosts); ++i) {
-               _Bool has;
-
-               has = sdb_store_has_host(golden_hosts[i].name);
-               fail_unless(has == golden_hosts[i].has,
-                               "sdb_store_has_host(%s) = %d; expected: %d",
-                               golden_hosts[i].name, has, golden_hosts[i].has);
+               sdb_store_obj_t *have;
+
+               have = sdb_store_get_host(golden_hosts[i].name);
+               fail_unless((have != NULL) == golden_hosts[i].have,
+                               "sdb_store_get_host(%s) = %p; expected: %s",
+                               golden_hosts[i].name, have,
+                               golden_hosts[i].have ? "<host>" : "NULL");
+               sdb_object_deref(SDB_OBJ(have));
        }
 }
 END_TEST
@@ -131,9 +145,9 @@ START_TEST(test_store_get_host)
        size_t i;
 
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_hosts); ++i) {
-               int status = sdb_store_host(golden_hosts[i], 1);
+               int status = sdb_plugin_store_host(golden_hosts[i], 1);
                fail_unless(status >= 0,
-                               "sdb_store_host(%s) = %d; expected: >=0",
+                               "sdb_plugin_store_host(%s) = %d; expected: >=0",
                                golden_hosts[i], status);
        }
 
@@ -141,10 +155,6 @@ START_TEST(test_store_get_host)
                sdb_store_obj_t *sobj1, *sobj2;
                int ref_cnt;
 
-               fail_unless(sdb_store_has_host(golden_hosts[i]),
-                               "sdb_store_has_host(%s) = FALSE; expected: TRUE",
-                               golden_hosts[i]);
-
                sobj1 = sdb_store_get_host(golden_hosts[i]);
                fail_unless(sobj1 != NULL,
                                "sdb_store_get_host(%s) = NULL; expected: <host>",
@@ -174,10 +184,6 @@ START_TEST(test_store_get_host)
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(unknown_hosts); ++i) {
                sdb_store_obj_t *sobj;
 
-               fail_unless(!sdb_store_has_host(unknown_hosts[i]),
-                               "sdb_store_has_host(%s) = TRUE; expected: FALSE",
-                               unknown_hosts[i]);
-
                sobj = sdb_store_get_host(unknown_hosts[i]);
                fail_unless(!sobj, "sdb_store_get_host(%s) = <host:%s>; expected: NULL",
                                unknown_hosts[i], sobj ? SDB_OBJ(sobj)->name : "NULL");
@@ -206,8 +212,8 @@ START_TEST(test_store_attr)
 
        size_t i;
 
-       sdb_store_host("l", 1);
-       sdb_store_host("m", 1);
+       sdb_plugin_store_host("l", 1);
+       sdb_plugin_store_host("m", 1);
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
                sdb_data_t datum;
                int status;
@@ -216,11 +222,11 @@ START_TEST(test_store_attr)
                datum.type = SDB_TYPE_STRING;
                datum.data.string = golden_data[i].value;
 
-               status = sdb_store_attribute(golden_data[i].host,
+               status = sdb_plugin_store_attribute(golden_data[i].host,
                                golden_data[i].key, &datum,
                                golden_data[i].last_update);
                fail_unless(status == golden_data[i].expected,
-                               "sdb_store_attribute(%s, %s, %s, %d) = %d; expected: %d",
+                               "sdb_plugin_store_attribute(%s, %s, %s, %d) = %d; expected: %d",
                                golden_data[i].host, golden_data[i].key, golden_data[i].value,
                                golden_data[i].last_update, status, golden_data[i].expected);
        }
@@ -259,16 +265,16 @@ START_TEST(test_store_metric)
 
        size_t i;
 
-       sdb_store_host("m", 1);
-       sdb_store_host("l", 1);
+       sdb_plugin_store_host("m", 1);
+       sdb_plugin_store_host("l", 1);
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
                int status;
 
-               status = sdb_store_metric(golden_data[i].host,
+               status = sdb_plugin_store_metric(golden_data[i].host,
                                golden_data[i].metric, golden_data[i].store,
                                golden_data[i].last_update);
                fail_unless(status == golden_data[i].expected,
-                               "sdb_store_metric(%s, %s, %p, %d) = %d; expected: %d",
+                               "sdb_plugin_store_metric(%s, %s, %p, %d) = %d; expected: %d",
                                golden_data[i].host, golden_data[i].metric,
                                golden_data[i].store, golden_data[i].last_update,
                                status, golden_data[i].expected);
@@ -303,20 +309,20 @@ START_TEST(test_store_metric_attr)
 
        size_t i;
 
-       sdb_store_host("m", 1);
-       sdb_store_host("l", 1);
-       sdb_store_metric("m", "m1", NULL, 1);
-       sdb_store_metric("l", "m1", NULL, 1);
-       sdb_store_metric("l", "m2", NULL, 1);
+       sdb_plugin_store_host("m", 1);
+       sdb_plugin_store_host("l", 1);
+       sdb_plugin_store_metric("m", "m1", NULL, 1);
+       sdb_plugin_store_metric("l", "m1", NULL, 1);
+       sdb_plugin_store_metric("l", "m2", NULL, 1);
 
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
                int status;
 
-               status = sdb_store_metric_attr(golden_data[i].host,
+               status = sdb_plugin_store_metric_attribute(golden_data[i].host,
                                golden_data[i].metric, golden_data[i].attr,
                                &golden_data[i].value, golden_data[i].last_update);
                fail_unless(status == golden_data[i].expected,
-                               "sdb_store_metric_attr(%s, %s, %s, %d, %d) = %d; "
+                               "sdb_plugin_store_metric_attribute(%s, %s, %s, %d, %d) = %d; "
                                "expected: %d", golden_data[i].host, golden_data[i].metric,
                                golden_data[i].attr, golden_data[i].value.data.integer,
                                golden_data[i].last_update, status, golden_data[i].expected);
@@ -344,15 +350,15 @@ START_TEST(test_store_service)
 
        size_t i;
 
-       sdb_store_host("m", 1);
-       sdb_store_host("l", 1);
+       sdb_plugin_store_host("m", 1);
+       sdb_plugin_store_host("l", 1);
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
                int status;
 
-               status = sdb_store_service(golden_data[i].host,
+               status = sdb_plugin_store_service(golden_data[i].host,
                                golden_data[i].svc, golden_data[i].last_update);
                fail_unless(status == golden_data[i].expected,
-                               "sdb_store_service(%s, %s, %d) = %d; expected: %d",
+                               "sdb_plugin_store_service(%s, %s, %d) = %d; expected: %d",
                                golden_data[i].host, golden_data[i].svc,
                                golden_data[i].last_update, status, golden_data[i].expected);
        }
@@ -386,20 +392,20 @@ START_TEST(test_store_service_attr)
 
        size_t i;
 
-       sdb_store_host("m", 1);
-       sdb_store_host("l", 1);
-       sdb_store_service("m", "s1", 1);
-       sdb_store_service("l", "s1", 1);
-       sdb_store_service("l", "s2", 1);
+       sdb_plugin_store_host("m", 1);
+       sdb_plugin_store_host("l", 1);
+       sdb_plugin_store_service("m", "s1", 1);
+       sdb_plugin_store_service("l", "s1", 1);
+       sdb_plugin_store_service("l", "s2", 1);
 
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
                int status;
 
-               status = sdb_store_service_attr(golden_data[i].host,
+               status = sdb_plugin_store_service_attribute(golden_data[i].host,
                                golden_data[i].svc, golden_data[i].attr,
                                &golden_data[i].value, golden_data[i].last_update);
                fail_unless(status == golden_data[i].expected,
-                               "sdb_store_service_attr(%s, %s, %s, %d, %d) = %d; "
+                               "sdb_plugin_store_service_attribute(%s, %s, %s, %d, %d) = %d; "
                                "expected: %d", golden_data[i].host, golden_data[i].svc,
                                golden_data[i].attr, golden_data[i].value.data.integer,
                                golden_data[i].last_update, status, golden_data[i].expected);
@@ -407,406 +413,209 @@ START_TEST(test_store_service_attr)
 }
 END_TEST
 
-static void
-verify_json_output(sdb_strbuf_t *buf, const char *expected,
-               sdb_store_matcher_t *filter, int flags)
+static struct {
+       const char *hostname;
+       const char *attr; /* optional */
+       int field;
+       int expected;
+       sdb_data_t value;
+} get_field_data[] = {
+       { NULL,   NULL, 0, -1, { SDB_TYPE_NULL, { 0 } } },
+       { NULL,   NULL,   SDB_FIELD_LAST_UPDATE, -1, { SDB_TYPE_NULL, { 0 } } },
+       { NULL,   NULL,   SDB_FIELD_INTERVAL,    -1, { SDB_TYPE_NULL, { 0 } } },
+       { NULL,   NULL,   SDB_FIELD_AGE,         -1, { SDB_TYPE_NULL, { 0 } } },
+       { NULL,   NULL,   SDB_FIELD_NAME,        -1, { SDB_TYPE_NULL, { 0 } } },
+       { NULL,   NULL,   SDB_FIELD_BACKEND,     -1, { SDB_TYPE_NULL, { 0 } } },
+       { NULL,   NULL,   SDB_FIELD_VALUE,       -1, { SDB_TYPE_NULL, { 0 } } },
+       { "host", NULL,   SDB_FIELD_LAST_UPDATE,  0, { SDB_TYPE_DATETIME, { .datetime = 20 } } },
+       { "host", NULL,   SDB_FIELD_INTERVAL,     0, { SDB_TYPE_DATETIME, { .datetime = 10 } } },
+       /* the test will handle AGE specially */
+       { "host", NULL,   SDB_FIELD_AGE,          0, { SDB_TYPE_NULL, { 0 } } },
+       { "host", NULL,   SDB_FIELD_NAME,         0, { SDB_TYPE_STRING, { .string = "host" } } },
+       { "host", NULL,   SDB_FIELD_BACKEND,      0, { SDB_TYPE_ARRAY | SDB_TYPE_STRING, { .array = { 0, NULL } } } },
+       { "host", NULL,   SDB_FIELD_VALUE,       -1, { SDB_TYPE_NULL, { 0 } } },
+       { "host", "attr", SDB_FIELD_LAST_UPDATE,  0, { SDB_TYPE_DATETIME, { .datetime = 20 } } },
+       { "host", "attr", SDB_FIELD_INTERVAL,     0, { SDB_TYPE_DATETIME, { .datetime = 10 } } },
+       /* the test will handle AGE specially */
+       { "host", "attr", SDB_FIELD_AGE,          0, { SDB_TYPE_NULL, { 0 } } },
+       { "host", "attr", SDB_FIELD_NAME,         0, { SDB_TYPE_STRING, { .string = "attr" } } },
+       { "host", "attr", SDB_FIELD_BACKEND,      0, { SDB_TYPE_ARRAY | SDB_TYPE_STRING, { .array = { 0, NULL } } } },
+       { "host", "attr", SDB_FIELD_VALUE,        0, { SDB_TYPE_INTEGER, { .integer = 1 } } },
+       { "host", "attr", SDB_FIELD_VALUE,        0, { SDB_TYPE_DECIMAL, { .decimal = 2.0 } } },
+       { "host", "attr", SDB_FIELD_VALUE,        0, { SDB_TYPE_STRING, { .string = "foo" } } },
+       { "host", "attr", SDB_FIELD_VALUE,        0, { SDB_TYPE_DATETIME, { .datetime = 1234567890L } } },
+       { "host", "a",    SDB_FIELD_LAST_UPDATE, -1, { SDB_TYPE_NULL, { 0 } } },
+       { "host", "a",    SDB_FIELD_INTERVAL,    -1, { SDB_TYPE_NULL, { 0 } } },
+       { "host", "a",    SDB_FIELD_AGE,         -1, { SDB_TYPE_NULL, { 0 } } },
+       { "host", "a",    SDB_FIELD_NAME,        -1, { SDB_TYPE_NULL, { 0 } } },
+       { "host", "a",    SDB_FIELD_BACKEND,     -1, { SDB_TYPE_NULL, { 0 } } },
+       { "host", "a",    SDB_FIELD_VALUE,       -1, { SDB_TYPE_NULL, { 0 } } },
+       { "host", "a",    SDB_FIELD_VALUE,       -1, { SDB_TYPE_NULL, { 0 } } },
+       { "host", "a",    SDB_FIELD_VALUE,       -1, { SDB_TYPE_NULL, { 0 } } },
+       { "host", "a",    SDB_FIELD_VALUE,       -1, { SDB_TYPE_NULL, { 0 } } },
+};
+
+/* returns a tuple <type> <name> */
+#define OBJ_NAME(obj) \
+       (obj) ? SDB_STORE_TYPE_TO_NAME(obj->type) : "NULL", \
+       (obj) ? SDB_OBJ(obj)->name : ""
+START_TEST(test_get_field)
 {
-       int pos;
-       size_t len1, len2;
-       size_t i;
+       sdb_store_obj_t *obj = NULL;
+       sdb_data_t value = SDB_DATA_INIT;
+       char value_str[128], expected_value_str[128];
+       sdb_time_t now = sdb_gettime();
+       int check;
 
-       len1 = strlen(sdb_strbuf_string(buf));
-       len2 = strlen(expected);
+       sdb_plugin_store_host("host", 10);
+       sdb_plugin_store_host("host", 20);
+       sdb_plugin_store_attribute("host", "attr", &get_field_data[_i].value, 10);
+       sdb_plugin_store_attribute("host", "attr", &get_field_data[_i].value, 20);
 
-       pos = -1;
-       if (len1 != len2)
-               pos = (int)(len1 <= len2 ? len1 : len2);
+       if (get_field_data[_i].hostname) {
+               obj = sdb_store_get_host(get_field_data[_i].hostname);
+               ck_assert(obj != NULL);
 
-       for (i = 0; i < (len1 <= len2 ? len1 : len2); ++i) {
-               if (sdb_strbuf_string(buf)[i] != expected[i]) {
-                       pos = (int)i;
-                       break;
+               if (get_field_data[_i].attr) {
+                       sdb_store_obj_t *tmp = sdb_store_get_child(obj,
+                                       SDB_ATTRIBUTE, get_field_data[_i].attr);
+                       sdb_object_deref(SDB_OBJ(obj));
+                       obj = tmp;
                }
        }
 
-       fail_unless(pos == -1,
-                       "sdb_store_tojson(<buf>, %p, %x) returned unexpected result\n"
-                       "         got: %s\n              %*s\n    expected: %s",
-                       filter, flags, sdb_strbuf_string(buf), pos + 1, "^",
-                       expected);
-} /* verify_json_output */
+       check = sdb_store_get_field(obj, get_field_data[_i].field, NULL);
+       fail_unless(check == get_field_data[_i].expected,
+                       "sdb_store_get_field(%s %s, %s, NULL) = %d; expected: %d",
+                       OBJ_NAME(obj), SDB_FIELD_TO_NAME(get_field_data[_i].field),
+                       check, get_field_data[_i].expected);
+       check = sdb_store_get_field(obj, get_field_data[_i].field, &value);
+       fail_unless(check == get_field_data[_i].expected,
+                       "sdb_store_get_field(%s %s, %s, <value>) = %d; expected: %d",
+                       OBJ_NAME(obj), SDB_FIELD_TO_NAME(get_field_data[_i].field),
+                       check, get_field_data[_i].expected);
+
+       if (get_field_data[_i].expected) {
+               sdb_object_deref(SDB_OBJ(obj));
+               return;
+       }
 
-START_TEST(test_store_tojson)
-{
-       sdb_strbuf_t *buf;
-       size_t i;
+       if (get_field_data[_i].field == SDB_FIELD_AGE) {
+               get_field_data[_i].value.type = SDB_TYPE_DATETIME;
+               get_field_data[_i].value.data.datetime = now;
+       }
 
+       sdb_data_format(&value, value_str, sizeof(value_str), 0);
+       sdb_data_format(&get_field_data[_i].value, expected_value_str,
+                       sizeof(expected_value_str), 0);
+
+       if (get_field_data[_i].field == SDB_FIELD_AGE) {
+               fail_unless((value.type == SDB_TYPE_DATETIME)
+                               && (value.data.datetime >= now),
+                               "sdb_store_get_field(%s %s, %s, <value>) "
+                               "returned value %s; expected >=%s", OBJ_NAME(obj),
+                               SDB_FIELD_TO_NAME(get_field_data[_i].field),
+                               value_str, expected_value_str);
+       }
+       else {
+               fail_unless(! sdb_data_cmp(&value, &get_field_data[_i].value),
+                               "sdb_store_get_field(%s %s, %s, <value>) "
+                               "returned value %s; expected %s", OBJ_NAME(obj),
+                               SDB_FIELD_TO_NAME(get_field_data[_i].field),
+                               value_str, expected_value_str);
+       }
+       sdb_data_free_datum(&value);
+       sdb_object_deref(SDB_OBJ(obj));
+}
+END_TEST
+#undef OBJ_NAME
+
+START_TEST(test_get_child)
+{
        struct {
-               struct {
-                       sdb_store_matcher_t *(*m)(sdb_store_expr_t *,
-                                       sdb_store_expr_t *);
-                       int field;
-                       sdb_data_t value;
-               } filter;
-               int flags;
-               const char *expected;
+               const char *host;
+               const char *name;
+               int type;
+               int expected;
        } golden_data[] = {
-               { { NULL, 0, SDB_DATA_INIT }, 0,
-                       "["
-                               "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                       "\"attributes\": ["
-                                               "{\"name\": \"k1\", \"value\": \"v1\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": []},"
-                                               "{\"name\": \"k2\", \"value\": \"v2\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": []},"
-                                               "{\"name\": \"k3\", \"value\": \"v3\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": []}"
-                                       "], "
-                                       "\"metrics\": ["
-                                               "{\"name\": \"m1\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                                       "\"attributes\": ["
-                                                               "{\"name\": \"k3\", \"value\": 42, "
-                                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                                       "\"update_interval\": \"0s\", \"backends\": []}"
-                                                       "]},"
-                                               "{\"name\": \"m2\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                                       "\"attributes\": []}"
-                                       "], "
-                                       "\"services\": []},"
-                               "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                       "\"attributes\": [], "
-                                       "\"metrics\": ["
-                                               "{\"name\": \"m1\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                                       "\"attributes\": []}"
-                                       "], "
-                                       "\"services\": ["
-                                               "{\"name\": \"s1\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                                       "\"attributes\": []},"
-                                               "{\"name\": \"s2\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                                       "\"attributes\": ["
-                                                               "{\"name\": \"k1\", \"value\": 123, "
-                                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                                       "\"update_interval\": \"0s\", \"backends\": []},"
-                                                               "{\"name\": \"k2\", \"value\": 4711, "
-                                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                                       "\"update_interval\": \"0s\", \"backends\": []}"
-                                                       "]}"
-                                       "]}"
-                       "]" },
-               { { NULL, 0, SDB_DATA_INIT }, SDB_SKIP_SERVICES,
-                       "["
-                               "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                       "\"attributes\": ["
-                                               "{\"name\": \"k1\", \"value\": \"v1\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": []},"
-                                               "{\"name\": \"k2\", \"value\": \"v2\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": []},"
-                                               "{\"name\": \"k3\", \"value\": \"v3\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": []}"
-                                       "], "
-                                       "\"metrics\": ["
-                                               "{\"name\": \"m1\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                                       "\"attributes\": ["
-                                                               "{\"name\": \"k3\", \"value\": 42, "
-                                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                                       "\"update_interval\": \"0s\", \"backends\": []}"
-                                                       "]},"
-                                               "{\"name\": \"m2\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                                       "\"attributes\": []}"
-                                       "]},"
-                               "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                       "\"attributes\": [], "
-                                       "\"metrics\": ["
-                                               "{\"name\": \"m1\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                                       "\"attributes\": []}"
-                                       "]}"
-                       "]" },
-               { { NULL, 0, SDB_DATA_INIT }, SDB_SKIP_METRICS,
-                       "["
-                               "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                       "\"attributes\": ["
-                                               "{\"name\": \"k1\", \"value\": \"v1\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": []},"
-                                               "{\"name\": \"k2\", \"value\": \"v2\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": []},"
-                                               "{\"name\": \"k3\", \"value\": \"v3\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": []}"
-                                       "], "
-                                       "\"services\": []},"
-                               "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                       "\"attributes\": [], "
-                                       "\"services\": ["
-                                               "{\"name\": \"s1\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                                       "\"attributes\": []},"
-                                               "{\"name\": \"s2\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                                       "\"attributes\": ["
-                                                               "{\"name\": \"k1\", \"value\": 123, "
-                                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                                       "\"update_interval\": \"0s\", \"backends\": []},"
-                                                               "{\"name\": \"k2\", \"value\": 4711, "
-                                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                                       "\"update_interval\": \"0s\", \"backends\": []}"
-                                                       "]}"
-                                       "]}"
-                       "]" },
-               { { NULL, 0, SDB_DATA_INIT }, SDB_SKIP_ATTRIBUTES,
-                       "["
-                               "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                       "\"metrics\": ["
-                                               "{\"name\": \"m1\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": []},"
-                                               "{\"name\": \"m2\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": []}"
-                                       "], "
-                                       "\"services\": []},"
-                               "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                       "\"metrics\": ["
-                                               "{\"name\": \"m1\", "
-                                                       "\"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\": []},"
-                                               "{\"name\": \"s2\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": []}"
-                                       "]}"
-                       "]" },
-               { { NULL, 0, SDB_DATA_INIT }, SDB_SKIP_ALL,
-                       "["
-                               "{\"name\": \"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\": []}"
-                       "]" },
-               { { sdb_store_eq_matcher, SDB_FIELD_NAME,
-                               { SDB_TYPE_STRING, { .string = "h1" } } }, 0,
-                       "["
-                               "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                       "\"attributes\": [], \"metrics\": [], \"services\": []}"
-                       "]" },
-               { { sdb_store_gt_matcher, SDB_FIELD_LAST_UPDATE,
-                               { SDB_TYPE_DATETIME, { .datetime = 1 } } }, 0,
-                       "["
-                               "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                       "\"attributes\": [], "
-                                       "\"metrics\": [], "
-                                       "\"services\": ["
-                                               "{\"name\": \"s2\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                                       "\"attributes\": ["
-                                                               "{\"name\": \"k1\", \"value\": 123, "
-                                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                                       "\"update_interval\": \"0s\", \"backends\": []},"
-                                                       "]}"
-                                       "]}"
-                       "]" },
-               { { sdb_store_le_matcher, SDB_FIELD_LAST_UPDATE,
-                               { SDB_TYPE_DATETIME, { .datetime = 1 } } }, 0,
-                       "["
-                               "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                       "\"attributes\": ["
-                                               "{\"name\": \"k1\", \"value\": \"v1\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": []},"
-                                       "], "
-                                       "\"metrics\": ["
-                                               "{\"name\": \"m2\", "
-                                                       "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                                       "\"attributes\": []}"
-                                       "], "
-                                       "\"services\": []}"
-                       "]" },
-               { { sdb_store_ge_matcher, SDB_FIELD_LAST_UPDATE,
-                               { SDB_TYPE_DATETIME, { .datetime = 3 } } }, 0,
-                       "["
-                               "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                       "\"update_interval\": \"0s\", \"backends\": [], "
-                                       "\"attributes\": [], "
-                                       "\"metrics\": [], "
-                                       "\"services\": []}"
-                       "]" },
+               { "h1", NULL, SDB_HOST,       0 },
+               { "h1", NULL, SDB_SERVICE,   -1 },
+               { "h1", NULL, SDB_METRIC,    -1 },
+               { "h1", NULL, SDB_ATTRIBUTE, -1 },
+               { "h2", NULL, SDB_HOST,       0 },
+               { "h2", NULL, SDB_SERVICE,   -1 },
+               { "h2", NULL, SDB_METRIC,    -1 },
+               { "h2", NULL, SDB_ATTRIBUTE, -1 },
+               { "h3", NULL, SDB_HOST,      -1 },
+               { "h1", "k1", SDB_ATTRIBUTE,  0 },
+               { "h1", "x1", SDB_ATTRIBUTE, -1 },
+               { "h2", "k1", SDB_ATTRIBUTE, -1 },
+               { "h1", "k1", SDB_SERVICE,   -1 },
+               { "h1", "k1", SDB_METRIC,    -1 },
+               { "h1", "s1", SDB_SERVICE,   -1 },
+               { "h2", "s1", SDB_SERVICE,    0 },
+               { "h1", "m2", SDB_METRIC,     0 },
+               { "h2", "m2", SDB_METRIC,    -1 },
        };
 
-       buf = sdb_strbuf_create(0);
-       fail_unless(buf != NULL, "INTERNAL ERROR: failed to create string buffer");
+       size_t i;
+
        populate();
 
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
-               sdb_store_matcher_t *filter = NULL;
-               int status;
-
-               sdb_strbuf_clear(buf);
-
-               if (golden_data[i].filter.m) {
-                       sdb_store_expr_t *field;
-                       sdb_store_expr_t *value;
-
-                       field = sdb_store_expr_fieldvalue(golden_data[i].filter.field);
-                       fail_unless(field != NULL,
-                                       "INTERNAL ERROR: sdb_store_expr_fieldvalue() = NULL");
-                       value = sdb_store_expr_constvalue(&golden_data[i].filter.value);
-                       fail_unless(value != NULL,
-                                       "INTERNAL ERROR: sdb_store_expr_constvalue() = NULL");
-
-                       filter = golden_data[i].filter.m(field, value);
-                       fail_unless(filter != NULL,
-                                       "INTERNAL ERROR: sdb_store_*_matcher() = NULL");
-
-                       sdb_object_deref(SDB_OBJ(field));
-                       sdb_object_deref(SDB_OBJ(value));
+               sdb_store_obj_t *obj;
+               const char *expected_name = golden_data[i].host;
+
+               obj = sdb_store_get_host(golden_data[i].host);
+               if (golden_data[i].expected && (golden_data[i].type == SDB_HOST))
+                       fail_unless(obj == NULL,
+                                       "sdb_store_get_host(%s) = %p; expected: NULL",
+                                       golden_data[i].host, obj);
+               else
+                       fail_unless(obj != NULL,
+                                       "sdb_store_get_host(%s) = NULL; expected: <host>",
+                                       golden_data[i].host);
+
+               if (golden_data[i].type != SDB_HOST) {
+                       sdb_store_obj_t *tmp;
+
+                       expected_name = golden_data[i].name;
+
+                       tmp = sdb_store_get_child(obj,
+                                       golden_data[i].type, golden_data[i].name);
+                       if (golden_data[i].expected)
+                               fail_unless(tmp == NULL,
+                                               "sdb_store_get_child(<%s>, %s, %s) = %p; "
+                                               "expected: NULL", golden_data[i].host,
+                                               SDB_STORE_TYPE_TO_NAME(golden_data[i].type),
+                                               golden_data[i].name, tmp);
+                       else
+                               fail_unless(tmp != NULL,
+                                               "sdb_store_get_child(<%s>, %s, %s) = NULL; "
+                                               "expected: <obj>", golden_data[i].host,
+                                               SDB_STORE_TYPE_TO_NAME(golden_data[i].type),
+                                               golden_data[i].name);
+
+                       sdb_object_deref(SDB_OBJ(obj));
+                       obj = tmp;
                }
 
-               status = sdb_store_tojson(buf, filter, golden_data[i].flags);
-               fail_unless(status == 0,
-                               "sdb_store_tojson(<buf>, %p, %x) = %d; expected: 0",
-                               filter, golden_data[i].flags, status);
-
-               verify_json_output(buf, golden_data[i].expected,
-                               filter, golden_data[i].flags);
-               sdb_object_deref(SDB_OBJ(filter));
+               if (golden_data[i].expected)
+                       continue;
+
+               fail_unless(obj->type == golden_data[i].type,
+                               "sdb_store_get_<%s>(%s, %s) returned object of type %d; "
+                               "expected: %d", SDB_STORE_TYPE_TO_NAME(golden_data[i].type),
+                               golden_data[i].host, golden_data[i].name, obj->type,
+                               golden_data[i].type);
+               fail_unless(! strcasecmp(SDB_OBJ(obj)->name, expected_name),
+                               "sdb_store_get_<%s>(%s, %s) returned object named '%s'; "
+                               "expected: '%s'", SDB_STORE_TYPE_TO_NAME(golden_data[i].type),
+                               golden_data[i].host, golden_data[i].name, SDB_OBJ(obj)->name,
+                               expected_name);
+
+               sdb_object_deref(SDB_OBJ(obj));
        }
-       sdb_strbuf_destroy(buf);
-}
-END_TEST
-
-START_TEST(test_get_field)
-{
-       sdb_store_obj_t *host;
-       sdb_data_t value = SDB_DATA_INIT;
-       int check;
-
-       sdb_store_host("host", 10);
-       sdb_store_host("host", 20);
-
-       host = sdb_store_get_host("host");
-       fail_unless(host != NULL,
-                       "INTERNAL ERROR: store doesn't have host after adding it");
-
-       check = sdb_store_get_field(NULL, 0, NULL);
-       fail_unless(check < 0,
-                       "sdb_store_get_field(NULL, 0, NULL) = %d; expected: <0");
-       check = sdb_store_get_field(NULL, SDB_FIELD_LAST_UPDATE, NULL);
-       fail_unless(check < 0,
-                       "sdb_store_get_field(NULL, SDB_FIELD_LAST_UPDATE, NULL) = %d; "
-                       "expected: <0");
-       check = sdb_store_get_field(NULL, SDB_FIELD_LAST_UPDATE, &value);
-       fail_unless(check < 0,
-                       "sdb_store_get_field(NULL, SDB_FIELD_LAST_UPDATE, <value>) = %d; "
-                       "expected: <0");
-
-       check = sdb_store_get_field(host, SDB_FIELD_LAST_UPDATE, NULL);
-       fail_unless(check == 0,
-                       "sdb_store_get_field(<host>, SDB_FIELD_LAST_UPDATE, NULL) = %d; "
-                       "expected: 0");
-       /* 'name' is dynamically allocated; make sure it's not leaked even
-        * if there is no result parameter */
-       check = sdb_store_get_field(host, SDB_FIELD_NAME, NULL);
-       fail_unless(check == 0,
-                       "sdb_store_get_field(<host>, SDB_FIELD_LAST_UPDATE, NULL) = %d; "
-                       "expected: 0");
-
-       check = sdb_store_get_field(host, SDB_FIELD_NAME, &value);
-       fail_unless(check == 0,
-                       "sdb_store_get_field(<host>, SDB_FIELD_NAME, <value>) = "
-                       "%d; expected: 0");
-       fail_unless((value.type == SDB_TYPE_STRING)
-                       && (! strcmp(value.data.string, "host")),
-                       "sdb_store_get_field(<host>, SDB_FIELD_NAME, <value>) "
-                       "returned value {%d, %s}; expected {%d, host}",
-                       value.type, value.data.string, SDB_TYPE_STRING);
-       sdb_data_free_datum(&value);
-
-       check = sdb_store_get_field(host, SDB_FIELD_LAST_UPDATE, &value);
-       fail_unless(check == 0,
-                       "sdb_store_get_field(<host>, SDB_FIELD_LAST_UPDATE, <value>) = "
-                       "%d; expected: 0");
-       fail_unless((value.type == SDB_TYPE_DATETIME)
-                       && (value.data.datetime == 20),
-                       "sdb_store_get_field(<host>, SDB_FIELD_LAST_UPDATE, <value>) "
-                       "returned value {%d, %lu}; expected {%d, 20}",
-                       value.type, value.data.datetime, SDB_TYPE_DATETIME);
-
-       check = sdb_store_get_field(host, SDB_FIELD_AGE, &value);
-       fail_unless(check == 0,
-                       "sdb_store_get_field(<host>, SDB_FIELD_AGE, <value>) = "
-                       "%d; expected: 0");
-       /* let's assume we're at least in year 1980 ;-) */
-       fail_unless((value.type == SDB_TYPE_DATETIME)
-                       && (value.data.datetime > 10L * SDB_INTERVAL_YEAR),
-                       "sdb_store_get_field(<host>, SDB_FIELD_AGE, <value>) "
-                       "returned value {%d, %lu}; expected {%d, >%lu}",
-                       value.type, value.data.datetime,
-                       SDB_TYPE_DATETIME, 10L * SDB_INTERVAL_YEAR);
-
-       check = sdb_store_get_field(host, SDB_FIELD_INTERVAL, &value);
-       fail_unless(check == 0,
-                       "sdb_store_get_field(<host>, SDB_FIELD_INTERVAL, <value>) = "
-                       "%d; expected: 0");
-       fail_unless((value.type == SDB_TYPE_DATETIME)
-                       && (value.data.datetime == 10),
-                       "sdb_store_get_field(<host>, SDB_FIELD_INTERVAL, <value>) "
-                       "returned value {%d, %lu}; expected {%d, 10}",
-                       value.type, value.data.datetime, SDB_TYPE_DATETIME);
-
-       check = sdb_store_get_field(host, SDB_FIELD_BACKEND, &value);
-       fail_unless(check == 0,
-                       "sdb_store_get_field(<host>, SDB_FIELD_BACKEND, <value>) = "
-                       "%d; expected: 0");
-       /* there are no backends in this test */
-       fail_unless((value.type == (SDB_TYPE_ARRAY | SDB_TYPE_STRING))
-                       && (value.data.array.length == 0)
-                       && (value.data.array.values == NULL),
-                       "sdb_store_get_field(<host>, SDB_FIELD_BACKEND, <value>) "
-                       "returned value {%d, %lu, %p}; expected {%d, 0, NULL}",
-                       value.type, value.data.array.length, value.data.array.values,
-                       SDB_TYPE_ARRAY | SDB_TYPE_STRING);
 }
 END_TEST
 
@@ -815,51 +624,51 @@ START_TEST(test_interval)
        sdb_store_obj_t *host;
 
        /* 10 us interval */
-       sdb_store_host("host", 10);
-       sdb_store_host("host", 20);
-       sdb_store_host("host", 30);
-       sdb_store_host("host", 40);
+       sdb_plugin_store_host("host", 10);
+       sdb_plugin_store_host("host", 20);
+       sdb_plugin_store_host("host", 30);
+       sdb_plugin_store_host("host", 40);
 
        host = sdb_store_get_host("host");
        fail_unless(host != NULL,
                        "INTERNAL ERROR: store doesn't have host after adding it");
 
        fail_unless(host->interval == 10,
-                       "sdb_store_host() did not calculate interval correctly: "
+                       "sdb_plugin_store_host() did not calculate interval correctly: "
                        "got: %"PRIsdbTIME"; expected: %"PRIsdbTIME, host->interval, 10);
 
        /* multiple updates for the same timestamp don't modify the interval */
-       sdb_store_host("host", 40);
-       sdb_store_host("host", 40);
-       sdb_store_host("host", 40);
-       sdb_store_host("host", 40);
+       sdb_plugin_store_host("host", 40);
+       sdb_plugin_store_host("host", 40);
+       sdb_plugin_store_host("host", 40);
+       sdb_plugin_store_host("host", 40);
 
        fail_unless(host->interval == 10,
-                       "sdb_store_host() changed interval when doing multiple updates "
+                       "sdb_plugin_store_host() changed interval when doing multiple updates "
                        "using the same timestamp; got: %"PRIsdbTIME"; "
                        "expected: %"PRIsdbTIME, host->interval, 10);
 
        /* multiple updates using an timestamp don't modify the interval */
-       sdb_store_host("host", 20);
-       sdb_store_host("host", 20);
-       sdb_store_host("host", 20);
-       sdb_store_host("host", 20);
+       sdb_plugin_store_host("host", 20);
+       sdb_plugin_store_host("host", 20);
+       sdb_plugin_store_host("host", 20);
+       sdb_plugin_store_host("host", 20);
 
        fail_unless(host->interval == 10,
-                       "sdb_store_host() changed interval when doing multiple updates "
+                       "sdb_plugin_store_host() changed interval when doing multiple updates "
                        "using an old timestamp; got: %"PRIsdbTIME"; expected: %"PRIsdbTIME,
                        host->interval, 10);
 
        /* new interval: 20 us */
-       sdb_store_host("host", 60);
+       sdb_plugin_store_host("host", 60);
        fail_unless(host->interval == 11,
-                       "sdb_store_host() did not calculate interval correctly: "
+                       "sdb_plugin_store_host() did not calculate interval correctly: "
                        "got: %"PRIsdbTIME"; expected: %"PRIsdbTIME, host->interval, 11);
 
        /* new interval: 40 us */
-       sdb_store_host("host", 100);
+       sdb_plugin_store_host("host", 100);
        fail_unless(host->interval == 13,
-                       "sdb_store_host() did not calculate interval correctly: "
+                       "sdb_plugin_store_host() did not calculate interval correctly: "
                        "got: %"PRIsdbTIME"; expected: %"PRIsdbTIME, host->interval, 11);
 
        sdb_object_deref(SDB_OBJ(host));
@@ -867,10 +676,13 @@ START_TEST(test_interval)
 END_TEST
 
 static int
-scan_count(sdb_store_obj_t *obj, void *user_data)
+scan_count(sdb_store_obj_t *obj, sdb_store_matcher_t *filter, void *user_data)
 {
        intptr_t *i = user_data;
 
+       if (! sdb_store_matcher_matches(filter, obj, NULL))
+               return 0;
+
        fail_unless(obj != NULL,
                        "sdb_store_scan callback received NULL obj; expected: "
                        "<store base obj>");
@@ -883,10 +695,13 @@ scan_count(sdb_store_obj_t *obj, void *user_data)
 } /* scan_count */
 
 static int
-scan_error(sdb_store_obj_t *obj, void *user_data)
+scan_error(sdb_store_obj_t *obj, sdb_store_matcher_t *filter, void *user_data)
 {
        intptr_t *i = user_data;
 
+       if (! sdb_store_matcher_matches(filter, obj, NULL))
+               return 0;
+
        fail_unless(obj != NULL,
                        "sdb_store_scan callback received NULL obj; expected: "
                        "<store base obj>");
@@ -906,8 +721,8 @@ START_TEST(test_scan)
        /* empty store */
        check = sdb_store_scan(SDB_HOST, /* m, filter = */ NULL, NULL,
                        scan_count, &i);
-       fail_unless(check == -1,
-                       "sdb_store_scan(HOST), empty store = %d; expected: -1", check);
+       fail_unless(check == 0,
+                       "sdb_store_scan(HOST), empty store = %d; expected: 0", check);
        fail_unless(i == 0,
                        "sdb_store_scan(HOST) called callback %d times; "
                        "expected: 0", (int)i);
@@ -951,14 +766,9 @@ START_TEST(test_scan)
 }
 END_TEST
 
-Suite *
-core_store_suite(void)
+TEST_MAIN("core::store")
 {
-       Suite *s = suite_create("core::store");
-       TCase *tc;
-
-       tc = tcase_create("core");
-       tcase_add_test(tc, test_store_tojson);
+       TCase *tc = tcase_create("core");
        tcase_add_test(tc, test_store_host);
        tcase_add_test(tc, test_store_get_host);
        tcase_add_test(tc, test_store_attr);
@@ -966,14 +776,14 @@ core_store_suite(void)
        tcase_add_test(tc, test_store_metric_attr);
        tcase_add_test(tc, test_store_service);
        tcase_add_test(tc, test_store_service_attr);
-       tcase_add_test(tc, test_get_field);
+       TC_ADD_LOOP_TEST(tc, get_field);
+       tcase_add_test(tc, test_get_child);
        tcase_add_test(tc, test_interval);
        tcase_add_test(tc, test_scan);
-       tcase_add_unchecked_fixture(tc, NULL, sdb_store_clear);
-       suite_add_tcase(s, tc);
-
-       return s;
-} /* core_store_suite */
+       tcase_add_unchecked_fixture(tc, init, sdb_store_clear);
+       ADD_TCASE(tc);
+}
+TEST_MAIN_END
 
 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */