Code

frontend/grammar: Access attribute values using attributes[<name>].
[sysdb.git] / t / unit / core / store_lookup_test.c
index d1dc82f3664783862ed84386ad309e4675066c4c..af680f033865d773a35ed680176818d865c7110d 100644 (file)
@@ -77,9 +77,9 @@ populate(void)
 
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(metrics); ++i) {
                int status = sdb_store_metric(metrics[i].host,
-                               metrics[i].metric, 1);
+                               metrics[i].metric, /* store */ NULL, 1);
                fail_unless(status == 0,
-                               "sdb_store_metric(%s, %s, 1) = %d; expected: 0",
+                               "sdb_store_metric(%s, %s, NULL, 1) = %d; expected: 0",
                                metrics[i].host, metrics[i].metric, status);
        }
 
@@ -287,6 +287,7 @@ START_TEST(test_attr_cond)
                { "k1", { SDB_TYPE_STRING,  { .string  = "v1" } },  0, 1, 1, 1, 0 },
                { "k1", { SDB_TYPE_STRING,  { .string  = "v2" } },  1, 1, 0, 0, 0 },
                { "k1", { SDB_TYPE_STRING,  { .string  = "v0" } },  0, 0, 0, 1, 1 },
+               { "k1", { SDB_TYPE_STRING,  { .string  = "0" } },   0, 0, 0, 1, 1 },
                { "k2", { SDB_TYPE_INTEGER, { .integer = 123 } },   0, 1, 1, 1, 0 },
                { "k2", { SDB_TYPE_INTEGER, { .integer = 124 } },   1, 1, 0, 0, 0 },
                { "k2", { SDB_TYPE_INTEGER, { .integer = 122 } },   0, 0, 0, 1, 1 },
@@ -295,8 +296,8 @@ START_TEST(test_attr_cond)
                { "k3", { SDB_TYPE_STRING,  { .string  = "123" } }, 0, 0, 0, 0, 0 },
                { "k3", { SDB_TYPE_INTEGER, { .integer = 123 } },   0, 0, 0, 0, 0 },
                /* type mismatch */
-               { "k1", { SDB_TYPE_INTEGER, { .integer = 0 } },     0, 0, 0, 0, 0 },
-               { "k2", { SDB_TYPE_STRING,  { .string  = "123" } }, 0, 0, 0, 0, 0 },
+               { "k1", { SDB_TYPE_INTEGER, { .integer = 0 } },     0, 0, 0, 1, 1 },
+               { "k2", { SDB_TYPE_STRING,  { .string  = "123" } }, 0, 1, 1, 1, 0 },
        };
 
        int status;
@@ -394,6 +395,12 @@ START_TEST(test_obj_cond)
                        { SDB_TYPE_INTEGER, { .integer = 0 } }, 0, 0, 0, 0, 0 },
                { "a", SDB_FIELD_BACKEND,
                        { SDB_TYPE_INTEGER, { .integer = 0 } }, 0, 0, 0, 0, 0 },
+               { "a", SDB_FIELD_BACKEND,
+                       { SDB_TYPE_INTEGER, { .integer = 0 } }, 0, 0, 0, 0, 0 },
+               /* (64bit) integer value without zero-bytes */
+               { "a", SDB_FIELD_BACKEND,
+                       { SDB_TYPE_INTEGER, { .integer = 0xffffffffffffffffL } },
+                       0, 0, 0, 0, 0 },
        };
 
        int status;
