Code

store: Removed sdb_store_matcher_tostring().
authorSebastian Harl <sh@tokkee.org>
Tue, 21 Oct 2014 07:50:42 +0000 (09:50 +0200)
committerSebastian Harl <sh@tokkee.org>
Tue, 21 Oct 2014 07:50:42 +0000 (09:50 +0200)
This function was mainly used for debugging and more verbose error messages
upon test failures. Given that we have more fine-grained tests now, keeping
the tostring() methods up-to-date is rather annoying but for little benefit.

Instead, we should have a real pretty-printer or similar at some point.

src/core/store-private.h
src/core/store_lookup.c
src/include/core/store.h
t/unit/core/store_lookup_test.c
t/unit/core/store_test.c

index 750a0b32bbb4e83706f5ac7658e25cf8e48904bf..c6350b3530c4a2518ce0a515da601c1256768700 100644 (file)
@@ -156,8 +156,8 @@ typedef struct {
  * matchers
  */
 
-/* when adding to this, also update 'MATCHER_SYM' below as well as 'matchers'
- * and 'matchers_tostring' in store_lookup.c */
+/* when adding to this, also update 'MATCHER_SYM' below and 'matchers' in
+ * store_lookup.c */
 enum {
        MATCHER_OR,
        MATCHER_AND,
index e112f4cc9fc35c47714d06042cb42b7cd1f6915d..f1baea644a4c2f2b2ee16e18ecc3d531f0e4f723 100644 (file)
@@ -704,15 +704,6 @@ string_matcher_destroy(string_matcher_t *m)
        }
 } /* string_matcher_destroy */
 
-static char *
-string_tostring(string_matcher_t *m, char *buf, size_t buflen)
-{
-       snprintf(buf, buflen, "{ %s%s%s, %p }",
-                       m->name ? "'" : "", m->name ? m->name : "NULL", m->name ? "'" : "",
-                       m->name_re);
-       return buf;
-} /* string_tostring */
-
 /* initializes a name matcher */
 static int
 name_matcher_init(sdb_object_t *obj, va_list ap)
@@ -729,17 +720,6 @@ name_matcher_destroy(sdb_object_t *obj)
        string_matcher_destroy(&m->name);
 } /* name_matcher_destroy */
 
-static char *
-name_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
-{
-       char name[buflen + 1];
-       assert(m->type == MATCHER_NAME);
-       snprintf(buf, buflen, "OBJ[%s]{ NAME%s }",
-                       SDB_STORE_TYPE_TO_NAME(NAME_M(m)->obj_type),
-                       string_tostring(&NAME_M(m)->name, name, sizeof(name)));
-       return buf;
-} /* name_tostring */
-
 static int
 attr_matcher_init(sdb_object_t *obj, va_list ap)
 {
@@ -765,22 +745,6 @@ attr_matcher_destroy(sdb_object_t *obj)
        string_matcher_destroy(&attr->value);
 } /* attr_matcher_destroy */
 
-static char *
-attr_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
-{
-       char value[buflen + 1];
-
-       if (! m) {
-               snprintf(buf, buflen, "ATTR{}");
-               return buf;
-       }
-
-       assert(m->type == MATCHER_ATTR);
-       snprintf(buf, buflen, "ATTR[%s]{ VALUE%s }", ATTR_M(m)->name,
-                       string_tostring(&ATTR_M(m)->value, value, sizeof(value)));
-       return buf;
-} /* attr_tostring */
-
 static int
 cond_matcher_init(sdb_object_t *obj, va_list ap)
 {
@@ -803,40 +767,6 @@ cond_matcher_destroy(sdb_object_t *obj)
        sdb_object_deref(SDB_OBJ(COND_M(obj)->cond));
 } /* cond_matcher_destroy */
 
