Code

store, frontend: Renamed sdb_store_lookup() to sdb_store_scan().
[sysdb.git] / t / unit / core / store_lookup_test.c
index 7536f390bc96cfe9b556326271925c367ff6d0a7..351ae18da7dfd899c918c897da267503597d644b 100644 (file)
@@ -410,36 +410,36 @@ START_TEST(test_parse_cmp)
                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",      NULL,   "=",  &hostname, MATCHER_NAME },
+               { "host",      NULL,   "!=", &hostname, MATCHER_NOT },
+               { "host",      NULL,   "=~", &hostname, MATCHER_NAME },
+               { "host",      NULL,   "!~", &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 },
+               { "host",      NULL,   "&^", &hostname, -1 },
+               { "host",      NULL,   "<",  &hostname, -1 },
+               { "host",      NULL,   "<=", &hostname, -1 },
+               { "host",      NULL,   ">=", &hostname, -1 },
+               { "host",      NULL,   ">",  &hostname, -1 },
+               { "service",   NULL,   "=",  &srvname,  MATCHER_NAME },
+               { "service",   NULL,   "!=", &srvname,  MATCHER_NOT },
+               { "service",   NULL,   "=~", &srvname,  MATCHER_NAME },
+               { "service",   NULL,   "!~", &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 },
+               { "service",   NULL,   "&^", &srvname,  -1 },
+               { "service",   NULL,   "<",  &srvname,  -1 },
+               { "service",   NULL,   "<=", &srvname,  -1 },
+               { "service",   NULL,   ">=", &srvname,  -1 },
+               { "service",   NULL,   ">",  &srvname,  -1 },
+               { "attribute", NULL,   "=",  &attrname, MATCHER_NAME },
+               { "attribute", NULL,   "!=", &attrname, MATCHER_NOT },
+               { "attribute", NULL,   "=~", &attrname, MATCHER_NAME },
+               { "attribute", NULL,   "!~", &attrname, MATCHER_NOT },
+               { "attribute", NULL,   "<",  &attrname, -1 },
+               { "attribute", NULL,   "<=", &attrname, -1 },
+               { "attribute", NULL,   ">=", &attrname, -1 },
+               { "attribute", NULL,   ">",  &attrname, -1 },
                { "attribute", "attr", "=",  &attrname, MATCHER_ATTR },
                { "attribute", "attr", "!=", &attrname, MATCHER_NOT },
                { "attribute", "attr", "=~", &attrname, MATCHER_ATTR },
@@ -452,7 +452,7 @@ START_TEST(test_parse_cmp)
                { "attribute", "attr", ">",  &attrname, MATCHER_GT },
                { "attribute", "attr", "IS", NULL,      MATCHER_ISNULL },
                { "attribute", "attr", "IS", &attrname, -1 },
-               { "foo",       "name", "=",  &attrname, -1 },
+               { "foo",       NULL,   "=",  &attrname, -1 },
                { "foo",       "attr", "=",  &attrname, -1 },
        };
 
@@ -491,22 +491,22 @@ START_TEST(test_parse_cmp)
 END_TEST
 
 static int
-lookup_cb(sdb_store_obj_t *obj, void *user_data)
+scan_cb(sdb_store_obj_t *obj, void *user_data)
 {
        int *i = user_data;
 
        fail_unless(obj != NULL,
-                       "sdb_store_lookup callback received NULL obj; expected: "
+                       "sdb_store_scan callback received NULL obj; expected: "
                        "<store base obj>");
        fail_unless(i != NULL,
-                       "sdb_store_lookup callback received NULL user_data; "
+                       "sdb_store_scan callback received NULL user_data; "
                        "expected: <pointer to data>");
 
        ++(*i);
        return 0;
-} /* lookup_cb */
+} /* scan_cb */
 
