X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=t%2Funit%2Fcore%2Fstore_lookup_test.c;h=49f2268a24d0758dc5165934bb5c75d7908a9947;hp=f202c6ba463ffd291f8da2b6a95071b6ca2a6c07;hb=9345a64b2fa015c30d6b3fcba76211f8d0d7cfd6;hpb=8b3cabcc3ff88a9b676bb29aa1f14f1036ef19c8 diff --git a/t/unit/core/store_lookup_test.c b/t/unit/core/store_lookup_test.c index f202c6b..49f2268 100644 --- a/t/unit/core/store_lookup_test.c +++ b/t/unit/core/store_lookup_test.c @@ -29,13 +29,12 @@ # include "config.h" #endif +#include "core/plugin.h" #include "core/store.h" #include "core/store-private.h" -#include "frontend/parser.h" +#include "parser/parser.h" #include "testutils.h" -#include - #include #include @@ -75,34 +74,36 @@ populate(void) size_t i; + sdb_store_init(); + for (i = 0; i < SDB_STATIC_ARRAY_LEN(hosts); ++i) { - int status = sdb_store_host(hosts[i], 1); + int status = sdb_plugin_store_host(hosts[i], 1); fail_unless(status == 0, - "sdb_store_host(%s, 1) = %d; expected: 0", + "sdb_plugin_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_plugin_store_metric(metrics[i].host, metrics[i].metric, /* store */ NULL, 1); fail_unless(status == 0, - "sdb_store_metric(%s, %s, NULL, 1) = %d; expected: 0", + "sdb_plugin_store_metric(%s, %s, NULL, 1) = %d; expected: 0", metrics[i].host, metrics[i].metric, status); } for (i = 0; i < SDB_STATIC_ARRAY_LEN(services); ++i) { - int status = sdb_store_service(services[i].host, + int status = sdb_plugin_store_service(services[i].host, services[i].service, 1); fail_unless(status == 0, - "sdb_store_service(%s, %s, 1) = %d; expected: 0", + "sdb_plugin_store_service(%s, %s, 1) = %d; expected: 0", services[i].host, services[i].service, status); } for (i = 0; i < SDB_STATIC_ARRAY_LEN(attrs); ++i) { - int status = sdb_store_attribute(attrs[i].host, + int status = sdb_plugin_store_attribute(attrs[i].host, attrs[i].name, &attrs[i].value, 1); fail_unless(status == 0, - "sdb_store_attribute(%s, %s, , 1) = %d; expected: 0", + "sdb_plugin_store_attribute(%s, %s, , 1) = %d; expected: 0", attrs[i].host, attrs[i].name, status); } } /* populate */ @@ -152,7 +153,7 @@ START_TEST(test_cmp_name) { sdb_store_obj_t *host; sdb_data_t datum; - sdb_store_expr_t *obj, *value; + sdb_store_expr_t *obj = NULL, *value; sdb_store_matcher_t *m, *n; int status; @@ -163,10 +164,12 @@ START_TEST(test_cmp_name) datum.type = SDB_TYPE_STRING; datum.data.string = cmp_name_data[_i].name; - obj = sdb_store_expr_fieldvalue(SDB_FIELD_NAME); - fail_unless(obj != NULL, - "sdb_store_expr_fieldvalue(SDB_STORE_NAME) = NULL; " - "expected: "); + if (cmp_name_data[_i].type == SDB_HOST) { + obj = sdb_store_expr_fieldvalue(SDB_FIELD_NAME); + fail_unless(obj != NULL, + "sdb_store_expr_fieldvalue(SDB_STORE_NAME) = NULL; " + "expected: "); + } value = sdb_store_expr_constvalue(&datum); fail_unless(value != NULL, "sdb_store_expr_constvalue(%s) = NULL; " @@ -176,9 +179,15 @@ START_TEST(test_cmp_name) m = sdb_store_regex_matcher(obj, value); else m = sdb_store_eq_matcher(obj, value); + if (cmp_name_data[_i].type != SDB_HOST) { + sdb_store_expr_t *iter; sdb_store_matcher_t *tmp; - tmp = sdb_store_any_matcher(cmp_name_data[_i].type, m); + obj = sdb_store_expr_fieldvalue(SDB_FIELD_NAME); + iter = sdb_store_expr_typed(cmp_name_data[_i].type, obj); + tmp = sdb_store_any_matcher(iter, m); + ck_assert(iter && m); + sdb_object_deref(SDB_OBJ(iter)); sdb_object_deref(SDB_OBJ(m)); m = tmp; } @@ -257,7 +266,7 @@ START_TEST(test_cmp_attr) }; const char *op_str[] = { "<", "<=", "=", ">=", ">" }; - assert(SDB_STATIC_ARRAY_LEN(tests) == SDB_STATIC_ARRAY_LEN(op_str)); + ck_assert(SDB_STATIC_ARRAY_LEN(tests) == SDB_STATIC_ARRAY_LEN(op_str)); host = sdb_store_get_host("a"); fail_unless(host != NULL, @@ -365,7 +374,7 @@ START_TEST(test_cmp_obj) }; char *op_str[] = { "<", "<=", "=", ">=", ">" }; - assert(SDB_STATIC_ARRAY_LEN(tests) == SDB_STATIC_ARRAY_LEN(op_str)); + ck_assert(SDB_STATIC_ARRAY_LEN(tests) == SDB_STATIC_ARRAY_LEN(op_str)); host = sdb_store_get_host(cmp_obj_data[_i].host); fail_unless(host != NULL, @@ -419,8 +428,8 @@ START_TEST(test_store_match_op) sdb_data_t d = { SDB_TYPE_STRING, { .string = "a" } }; sdb_store_expr_t *e = sdb_store_expr_constvalue(&d); - sdb_store_matcher_t *always = sdb_store_isnnull_matcher(e); sdb_store_matcher_t *never = sdb_store_isnull_matcher(e); + sdb_store_matcher_t *always = sdb_store_inv_matcher(never); struct { const char *op; @@ -561,11 +570,17 @@ struct { { "ANY attribute.name = 'x'", NULL, 0 }, { "ANY attribute.name =~ 'x'", NULL, 0 }, { "ALL attribute.name = 'k1'", NULL, 2 }, + { "ANY attribute.value = 'v1'", NULL, 1 }, + { "ANY attribute.value =~ 'v'", NULL, 2 }, + { "ANY attribute.value = 123", NULL, 1 }, { "host.name = 'a'", NULL, 1 }, { "host.attribute['k1'] =~ 'v1'", NULL, 1 }, { "host.attribute['x1'] IS NULL", NULL, 3 }, + /* not a boolean so neither TRUE nor FALSE: */ + { "attribute['k1'] IS TRUE", NULL, 0 }, + { "attribute['k1'] IS FALSE", NULL, 0 }, { "attribute['k1'] = 'v1'", NULL, 1 }, { "attribute['k1'] = 'v1'", "name != 'k1'", 0 }, @@ -581,8 +596,13 @@ struct { { "attribute['x1'] !~ 'v'", NULL, 0 }, { "attribute['k1'] IS NULL", NULL, 1 }, { "attribute['x1'] IS NULL", NULL, 3 }, + { "attribute['k1'] IS TRUE", NULL, 0 }, + { "attribute['x1'] IS TRUE", NULL, 0 }, + { "attribute['k1'] IS FALSE", NULL, 0 }, + { "attribute['x1'] IS FALSE", NULL, 0 }, { "attribute['k1'] IS NOT NULL", NULL, 2 }, { "attribute['x1'] IS NOT NULL", NULL, 0 }, + { "attribute['x1'] IS NOT TRUE", NULL, 3 }, { "attribute['k2'] < 123", NULL, 0 }, { "attribute['k2'] <= 123", NULL, 1 }, { "attribute['k2'] >= 123", NULL, 1 }, @@ -599,6 +619,7 @@ START_TEST(test_scan) { sdb_strbuf_t *errbuf = sdb_strbuf_create(64); sdb_store_matcher_t *m, *filter = NULL; + sdb_ast_node_t *ast; int check, n; n = 0; @@ -609,17 +630,21 @@ START_TEST(test_scan) fail_unless(n == 3, "sdb_store_scan called callback %d times; expected: 3", (int)n); - m = sdb_fe_parse_matcher(scan_data[_i].query, -1, errbuf); + ast = sdb_parser_parse_conditional(scan_data[_i].query, -1, errbuf); + m = sdb_store_query_prepare_matcher(ast); + sdb_object_deref(SDB_OBJ(ast)); fail_unless(m != NULL, - "sdb_fe_parse_matcher(%s, -1) = NULL; expected: " + "sdb_parser_parse_conditional(%s, -1) = NULL; expected: " "(parser error: %s)", scan_data[_i].query, sdb_strbuf_string(errbuf)); if (scan_data[_i].filter) { - filter = sdb_fe_parse_matcher(scan_data[_i].filter, -1, errbuf); + ast = sdb_parser_parse_conditional(scan_data[_i].filter, -1, errbuf); + filter = sdb_store_query_prepare_matcher(ast); + sdb_object_deref(SDB_OBJ(ast)); fail_unless(filter != NULL, - "sdb_fe_parse_matcher(%s, -1) = NULL; " - "expected: (parser error: %s)", + "sdb_parser_parse_conditional(%s, -1) = NULL; " + "expected: (parser error: %s)", scan_data[_i].filter, sdb_strbuf_string(errbuf)); }