-static char *
-cond_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
-{
-       const char *type, *id;
-       sdb_data_t value = SDB_DATA_INIT;
-       char value_str[buflen];
-       sdb_store_expr_t *expr;
-
-       if (COND_M(m)->cond->cmp == attr_cmp) {
-               type = "ATTR";
-               id = ATTR_C(COND_M(m)->cond)->name;
-               expr = ATTR_C(COND_M(m)->cond)->expr;
-       }
-       else if (COND_M(m)->cond->cmp == obj_cmp) {
-               type = "OBJ";
-               id = SDB_FIELD_TO_NAME(OBJ_C(COND_M(m)->cond)->field);
-               expr = OBJ_C(COND_M(m)->cond)->expr;
-       }
-       else {
-               snprintf(buf, buflen, "<unknown>");
-               return buf;
-       }
-
-       if (sdb_store_expr_eval(expr, /* obj */ NULL, &value, /* filter */ NULL))
-               snprintf(value_str, sizeof(value_str), "ERR");
-       else if (sdb_data_format(&value, value_str, sizeof(value_str),
-                               SDB_SINGLE_QUOTED) < 0)
-               snprintf(value_str, sizeof(value_str), "ERR");
-       snprintf(buf, buflen, "%s[%s]{ %s %s }", type, id,
-                       MATCHER_SYM(m->type), value_str);
-       sdb_data_free_datum(&value);
-       return buf;
-} /* cond_tostring */
-
 static int
 op_matcher_init(sdb_object_t *obj, va_list ap)
 {
@@ -863,25 +793,6 @@ op_matcher_destroy(sdb_object_t *obj)
                sdb_object_deref(SDB_OBJ(OP_M(obj)->right));
 } /* op_matcher_destroy */
 
-static char *
-op_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
-{
-       char left[buflen + 1], right[buflen + 1];
-
-       if (! m) {
-               /* this should not happen */
-               snprintf(buf, buflen, "()");
-               return buf;
-       }
-
-       assert((m->type == MATCHER_OR) || (m->type == MATCHER_AND));
-       snprintf(buf, buflen, "(%s, %s, %s)",
-                       m->type == MATCHER_OR ? "OR" : "AND",
-                       sdb_store_matcher_tostring(OP_M(m)->left, left, sizeof(left)),
-                       sdb_store_matcher_tostring(OP_M(m)->right, right, sizeof(right)));
-       return buf;
-} /* op_tostring */
-
 static int
 child_matcher_init(sdb_object_t *obj, va_list ap)
 {
@@ -901,16 +812,6 @@ child_matcher_destroy(sdb_object_t *obj)
        sdb_object_deref(SDB_OBJ(CHILD_M(obj)->m));
 } /* child_matcher_destroy */
 
-static char *
-child_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
-{
-       snprintf(buf, buflen, "%s:", MATCHER_SYM(m->type));
-       buf[buflen - 1] = '\0';
-       sdb_store_matcher_tostring(CHILD_M(m)->m,
-                       buf + strlen(buf), buflen - strlen(buf));
-       return buf;
-} /* child_tostring */
-
 static int
 cmp_matcher_init(sdb_object_t *obj, va_list ap)
 {
@@ -933,20 +834,6 @@ cmp_matcher_destroy(sdb_object_t *obj)
        sdb_object_deref(SDB_OBJ(CMP_M(obj)->right));
 } /* cmp_matcher_destroy */
 
-static char *
-cmp_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
-{
-       if (! m) {
-               /* this should not happen */
-               snprintf(buf, buflen, "()");
-               return buf;
-       }
-
-       /* TODO */
-       snprintf(buf, buflen, "CMP_MATCHER(%d)", m->type);
-       return buf;
-} /* cmp_tostring */
-
 static int
 uop_matcher_init(sdb_object_t *obj, va_list ap)
 {
@@ -969,23 +856,6 @@ uop_matcher_destroy(sdb_object_t *obj)
                sdb_object_deref(SDB_OBJ(UOP_M(obj)->op));
 } /* uop_matcher_destroy */
 
-static char *
-uop_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
-{
-       char op[buflen + 1];
-
-       if (! m) {
-               /* this should not happen */
-               snprintf(buf, buflen, "()");
-               return buf;
-       }
-
-       assert(m->type == MATCHER_NOT);
-       snprintf(buf, buflen, "(NOT, %s)",
-                       sdb_store_matcher_tostring(UOP_M(m)->op, op, sizeof(op)));
-       return buf;
-} /* uop_tostring */
-
 static int
 isnull_matcher_init(sdb_object_t *obj, va_list ap)
 {
@@ -1005,17 +875,6 @@ isnull_matcher_destroy(sdb_object_t *obj)
        ISNULL_M(obj)->expr = NULL;
 } /* isnull_matcher_destroy */
 
