X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=t%2Funit%2Fcore%2Fstore_lookup_test.c;h=9f486836aaec3daf85818ed07c7d17c67c327c63;hp=b4c6015b7bfb0dcfe2d338eb05af51555491efca;hb=873627f033f749c6dc48293de1183ca4f6961926;hpb=9097c9c3259b2943dc0088b250ec871172025303 diff --git a/t/unit/core/store_lookup_test.c b/t/unit/core/store_lookup_test.c index b4c6015..9f48683 100644 --- a/t/unit/core/store_lookup_test.c +++ b/t/unit/core/store_lookup_test.c @@ -29,6 +29,7 @@ # include "config.h" #endif +#include "core/plugin.h" #include "core/store.h" #include "core/store-private.h" #include "parser/parser.h" @@ -37,6 +38,8 @@ #include #include +static sdb_store_t *store; + static void populate(void) { @@ -73,15 +76,18 @@ populate(void) size_t i; + store = sdb_store_create(); + ck_assert(store != NULL); + for (i = 0; i < SDB_STATIC_ARRAY_LEN(hosts); ++i) { - int status = sdb_store_host(hosts[i], 1); + int status = sdb_store_host(store, hosts[i], 1); fail_unless(status == 0, "sdb_store_host(%s, 1) = %d; expected: 0", hosts[i], status); } for (i = 0; i < SDB_STATIC_ARRAY_LEN(metrics); ++i) { - int status = sdb_store_metric(metrics[i].host, + int status = sdb_store_metric(store, metrics[i].host, metrics[i].metric, /* store */ NULL, 1); fail_unless(status == 0, "sdb_store_metric(%s, %s, NULL, 1) = %d; expected: 0", @@ -89,7 +95,7 @@ populate(void) } for (i = 0; i < SDB_STATIC_ARRAY_LEN(services); ++i) { - int status = sdb_store_service(services[i].host, + int status = sdb_store_service(store, services[i].host, services[i].service, 1); fail_unless(status == 0, "sdb_store_service(%s, %s, 1) = %d; expected: 0", @@ -97,7 +103,7 @@ populate(void) } for (i = 0; i < SDB_STATIC_ARRAY_LEN(attrs); ++i) { - int status = sdb_store_attribute(attrs[i].host, + int status = sdb_store_attribute(store, attrs[i].host, attrs[i].name, &attrs[i].value, 1); fail_unless(status == 0, "sdb_store_attribute(%s, %s, , 1) = %d; expected: 0", @@ -105,6 +111,13 @@ populate(void) } } /* populate */ +static void +turndown(void) +{ + sdb_object_deref(SDB_OBJ(store)); + store = NULL; +} /* turndown */ + struct { int type; char *name; @@ -154,7 +167,7 @@ START_TEST(test_cmp_name) sdb_store_matcher_t *m, *n; int status; - host = sdb_store_get_host("a"); + host = sdb_store_get_host(store, "a"); fail_unless(host != NULL, "sdb_store_get_host(a) = NULL; expected: "); @@ -265,7 +278,7 @@ START_TEST(test_cmp_attr) const char *op_str[] = { "<", "<=", "=", ">=", ">" }; ck_assert(SDB_STATIC_ARRAY_LEN(tests) == SDB_STATIC_ARRAY_LEN(op_str)); - host = sdb_store_get_host("a"); + host = sdb_store_get_host(store, "a"); fail_unless(host != NULL, "sdb_store_get_host(a) = NULL; expected: "); @@ -373,7 +386,7 @@ START_TEST(test_cmp_obj) ck_assert(SDB_STATIC_ARRAY_LEN(tests) == SDB_STATIC_ARRAY_LEN(op_str)); - host = sdb_store_get_host(cmp_obj_data[_i].host); + host = sdb_store_get_host(store, cmp_obj_data[_i].host); fail_unless(host != NULL, "sdb_store_get_host(%s) = NULL; expected: ", cmp_obj_data[_i].host); @@ -447,7 +460,7 @@ START_TEST(test_store_match_op) int status; size_t i; - obj = sdb_store_get_host("a"); + obj = sdb_store_get_host(store, "a"); status = sdb_store_matcher_matches(always, obj, /* filter */ NULL); fail_unless(status == 1, @@ -620,7 +633,8 @@ START_TEST(test_scan) int check, n; n = 0; - check = sdb_store_scan(SDB_HOST, /* matcher */ NULL, /* filter */ NULL, + check = sdb_store_scan(store, SDB_HOST, + /* matcher */ NULL, /* filter */ NULL, scan_cb, &n); fail_unless(check == 0, "sdb_store_scan() = %d; expected: 0", check); @@ -646,7 +660,7 @@ START_TEST(test_scan) } n = 0; - sdb_store_scan(SDB_HOST, m, filter, scan_cb, &n); + sdb_store_scan(store, SDB_HOST, m, filter, scan_cb, &n); fail_unless(n == scan_data[_i].expected, "sdb_store_scan(HOST, matcher{%s}, filter{%s}) " "found %d hosts; expected: %d", scan_data[_i].query, @@ -661,7 +675,7 @@ END_TEST TEST_MAIN("core::store_lookup") { TCase *tc = tcase_create("core"); - tcase_add_checked_fixture(tc, populate, sdb_store_clear); + tcase_add_checked_fixture(tc, populate, turndown); TC_ADD_LOOP_TEST(tc, cmp_name); TC_ADD_LOOP_TEST(tc, cmp_attr); TC_ADD_LOOP_TEST(tc, cmp_obj);