index 4e3e6971b4b7ad07529c74c1fc652a0fd51ca768..d6a71e566aea8e0919819984cec6814d55ef0c82 100644 (file)
START_TEST(test_store_match_name)
{
- sdb_store_base_t *obj;
+ sdb_store_obj_t *obj;
struct {
int type;
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 },
START_TEST(test_store_cond)
{
- sdb_store_base_t *obj;
+ sdb_store_obj_t *obj;
struct {
const char *attr;
golden_data[i].attr, buf);
for (j = 0; j < SDB_STATIC_ARRAY_LEN(tests); ++j) {
- sdb_store_matcher_t *m = tests[j].matcher(c);
+ sdb_store_matcher_t *m;
char m_str[1024];
- sdb_object_deref(SDB_OBJ(c));
+
+ m = tests[j].matcher(c);
+ 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",
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);
START_TEST(test_parse_cmp)
{
+ sdb_data_t hostname = { SDB_TYPE_STRING, { .string = "hostname" } };
+ sdb_data_t srvname = { SDB_TYPE_STRING, { .string = "srvname" } };
+ sdb_data_t attrname = { SDB_TYPE_STRING, { .string = "attrname" } };
+
sdb_store_matcher_t *check;
size_t i;
const char *obj_type;
const char *attr;
const char *op;
- const char *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", "=", "bar", -1 },
- { "foo", "attr", "=", "bar", -1 },
+ { "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 },
+ { "attribute", "attr", "IS", NULL, MATCHER_ISNULL },
+ { "foo", "name", "=", &attrname, -1 },
+ { "foo", "attr", "=", &attrname, -1 },
};
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
+ 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);
+ golden_data[i].attr, golden_data[i].op,
+ golden_data[i].value);
+
+ if (sdb_data_format(golden_data[i].value,
+ buf, sizeof(buf), SDB_UNQUOTED) < 0)
+ snprintf(buf, sizeof(buf), "ERR");
if (golden_data[i].expected == -1) {
fail_unless(check == NULL,
"sdb_store_matcher_parse_cmp(%s, %s, %s, %s) = %p; "
"expected: NULL", golden_data[i].obj_type,
- golden_data[i].attr, golden_data[i].op,
- golden_data[i].value, check);
+ golden_data[i].attr, golden_data[i].op, buf, check);
continue;
}
fail_unless(check != NULL,
"sdb_store_matcher_parse_cmp(%s, %s, %s, %s) = %p; "
"expected: NULL", golden_data[i].obj_type,
- golden_data[i].attr, golden_data[i].op,
- golden_data[i].value, check);
+ golden_data[i].attr, golden_data[i].op, buf, check);
fail_unless(M(check)->type == golden_data[i].expected,
"sdb_store_matcher_parse_cmp(%s, %s, %s, %s) returned matcher "
"of type %d; expected: %d", golden_data[i].obj_type,
- golden_data[i].attr, golden_data[i].op, golden_data[i].value,
+ golden_data[i].attr, golden_data[i].op, buf,
M(check)->type, golden_data[i].expected);
sdb_object_deref(SDB_OBJ(check));
END_TEST
static int
-lookup_cb(sdb_store_base_t *obj, void *user_data)
+lookup_cb(sdb_store_obj_t *obj, void *user_data)
{
int *i = user_data;
int expected;
const char *tostring_re;
} golden_data[] = {
- { "host.name = 'a'", 1,
+ { "host.name = 'a'", 1,
"OBJ\\[host\\]\\{ NAME\\{ 'a', \\(nil\\) \\} \\}" },
- { "host.name =~ 'a|b'", 2,
+ { "host.name =~ 'a|b'", 2,
"OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" },
- { "host.name =~ 'host'", 0,
+ { "host.name =~ 'host'", 0,
"OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" },
- { "host.name =~ '.'", 3,
+ { "host.name =~ '.'", 3,
"OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" },
- { "service.name = 's1'", 2,
+ { "service.name = 's1'", 2,
"OBJ\\[service\\]\\{ NAME\\{ 's1', \\(nil\\) } \\}" },
- { "service.name =~ 's'", 2,
+ { "service.name =~ 's'", 2,
"OBJ\\[service\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}" },
- { "service.name !~ 's'", 1,
+ { "service.name !~ 's'", 1,
"\\(NOT, OBJ\\[service\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}\\)" },
- { "attribute.name = 'k1'", 1,
+ { "attribute.name = 'k1'", 1,
"OBJ\\[attribute\\]\\{ NAME\\{ 'k1', \\(nil\\) \\} " },
- { "attribute.name = 'x'", 0,
+ { "attribute.name = 'x'", 0,
"OBJ\\[attribute\\]\\{ NAME\\{ 'x', \\(nil\\) \\}" },
- { "attribute.k1 = 'v1'", 1,
+ { "attribute.k1 = 'v1'", 1,
"ATTR\\[k1\\]\\{ VALUE\\{ 'v1', \\(nil\\) \\} \\}" },
- { "attribute.k1 != 'v1'", 2,
+ { "attribute.k1 IS NULL", 2,
+ "\\(IS NULL, ATTR\\[k1\\]\\)" },
+ { "attribute.x1 IS NULL", 3,
+ "\\(IS NULL, ATTR\\[x1\\]\\)" },
+ { "attribute.k1 IS NOT NULL", 1,
+ "\\(NOT, \\(IS NULL, ATTR\\[k1\\]\\)\\)" },
+ { "attribute.x1 IS NOT NULL", 0,
+ "\\(NOT, \\(IS NULL, ATTR\\[x1\\]\\)\\)" },
+ { "attribute.k2 < 123", 0,
+ "ATTR\\[k2\\]\\{ < 123 \\}" },
+ { "attribute.k2 <= 123", 1,
+ "ATTR\\[k2\\]\\{ <= 123 \\}" },
+ { "attribute.k2 >= 123", 1,
+ "ATTR\\[k2\\]\\{ >= 123 \\}" },
+ { "attribute.k2 > 123", 0,
+ "ATTR\\[k2\\]\\{ > 123 \\}" },
+ { "attribute.k2 = 123", 1,
+ "ATTR\\[k2\\]\\{ = 123 \\}" },
+ { "attribute.k2 != 123", 2,
+ "\\(NOT, ATTR\\[k2\\]\\{ = 123 \\}\\)" },
+ { "attribute.k1 != 'v1'", 2,
"\\(NOT, ATTR\\[k1\\]\\{ VALUE\\{ 'v1', \\(nil\\) \\} \\}\\)" },
- { "attribute.k1 != 'v2'", 3,
+ { "attribute.k1 != 'v2'", 3,
"\\(NOT, ATTR\\[k1\\]\\{ VALUE\\{ 'v2', \\(nil\\) \\} \\}\\)" },
{ "attribute.name != 'x' "
- "AND attribute.y !~ 'x'", 3,
+ "AND attribute.y !~ 'x'", 3,
"\\(AND, "
"\\(NOT, OBJ\\[attribute\\]\\{ NAME\\{ 'x', \\(nil\\) \\} \\}\\), "
"\\(NOT, ATTR\\[y\\]\\{ VALUE\\{ NULL, "PTR_RE" \\} \\}\\)\\)" },