-static char *
-isnull_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
-{
-       /* XXX */
-       if (m->type == MATCHER_ISNULL)
-               strncpy(buf, "(IS NULL)", buflen);
-       else
-               strncpy(buf, "(IS NOT NULL)", buflen);
-       return buf;
-} /* isnull_tostring */
-
 static sdb_type_t name_type = {
        /* size = */ sizeof(name_matcher_t),
        /* init = */ name_matcher_init,
@@ -1064,38 +923,6 @@ static sdb_type_t isnull_type = {
        /* destroy = */ isnull_matcher_destroy,
 };
 
-typedef char *(*matcher_tostring_cb)(sdb_store_matcher_t *, char *, size_t);
-
-/* this array needs to be indexable by the matcher types;
- * -> update the enum in store-private.h when updating this */
-static matcher_tostring_cb
-matchers_tostring[] = {
-       op_tostring,
-       op_tostring,
-       uop_tostring,
-       name_tostring,
-       attr_tostring,
-       child_tostring,
-       child_tostring,
-       child_tostring,
-       cond_tostring,
-       cond_tostring,
-       cond_tostring,
-       cond_tostring,
-       cond_tostring,
-       cmp_tostring,
-       cmp_tostring,
-       cmp_tostring,
-       cmp_tostring,
-       cmp_tostring,
-       cmp_tostring,
-       cmp_tostring,
-       cmp_tostring,
-       cmp_tostring,
-       isnull_tostring,
-       isnull_tostring,
-};
-
 /*
  * public API
  */
@@ -1537,18 +1364,6 @@ sdb_store_matcher_matches(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
        return matchers[m->type](m, obj, filter);
 } /* sdb_store_matcher_matches */
 
-char *
-sdb_store_matcher_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
-{
-       if (! m)
-               return NULL;
-
-       if ((m->type < 0)
-                       || (((size_t)m->type >= SDB_STATIC_ARRAY_LEN(matchers_tostring))))
-               return NULL;
-       return matchers_tostring[m->type](m, buf, buflen);
-} /* sdb_store_matcher_tostring */
-
 int
 sdb_store_scan(sdb_store_matcher_t *m, sdb_store_matcher_t *filter,
                sdb_store_lookup_cb cb, void *user_data)
index 2e1e558a87fbc11a2c983261b83235b8448c0129..2624194955c3ed9ebee454fec4e83dc017e0c8ec 100644 (file)
@@ -593,14 +593,6 @@ int
 sdb_store_matcher_matches(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
                sdb_store_matcher_t *filter);
 
-/*
- * sdb_store_matcher_tostring:
- * Format a matcher object as string. This is meant for logging or debugging
- * purposes.
- */
-char *
-sdb_store_matcher_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen);
-
 /*
  * sdb_store_lookup_cb:
  * Lookup callback. It is called for each matching object when looking up data
index f9ffabe6d08d39632bb6823cc728af8eb9b6f465..c5aad2c51f3670cd6f469d7650de349d6504a56a 100644 (file)
@@ -162,7 +162,6 @@ START_TEST(test_store_match_name)
 
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
                sdb_store_matcher_t *m, *n;
-               char buf[1024];
                int status;
 
                m = sdb_store_name_matcher(golden_data[i].type,
@@ -174,10 +173,9 @@ START_TEST(test_store_match_name)
 
                status = sdb_store_matcher_matches(m, obj, /* filter */ NULL);
                fail_unless(status == golden_data[i].expected,
-                               "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_store_matcher_matches(%s->%s, <host a>, NULL) = %d; "
+                               "expected: %d", SDB_STORE_TYPE_TO_NAME(golden_data[i].type),
+                               golden_data[i].name, status, golden_data[i].expected);
 
                n = sdb_store_inv_matcher(m);
                fail_unless(n != NULL,
@@ -187,10 +185,9 @@ START_TEST(test_store_match_name)
                /* now match the inverted set of objects */
                status = sdb_store_matcher_matches(n, obj, /* filter */ NULL);
                fail_unless(status == !golden_data[i].expected,
-                               "sdb_store_matcher_matches(%s, <host a>, NULL) = %d; "
-                               "expected: %d",
-                               sdb_store_matcher_tostring(n, buf, sizeof(buf)),
-                               status, !golden_data[i].expected);
+                               "sdb_store_matcher_matches(%s->%s, <host a>, NULL) = %d; "
+                               "expected: %d", SDB_STORE_TYPE_TO_NAME(golden_data[i].type),
+                               golden_data[i].name, status, !golden_data[i].expected);
 
                sdb_object_deref(SDB_OBJ(n));
        }