-START_TEST(test_lookup)
+START_TEST(test_scan)
 {
 #define PTR_RE "0x[0-9a-f]+"
        struct {
@@ -514,23 +514,23 @@ START_TEST(test_lookup)
                int expected;
                const char *tostring_re;
        } golden_data[] = {
-               { "host.name = 'a'",          1,
+               { "host = 'a'",               1,
                        "OBJ\\[host\\]\\{ NAME\\{ 'a', \\(nil\\) \\} \\}" },
-               { "host.name =~ 'a|b'",       2,
+               { "host =~ 'a|b'",            2,
                        "OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" },
-               { "host.name =~ 'host'",      0,
+               { "host =~ 'host'",           0,
                        "OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" },
-               { "host.name =~ '.'",         3,
+               { "host =~ '.'",              3,
                        "OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" },
-               { "service.name = 's1'",      2,
+               { "service = 's1'",           2,
                        "OBJ\\[service\\]\\{ NAME\\{ 's1', \\(nil\\) } \\}" },
-               { "service.name =~ 's'",      2,
+               { "service =~ 's'",           2,
                        "OBJ\\[service\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}" },
-               { "service.name !~ 's'",      1,
+               { "service !~ 's'",           1,
                        "\\(NOT, OBJ\\[service\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}\\)" },
-               { "attribute.name = 'k1'",    1,
+               { "attribute = 'k1'",         1,
                        "OBJ\\[attribute\\]\\{ NAME\\{ 'k1', \\(nil\\) \\} " },
-               { "attribute.name = 'x'",     0,
+               { "attribute = 'x'",          0,
                        "OBJ\\[attribute\\]\\{ NAME\\{ 'x', \\(nil\\) \\}" },
                { "attribute.k1 = 'v1'",      1,
                        "ATTR\\[k1\\]\\{ VALUE\\{ 'v1', \\(nil\\) \\} \\}" },
@@ -558,7 +558,7 @@ START_TEST(test_lookup)
                        "\\(NOT, ATTR\\[k1\\]\\{ VALUE\\{ 'v1', \\(nil\\) \\} \\}\\)" },
                { "attribute.k1 != 'v2'",     3,
                        "\\(NOT, ATTR\\[k1\\]\\{ VALUE\\{ 'v2', \\(nil\\) \\} \\}\\)" },
-               { "attribute.name != 'x' "
+               { "attribute != 'x' "
                  "AND attribute.y !~ 'x'",   3,
                        "\\(AND, "
                                "\\(NOT, OBJ\\[attribute\\]\\{ NAME\\{ 'x', \\(nil\\) \\} \\}\\), "
@@ -569,11 +569,11 @@ START_TEST(test_lookup)
        size_t i;
 
        n = 0;
-       check = sdb_store_lookup(NULL, lookup_cb, &n);
+       check = sdb_store_scan(NULL, scan_cb, &n);
        fail_unless(check == 0,
-                       "sdb_store_lookup() = %d; expected: 0", check);
+                       "sdb_store_scan() = %d; expected: 0", check);
        fail_unless(n == 3,
-                       "sdb_store_lookup called callback %d times; expected: 3", (int)n);
+                       "sdb_store_scan called callback %d times; expected: 3", (int)n);
 
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
                sdb_store_matcher_t *m;
@@ -591,9 +591,9 @@ START_TEST(test_lookup)
                                golden_data[i].tostring_re);
 
                n = 0;
-               sdb_store_lookup(m, lookup_cb, &n);
+               sdb_store_scan(m, scan_cb, &n);
                fail_unless(n == golden_data[i].expected,
-                               "sdb_store_lookup(matcher{%s}) found %d hosts; expected: %d",
+                               "sdb_store_scan(matcher{%s}) found %d hosts; expected: %d",
                                golden_data[i].query, n, golden_data[i].expected);
                sdb_object_deref(SDB_OBJ(m));
        }
@@ -613,7 +613,7 @@ core_store_lookup_suite(void)
        tcase_add_test(tc, test_store_cond);
        tcase_add_test(tc, test_store_match_op);
        tcase_add_test(tc, test_parse_cmp);
-       tcase_add_test(tc, test_lookup);
+       tcase_add_test(tc, test_scan);
        suite_add_tcase(s, tc);
 
        return s;