Code

store_lookup_test: Added some tests for attribute.FOO IS NULL.
authorSebastian Harl <sh@tokkee.org>
Sun, 20 Jul 2014 19:24:42 +0000 (21:24 +0200)
committerSebastian Harl <sh@tokkee.org>
Sun, 20 Jul 2014 19:24:42 +0000 (21:24 +0200)
src/core/store_lookup.c
t/unit/core/store_lookup_test.c

index 557b93662f55d0ce4a83329112c98a2382b74a85..317be555b7be0560833fd056e47daf8e1d0e72e7 100644 (file)
@@ -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 */
 
index 1d4bf7aa267bda7a358de48ce58dd788391691aa..d6a71e566aea8e0919819984cec6814d55ef0c82 100644 (file)
@@ -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" \\} \\}\\)\\)" },