@@ -241,7 +238,6 @@ START_TEST(test_store_match_attr)
 
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
                sdb_store_matcher_t *m, *n;
-               char buf[1024];
                int status;
 
                m = sdb_store_attr_matcher(golden_data[i].attr_name,
@@ -251,10 +247,9 @@ START_TEST(test_store_match_attr)
 
                status = sdb_store_matcher_matches(m, obj, /* filter */ NULL);
                fail_unless(status == golden_data[i].expected,
-                               "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_store_matcher_matches(attribute[%s] = %s, "
+                               "<host a>, NULL) = %d; expected: %d", golden_data[i].attr_name,
+                               golden_data[i].attr_value, status, golden_data[i].expected);
 
                n = sdb_store_inv_matcher(m);
                fail_unless(n != NULL,
@@ -264,9 +259,9 @@ START_TEST(test_store_match_attr)
                /* now match the inverted set of objects */
                status = sdb_store_matcher_matches(n, obj, /* filter */ NULL);
                fail_unless(status == !golden_data[i].expected,
-                               "sdb_store_matcher_matches({%s, <host a>, NULL) = %d; "
-                               "expected: %d",
-                               sdb_store_matcher_tostring(n, buf, sizeof(buf)),
+                               "sdb_store_matcher_matches(attribute[%s] = %s, "
+                               "<host a>, NULL) = %d; expected: %d",
+                               golden_data[i].attr_name, golden_data[i].attr_value,
                                status, !golden_data[i].expected);
 
                sdb_object_deref(SDB_OBJ(n));
@@ -341,7 +336,6 @@ START_TEST(test_attr_cond)
 
                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,
@@ -349,10 +343,8 @@ START_TEST(test_attr_cond)
 
                        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_store_matcher_matches(<m>, <obj>, NULL) = %d; "
+                                       "expected: %d", status, tests[j].expected);
 
                        sdb_object_deref(SDB_OBJ(m));
                }
@@ -452,7 +444,6 @@ START_TEST(test_obj_cond)
 
                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,
@@ -460,10 +451,8 @@ START_TEST(test_obj_cond)
 
                        status = sdb_store_matcher_matches(m, obj, /* filter */ NULL);
                        fail_unless(status == tests[j].expected,
-                                       "sdb_store_matcher_matches(%s, <host '%s'>, NULL) = %d; "
-                                       "expected: %d",
-                                       sdb_store_matcher_tostring(m, m_str, sizeof(m_str)),
-                                       status, tests[j].expected);
+                                       "sdb_store_matcher_matches(<m>, <host '%s'>, NULL) = %d; "
+                                       "expected: %d", status, tests[j].expected);
 
                        sdb_object_deref(SDB_OBJ(m));
                }
@@ -777,90 +766,51 @@ scan_cb(sdb_store_obj_t *obj, void *user_data)
 
 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 = 'a'", NULL,                  1,
