index 4acfc0f4821d67f576037792804f624893af6652..c256b232ae049096eaace1a86652ff84a77b6e5d 100644 (file)
m = sdb_store_eq_matcher(obj, value);
if (golden_data[i].type != SDB_HOST) {
sdb_store_matcher_t *tmp;
- tmp = sdb_store_child_matcher(golden_data[i].type, m);
+ tmp = sdb_store_any_matcher(golden_data[i].type, m);
sdb_object_deref(SDB_OBJ(m));
m = tmp;
}
{ sdb_store_gt_matcher, golden_data[i].expected_gt },
};
+ const char *op_str[] = { "<", "<=", "=", ">=", ">" };
+ assert(SDB_STATIC_ARRAY_LEN(tests) == SDB_STATIC_ARRAY_LEN(op_str));
+
sdb_data_format(&golden_data[i].value,
value_str, sizeof(value_str), SDB_UNQUOTED);
status = sdb_store_matcher_matches(m, host, /* filter */ NULL);
fail_unless(status == tests[j].expected,
- "sdb_store_matcher_matches(<m>, <host>, NULL) = %d; "
- "expected: %d", status, tests[j].expected);
+ "sdb_store_matcher_matches(<attr[%s] %s %s>, "
+ "<host>, NULL) = %d; expected: %d",
+ golden_data[i].attr, op_str[j], value_str,
+ status, tests[j].expected);
sdb_object_deref(SDB_OBJ(m));
}
{ "a", SDB_FIELD_INTERVAL,
{ SDB_TYPE_DATETIME, { .datetime = 1 } }, 1, 1, 0, 0, 0 },
/* type mismatch */
- /* TODO: let matchers only use data_strcmp for attributes
- * everything else has a well-known type
{ "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_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;
END_TEST
static int
-scan_cb(sdb_store_obj_t *obj, void *user_data)
+scan_cb(sdb_store_obj_t *obj, sdb_store_matcher_t *filter, void *user_data)
{
int *i = user_data;
+ if (! sdb_store_matcher_matches(filter, obj, NULL))
+ return 0;
+
fail_unless(obj != NULL,
"sdb_store_scan callback received NULL obj; expected: "
"<store base obj>");
{ "host =~ 'a|b'", NULL, 2 },
{ "host =~ 'host'", NULL, 0 },
{ "host =~ '.'", NULL, 3 },
- { "metric = 'm1'", NULL, 2 },
- { "metric= 'm1'", "host = 'x'", 0 }, /* filter never matches */
- { "metric = 'm1'",
+ { "ANY metric = 'm1'", NULL, 2 },
+ { "ANY metric= 'm1'", "host = 'x'", 0 }, /* filter never matches */
+ { "ANY metric = 'm1'",
"NOT attribute['x'] = ''", 2 }, /* filter always matches */
- { "metric =~ 'm'", NULL, 2 },
- { "metric !~ 'm'", NULL, 1 },
- { "metric =~ 'x'", NULL, 0 },
- { "service = 's1'", NULL, 2 },
- { "service = 's1'", "host = 'x'", 0 }, /* filter never matches */
- { "service = 's1'",
+ { "ANY metric =~ 'm'", NULL, 2 },
+ { "ALL metric =~ 'm'", NULL, 3 },
+ { "ANY metric =~ 'm'", "name !~ '1'", 1 },
+ { "ANY metric =~ 'm'", "name !~ 'm'", 0 },
+ { "ALL metric =~ '1'", NULL, 2 },
+ { "ALL metric =~ '2'", NULL, 1 },
+ { "ANY metric !~ 'm'", NULL, 0 },
+ { "ALL metric !~ 'm'", NULL, 1 },
+ { "ANY metric =~ 'x'", NULL, 0 },
+ { "ANY service = 's1'", NULL, 2 },
+ { "ANY service = 's1'", "host = 'x'", 0 }, /* filter never matches */
+ { "ANY service = 's1'",
"NOT attribute['x'] = ''", 2 }, /* filter always matches */
- { "service =~ 's'", NULL, 2 },
- { "service !~ 's'", NULL, 1 },
- { "attribute = 'k1'", NULL, 2 },
- { "attribute = 'k1'", "host = 'x'", 0 }, /* filter never matches */
- { "attribute = 'k1'",
+ { "ANY service =~ 's'", NULL, 2 },
+ { "ANY service =~ 's'", "name !~ 's'", 0 },
+ { "ANY service =~ 's'", "name !~ '1'", 2 },
+ { "ANY service !~ 's'", NULL, 0 },
+ { "ANY attribute = 'k1'", NULL, 2 },
+ { "ANY attribute = 'k1'", "host = 'x'",0 }, /* filter never matches */
+ { "ANY attribute = 'k1'",
"NOT attribute['x'] = ''", 2 }, /* filter always matches */
- { "attribute =~ 'k'", NULL, 2 },
- { "attribute =~ '1'", NULL, 2 },
- { "attribute =~ '2'", NULL, 1 },
- { "attribute = 'x'", NULL, 0 },
- { "attribute =~ 'x'", NULL, 0 },
+ { "ANY attribute =~ 'k'", NULL, 2 },
+ { "ANY attribute =~ 'k'",
+ "name !~ '1'", 1 },
+ { "ANY attribute =~ 'k'",
+ "name !~ 'k'", 0 },
+ { "ANY attribute =~ '1'", NULL, 2 },
+ { "ANY attribute =~ '2'", NULL, 1 },
+ { "ANY attribute = 'x'", NULL, 0 },
+ { "ANY attribute =~ 'x'", NULL, 0 },
+ { "ALL attribute = 'k1'", NULL, 2 },
{ "attribute['k1'] = 'v1'", NULL, 1 },
+ { "attribute['k1'] = 'v1'",
+ "name != 'k1'", 0 },
{ "attribute['k1'] =~ 'v1'", NULL, 1 },
{ "attribute['k1'] =~ '^v1$'", NULL, 1 },
{ "attribute['k1'] =~ 'v'", NULL, 2 },
{ "attribute['k2'] != 123", NULL, 0 },
{ "attribute['k1'] != 'v1'", NULL, 1 },
{ "attribute['k1'] != 'v2'", NULL, 1 },
- { "attribute != 'x' "
- "AND attribute['y'] !~ 'x'", NULL, 3 },
+ { "ANY attribute != 'x' "
+ "AND attribute['y'] !~ 'x'", NULL, 2 },
};
+ sdb_strbuf_t *errbuf = sdb_strbuf_create(64);
int check, n;
size_t i;
n = 0;
- check = sdb_store_scan(/* matcher */ NULL, /* filter */ NULL,
+ check = sdb_store_scan(SDB_HOST, /* matcher */ NULL, /* filter */ NULL,
scan_cb, &n);
fail_unless(check == 0,
"sdb_store_scan() = %d; expected: 0", check);
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
sdb_store_matcher_t *m, *filter = NULL;
- m = sdb_fe_parse_matcher(golden_data[i].query, -1);
+ m = sdb_fe_parse_matcher(golden_data[i].query, -1, errbuf);
fail_unless(m != NULL,
- "sdb_fe_parse_matcher(%s, -1) = NULL; expected: <matcher>",
- golden_data[i].query);
+ "sdb_fe_parse_matcher(%s, -1) = NULL; expected: <matcher> "
+ "(parser error: %s)", golden_data[i].query,
+ sdb_strbuf_string(errbuf));
if (golden_data[i].filter) {
- filter = sdb_fe_parse_matcher(golden_data[i].filter, -1);
+ filter = sdb_fe_parse_matcher(golden_data[i].filter, -1, errbuf);
fail_unless(filter != NULL,
"sdb_fe_parse_matcher(%s, -1) = NULL; "
- "expected: <matcher>", golden_data[i].filter);
+ "expected: <matcher> (parser error: %s)",
+ golden_data[i].filter, sdb_strbuf_string(errbuf));
}
n = 0;
- sdb_store_scan(m, filter, scan_cb, &n);
+ sdb_store_scan(SDB_HOST, m, filter, scan_cb, &n);
fail_unless(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_store_scan(HOST, 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));
}
+
+ sdb_strbuf_destroy(errbuf);
}
END_TEST