From f7b69fc811459ae37b86df61b1ee5b665d63a3f1 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 20 Jul 2014 21:24:42 +0200 Subject: [PATCH] store_lookup_test: Added some tests for attribute.FOO IS NULL. --- src/core/store_lookup.c | 2 +- t/unit/core/store_lookup_test.c | 137 +++++++++++++++++--------------- 2 files changed, 74 insertions(+), 65 deletions(-) diff --git a/src/core/store_lookup.c b/src/core/store_lookup.c index 557b936..317be55 100644 --- a/src/core/store_lookup.c +++ b/src/core/store_lookup.c @@ -580,7 +580,7 @@ isnull_matcher_destroy(sdb_object_t *obj) static char * isnull_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen) { - snprintf(buf, buflen, "(IS NULL, attr.%s)", ISNULL_M(m)->attr_name); + snprintf(buf, buflen, "(IS NULL, ATTR[%s])", ISNULL_M(m)->attr_name); return buf; } /* isnull_tostring */ diff --git a/t/unit/core/store_lookup_test.c b/t/unit/core/store_lookup_test.c index 1d4bf7a..d6a71e5 100644 --- a/t/unit/core/store_lookup_test.c +++ b/t/unit/core/store_lookup_test.c @@ -407,51 +407,52 @@ START_TEST(test_parse_cmp) const char *obj_type; const char *attr; const char *op; - const sdb_data_t value; + const sdb_data_t *value; int expected; } golden_data[] = { - { "host", "name", "=", hostname, MATCHER_NAME }, - { "host", "name", "!=", hostname, MATCHER_NOT }, - { "host", "name", "=~", hostname, MATCHER_NAME }, - { "host", "name", "!~", hostname, MATCHER_NOT }, - { "host", "attr", "=", hostname, -1 }, - { "host", "attr", "!=", hostname, -1 }, - { "host", "name", "&^", hostname, -1 }, - { "host", "name", "<", hostname, -1 }, - { "host", "name", "<=", hostname, -1 }, - { "host", "name", ">=", hostname, -1 }, - { "host", "name", ">", hostname, -1 }, - { "service", "name", "=", srvname, MATCHER_NAME }, - { "service", "name", "!=", srvname, MATCHER_NOT }, - { "service", "name", "=~", srvname, MATCHER_NAME }, - { "service", "name", "!~", srvname, MATCHER_NOT }, - { "service", "attr", "=", srvname, -1 }, - { "service", "attr", "!=", srvname, -1 }, - { "service", "name", "&^", srvname, -1 }, - { "service", "name", "<", srvname, -1 }, - { "service", "name", "<=", srvname, -1 }, - { "service", "name", ">=", srvname, -1 }, - { "service", "name", ">", srvname, -1 }, - { "attribute", "name", "=", attrname, MATCHER_NAME }, - { "attribute", "name", "!=", attrname, MATCHER_NOT }, - { "attribute", "name", "=~", attrname, MATCHER_NAME }, - { "attribute", "name", "!~", attrname, MATCHER_NOT }, - { "attribute", "name", "<", attrname, -1 }, - { "attribute", "name", "<=", attrname, -1 }, - { "attribute", "name", ">=", attrname, -1 }, - { "attribute", "name", ">", attrname, -1 }, - { "attribute", "attr", "=", attrname, MATCHER_ATTR }, - { "attribute", "attr", "!=", attrname, MATCHER_NOT }, - { "attribute", "attr", "=~", attrname, MATCHER_ATTR }, - { "attribute", "attr", "!~", attrname, MATCHER_NOT }, - { "attribute", "attr", "&^", attrname, -1 }, - { "attribute", "attr", "<", attrname, MATCHER_LT }, - { "attribute", "attr", "<=", attrname, MATCHER_LE }, -/* { "attribute", "attr", "=", attrname, MATCHER_EQ }, */ - { "attribute", "attr", ">=", attrname, MATCHER_GE }, - { "attribute", "attr", ">", attrname, MATCHER_GT }, - { "foo", "name", "=", attrname, -1 }, - { "foo", "attr", "=", attrname, -1 }, + { "host", "name", "=", &hostname, MATCHER_NAME }, + { "host", "name", "!=", &hostname, MATCHER_NOT }, + { "host", "name", "=~", &hostname, MATCHER_NAME }, + { "host", "name", "!~", &hostname, MATCHER_NOT }, + { "host", "attr", "=", &hostname, -1 }, + { "host", "attr", "!=", &hostname, -1 }, + { "host", "name", "&^", &hostname, -1 }, + { "host", "name", "<", &hostname, -1 }, + { "host", "name", "<=", &hostname, -1 }, + { "host", "name", ">=", &hostname, -1 }, + { "host", "name", ">", &hostname, -1 }, + { "service", "name", "=", &srvname, MATCHER_NAME }, + { "service", "name", "!=", &srvname, MATCHER_NOT }, + { "service", "name", "=~", &srvname, MATCHER_NAME }, + { "service", "name", "!~", &srvname, MATCHER_NOT }, + { "service", "attr", "=", &srvname, -1 }, + { "service", "attr", "!=", &srvname, -1 }, + { "service", "name", "&^", &srvname, -1 }, + { "service", "name", "<", &srvname, -1 }, + { "service", "name", "<=", &srvname, -1 }, + { "service", "name", ">=", &srvname, -1 }, + { "service", "name", ">", &srvname, -1 }, + { "attribute", "name", "=", &attrname, MATCHER_NAME }, + { "attribute", "name", "!=", &attrname, MATCHER_NOT }, + { "attribute", "name", "=~", &attrname, MATCHER_NAME }, + { "attribute", "name", "!~", &attrname, MATCHER_NOT }, + { "attribute", "name", "<", &attrname, -1 }, + { "attribute", "name", "<=", &attrname, -1 }, + { "attribute", "name", ">=", &attrname, -1 }, + { "attribute", "name", ">", &attrname, -1 }, + { "attribute", "attr", "=", &attrname, MATCHER_ATTR }, + { "attribute", "attr", "!=", &attrname, MATCHER_NOT }, + { "attribute", "attr", "=~", &attrname, MATCHER_ATTR }, + { "attribute", "attr", "!~", &attrname, MATCHER_NOT }, + { "attribute", "attr", "&^", &attrname, -1 }, + { "attribute", "attr", "<", &attrname, MATCHER_LT }, + { "attribute", "attr", "<=", &attrname, MATCHER_LE }, +/* { "attribute", "attr", "=", &attrname, MATCHER_EQ }, */ + { "attribute", "attr", ">=", &attrname, MATCHER_GE }, + { "attribute", "attr", ">", &attrname, MATCHER_GT }, + { "attribute", "attr", "IS", NULL, MATCHER_ISNULL }, + { "foo", "name", "=", &attrname, -1 }, + { "foo", "attr", "=", &attrname, -1 }, }; for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) { @@ -459,9 +460,9 @@ START_TEST(test_parse_cmp) check = sdb_store_matcher_parse_cmp(golden_data[i].obj_type, golden_data[i].attr, golden_data[i].op, - &golden_data[i].value); + golden_data[i].value); - if (sdb_data_format(&golden_data[i].value, + if (sdb_data_format(golden_data[i].value, buf, sizeof(buf), SDB_UNQUOTED) < 0) snprintf(buf, sizeof(buf), "ERR"); @@ -512,44 +513,52 @@ START_TEST(test_lookup) int expected; const char *tostring_re; } golden_data[] = { - { "host.name = 'a'", 1, + { "host.name = 'a'", 1, "OBJ\\[host\\]\\{ NAME\\{ 'a', \\(nil\\) \\} \\}" }, - { "host.name =~ 'a|b'", 2, + { "host.name =~ 'a|b'", 2, "OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" }, - { "host.name =~ 'host'", 0, + { "host.name =~ 'host'", 0, "OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" }, - { "host.name =~ '.'", 3, + { "host.name =~ '.'", 3, "OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" }, - { "service.name = 's1'", 2, + { "service.name = 's1'", 2, "OBJ\\[service\\]\\{ NAME\\{ 's1', \\(nil\\) } \\}" }, - { "service.name =~ 's'", 2, + { "service.name =~ 's'", 2, "OBJ\\[service\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}" }, - { "service.name !~ 's'", 1, + { "service.name !~ 's'", 1, "\\(NOT, OBJ\\[service\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}\\)" }, - { "attribute.name = 'k1'", 1, + { "attribute.name = 'k1'", 1, "OBJ\\[attribute\\]\\{ NAME\\{ 'k1', \\(nil\\) \\} " }, - { "attribute.name = 'x'", 0, + { "attribute.name = 'x'", 0, "OBJ\\[attribute\\]\\{ NAME\\{ 'x', \\(nil\\) \\}" }, - { "attribute.k1 = 'v1'", 1, + { "attribute.k1 = 'v1'", 1, "ATTR\\[k1\\]\\{ VALUE\\{ 'v1', \\(nil\\) \\} \\}" }, - { "attribute.k2 < 123", 0, + { "attribute.k1 IS NULL", 2, + "\\(IS NULL, ATTR\\[k1\\]\\)" }, + { "attribute.x1 IS NULL", 3, + "\\(IS NULL, ATTR\\[x1\\]\\)" }, + { "attribute.k1 IS NOT NULL", 1, + "\\(NOT, \\(IS NULL, ATTR\\[k1\\]\\)\\)" }, + { "attribute.x1 IS NOT NULL", 0, + "\\(NOT, \\(IS NULL, ATTR\\[x1\\]\\)\\)" }, + { "attribute.k2 < 123", 0, "ATTR\\[k2\\]\\{ < 123 \\}" }, - { "attribute.k2 <= 123", 1, + { "attribute.k2 <= 123", 1, "ATTR\\[k2\\]\\{ <= 123 \\}" }, - { "attribute.k2 >= 123", 1, + { "attribute.k2 >= 123", 1, "ATTR\\[k2\\]\\{ >= 123 \\}" }, - { "attribute.k2 > 123", 0, + { "attribute.k2 > 123", 0, "ATTR\\[k2\\]\\{ > 123 \\}" }, - { "attribute.k2 = 123", 1, + { "attribute.k2 = 123", 1, "ATTR\\[k2\\]\\{ = 123 \\}" }, - { "attribute.k2 != 123", 2, + { "attribute.k2 != 123", 2, "\\(NOT, ATTR\\[k2\\]\\{ = 123 \\}\\)" }, - { "attribute.k1 != 'v1'", 2, + { "attribute.k1 != 'v1'", 2, "\\(NOT, ATTR\\[k1\\]\\{ VALUE\\{ 'v1', \\(nil\\) \\} \\}\\)" }, - { "attribute.k1 != 'v2'", 3, + { "attribute.k1 != 'v2'", 3, "\\(NOT, ATTR\\[k1\\]\\{ VALUE\\{ 'v2', \\(nil\\) \\} \\}\\)" }, { "attribute.name != 'x' " - "AND attribute.y !~ 'x'", 3, + "AND attribute.y !~ 'x'", 3, "\\(AND, " "\\(NOT, OBJ\\[attribute\\]\\{ NAME\\{ 'x', \\(nil\\) \\} \\}\\), " "\\(NOT, ATTR\\[y\\]\\{ VALUE\\{ NULL, "PTR_RE" \\} \\}\\)\\)" }, -- 2.30.2