Code

Merged branch 'master' of git://git.tokkee.org/sysdb.
authorSebastian Harl <sh@tokkee.org>
Mon, 23 Jun 2014 18:34:43 +0000 (20:34 +0200)
committerSebastian Harl <sh@tokkee.org>
Mon, 23 Jun 2014 18:34:43 +0000 (20:34 +0200)
1  2 
t/unit/core/store_lookup_test.c

index e90dd06c1acee054d6388dcbd0ef7e5b99c4e4d0,b5cb0d2000df93f75249ccb9fb31064cd542123c..4a935429923bb4dd1118c092756387cf1393fc0e
@@@ -302,26 -302,16 +302,26 @@@ START_TEST(test_store_cond
                                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
  
@@@ -397,6 -387,10 +397,10 @@@ END_TES
  
  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 },
-               { "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 },
-               { "attribute", "name", "=",  "attrname", MATCHER_NAME },
-               { "attribute", "name", "!=", "attrname", MATCHER_NOT },
-               { "attribute", "name", "=~", "attrname", MATCHER_NAME },
-               { "attribute", "name", "!~", "attrname", MATCHER_NOT },
-               { "attribute", "attr", "=",  "attrname", MATCHER_ATTR },
-               { "attribute", "attr", "!=", "attrname", MATCHER_NOT },
-               { "attribute", "attr", "=~", "attrname", MATCHER_ATTR },
-               { "attribute", "attr", "!~", "attrname", MATCHER_NOT },
-               { "attribute", "attr", "&^", "attrname", -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 },
+               { "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));