-                       "OBJ\\[host\\]\\{ NAME\\{ 'a', \\(nil\\) \\} \\}" },
-               { "host = 'a'", "host = 'x'",          0, /* filter never matches */
-                       "OBJ\\[host\\]\\{ NAME\\{ 'a', \\(nil\\) \\} \\}" },
+               { "host = 'a'", NULL,                  1 },
+               { "host = 'a'", "host = 'x'",          0 }, /* filter never matches */
                { "host = 'a'",
-                       "NOT attribute['x'] = ''",         1, /* filter always matches */
-                       "OBJ\\[host\\]\\{ NAME\\{ 'a', \\(nil\\) \\} \\}" },
-               { "host =~ 'a|b'", NULL,               2,
-                       "OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" },
-               { "host =~ 'host'", NULL,              0,
-                       "OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" },
-               { "host =~ '.'", NULL,                 3,
-                       "OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" },
-               { "metric = 'm1'", NULL,               2,
-                       "OBJ\\[metric\\]\\{ NAME\\{ 'm1', \\(nil\\) } \\}" },
-               { "metric= 'm1'", "host = 'x'",        0, /* filter never matches */
-                       "OBJ\\[metric\\]\\{ NAME\\{ 'm1', \\(nil\\) } \\}" },
+                       "NOT attribute['x'] = ''",         1 }, /* filter always matches */
+               { "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'",
-                       "NOT attribute['x'] = ''",         2, /* filter always matches */
-                       "OBJ\\[metric\\]\\{ NAME\\{ 'm1', \\(nil\\) } \\}" },
-               { "metric =~ 'm'", NULL,               2,
-                       "OBJ\\[metric\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}" },
-               { "metric !~ 'm'", NULL,               1,
-                       "\\(NOT, OBJ\\[metric\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}\\)" },
-               { "metric =~ 'x'", NULL,               0,
-                       "OBJ\\[metric\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}" },
-               { "service = 's1'", NULL,              2,
-                       "OBJ\\[service\\]\\{ NAME\\{ 's1', \\(nil\\) } \\}" },
-               { "service = 's1'", "host = 'x'",      0, /* filter never matches */
-                       "OBJ\\[service\\]\\{ NAME\\{ 's1', \\(nil\\) } \\}" },
+                       "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'",
-                       "NOT attribute['x'] = ''",         2, /* filter always matches */
-                       "OBJ\\[service\\]\\{ NAME\\{ 's1', \\(nil\\) } \\}" },
-               { "service =~ 's'", NULL,              2,
-                       "OBJ\\[service\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}" },
-               { "service !~ 's'", NULL,              1,
-                       "\\(NOT, OBJ\\[service\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}\\)" },
-               { "attribute = 'k1'", NULL,            2,
-                       "OBJ\\[attribute\\]\\{ NAME\\{ 'k1', \\(nil\\) \\} " },
-               { "attribute = 'k1'", "host = 'x'",    0, /* filter never matches */
-                       "OBJ\\[attribute\\]\\{ NAME\\{ 'k1', \\(nil\\) \\} " },
+                       "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'",
-                       "NOT attribute['x'] = ''",         2, /* filter always matches */
-                       "OBJ\\[attribute\\]\\{ NAME\\{ 'k1', \\(nil\\) \\} " },
-               { "attribute = 'x'", NULL,             0,
-                       "OBJ\\[attribute\\]\\{ NAME\\{ 'x', \\(nil\\) \\}" },
-               { "attribute['k1'] = 'v1'", NULL,      1,
-                       "CMP_MATCHER\\(15\\)" },
-               { "attribute['k1'] IS NULL", NULL,     1,
-                       "\\(IS NULL\\)" },
-               { "attribute['x1'] IS NULL", NULL,     3,
-                       "\\(IS NULL\\)" },
-               { "attribute['k1'] IS NOT NULL", NULL, 2,
-                       "\\(IS NOT NULL\\)" },
-               { "attribute['x1'] IS NOT NULL", NULL, 0,
-                       "\\(IS NOT NULL\\)" },
-               { "attribute['k2'] < 123", NULL,       0,
-                       "CMP_MATCHER\\(13\\)" },
-               { "attribute['k2'] <= 123", NULL,      1,
-                       "CMP_MATCHER\\(14\\)" },
-               { "attribute['k2'] >= 123", NULL,      1,
-                       "CMP_MATCHER\\(17\\)" },
-               { "attribute['k2'] > 123", NULL,       0,
-                       "CMP_MATCHER\\(18\\)" },
-               { "attribute['k2'] = 123", NULL,       1,
-                       "CMP_MATCHER\\(15\\)" },
-               { "attribute['k2'] != 123", NULL,      0,
-                       "CMP_MATCHER\\(16\\)" },
-               { "attribute['k1'] != 'v1'", NULL,     1,
-                       "CMP_MATCHER\\(16\\)" },
-               { "attribute['k1'] != 'v2'", NULL,     1,
-                       "CMP_MATCHER\\(16\\)" },
+                       "NOT attribute['x'] = ''",         2 }, /* filter always matches */
+               { "attribute = 'x'", NULL,             0 },
+               { "attribute['k1'] = 'v1'", NULL,      1 },
+               { "attribute['k1'] IS NULL", NULL,     1 },
+               { "attribute['x1'] IS NULL", NULL,     3 },
+               { "attribute['k1'] IS NOT NULL", NULL, 2 },
+               { "attribute['x1'] IS NOT NULL", NULL, 0 },
+               { "attribute['k2'] < 123", NULL,       0 },
+               { "attribute['k2'] <= 123", NULL,      1 },
+               { "attribute['k2'] >= 123", NULL,      1 },
+               { "attribute['k2'] > 123", NULL,       0 },
+               { "attribute['k2'] = 123", NULL,       1 },
+               { "attribute['k2'] != 123", NULL,      0 },
+               { "attribute['k1'] != 'v1'", NULL,     1 },
+               { "attribute['k1'] != 'v2'", NULL,     1 },
                { "attribute != 'x' "
-                 "AND attribute['y'] !~ 'x'", NULL,   3,
-                       "\\(AND, "
-                               "\\(NOT, OBJ\\[attribute\\]\\{ NAME\\{ 'x', \\(nil\\) \\} \\}\\), "
-                               "CMP_MATCHER\\(21\\)" },
+                 "AND attribute['y'] !~ 'x'", NULL,   3 },
        };
 
        int check, n;