@@ -532,10 +539,11 @@ END_TEST
 
 START_TEST(test_parse_cmp)
 {
-       sdb_data_t hostname   = { SDB_TYPE_STRING, { .string = "hostname" } };
-       sdb_data_t metricname = { SDB_TYPE_STRING, { .string = "metricname" } };
-       sdb_data_t srvname    = { SDB_TYPE_STRING, { .string = "srvname" } };
-       sdb_data_t attrname   = { SDB_TYPE_STRING, { .string = "attrname" } };
+       sdb_data_t hostname   = { SDB_TYPE_STRING,  { .string  = "hostname" } };
+       sdb_data_t metricname = { SDB_TYPE_STRING,  { .string  = "metricname" } };
+       sdb_data_t srvname    = { SDB_TYPE_STRING,  { .string  = "srvname" } };
+       sdb_data_t attrname   = { SDB_TYPE_STRING,  { .string  = "attrname" } };
+       sdb_data_t attrvalue  = { SDB_TYPE_INTEGER, { .integer = 4711 } };
 
        sdb_store_matcher_t *check;
 
@@ -554,6 +562,8 @@ START_TEST(test_parse_cmp)
                { "host",      NULL,   "!~", &hostname,   MATCHER_NOT },
                { "host",      "attr", "=",  &hostname,   -1 },
                { "host",      "attr", "!=", &hostname,   -1 },
+               { "host",      "attr", "!=", &attrvalue,  -1 },
+               { "host",      "attr", "<=", &attrvalue,  -1 },
                { "host",      NULL,   "&^", &hostname,   -1 },
                { "host",      NULL,   "<",  &hostname,   -1 },
                { "host",      NULL,   "<=", &hostname,   -1 },
@@ -566,6 +576,8 @@ START_TEST(test_parse_cmp)
                { "metric",    NULL,   "!~", &metricname, MATCHER_NOT },
                { "metric",    "attr", "=",  &metricname, -1 },
                { "metric",    "attr", "!=", &metricname, -1 },
+               { "metric",    "attr", "!=", &attrvalue,  -1 },
+               { "metric",    "attr", "<=", &attrvalue,  -1 },
                { "metric",    NULL,   "&^", &metricname, -1 },
                { "metric",    NULL,   "<",  &metricname, -1 },
                { "metric",    NULL,   "<=", &metricname, -1 },
@@ -578,6 +590,8 @@ START_TEST(test_parse_cmp)
                { "service",   NULL,   "!~", &srvname,    MATCHER_NOT },
                { "service",   "attr", "=",  &srvname,    -1 },
                { "service",   "attr", "!=", &srvname,    -1 },
+               { "service",   "attr", "!=", &attrvalue,  -1 },
+               { "service",   "attr", "<=", &attrvalue,  -1 },
                { "service",   NULL,   "&^", &srvname,    -1 },
                { "service",   NULL,   "<",  &srvname,    -1 },
                { "service",   NULL,   "<=", &srvname,    -1 },
@@ -759,80 +773,80 @@ START_TEST(test_scan)
                int expected;
                const char *tostring_re;
        } golden_data[] = {
-               { "host = 'a'", NULL,               1,
+               { "host = 'a'", NULL,                1,
                        "OBJ\\[host\\]\\{ NAME\\{ 'a', \\(nil\\) \\} \\}" },
-               { "host = 'a'", "host = 'x'",       0, /* filter never matches */
+               { "host = 'a'", "host = 'x'",        0, /* filter never matches */
                        "OBJ\\[host\\]\\{ NAME\\{ 'a', \\(nil\\) \\} \\}" },
                { "host = 'a'",
-                       "NOT attribute.x = ''",         1, /* filter always matches */
+                       "NOT attribute[x] = ''",         1, /* filter always matches */
                        "OBJ\\[host\\]\\{ NAME\\{ 'a', \\(nil\\) \\} \\}" },
-               { "host =~ 'a|b'", NULL,            2,
+               { "host =~ 'a|b'", NULL,             2,
                        "OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" },
-               { "host =~ 'host'", NULL,           0,
+               { "host =~ 'host'", NULL,            0,
                        "OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" },
-               { "host =~ '.'", NULL,              3,
+               { "host =~ '.'", NULL,               3,
                        "OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" },
-               { "metric = 'm1'", NULL,            2,
+               { "metric = 'm1'", NULL,             2,
                        "OBJ\\[metric\\]\\{ NAME\\{ 'm1', \\(nil\\) } \\}" },
-               { "metric= 'm1'", "host = 'x'",     0, /* filter never matches */
+               { "metric= 'm1'", "host = 'x'",      0, /* filter never matches */
                        "OBJ\\[metric\\]\\{ NAME\\{ 'm1', \\(nil\\) } \\}" },
                { "metric = 'm1'",
-                       "NOT attribute.x = ''",         2, /* filter always matches */
+                       "NOT attribute[x] = ''",         2, /* filter always matches */
                        "OBJ\\[metric\\]\\{ NAME\\{ 'm1', \\(nil\\) } \\}" },
-               { "metric =~ 'm'", NULL,            2,
+               { "metric =~ 'm'", NULL,             2,
                        "OBJ\\[metric\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}" },
-               { "metric !~ 'm'", NULL,            1,
+               { "metric !~ 'm'", NULL,             1,
                        "\\(NOT, OBJ\\[metric\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}\\)" },
-               { "metric =~ 'x'", NULL,            0,
+               { "metric =~ 'x'", NULL,             0,
                        "OBJ\\[metric\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}" },
-               { "service = 's1'", NULL,           2,
+               { "service = 's1'", NULL,            2,
                        "OBJ\\[service\\]\\{ NAME\\{ 's1', \\(nil\\) } \\}" },
-               { "service = 's1'", "host = 'x'",   0, /* filter never matches */
+               { "service = 's1'", "host = 'x'",    0, /* filter never matches */
                        "OBJ\\[service\\]\\{ NAME\\{ 's1', \\(nil\\) } \\}" },
                { "service = 's1'",
-                       "NOT attribute.x = ''",         2, /* filter always matches */
+                       "NOT attribute[x] = ''",         2, /* filter always matches */
                        "OBJ\\[service\\]\\{ NAME\\{ 's1', \\(nil\\) } \\}" },
-               { "service =~ 's'", NULL,           2,
+               { "service =~ 's'", NULL,            2,
                        "OBJ\\[service\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}" },
-               { "service !~ 's'", NULL,           1,
+               { "service !~ 's'", NULL,            1,
                        "\\(NOT, OBJ\\[service\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}\\)" },
-               { "attribute = 'k1'", NULL,         1,
+               { "attribute = 'k1'", NULL,          1,
                        "OBJ\\[attribute\\]\\{ NAME\\{ 'k1', \\(nil\\) \\} " },
-               { "attribute = 'k1'", "host = 'x'", 0, /* filter never matches */
+               { "attribute = 'k1'", "host = 'x'",  0, /* filter never matches */
                        "OBJ\\[attribute\\]\\{ NAME\\{ 'k1', \\(nil\\) \\} " },
                { "attribute = 'k1'",
-                       "NOT attribute.x = ''",         1, /* filter always matches */
+                       "NOT attribute[x] = ''",         1, /* filter always matches */
                        "OBJ\\[attribute\\]\\{ NAME\\{ 'k1', \\(nil\\) \\} " },
-               { "attribute = 'x'", NULL,          0,
+               { "attribute = 'x'", NULL,           0,
                        "OBJ\\[attribute\\]\\{ NAME\\{ 'x', \\(nil\\) \\}" },
-               { "attribute.k1 = 'v1'", NULL,      1,
+               { "attribute[k1] = 'v1'", NULL,      1,
                        "ATTR\\[k1\\]\\{ VALUE\\{ 'v1', \\(nil\\) \\} \\}" },
-               { "attribute.k1 IS NULL", NULL,     2,
+               { "attribute[k1] IS NULL", NULL,     2,
                        "\\(IS NULL, ATTR\\[k1\\]\\)" },
-               { "attribute.x1 IS NULL", NULL,     3,
+               { "attribute[x1] IS NULL", NULL,     3,
                        "\\(IS NULL, ATTR\\[x1\\]\\)" },
-               { "attribute.k1 IS NOT NULL", NULL, 1,
+               { "attribute[k1] IS NOT NULL", NULL, 1,
                        "\\(NOT, \\(IS NULL, ATTR\\[k1\\]\\)\\)" },
-               { "attribute.x1 IS NOT NULL", NULL, 0,
+               { "attribute[x1] IS NOT NULL", NULL, 0,
                        "\\(NOT, \\(IS NULL, ATTR\\[x1\\]\\)\\)" },
-               { "attribute.k2 < 123", NULL,       0,
+               { "attribute[k2] < 123", NULL,       0,
                        "ATTR\\[k2\\]\\{ < 123 \\}" },
-               { "attribute.k2 <= 123", NULL,      1,
+               { "attribute[k2] <= 123", NULL,      1,
                        "ATTR\\[k2\\]\\{ <= 123 \\}" },
-               { "attribute.k2 >= 123", NULL,      1,
+               { "attribute[k2] >= 123", NULL,      1,
                        "ATTR\\[k2\\]\\{ >= 123 \\}" },
-               { "attribute.k2 > 123", NULL,       0,
+               { "attribute[k2] > 123", NULL,       0,
                        "ATTR\\[k2\\]\\{ > 123 \\}" },
-               { "attribute.k2 = 123", NULL,       1,
+               { "attribute[k2] = 123", NULL,       1,
                        "ATTR\\[k2\\]\\{ = 123 \\}" },
-               { "attribute.k2 != 123", NULL,      2,
+               { "attribute[k2] != 123", NULL,      2,
                        "\\(NOT, ATTR\\[k2\\]\\{ = 123 \\}\\)" },
-               { "attribute.k1 != 'v1'", NULL,     2,
+               { "attribute[k1] != 'v1'", NULL,     2,
                        "\\(NOT, ATTR\\[k1\\]\\{ VALUE\\{ 'v1', \\(nil\\) \\} \\}\\)" },
-               { "attribute.k1 != 'v2'", NULL,     3,
+               { "attribute[k1] != 'v2'", NULL,     3,
                        "\\(NOT, ATTR\\[k1\\]\\{ VALUE\\{ 'v2', \\(nil\\) \\} \\}\\)" },
                { "attribute != 'x' "
-                 "AND attribute.y !~ 'x'", NULL,   3,
+                 "AND attribute[y] !~ 'x'", NULL,   3,
                        "\\(AND, "
                                "\\(NOT, OBJ\\[attribute\\]\\{ NAME\\{ 'x', \\(nil\\) \\} \\}\\), "
                                "\\(NOT, ATTR\\[y\\]\\{ VALUE\\{ NULL, "PTR_RE" \\} \\}\\)\\)" },