X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=t%2Funit%2Fcore%2Fstore_lookup_test.c;h=1a55d87844883b0af20bad5231dec0420c573072;hb=b0af45ebf920955095b9fdeaddbde0107c6e519f;hp=c143a8aacc2dca51d291cb5485e34cb26454fc56;hpb=fcd4fcb0afee7df6ff0e9f305f9ef43445f88545;p=sysdb.git diff --git a/t/unit/core/store_lookup_test.c b/t/unit/core/store_lookup_test.c index c143a8a..1a55d87 100644 --- a/t/unit/core/store_lookup_test.c +++ b/t/unit/core/store_lookup_test.c @@ -90,9 +90,6 @@ START_TEST(test_store_match) const char *hostname; const char *hostname_re; - const char *service_name; - const char *service_name_re; - const char *attr_name; const char *attr_name_re; const char *attr_value; @@ -102,107 +99,54 @@ START_TEST(test_store_match) } golden_data[] = { { /* host */ NULL, NULL, - /* svc */ NULL, NULL, /* attr */ NULL, NULL, NULL, NULL, 1 }, { /* host */ "a", NULL, - /* svc */ NULL, NULL, /* attr */ NULL, NULL, NULL, NULL, 1 }, { /* host */ "b", NULL, - /* svc */ NULL, NULL, /* attr */ NULL, NULL, NULL, NULL, 0 }, { /* host */ NULL, "^a$", - /* svc */ NULL, NULL, /* attr */ NULL, NULL, NULL, NULL, 1 }, { /* host */ NULL, "^b$", - /* svc */ NULL, NULL, /* attr */ NULL, NULL, NULL, NULL, 0 }, { /* host */ "a", "^a$", - /* svc */ NULL, NULL, /* attr */ NULL, NULL, NULL, NULL, 1 }, { /* host */ "a", "^b$", - /* svc */ NULL, NULL, /* attr */ NULL, NULL, NULL, NULL, 0 }, { /* host */ "b", "^a$", - /* svc */ NULL, NULL, - /* attr */ NULL, NULL, NULL, NULL, 0 - }, - { - /* host */ "a", "^a$", - /* svc */ "s1", NULL, - /* attr */ NULL, NULL, NULL, NULL, 1 - }, - { - /* host */ "a", "^a$", - /* svc */ NULL, "^s1$", - /* attr */ NULL, NULL, NULL, NULL, 1 - }, - { - /* host */ "a", "^a$", - /* svc */ "s1", "^s1$", - /* attr */ NULL, NULL, NULL, NULL, 1 - }, - { - /* host */ "a", "^a$", - /* svc */ "x1", NULL, - /* attr */ NULL, NULL, NULL, NULL, 0 - }, - { - /* host */ "a", "^a$", - /* svc */ NULL, "x", - /* attr */ NULL, NULL, NULL, NULL, 0 - }, - { - /* host */ "a", "^a$", - /* svc */ "x1", "x", - /* attr */ NULL, NULL, NULL, NULL, 0 - }, - { - /* host */ "a", "^a$", - /* svc */ "s1", "x", /* attr */ NULL, NULL, NULL, NULL, 0 }, { /* host */ "a", "^a$", - /* svc */ "x1", "s", - /* attr */ NULL, NULL, NULL, NULL, 0 - }, - { - /* host */ "a", "^a$", - /* svc */ "s1", "^s1$", /* attr */ "k1", NULL, NULL, NULL, 1 }, { /* host */ "a", "^a$", - /* svc */ "s1", "^s1$", /* attr */ NULL, "^k", NULL, NULL, 1 }, { /* host */ "a", "^a$", - /* svc */ "s1", "^s1$", /* attr */ NULL, NULL, "v1", NULL, 1 }, { /* host */ "a", "^a$", - /* svc */ "s1", "^s1$", /* attr */ NULL, NULL, NULL, "^v1$", 1 }, { /* host */ "a", "^a$", - /* svc */ "s1", "^s1$", /* attr */ "k1", "1", "v1", "1", 1 }, }; @@ -214,14 +158,9 @@ START_TEST(test_store_match) "sdb_store_get_host(a) = NULL; expected: "); for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) { - sdb_store_matcher_t *h, *s, *a, *n; + sdb_store_matcher_t *h, *a, *n; int status; - s = sdb_store_service_matcher(golden_data[i].service_name, - golden_data[i].service_name_re, NULL); - fail_unless(s != NULL, - "sdb_store_service_matcher() = NULL; expected: "); - a = sdb_store_attr_matcher(golden_data[i].attr_name, golden_data[i].attr_name_re, golden_data[i].attr_value, golden_data[i].attr_value_re); @@ -229,19 +168,17 @@ START_TEST(test_store_match) "sdb_store_attr_matcher() = NULL; expected: "); h = sdb_store_host_matcher(golden_data[i].hostname, - golden_data[i].hostname_re, s, a); + golden_data[i].hostname_re, a); fail_unless(h != NULL, "sdb_store_host_matcher() = NULL: expected: "); /* pass ownership to the host matcher */ - sdb_object_deref(SDB_OBJ(s)); sdb_object_deref(SDB_OBJ(a)); status = sdb_store_matcher_matches(h, obj); fail_unless(status == golden_data[i].expected, - "sdb_store_matcher_matches({{%s, %s},{%s, %s}," + "sdb_store_matcher_matches({{%s, %s}," "{%s, %s, %s, %s}}, ) = %d; expected: %d", golden_data[i].hostname, golden_data[i].hostname_re, - golden_data[i].service_name, golden_data[i].service_name_re, golden_data[i].attr_name, golden_data[i].attr_name_re, golden_data[i].attr_value, golden_data[i].attr_value_re, status, golden_data[i].expected); @@ -254,10 +191,9 @@ START_TEST(test_store_match) /* now match the inverted set of objects */ status = sdb_store_matcher_matches(n, obj); fail_unless(status == !golden_data[i].expected, - "sdb_store_matcher_matches(NOT{{%s, %s},{%s, %s}," + "sdb_store_matcher_matches(NOT{{%s, %s}," "{%s, %s, %s, %s}}, ) = %d; expected: %d", golden_data[i].hostname, golden_data[i].hostname_re, - golden_data[i].service_name, golden_data[i].service_name_re, golden_data[i].attr_name, golden_data[i].attr_name_re, golden_data[i].attr_value, golden_data[i].attr_value_re, status, !golden_data[i].expected); @@ -357,8 +293,8 @@ START_TEST(test_store_match_op) { sdb_store_base_t *obj; - sdb_store_matcher_t *always = sdb_store_host_matcher(NULL, NULL, NULL, NULL); - sdb_store_matcher_t *never = sdb_store_host_matcher("a", "b", NULL, NULL); + sdb_store_matcher_t *always = sdb_store_host_matcher(NULL, NULL, NULL); + sdb_store_matcher_t *never = sdb_store_host_matcher("a", "b", NULL); struct { const char *op; @@ -436,23 +372,23 @@ START_TEST(test_parse_cmp) const char *value; int expected; } golden_data[] = { - { "host", "name", "=", "hostname", MATCHER_HOST }, + { "host", "name", "=", "hostname", MATCHER_NAME }, { "host", "name", "!=", "hostname", MATCHER_NOT }, - { "host", "name", "=~", "hostname", MATCHER_HOST }, + { "host", "name", "=~", "hostname", MATCHER_NAME }, { "host", "name", "!~", "hostname", MATCHER_NOT }, { "host", "attr", "=", "hostname", -1 }, { "host", "attr", "!=", "hostname", -1 }, { "host", "name", "&^", "hostname", -1 }, - { "service", "name", "=", "srvname", MATCHER_HOST }, + { "service", "name", "=", "srvname", MATCHER_NAME }, { "service", "name", "!=", "srvname", MATCHER_NOT }, - { "service", "name", "=~", "srvname", MATCHER_HOST }, + { "service", "name", "=~", "srvname", MATCHER_NAME }, { "service", "name", "!~", "srvname", MATCHER_NOT }, { "service", "attr", "=", "srvname", -1 }, { "service", "attr", "!=", "srvname", -1 }, { "service", "name", "&^", "srvname", -1 }, - { "attribute", "name", "=", "attrname", MATCHER_HOST }, + { "attribute", "name", "=", "attrname", MATCHER_NAME }, { "attribute", "name", "!=", "attrname", MATCHER_NOT }, - { "attribute", "name", "=~", "attrname", MATCHER_HOST }, + { "attribute", "name", "=~", "attrname", MATCHER_NAME }, { "attribute", "name", "!~", "attrname", MATCHER_NOT }, { "attribute", "attr", "=", "attrname", MATCHER_HOST }, { "attribute", "attr", "!=", "attrname", MATCHER_NOT }, @@ -515,50 +451,39 @@ START_TEST(test_lookup) const char *tostring_re; } golden_data[] = { { "host.name = 'a'", 1, - "HOST\\{ NAME\\{ 'a', \\(nil\\) \\}, SERVICE\\{\\}, ATTR\\{\\} \\}" }, + "OBJ\\[host\\]\\{ NAME\\{ 'a', \\(nil\\) \\} \\}" }, { "host.name =~ 'a|b'", 2, - "HOST\\{ NAME\\{ NULL, "PTR_RE" \\}, SERVICE\\{\\}, ATTR\\{\\} \\}" }, + "OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" }, { "host.name =~ 'host'", 0, - "HOST\\{ NAME\\{ NULL, "PTR_RE" \\}, SERVICE\\{\\}, ATTR\\{\\} \\}" }, + "OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" }, { "host.name =~ '.'", 3, - "HOST\\{ NAME\\{ NULL, "PTR_RE" \\}, SERVICE\\{\\}, ATTR\\{\\} \\}" }, + "OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" }, { "service.name = 's1'", 2, - "HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, SERVICE\\{ " - "NAME\\{ 's1', \\(nil\\) }, ATTR\\{\\} " - "\\}, ATTR\\{\\} \\}" }, + "OBJ\\[service\\]\\{ NAME\\{ 's1', \\(nil\\) } \\}" }, { "service.name =~ 's'", 2, - "HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, SERVICE\\{ " - "NAME\\{ NULL, "PTR_RE" }, ATTR\\{\\} " - "\\}, ATTR\\{\\} \\}" }, + "OBJ\\[service\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}" }, { "service.name !~ 's'", 1, - "(NOT, HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, SERVICE\\{ " - "NAME\\{ NULL, "PTR_RE" }, ATTR\\{\\} " - "\\}, ATTR\\{\\} \\})" }, + "\\(NOT, OBJ\\[service\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}\\)" }, { "attribute.name = 'k1'", 1, - "HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, SERVICE\\{\\}, ATTR\\{ " - "NAME\\{ 'k1', \\(nil\\) }, VALUE\\{ NULL, \\(nil\\) \\} " - "\\} \\}" }, + "OBJ\\[attribute\\]\\{ NAME\\{ 'k1', \\(nil\\) \\} " }, { "attribute.name = 'x'", 0, - "HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, SERVICE\\{\\}, ATTR\\{ " - "NAME\\{ 'x', \\(nil\\) }, VALUE\\{ NULL, \\(nil\\) \\} " - "\\} \\}" }, + "OBJ\\[attribute\\]\\{ NAME\\{ 'x', \\(nil\\) \\}" }, { "attribute.k1 = 'v1'", 1, - "HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, SERVICE\\{\\}, ATTR\\{ " + "HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, ATTR\\{ " "NAME\\{ 'k1', \\(nil\\) }, VALUE\\{ 'v1', \\(nil\\) \\} " "\\} \\}" }, { "attribute.k1 != 'v1'", 2, - "(NOT, HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, SERVICE\\{\\}, ATTR\\{ " + "\\(NOT, HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, ATTR\\{ " "NAME\\{ 'k1', \\(nil\\) }, VALUE\\{ 'v1', \\(nil\\) \\} " "\\} \\})" }, { "attribute.k1 != 'v2'", 3, - "(NOT, HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, SERVICE\\{\\}, ATTR\\{ " + "\\(NOT, HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, ATTR\\{ " "NAME\\{ 'k1', \\(nil\\) }, VALUE\\{ 'v2', \\(nil\\) \\} " "\\} \\})" }, { "attribute.name != 'x' " "AND attribute.y !~ 'x'", 3, - "\\(AND, \\(NOT, HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, SERVICE\\{\\}, ATTR\\{ " - "NAME\\{ 'x', \\(nil\\) }, VALUE\\{ NULL, \\(nil\\) \\} " - "\\} \\}\\), \\(NOT, HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, SERVICE\\{\\}, ATTR\\{ " + "\\(AND, \\(NOT, OBJ\\[attribute\\]\\{ NAME\\{ 'x', \\(nil\\) \\} " + "\\}\\), \\(NOT, HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, ATTR\\{ " "NAME\\{ 'y', \\(nil\\) }, VALUE\\{ NULL, "PTR_RE" \\} " "\\} \\}\\)\\)" }, };