@@ -876,7 +826,6 @@ START_TEST(test_scan)
 
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
                sdb_store_matcher_t *m, *filter = NULL;
-               char buf[4096];
 
                m = sdb_fe_parse_matcher(golden_data[i].query, -1);
                fail_unless(m != NULL,
@@ -890,13 +839,6 @@ START_TEST(test_scan)
                                        "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].query,
-                               sdb_store_matcher_tostring(m, buf, sizeof(buf)),
-                               golden_data[i].tostring_re);
-
                n = 0;
                sdb_store_scan(m, filter, scan_cb, &n);
                fail_unless(n == golden_data[i].expected,
index 826d938fc4444a5d02a0bde60812dcb83ebc0933..ddf5ff29a1bb62385fc3f7158cc8e8d22a4fbd8c 100644 (file)
@@ -408,7 +408,7 @@ END_TEST
 
 static void
 verify_json_output(sdb_strbuf_t *buf, const char *expected,
-               const char *filter_str, int flags)
+               sdb_store_matcher_t *filter, int flags)
 {
        int pos;
        size_t len1, len2;
@@ -429,9 +429,9 @@ verify_json_output(sdb_strbuf_t *buf, const char *expected,
        }
 
        fail_unless(pos == -1,
-                       "sdb_store_tojson(<buf>, %s, %x) returned unexpected result\n"
+                       "sdb_store_tojson(<buf>, %p, %x) returned unexpected result\n"
                        "         got: %s\n              %*s\n    expected: %s",
-                       filter_str, flags, sdb_strbuf_string(buf), pos + 1, "^",
+                       filter, flags, sdb_strbuf_string(buf), pos + 1, "^",
                        expected);
 } /* verify_json_output */
 
@@ -664,7 +664,6 @@ START_TEST(test_store_tojson)
 
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
                sdb_store_matcher_t *filter = NULL;
-               char filter_str[1024] = "<none>";
                int status;
 
                sdb_strbuf_clear(buf);
@@ -684,19 +683,15 @@ START_TEST(test_store_tojson)
                        sdb_object_deref(SDB_OBJ(c));
                        fail_unless(filter != NULL,
                                        "INTERNAL ERROR: sdb_store_*_matcher() = NULL");
-
-                       if (sdb_store_matcher_tostring(filter,
-                                               filter_str, sizeof(filter_str)))
-                               snprintf(filter_str, sizeof(filter_str), "ERR");
                }
 
                status = sdb_store_tojson(buf, filter, golden_data[i].flags);
                fail_unless(status == 0,
-                               "sdb_store_tojson(<buf>, %s, %x) = %d; expected: 0",
-                               filter_str, golden_data[i].flags, status);
+                               "sdb_store_tojson(<buf>, %p, %x) = %d; expected: 0",
+                               filter, golden_data[i].flags, status);
 
                verify_json_output(buf, golden_data[i].expected,
-                               filter_str, golden_data[i].flags);
+                               filter, golden_data[i].flags);
                sdb_object_deref(SDB_OBJ(filter));
        }
        sdb_strbuf_destroy(buf);