index 3c99bb15553d64f0407489b21a3db56334977935..c256b232ae049096eaace1a86652ff84a77b6e5d 100644 (file)
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>");
{ "ANY metric = 'm1'",
"NOT attribute['x'] = ''", 2 }, /* filter always matches */
{ "ANY metric =~ 'm'", NULL, 2 },
- { "ANY metric !~ 'm'", NULL, 1 },
+ { "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 */
{ "ANY service =~ 's'", NULL, 2 },
- { "ANY service !~ 's'", NULL, 1 },
+ { "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 */
{ "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['k1'] != 'v1'", NULL, 1 },
{ "attribute['k1'] != 'v2'", NULL, 1 },
{ "ANY attribute != 'x' "
- "AND attribute['y'] !~ 'x'", NULL, 3 },
+ "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