index 6dd7bb3fa1916a2119cc1985f9c2dc7393a3db47..89ef451aba32dc285c3a6fd47c5ef61f7c13c782 100644 (file)
START_TEST(test_store_match_name)
{
- sdb_store_base_t *obj;
+ sdb_store_obj_t *obj;
struct {
int type;
m = sdb_store_name_matcher(golden_data[i].type,
golden_data[i].name, golden_data[i].re);
fail_unless(m != NULL,
- "sdb_store_service_matcher(%d, %s, %d) = NULL; expected: <matcher>",
- golden_data[i].type, golden_data[i].name, golden_data[i].re);
+ "sdb_store_service_matcher(%d, %s, %d) = NULL; "
+ "expected: <matcher>", golden_data[i].type,
+ golden_data[i].name, golden_data[i].re);
- status = sdb_store_matcher_matches(m, obj);
+ status = sdb_store_matcher_matches(m, obj, /* filter */ NULL);
fail_unless(status == golden_data[i].expected,
- "sdb_store_matcher_matches(%s, <host a>) = %d; expected: %d",
+ "sdb_store_matcher_matches(%s, <host a>, NULL) = %d; "
+ "expected: %d",
sdb_store_matcher_tostring(m, buf, sizeof(buf)),
status, golden_data[i].expected);
sdb_object_deref(SDB_OBJ(m));
/* now match the inverted set of objects */
- status = sdb_store_matcher_matches(n, obj);
+ status = sdb_store_matcher_matches(n, obj, /* filter */ NULL);
fail_unless(status == !golden_data[i].expected,
- "sdb_store_matcher_matches(%s, <host a>) = %d; expected: %d",
+ "sdb_store_matcher_matches(%s, <host a>, NULL) = %d; "
+ "expected: %d",
sdb_store_matcher_tostring(n, buf, sizeof(buf)),
status, !golden_data[i].expected);
START_TEST(test_store_match_attr)
{
- sdb_store_base_t *obj;
+ sdb_store_obj_t *obj;
struct {
const char *attr_name;
{ "1", NULL, 1, 0 },
{ "k3", NULL, 0, 0 },
{ "k3", NULL, 1, 0 },
- { "k3", NULL, 0, 0 },
- { "k3", NULL, 1, 0 },
{ "k1", "v1", 0, 1 },
{ "k1", "v1", 1, 1 },
{ "k1", "^v1$", 1, 1 },
fail_unless(m != NULL,
"sdb_store_attr_matcher() = NULL; expected: <matcher>");
- status = sdb_store_matcher_matches(m, obj);
+ status = sdb_store_matcher_matches(m, obj, /* filter */ NULL);
fail_unless(status == golden_data[i].expected,
- "sdb_store_matcher_matches({%s, <host a>) = %d; expected: %d",
+ "sdb_store_matcher_matches({%s, <host a>, NULL) = %d; "
+ "expected: %d",
sdb_store_matcher_tostring(m, buf, sizeof(buf)),
status, golden_data[i].expected);
sdb_object_deref(SDB_OBJ(m));
/* now match the inverted set of objects */
- status = sdb_store_matcher_matches(n, obj);
+ status = sdb_store_matcher_matches(n, obj, /* filter */ NULL);
fail_unless(status == !golden_data[i].expected,
- "sdb_store_matcher_matches({%s, <host a>) = %d; expected: %d",
+ "sdb_store_matcher_matches({%s, <host a>, NULL) = %d; "
+ "expected: %d",
sdb_store_matcher_tostring(n, buf, sizeof(buf)),
status, !golden_data[i].expected);
}
END_TEST
-START_TEST(test_store_cond)
+START_TEST(test_attr_cond)
{
- sdb_store_base_t *obj;
+ sdb_store_obj_t *obj;
struct {
const char *attr;
"sdb_store_get_host(a) = NULL; expected: <host>");
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
+ sdb_store_expr_t *expr;
sdb_store_cond_t *c;
char buf[1024];
size_t j;
struct {
sdb_store_matcher_t *(*matcher)(sdb_store_cond_t *);
- int *expected;
+ int expected;
} tests[] = {
- { sdb_store_lt_matcher, &golden_data[i].expected_lt },
- { sdb_store_le_matcher, &golden_data[i].expected_le },
- { sdb_store_eq_matcher, &golden_data[i].expected_eq },
- { sdb_store_ge_matcher, &golden_data[i].expected_ge },
- { sdb_store_gt_matcher, &golden_data[i].expected_gt },
+ { sdb_store_lt_matcher, golden_data[i].expected_lt },
+ { sdb_store_le_matcher, golden_data[i].expected_le },
+ { sdb_store_eq_matcher, golden_data[i].expected_eq },
+ { sdb_store_ge_matcher, golden_data[i].expected_ge },
+ { sdb_store_gt_matcher, golden_data[i].expected_gt },
};
sdb_data_format(&golden_data[i].value,
buf, sizeof(buf), SDB_UNQUOTED);
- c = sdb_store_attr_cond(golden_data[i].attr,
- &golden_data[i].value);
+ expr = sdb_store_expr_constvalue(&golden_data[i].value);
+ fail_unless(expr != NULL,
+ "sdb_store_expr_constvalue(%s) = NULL; expected: <expr>",
+ buf);
+
+ c = sdb_store_attr_cond(golden_data[i].attr, expr);
+ sdb_object_deref(SDB_OBJ(expr));
fail_unless(c != NULL,
- "sdb_store_attr_cond(%s, %s) = NULL; expected: <cond>",
+ "sdb_store_attr_cond(%s, expr{%s}) = NULL; expected: <cond>",
golden_data[i].attr, buf);
for (j = 0; j < SDB_STATIC_ARRAY_LEN(tests); ++j) {
fail_unless(m != NULL,
"sdb_store_<cond>_matcher() = NULL; expected: <matcher>");
- status = sdb_store_matcher_matches(m, obj);
- fail_unless(status == *tests[j].expected,
- "sdb_store_matcher_matches(%s) = %d; expected: %d",
+ status = sdb_store_matcher_matches(m, obj, /* filter */ NULL);
+ fail_unless(status == tests[j].expected,
+ "sdb_store_matcher_matches(%s, <obj>, NULL) = %d; "
+ "expected: %d",
sdb_store_matcher_tostring(m, m_str, sizeof(m_str)),
- status, *tests[j].expected);
+ status, tests[j].expected);
sdb_object_deref(SDB_OBJ(m));
}
}
END_TEST
+START_TEST(test_obj_cond)
+{
+ struct {
+ const char *host;
+ int field;
+ const sdb_data_t value;
+ int expected_lt, expected_le, expected_eq, expected_ge, expected_gt;
+ } golden_data[] = {
+ /* last-update = 1 for all objects */
+ { "a", SDB_FIELD_LAST_UPDATE,
+ { SDB_TYPE_DATETIME, { .datetime = 1 } }, 0, 1, 1, 1, 0 },
+ { "a", SDB_FIELD_LAST_UPDATE,
+ { SDB_TYPE_DATETIME, { .datetime = 2 } }, 1, 1, 0, 0, 0 },
+ { "a", SDB_FIELD_LAST_UPDATE,
+ { SDB_TYPE_DATETIME, { .datetime = 0 } }, 0, 0, 0, 1, 1 },
+ /* age > 0 for all objects */
+ { "a", SDB_FIELD_AGE,
+ { SDB_TYPE_DATETIME, { .datetime = 0 } }, 0, 0, 0, 1, 1 },
+ /* interval = 0 for all objects */
+ { "a", SDB_FIELD_INTERVAL,
+ { SDB_TYPE_DATETIME, { .datetime = 0 } }, 0, 1, 1, 1, 0 },
+ { "a", SDB_FIELD_INTERVAL,
+ { SDB_TYPE_DATETIME, { .datetime = 1 } }, 1, 1, 0, 0, 0 },
+ /* type mismatch */
+ { "a", SDB_FIELD_LAST_UPDATE,
+ { SDB_TYPE_INTEGER, { .integer = 0 } }, 0, 0, 0, 0, 0 },
+ { "a", SDB_FIELD_AGE,
+ { SDB_TYPE_INTEGER, { .integer = 0 } }, 0, 0, 0, 0, 0 },
+ { "a", SDB_FIELD_INTERVAL,
+ { SDB_TYPE_INTEGER, { .integer = 0 } }, 0, 0, 0, 0, 0 },
+ { "a", SDB_FIELD_BACKEND,
+ { SDB_TYPE_INTEGER, { .integer = 0 } }, 0, 0, 0, 0, 0 },
+ };
+
+ int status;
+ size_t i;
+
+ for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
+ sdb_store_obj_t *obj;
+ sdb_store_expr_t *expr;
+ sdb_store_cond_t *c;
+ char buf[1024];
+ size_t j;
+
+ struct {
+ sdb_store_matcher_t *(*matcher)(sdb_store_cond_t *);
+ int expected;
+ } tests[] = {
+ { sdb_store_lt_matcher, golden_data[i].expected_lt },
+ { sdb_store_le_matcher, golden_data[i].expected_le },
+ { sdb_store_eq_matcher, golden_data[i].expected_eq },
+ { sdb_store_ge_matcher, golden_data[i].expected_ge },
+ { sdb_store_gt_matcher, golden_data[i].expected_gt },
+ };
+
+ obj = sdb_store_get_host(golden_data[i].host);
+ fail_unless(obj != NULL,
+ "sdb_store_get_host(%s) = NULL; expected: <host>",
+ golden_data[i].host);
+
+ sdb_data_format(&golden_data[i].value,
+ buf, sizeof(buf), SDB_UNQUOTED);
+
+ expr = sdb_store_expr_constvalue(&golden_data[i].value);
+ fail_unless(expr != NULL,
+ "sdb_store_expr_constvalue(%s) = NULL; expected: <expr>",
+ buf);
+
+ c = sdb_store_obj_cond(golden_data[i].field, expr);
+ sdb_object_deref(SDB_OBJ(expr));
+ fail_unless(c != NULL,
+ "sdb_store_obj_cond(%d, expr{%s}) = NULL; expected: <cond>",
+ golden_data[i].field, buf);
+
+ for (j = 0; j < SDB_STATIC_ARRAY_LEN(tests); ++j) {
+ sdb_store_matcher_t *m;
+ char m_str[1024];
+
+ m = tests[j].matcher(c);
+ fail_unless(m != NULL,
+ "sdb_store_<cond>_matcher() = NULL; expected: <matcher>");
+
+ status = sdb_store_matcher_matches(m, obj, /* filter */ NULL);
+ fail_unless(status == tests[j].expected,
+ "sdb_store_matcher_matches(%s, <obj>, NULL) = %d; "
+ "expected: %d",
+ sdb_store_matcher_tostring(m, m_str, sizeof(m_str)),
+ status, tests[j].expected);
+
+ sdb_object_deref(SDB_OBJ(m));
+ }
+
+ sdb_object_deref(SDB_OBJ(c));
+ sdb_object_deref(SDB_OBJ(obj));
+ }
+}
+END_TEST
+
START_TEST(test_store_match_op)
{
- sdb_store_base_t *obj;
+ sdb_store_obj_t *obj;
sdb_store_matcher_t *always = sdb_store_name_matcher(SDB_HOST, "a", 0);
sdb_store_matcher_t *never = sdb_store_name_matcher(SDB_HOST, "z", 0);
obj = sdb_store_get_host("a");
- status = sdb_store_matcher_matches(always, obj);
+ status = sdb_store_matcher_matches(always, obj, /* filter */ NULL);
fail_unless(status == 1,
"INTERNAL ERROR: 'always' did not match host");
- status = sdb_store_matcher_matches(never, obj);
+ status = sdb_store_matcher_matches(never, obj, /* filter */ NULL);
fail_unless(status == 0,
"INTERNAL ERROR: 'never' matches host");
#define TO_NAME(v) (((v) == always) ? "always" \
: ((v) == never) ? "never" : "<unknown>")
- status = sdb_store_matcher_matches(m, obj);
+ status = sdb_store_matcher_matches(m, obj, /* filter */ NULL);
fail_unless(status == golden_data[i].expected,
- "%s(%s, %s) = %d; expected: %d", golden_data[i].op,
+ "%s(%s, %s, NULL) = %d; expected: %d", golden_data[i].op,
TO_NAME(golden_data[i].left), TO_NAME(golden_data[i].right),
status, golden_data[i].expected);
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", 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", NULL, "&^", &hostname, -1 },
+ { "host", NULL, "<", &hostname, -1 },
+ { "host", NULL, "<=", &hostname, -1 },
+ { "host", NULL, ">=", &hostname, -1 },
+ { "host", NULL, ">", &hostname, -1 },
+ { "host", NULL, "=", NULL, -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", NULL, "&^", &srvname, -1 },
+ { "service", NULL, "<", &srvname, -1 },
+ { "service", NULL, "<=", &srvname, -1 },
+ { "service", NULL, ">=", &srvname, -1 },
+ { "service", NULL, ">", &srvname, -1 },
+ { "service", NULL, "=", NULL, -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", NULL, "=", NULL, -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", "<", NULL, -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 },
+ { "attribute", "attr", "IS", &attrname, -1 },
+ { "foo", NULL, "=", &attrname, -1 },
+ { "foo", "attr", "=", &attrname, -1 },
};
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
+ sdb_store_expr_t *expr;
char buf[1024];
- check = sdb_store_matcher_parse_cmp(golden_data[i].obj_type,
- golden_data[i].attr, golden_data[i].op,
- &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");
+ expr = sdb_store_expr_constvalue(golden_data[i].value);
+ fail_unless(expr != NULL || golden_data[i].value == NULL,
+ "sdb_store_expr_constvalue(%s) = NULL; expected: <expr>",
+ buf);
+
+ check = sdb_store_matcher_parse_cmp(golden_data[i].obj_type,
+ golden_data[i].attr, golden_data[i].op, expr);
+ sdb_object_deref(SDB_OBJ(expr));
+
if (golden_data[i].expected == -1) {
fail_unless(check == NULL,
- "sdb_store_matcher_parse_cmp(%s, %s, %s, %s) = %p; "
+ "sdb_store_matcher_parse_cmp(%s, %s, %s, expr{%s}) = %p; "
"expected: NULL", golden_data[i].obj_type,
golden_data[i].attr, golden_data[i].op, buf, check);
continue;
END_TEST
static int
-lookup_cb(sdb_store_base_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 {
const char *query;
+ const char *filter;
int expected;
const char *tostring_re;
} golden_data[] = {
- { "host.name = 'a'", 1,
+ { "host = 'a'", NULL, 1,
+ "OBJ\\[host\\]\\{ NAME\\{ 'a', \\(nil\\) \\} \\}" },
+ { "host = 'a'", "host = 'x'", 0, /* filter never matches */
+ "OBJ\\[host\\]\\{ NAME\\{ 'a', \\(nil\\) \\} \\}" },
+ { "host = 'a'",
+ "NOT attribute.x = ''", 1, /* filter always matches */
"OBJ\\[host\\]\\{ NAME\\{ 'a', \\(nil\\) \\} \\}" },
- { "host.name =~ 'a|b'", 2,
+ { "host =~ 'a|b'", NULL, 2,
"OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" },
- { "host.name =~ 'host'", 0,
+ { "host =~ 'host'", NULL, 0,
"OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" },
- { "host.name =~ '.'", 3,
+ { "host =~ '.'", NULL, 3,
"OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" },
- { "service.name = 's1'", 2,
+ { "service = 's1'", NULL, 2,
"OBJ\\[service\\]\\{ NAME\\{ 's1', \\(nil\\) } \\}" },
- { "service.name =~ 's'", 2,
+ { "service = 's1'", "host = 'x'", 0, /* filter never matches */
+ "OBJ\\[service\\]\\{ NAME\\{ 's1', \\(nil\\) } \\}" },
+ { "service = 's1'",
+ "NOT attribute.x = ''", 2, /* filter always matches */
+ "OBJ\\[service\\]\\{ NAME\\{ 's1', \\(nil\\) } \\}" },
+ { "service =~ 's'", NULL, 2,
"OBJ\\[service\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}" },
- { "service.name !~ 's'", 1,
+ { "service !~ 's'", NULL, 1,
"\\(NOT, OBJ\\[service\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}\\)" },
- { "attribute.name = 'k1'", 1,
+ { "attribute = 'k1'", NULL, 1,
+ "OBJ\\[attribute\\]\\{ NAME\\{ 'k1', \\(nil\\) \\} " },
+ { "attribute = 'k1'", "host = 'x'", 0, /* filter never matches */
+ "OBJ\\[attribute\\]\\{ NAME\\{ 'k1', \\(nil\\) \\} " },
+ { "attribute = 'k1'",
+ "NOT attribute.x = ''", 1, /* filter always matches */
"OBJ\\[attribute\\]\\{ NAME\\{ 'k1', \\(nil\\) \\} " },
- { "attribute.name = 'x'", 0,
+ { "attribute = 'x'", NULL, 0,
"OBJ\\[attribute\\]\\{ NAME\\{ 'x', \\(nil\\) \\}" },
- { "attribute.k1 = 'v1'", 1,
+ { "attribute.k1 = 'v1'", NULL, 1,
"ATTR\\[k1\\]\\{ VALUE\\{ 'v1', \\(nil\\) \\} \\}" },
- { "attribute.k2 < 123", 0,
+ { "attribute.k1 IS NULL", NULL, 2,
+ "\\(IS NULL, ATTR\\[k1\\]\\)" },
+ { "attribute.x1 IS NULL", NULL, 3,
+ "\\(IS NULL, ATTR\\[x1\\]\\)" },
+ { "attribute.k1 IS NOT NULL", NULL, 1,
+ "\\(NOT, \\(IS NULL, ATTR\\[k1\\]\\)\\)" },
+ { "attribute.x1 IS NOT NULL", NULL, 0,
+ "\\(NOT, \\(IS NULL, ATTR\\[x1\\]\\)\\)" },
+ { "attribute.k2 < 123", NULL, 0,
"ATTR\\[k2\\]\\{ < 123 \\}" },
- { "attribute.k2 <= 123", 1,
+ { "attribute.k2 <= 123", NULL, 1,
"ATTR\\[k2\\]\\{ <= 123 \\}" },
- { "attribute.k2 >= 123", 1,
+ { "attribute.k2 >= 123", NULL, 1,
"ATTR\\[k2\\]\\{ >= 123 \\}" },
- { "attribute.k2 > 123", 0,
+ { "attribute.k2 > 123", NULL, 0,
"ATTR\\[k2\\]\\{ > 123 \\}" },
- { "attribute.k2 = 123", 1,
+ { "attribute.k2 = 123", NULL, 1,
"ATTR\\[k2\\]\\{ = 123 \\}" },
- { "attribute.k2 != 123", 2,
+ { "attribute.k2 != 123", NULL, 2,
"\\(NOT, ATTR\\[k2\\]\\{ = 123 \\}\\)" },
- { "attribute.k1 != 'v1'", 2,
+ { "attribute.k1 != 'v1'", NULL, 2,
"\\(NOT, ATTR\\[k1\\]\\{ VALUE\\{ 'v1', \\(nil\\) \\} \\}\\)" },
- { "attribute.k1 != 'v2'", 3,
+ { "attribute.k1 != 'v2'", NULL, 3,
"\\(NOT, ATTR\\[k1\\]\\{ VALUE\\{ 'v2', \\(nil\\) \\} \\}\\)" },
- { "attribute.name != 'x' "
- "AND attribute.y !~ 'x'", 3,
+ { "attribute != 'x' "
+ "AND attribute.y !~ 'x'", NULL, 3,
"\\(AND, "
"\\(NOT, OBJ\\[attribute\\]\\{ NAME\\{ 'x', \\(nil\\) \\} \\}\\), "
"\\(NOT, ATTR\\[y\\]\\{ VALUE\\{ NULL, "PTR_RE" \\} \\}\\)\\)" },
size_t i;
n = 0;
- check = sdb_store_lookup(NULL, lookup_cb, &n);
+ check = sdb_store_scan(/* matcher */ NULL, /* filter */ 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;
+ sdb_store_matcher_t *m, *filter = NULL;
char buf[4096];
m = sdb_fe_parse_matcher(golden_data[i].query, -1);
fail_unless(m != NULL,
"sdb_fe_parse_matcher(%s, -1) = NULL; expected: <matcher>",
golden_data[i].query);
+
+ if (golden_data[i].filter) {
+ filter = sdb_fe_parse_matcher(golden_data[i].filter, -1);
+ fail_unless(filter != NULL,
+ "sdb_fe_parse_matcher(%s, -1) = NULL; "
+ "expected: <matcher>", golden_data[i].filter);
+ }
+
fail_unless(sdb_regmatches(golden_data[i].tostring_re,
sdb_store_matcher_tostring(m, buf, sizeof(buf))) == 0,
"sdb_fe_parse_matcher(%s, -1) = %s; expected: %s",
golden_data[i].tostring_re);
n = 0;
- sdb_store_lookup(m, lookup_cb, &n);
+ sdb_store_scan(m, filter, scan_cb, &n);
fail_unless(n == golden_data[i].expected,
- "sdb_store_lookup(matcher{%s}) found %d hosts; expected: %d",
- golden_data[i].query, n, golden_data[i].expected);
+ "sdb_store_scan(matcher{%s}, filter{%s}) found %d hosts; "
+ "expected: %d", golden_data[i].query, golden_data[i].filter,
+ n, golden_data[i].expected);
+ sdb_object_deref(SDB_OBJ(filter));
sdb_object_deref(SDB_OBJ(m));
}
}
tcase_add_checked_fixture(tc, populate, sdb_store_clear);
tcase_add_test(tc, test_store_match_name);
tcase_add_test(tc, test_store_match_attr);
- tcase_add_test(tc, test_store_cond);
+ tcase_add_test(tc, test_attr_cond);
+ tcase_add_test(tc, test_obj_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;