struct ec_keyval *keyval, *dup;
char *val;
size_t i;
- int ret;
+ int ret, testres = 0;
keyval = ec_keyval();
if (keyval == NULL) {
return -1;
}
- EC_TEST_ASSERT(ec_keyval_len(keyval) == 0);
+ testres |= EC_TEST_CHECK(ec_keyval_len(keyval) == 0, "bad keyval len");
ret = ec_keyval_set(keyval, "key1", "val1", NULL);
- EC_TEST_ASSERT_STR(ret == 0, "cannot set key");
+ testres |= EC_TEST_CHECK(ret == 0, "cannot set key");
ret = ec_keyval_set(keyval, "key2", ec_strdup("val2"), ec_free_func);
- EC_TEST_ASSERT_STR(ret == 0, "cannot set key");
- EC_TEST_ASSERT(ec_keyval_len(keyval) == 2);
+ testres |= EC_TEST_CHECK(ret == 0, "cannot set key");
+ testres |= EC_TEST_CHECK(ec_keyval_len(keyval) == 2, "bad keyval len");
val = ec_keyval_get(keyval, "key1");
- EC_TEST_ASSERT(val != NULL && !strcmp(val, "val1"));
+ testres |= EC_TEST_CHECK(val != NULL && !strcmp(val, "val1"),
+ "invalid keyval value");
val = ec_keyval_get(keyval, "key2");
- EC_TEST_ASSERT(val != NULL && !strcmp(val, "val2"));
+ testres |= EC_TEST_CHECK(val != NULL && !strcmp(val, "val2"),
+ "invalid keyval value");
val = ec_keyval_get(keyval, "key3");
- EC_TEST_ASSERT(val == NULL);
+ testres |= EC_TEST_CHECK(val == NULL, "key3 should be NULL");
ret = ec_keyval_set(keyval, "key1", "another_val1", NULL);
- EC_TEST_ASSERT_STR(ret == 0, "cannot set key");
+ testres |= EC_TEST_CHECK(ret == 0, "cannot set key");
ret = ec_keyval_set(keyval, "key2", ec_strdup("another_val2"),
ec_free_func);
- EC_TEST_ASSERT_STR(ret == 0, "cannot set key");
- EC_TEST_ASSERT(ec_keyval_len(keyval) == 2);
+ testres |= EC_TEST_CHECK(ret == 0, "cannot set key");
+ testres |= EC_TEST_CHECK(ec_keyval_len(keyval) == 2,
+ "bad keyval len");
val = ec_keyval_get(keyval, "key1");
- EC_TEST_ASSERT(val != NULL && !strcmp(val, "another_val1"));
+ testres |= EC_TEST_CHECK(val != NULL && !strcmp(val, "another_val1"),
+ "invalid keyval value");
val = ec_keyval_get(keyval, "key2");
- EC_TEST_ASSERT(val != NULL && !strcmp(val, "another_val2"));
- EC_TEST_ASSERT(ec_keyval_has_key(keyval, "key1"));
+ testres |= EC_TEST_CHECK(val != NULL && !strcmp(val, "another_val2"),
+ "invalid keyval value");
+ testres |= EC_TEST_CHECK(ec_keyval_has_key(keyval, "key1"),
+ "key1 should be in keyval");
ret = ec_keyval_del(keyval, "key1");
- EC_TEST_ASSERT_STR(ret == 0, "cannot del key");
- EC_TEST_ASSERT(ec_keyval_len(keyval) == 1);
+ testres |= EC_TEST_CHECK(ret == 0, "cannot del key");
+ testres |= EC_TEST_CHECK(ec_keyval_len(keyval) == 1,
+ "invalid keyval len");
ec_keyval_dump(stdout, NULL);
ec_keyval_dump(stdout, keyval);
char key[8];
snprintf(key, sizeof(key), "k%zd", i);
ret = ec_keyval_set(keyval, key, "val", NULL);
- EC_TEST_ASSERT_STR(ret == 0, "cannot set key");
+ testres |= EC_TEST_CHECK(ret == 0, "cannot set key");
}
dup = ec_keyval_dup(keyval);
- EC_TEST_ASSERT_STR(dup != NULL, "cannot duplicate keyval");
+ testres |= EC_TEST_CHECK(dup != NULL, "cannot duplicate keyval");
if (dup != NULL) {
for (i = 0; i < 100; i++) {
char key[8];
snprintf(key, sizeof(key), "k%zd", i);
val = ec_keyval_get(dup, key);
- EC_TEST_ASSERT(val != NULL && !strcmp(val, "val"));
+ testres |= EC_TEST_CHECK(
+ val != NULL && !strcmp(val, "val"),
+ "invalid keyval value");
}
ec_keyval_free(dup);
dup = NULL;
/* einval */
ret = ec_keyval_set(keyval, NULL, "val1", NULL);
- EC_TEST_ASSERT(ret == -1);
+ testres |= EC_TEST_CHECK(ret == -1, "should not be able to set key");
val = ec_keyval_get(keyval, NULL);
- EC_TEST_ASSERT(val == NULL);
+ testres |= EC_TEST_CHECK(val == NULL, "get(NULL) should no success");
ec_keyval_free(keyval);
- return 0;
+ return testres;
}
/* LCOV_EXCL_STOP */
static int ec_node_any_testcase(void)
{
struct ec_node *node;
- int ret = 0;
+ int testres = 0;
node = ec_node("any", EC_NO_ID);
if (node == NULL) {
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo", "bar");
- ret |= EC_TEST_CHECK_PARSE(node, -1);
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo", "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, -1);
ec_node_free(node);
/* never completes */
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
ec_node_free(node);
- return ret;
+ return testres;
}
/* LCOV_EXCL_STOP */
static int ec_node_cmd_testcase(void)
{
struct ec_node *node;
- int ret = 0;
+ int testres = 0;
node = EC_NODE_CMD(EC_NO_ID,
"command [option] (subset1, subset2, subset3, subset4) x|y z*",
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, 2, "command", "1");
- ret |= EC_TEST_CHECK_PARSE(node, 3, "command", "subset1", "1");
- ret |= EC_TEST_CHECK_PARSE(node, 4, "command", "subset3", "subset2",
+ testres |= EC_TEST_CHECK_PARSE(node, 2, "command", "1");
+ testres |= EC_TEST_CHECK_PARSE(node, 3, "command", "subset1", "1");
+ testres |= EC_TEST_CHECK_PARSE(node, 4, "command", "subset3", "subset2",
"1");
- ret |= EC_TEST_CHECK_PARSE(node, 5, "command", "subset2", "subset3",
+ testres |= EC_TEST_CHECK_PARSE(node, 5, "command", "subset2", "subset3",
"subset1", "1");
- ret |= EC_TEST_CHECK_PARSE(node, 6, "command", "subset3", "subset1",
+ testres |= EC_TEST_CHECK_PARSE(node, 6, "command", "subset3", "subset1",
"subset4", "subset2", "4");
- ret |= EC_TEST_CHECK_PARSE(node, 2, "command", "23");
- ret |= EC_TEST_CHECK_PARSE(node, 3, "command", "option", "23");
- ret |= EC_TEST_CHECK_PARSE(node, 5, "command", "option", "23",
+ testres |= EC_TEST_CHECK_PARSE(node, 2, "command", "23");
+ testres |= EC_TEST_CHECK_PARSE(node, 3, "command", "option", "23");
+ testres |= EC_TEST_CHECK_PARSE(node, 5, "command", "option", "23",
"z", "z");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "command", "15");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "command", "15");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "foo");
ec_node_free(node);
node = EC_NODE_CMD(EC_NO_ID, "good morning [count] bob|bobby|michael",
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, 4, "good", "morning", "1", "bob");
+ testres |= EC_TEST_CHECK_PARSE(node, 4, "good", "morning", "1", "bob");
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"", EC_NODE_ENDLIST,
"good", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"g", EC_NODE_ENDLIST,
"good", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"good", "morning", "", EC_NODE_ENDLIST,
"bob", "bobby", "michael", EC_NODE_ENDLIST);
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, 0);
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo");
- ret |= EC_TEST_CHECK_PARSE(node, 2, "foo", "bar");
- ret |= EC_TEST_CHECK_PARSE(node, 0, "x");
+ testres |= EC_TEST_CHECK_PARSE(node, 0);
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, 2, "foo", "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 0, "x");
ec_node_free(node);
- return ret;
+ return testres;
}
/* LCOV_EXCL_STOP */
static int ec_node_dynamic_testcase(void)
{
struct ec_node *node;
- int ret = 0;
+ int testres = 0;
node = ec_node_many(EC_NO_ID,
ec_node_dynamic(EC_NO_ID, build_counter, NULL),
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, 1, "count-0");
- ret |= EC_TEST_CHECK_PARSE(node, 3, "count-0", "count-1", "count-2");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "count-0", "count-0");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "count-0");
+ testres |= EC_TEST_CHECK_PARSE(node, 3, "count-0", "count-1", "count-2");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "count-0", "count-0");
/* test completion */
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"c", EC_NODE_ENDLIST,
"count-0", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"count-0", "", EC_NODE_ENDLIST,
"count-1", EC_NODE_ENDLIST,
"count-1");
ec_node_free(node);
- return ret;
+ return testres;
}
/* LCOV_EXCL_STOP */
static int ec_node_empty_testcase(void)
{
struct ec_node *node;
- int ret = 0;
+ int testres = 0;
node = ec_node("empty", EC_NO_ID);
if (node == NULL) {
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, 0, "foo");
- ret |= EC_TEST_CHECK_PARSE(node, 0);
- ret |= EC_TEST_CHECK_PARSE(node, 0, "foo", "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 0, "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, 0);
+ testres |= EC_TEST_CHECK_PARSE(node, 0, "foo", "bar");
ec_node_free(node);
/* never completes */
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
ec_node_free(node);
- return ret;
+ return testres;
}
/* LCOV_EXCL_STOP */
static int ec_node_expr_testcase(void)
{
struct ec_node *node = NULL, *lex_node = NULL;
- int ret = 0;
+ int testres = 0;
node = ec_node("expr", "my_expr");
if (node == NULL)
ec_node_expr_add_post_op(node, ec_node_str(EC_NO_ID, "^")); /* square */
ec_node_expr_add_parenthesis(node, ec_node_str(EC_NO_ID, "("),
ec_node_str(EC_NO_ID, ")"));
- ret |= EC_TEST_CHECK_PARSE(node, 1, "1");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "1", "1");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "1", "*");
- ret |= EC_TEST_CHECK_PARSE(node, 3, "1", "*", "1");
- ret |= EC_TEST_CHECK_PARSE(node, 3, "1", "*", "1", "*");
- ret |= EC_TEST_CHECK_PARSE(node, 4, "1", "+", "!", "1");
- ret |= EC_TEST_CHECK_PARSE(node, 4, "1", "^", "+", "1");
- ret |= EC_TEST_CHECK_PARSE(node, 5, "1", "*", "1", "*", "1");
- ret |= EC_TEST_CHECK_PARSE(node, 5, "1", "*", "1", "+", "1");
- ret |= EC_TEST_CHECK_PARSE(node, 7, "1", "*", "1", "*", "1", "*", "1");
- ret |= EC_TEST_CHECK_PARSE(
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "1");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "1", "1");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "1", "*");
+ testres |= EC_TEST_CHECK_PARSE(node, 3, "1", "*", "1");
+ testres |= EC_TEST_CHECK_PARSE(node, 3, "1", "*", "1", "*");
+ testres |= EC_TEST_CHECK_PARSE(node, 4, "1", "+", "!", "1");
+ testres |= EC_TEST_CHECK_PARSE(node, 4, "1", "^", "+", "1");
+ testres |= EC_TEST_CHECK_PARSE(node, 5, "1", "*", "1", "*", "1");
+ testres |= EC_TEST_CHECK_PARSE(node, 5, "1", "*", "1", "+", "1");
+ testres |= EC_TEST_CHECK_PARSE(node, 7, "1", "*", "1", "*", "1", "*",
+ "1");
+ testres |= EC_TEST_CHECK_PARSE(
node, 10, "!", "(", "1", "*", "(", "1", "+", "1", ")", ")");
- ret |= EC_TEST_CHECK_PARSE(node, 5, "1", "+", "!", "1", "^");
+ testres |= EC_TEST_CHECK_PARSE(node, 5, "1", "+", "!", "1", "^");
/* prepend a lexer to the expression node */
lex_node = ec_node_re_lex(EC_NO_ID, ec_node_clone(node));
if (lex_node == NULL)
goto fail;
- ret |= ec_node_re_lex_add(lex_node, "[0-9]+", 1); /* vars */
- ret |= ec_node_re_lex_add(lex_node, "[+*!^()]", 1); /* operators */
- ret |= ec_node_re_lex_add(lex_node, "[ ]+", 0); /* spaces */
+ testres |= ec_node_re_lex_add(lex_node, "[0-9]+", 1); /* vars */
+ testres |= ec_node_re_lex_add(lex_node, "[+*!^()]", 1); /* operators */
+ testres |= ec_node_re_lex_add(lex_node, "[ ]+", 0); /* spaces */
/* valid expressions */
- ret |= EC_TEST_CHECK_PARSE(lex_node, 1, "!1");
- ret |= EC_TEST_CHECK_PARSE(lex_node, 1, "1^");
- ret |= EC_TEST_CHECK_PARSE(lex_node, 1, "1^ + 1");
- ret |= EC_TEST_CHECK_PARSE(lex_node, 1, "1 + 4 * (2 + 3^)^");
- ret |= EC_TEST_CHECK_PARSE(lex_node, 1, "(1)");
- ret |= EC_TEST_CHECK_PARSE(lex_node, 1, "3*!3+!3*(2+ 2)");
- ret |= EC_TEST_CHECK_PARSE(lex_node, 1, "!!(!1)^ + !(4 + (2*3))");
- ret |= EC_TEST_CHECK_PARSE(lex_node, 1, "(1 + 1)^ * 1^");
+ testres |= EC_TEST_CHECK_PARSE(lex_node, 1, "!1");
+ testres |= EC_TEST_CHECK_PARSE(lex_node, 1, "1^");
+ testres |= EC_TEST_CHECK_PARSE(lex_node, 1, "1^ + 1");
+ testres |= EC_TEST_CHECK_PARSE(lex_node, 1, "1 + 4 * (2 + 3^)^");
+ testres |= EC_TEST_CHECK_PARSE(lex_node, 1, "(1)");
+ testres |= EC_TEST_CHECK_PARSE(lex_node, 1, "3*!3+!3*(2+ 2)");
+ testres |= EC_TEST_CHECK_PARSE(lex_node, 1, "!!(!1)^ + !(4 + (2*3))");
+ testres |= EC_TEST_CHECK_PARSE(lex_node, 1, "(1 + 1)^ * 1^");
/* invalid expressions */
- ret |= EC_TEST_CHECK_PARSE(lex_node, -1, "");
- ret |= EC_TEST_CHECK_PARSE(lex_node, -1, "()");
- ret |= EC_TEST_CHECK_PARSE(lex_node, -1, "(");
- ret |= EC_TEST_CHECK_PARSE(lex_node, -1, ")");
- ret |= EC_TEST_CHECK_PARSE(lex_node, -1, "+1");
- ret |= EC_TEST_CHECK_PARSE(lex_node, -1, "1+");
- ret |= EC_TEST_CHECK_PARSE(lex_node, -1, "1+*1");
- ret |= EC_TEST_CHECK_PARSE(lex_node, -1, "1+(1*1");
- ret |= EC_TEST_CHECK_PARSE(lex_node, -1, "1+!1!1)");
-
- ret |= ec_node_expr_test_eval(lex_node, node, "1^", 1);
- ret |= ec_node_expr_test_eval(lex_node, node, "2^", 4);
- ret |= ec_node_expr_test_eval(lex_node, node, "!1", 0);
- ret |= ec_node_expr_test_eval(lex_node, node, "!0", 1);
-
- ret |= ec_node_expr_test_eval(lex_node, node, "1+1", 2);
- ret |= ec_node_expr_test_eval(lex_node, node, "1+2+3", 6);
- ret |= ec_node_expr_test_eval(lex_node, node, "1+1*2", 4);
- ret |= ec_node_expr_test_eval(lex_node, node, "2 * 2^", 8);
- ret |= ec_node_expr_test_eval(lex_node, node, "(1 + !0)^ * !0^", 4);
- ret |= ec_node_expr_test_eval(lex_node, node, "(1 + !1) * 3", 3);
+ testres |= EC_TEST_CHECK_PARSE(lex_node, -1, "");
+ testres |= EC_TEST_CHECK_PARSE(lex_node, -1, "()");
+ testres |= EC_TEST_CHECK_PARSE(lex_node, -1, "(");
+ testres |= EC_TEST_CHECK_PARSE(lex_node, -1, ")");
+ testres |= EC_TEST_CHECK_PARSE(lex_node, -1, "+1");
+ testres |= EC_TEST_CHECK_PARSE(lex_node, -1, "1+");
+ testres |= EC_TEST_CHECK_PARSE(lex_node, -1, "1+*1");
+ testres |= EC_TEST_CHECK_PARSE(lex_node, -1, "1+(1*1");
+ testres |= EC_TEST_CHECK_PARSE(lex_node, -1, "1+!1!1)");
+
+ testres |= ec_node_expr_test_eval(lex_node, node, "1^", 1);
+ testres |= ec_node_expr_test_eval(lex_node, node, "2^", 4);
+ testres |= ec_node_expr_test_eval(lex_node, node, "!1", 0);
+ testres |= ec_node_expr_test_eval(lex_node, node, "!0", 1);
+
+ testres |= ec_node_expr_test_eval(lex_node, node, "1+1", 2);
+ testres |= ec_node_expr_test_eval(lex_node, node, "1+2+3", 6);
+ testres |= ec_node_expr_test_eval(lex_node, node, "1+1*2", 4);
+ testres |= ec_node_expr_test_eval(lex_node, node, "2 * 2^", 8);
+ testres |= ec_node_expr_test_eval(lex_node, node, "(1 + !0)^ * !0^", 4);
+ testres |= ec_node_expr_test_eval(lex_node, node, "(1 + !1) * 3", 3);
ec_node_free(node);
ec_node_free(lex_node);
- return ret;
+ return testres;
fail:
ec_node_free(lex_node);
static int
test_lstat(const char *pathname, struct stat *buf)
{
-// return lstat(pathname, buf);
-
if (!strcmp(pathname, "/tmp/toto/")) {
struct stat st = { .st_mode = S_IFDIR };
memcpy(buf, &st, sizeof(*buf));
static DIR *
test_opendir(const char *name)
{
-// return opendir(name);
int *p;
if (strcmp(name, "/tmp/toto/")) {
static struct dirent *
test_readdir(DIR *dirp)
{
- //return readdir(dirp);
static struct dirent de[] = {
{ .d_type = DT_DIR, .d_name = ".." },
{ .d_type = DT_DIR, .d_name = "." },
static int ec_node_file_testcase(void)
{
struct ec_node *node;
- int ret = 0;
+ int testres = 0;
node = ec_node("file", EC_NO_ID);
if (node == NULL) {
ec_node_file_override_functions(node);
/* any string matches */
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "/tmp/bar");
- ret |= EC_TEST_CHECK_PARSE(node, -1);
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "/tmp/bar");
+ testres |= EC_TEST_CHECK_PARSE(node, -1);
/* test completion */
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"/tmp/toto/t", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE_PARTIAL(node,
+ testres |= EC_TEST_CHECK_COMPLETE_PARTIAL(node,
"/tmp/toto/t", EC_NODE_ENDLIST,
"/tmp/toto/titi/", "/tmp/toto/tutu/", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"/tmp/toto/f", EC_NODE_ENDLIST,
"/tmp/toto/foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"/tmp/toto/b", EC_NODE_ENDLIST,
"/tmp/toto/bar", "/tmp/toto/bar2", EC_NODE_ENDLIST);
ec_node_free(node);
- return ret;
+ return testres;
}
/* LCOV_EXCL_STOP */
struct ec_parsed *p;
struct ec_node *node;
const char *s;
- int ret = 0;
+ int testres = 0, ret;
uint64_t u64;
int64_t i64;
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, -1, "");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "0");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "1");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "256", "foo");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "0x100");
- ret |= EC_TEST_CHECK_PARSE(node, 1, " 1");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "-1");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "0x101");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "zzz");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "0x100000000000000000");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "4r");
- ec_node_uint_disable_limits(node);
- ret |= EC_TEST_CHECK_PARSE(node, 1, "0");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "0");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "1");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "256", "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "0x100");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, " 1");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "-1");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "0x101");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "zzz");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "0x100000000000000000");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "4r");
+ ret = ec_node_uint_disable_limits(node);
+ testres |= EC_TEST_CHECK(ret == 0, "cannot disable limits");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "0");
p = ec_node_parse(node, "1");
s = ec_strvec_val(ec_parsed_strvec(p), 0);
- EC_TEST_ASSERT(s != NULL &&
+ testres |= EC_TEST_CHECK(s != NULL &&
ec_node_uint_getval(node, s, &u64) == 0 &&
- u64 == 1);
+ u64 == 1, "bad integer value");
ec_parsed_free(p);
p = ec_node_parse(node, "10");
s = ec_strvec_val(ec_parsed_strvec(p), 0);
- EC_TEST_ASSERT(s != NULL &&
+ testres |= EC_TEST_CHECK(s != NULL &&
ec_node_uint_getval(node, s, &u64) == 0 &&
- u64 == 10);
+ u64 == 10, "bad integer value");
ec_parsed_free(p);
ec_node_free(node);
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, 1, "0");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "-1");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "7fffffffffffffff");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "0x7fffffffffffffff");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "0x8000000000000000");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "-2");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "zzz");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "4r");
- ec_node_int_disable_limits(node);
- ret |= EC_TEST_CHECK_PARSE(node, 1, "-2");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "0");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "-1");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "7fffffffffffffff");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "0x7fffffffffffffff");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "0x8000000000000000");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "-2");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "zzz");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "4r");
+ ret = ec_node_int_disable_limits(node);
+ testres |= EC_TEST_CHECK(ret == 0, "cannot disable limits");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "-2");
p = ec_node_parse(node, "10");
s = ec_strvec_val(ec_parsed_strvec(p), 0);
- EC_TEST_ASSERT(s != NULL &&
+ testres |= EC_TEST_CHECK(s != NULL &&
ec_node_int_getval(node, s, &i64) == 0 &&
- i64 == 16);
+ i64 == 16, "bad integer value");
ec_parsed_free(p);
ec_node_free(node);
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, 1, "0");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "-1");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "-9223372036854775808");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "0x0");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "1");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "0");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "-1");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "-9223372036854775808");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "0x0");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "1");
ec_node_free(node);
/* test completion */
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"x", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"1", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
ec_node_free(node);
- return ret;
+ return testres;
}
/* LCOV_EXCL_STOP */
static int ec_node_many_testcase(void)
{
struct ec_node *node;
- int ret = 0;
+ int testres = 0;
node = ec_node_many(EC_NO_ID, ec_node_str(EC_NO_ID, "foo"), 0, 0);
if (node == NULL) {
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, 0);
- ret |= EC_TEST_CHECK_PARSE(node, 0, "bar");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo", "bar");
- ret |= EC_TEST_CHECK_PARSE(node, 2, "foo", "foo", "bar");
- ret |= EC_TEST_CHECK_PARSE(node, 0);
+ testres |= EC_TEST_CHECK_PARSE(node, 0);
+ testres |= EC_TEST_CHECK_PARSE(node, 0, "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo", "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 2, "foo", "foo", "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 0);
ec_node_free(node);
node = ec_node_many(EC_NO_ID, ec_node_str(EC_NO_ID, "foo"), 1, 0);
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, -1, "bar");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo", "bar");
- ret |= EC_TEST_CHECK_PARSE(node, 2, "foo", "foo", "bar");
- ret |= EC_TEST_CHECK_PARSE(node, -1);
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo", "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 2, "foo", "foo", "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, -1);
ec_node_free(node);
node = ec_node_many(EC_NO_ID, ec_node_str(EC_NO_ID, "foo"), 1, 2);
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, -1, "bar");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo", "bar");
- ret |= EC_TEST_CHECK_PARSE(node, 2, "foo", "foo", "bar");
- ret |= EC_TEST_CHECK_PARSE(node, 2, "foo", "foo", "foo");
- ret |= EC_TEST_CHECK_PARSE(node, -1);
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo", "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 2, "foo", "foo", "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 2, "foo", "foo", "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, -1);
ec_node_free(node);
/* test completion */
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"f", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo", "", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo", "foo", "", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo", "foo", "foo", "", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo", "foo", "foo", "foo", "", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
ec_node_free(node);
- return ret;
+ return testres;
}
/* LCOV_EXCL_STOP */
static int ec_node_none_testcase(void)
{
struct ec_node *node;
- int ret = 0;
+ int testres = 0;
node = ec_node("none", EC_NO_ID);
if (node == NULL) {
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, -1, "foo");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "foo", "bar");
- ret |= EC_TEST_CHECK_PARSE(node, -1);
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "foo", "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, -1);
ec_node_free(node);
/* never completes */
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
ec_node_free(node);
- return ret;
+ return testres;
}
/* LCOV_EXCL_STOP */
static int ec_node_once_testcase(void)
{
struct ec_node *node;
- int ret = 0;
+ int testres = 0;
node = ec_node_many(EC_NO_ID,
EC_NODE_OR(EC_NO_ID,
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, 0);
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "bar");
- ret |= EC_TEST_CHECK_PARSE(node, 2, "foo", "bar");
- ret |= EC_TEST_CHECK_PARSE(node, 3, "foo", "bar", "bar");
- ret |= EC_TEST_CHECK_PARSE(node, 3, "bar", "foo", "bar");
- ret |= EC_TEST_CHECK_PARSE(node, 2, "bar", "foo", "foo");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo", "foo");
- ret |= EC_TEST_CHECK_PARSE(node, 0, "foox");
-
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_PARSE(node, 0);
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 2, "foo", "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 3, "foo", "bar", "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 3, "bar", "foo", "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 2, "bar", "foo", "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo", "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, 0, "foox");
+
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"", EC_NODE_ENDLIST,
"foo", "bar", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"f", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"b", EC_NODE_ENDLIST,
"bar", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo", "", EC_NODE_ENDLIST,
"bar", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"bar", "", EC_NODE_ENDLIST,
"foo", "bar", EC_NODE_ENDLIST);
ec_node_free(node);
- return ret;
+ return testres;
}
/* LCOV_EXCL_STOP */
static int ec_node_option_testcase(void)
{
struct ec_node *node;
- int ret = 0;
+ int testres = 0;
node = ec_node_option(EC_NO_ID, ec_node_str(EC_NO_ID, "foo"));
if (node == NULL) {
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo", "bar");
- ret |= EC_TEST_CHECK_PARSE(node, 0, "bar");
- ret |= EC_TEST_CHECK_PARSE(node, 0);
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo", "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 0, "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 0);
ec_node_free(node);
/* test completion */
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"f", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"b", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
ec_node_free(node);
- return ret;
+ return testres;
}
/* LCOV_EXCL_STOP */
static int ec_node_or_testcase(void)
{
struct ec_node *node;
- int ret = 0;
+ int testres = 0;
node = EC_NODE_OR(EC_NO_ID,
ec_node_str(EC_NO_ID, "foo"),
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "bar");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo", "bar");
- ret |= EC_TEST_CHECK_PARSE(node, -1, " ");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "foox");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "toto");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo", "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, " ");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "foox");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "toto");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "");
ec_node_free(node);
/* test completion */
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"", EC_NODE_ENDLIST,
"foo", "bar", "bar2", "toto", "titi", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"f", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"b", EC_NODE_ENDLIST,
"bar", "bar2", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"bar", EC_NODE_ENDLIST,
"bar", "bar2", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"t", EC_NODE_ENDLIST,
"toto", "titi", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"to", EC_NODE_ENDLIST,
"toto", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"x", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
ec_node_free(node);
- return ret;
+ return testres;
}
/* LCOV_EXCL_STOP */
static int ec_node_re_testcase(void)
{
struct ec_node *node;
- int ret = 0;
+ int testres = 0;
node = ec_node_re(EC_NO_ID, "fo+|bar");
if (node == NULL) {
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo", "bar");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "bar");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "foobar");
- ret |= EC_TEST_CHECK_PARSE(node, -1, " foo");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo", "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "foobar");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, " foo");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "");
ec_node_free(node);
- return ret;
+ return testres;
}
/* LCOV_EXCL_STOP */
static int ec_node_re_lex_testcase(void)
{
struct ec_node *node;
- int ret = 0;
+ int ret, testres = 0;
node = ec_node_re_lex(EC_NO_ID,
ec_node_many(EC_NO_ID,
return -1;
}
- /* XXX add ^ automatically ? */
- ret |= ec_node_re_lex_add(node, "[a-zA-Z]+", 1);
- ret |= ec_node_re_lex_add(node, "[0-9]+", 1);
- ret |= ec_node_re_lex_add(node, "=", 1);
- ret |= ec_node_re_lex_add(node, "-", 1);
- ret |= ec_node_re_lex_add(node, "\\+", 1);
- ret |= ec_node_re_lex_add(node, "[ ]+", 0);
+ ret = ec_node_re_lex_add(node, "[a-zA-Z]+", 1);
+ testres |= EC_TEST_CHECK(ret == 0, "cannot add regexp");
+ ret = ec_node_re_lex_add(node, "[0-9]+", 1);
+ testres |= EC_TEST_CHECK(ret == 0, "cannot add regexp");
+ ret = ec_node_re_lex_add(node, "=", 1);
+ testres |= EC_TEST_CHECK(ret == 0, "cannot add regexp");
+ ret = ec_node_re_lex_add(node, "-", 1);
+ testres |= EC_TEST_CHECK(ret == 0, "cannot add regexp");
+ ret = ec_node_re_lex_add(node, "\\+", 1);
+ testres |= EC_TEST_CHECK(ret == 0, "cannot add regexp");
+ ret = ec_node_re_lex_add(node, "[ ]+", 0);
+ testres |= EC_TEST_CHECK(ret == 0, "cannot add regexp");
if (ret != 0) {
EC_LOG(EC_LOG_ERR, "cannot add regexp to node\n");
ec_node_free(node);
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, 1, " foo bar 324 bar234");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo bar324");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "foobar");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, " foo bar 324 bar234");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo bar324");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "foobar");
ec_node_free(node);
- return ret;
+ return testres;
}
/* LCOV_EXCL_STOP */
static int ec_node_seq_testcase(void)
{
struct ec_node *node;
- int ret = 0;
+ int testres = 0;
node = EC_NODE_SEQ(EC_NO_ID,
ec_node_str(EC_NO_ID, "foo"),
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, 2, "foo", "bar");
- ret |= EC_TEST_CHECK_PARSE(node, 2, "foo", "bar", "toto");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "foo");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "foox", "bar");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "foo", "barx");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "bar", "foo");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "", "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, 2, "foo", "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 2, "foo", "bar", "toto");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "foox", "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "foo", "barx");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "bar", "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "", "foo");
ec_node_free(node);
/* test completion */
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ec_node_free(node);
- return 0;
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"f", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo", "", EC_NODE_ENDLIST,
"bar", "toto", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo", "t", EC_NODE_ENDLIST,
"toto", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo", "b", EC_NODE_ENDLIST,
"bar", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo", "bar", EC_NODE_ENDLIST,
"bar", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"x", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foobarx", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
ec_node_free(node);
- return ret;
+ return testres;
}
/* LCOV_EXCL_STOP */
static int ec_node_sh_lex_testcase(void)
{
struct ec_node *node;
- int ret = 0;
+ int testres = 0;
node = ec_node_sh_lex(EC_NO_ID,
EC_NODE_SEQ(EC_NO_ID,
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo bar");
- ret |= EC_TEST_CHECK_PARSE(node, 1, " foo bar");
- ret |= EC_TEST_CHECK_PARSE(node, 1, " 'foo' \"bar\"");
- ret |= EC_TEST_CHECK_PARSE(node, 1, " 'f'oo 'toto' bar");
- ret |= EC_TEST_CHECK_PARSE(node, -1, " foo toto bar'");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, " foo bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, " 'foo' \"bar\"");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, " 'f'oo 'toto' bar");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, " foo toto bar'");
ec_node_free(node);
/* test completion */
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
" ", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"f", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo ", EC_NODE_ENDLIST,
"bar", "toto", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo t", EC_NODE_ENDLIST,
"toto", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo b", EC_NODE_ENDLIST,
"bar", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo bar", EC_NODE_ENDLIST,
"bar", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo bar ", EC_NODE_ENDLIST,
"titi", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo toto bar ", EC_NODE_ENDLIST,
"titi", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"x", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo barx", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo 'b", EC_NODE_ENDLIST,
"'bar'", EC_NODE_ENDLIST);
ec_node_free(node);
- return ret;
+ return testres;
}
/* LCOV_EXCL_STOP */
static int ec_node_space_testcase(void)
{
struct ec_node *node;
- int ret = 0;
+ int testres = 0;
node = ec_node("space", EC_NO_ID);
if (node == NULL) {
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, 1, " ");
- ret |= EC_TEST_CHECK_PARSE(node, 1, " ", "foo");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "");
- ret |= EC_TEST_CHECK_PARSE(node, -1, " foo");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "foo ");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, " ");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, " ", "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, " foo");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "foo ");
ec_node_free(node);
/* test completion */
return -1;
}
/* never completes whatever the input */
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
" ", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
ec_node_free(node);
- return ret;
+ return testres;
}
/* LCOV_EXCL_STOP */
static int ec_node_str_testcase(void)
{
struct ec_node *node;
- int ret = 0;
+ int testres = 0;
node = ec_node_str(EC_NO_ID, "foo");
if (node == NULL) {
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- EC_TEST_ASSERT(!strcmp(ec_node_desc(node), "foo"));
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo", "bar");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "foobar");
- ret |= EC_TEST_CHECK_PARSE(node, -1, " foo");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "");
+ testres |= EC_TEST_CHECK(!strcmp(ec_node_desc(node), "foo"),
+ "Invalid node description.");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo", "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "foobar");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, " foo");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "");
ec_node_free(node);
node = ec_node_str(EC_NO_ID, "Здравствуйте");
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, 1, "Здравствуйте");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "Здравствуйте",
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "Здравствуйте");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "Здравствуйте",
"John!");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "foo");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "");
ec_node_free(node);
/* an empty string node always matches */
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, 1, "");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "", "foo");
- ret |= EC_TEST_CHECK_PARSE(node, -1, "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "", "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, "foo");
ec_node_free(node);
/* test completion */
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"f", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"x", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
ec_node_free(node);
- return ret;
+ return testres;
}
/* LCOV_EXCL_STOP */
static int ec_node_subset_testcase(void)
{
struct ec_node *node;
- int ret = 0;
+ int testres = 0;
node = EC_NODE_SUBSET(EC_NO_ID,
EC_NODE_OR(EC_NO_ID,
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, 0);
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "bar");
- ret |= EC_TEST_CHECK_PARSE(node, 2, "foo", "bar", "titi");
- ret |= EC_TEST_CHECK_PARSE(node, 3, "bar", "foo", "toto");
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo", "foo");
- ret |= EC_TEST_CHECK_PARSE(node, 2, "bar", "bar");
- ret |= EC_TEST_CHECK_PARSE(node, 2, "bar", "foo");
- ret |= EC_TEST_CHECK_PARSE(node, 0, " ");
- ret |= EC_TEST_CHECK_PARSE(node, 0, "foox");
+ testres |= EC_TEST_CHECK_PARSE(node, 0);
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 2, "foo", "bar", "titi");
+ testres |= EC_TEST_CHECK_PARSE(node, 3, "bar", "foo", "toto");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo", "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, 2, "bar", "bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 2, "bar", "foo");
+ testres |= EC_TEST_CHECK_PARSE(node, 0, " ");
+ testres |= EC_TEST_CHECK_PARSE(node, 0, "foox");
ec_node_free(node);
/* test completion */
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"", EC_NODE_ENDLIST,
"foo", "bar", "bar2", "toto", "titi", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"", EC_NODE_ENDLIST,
"bar2", "bar", "foo", "toto", "titi", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"bar", "bar2", "", EC_NODE_ENDLIST,
"foo", "toto", "titi", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"f", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"b", EC_NODE_ENDLIST,
"bar", "bar2", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"bar", EC_NODE_ENDLIST,
"bar", "bar2", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"bar", "b", EC_NODE_ENDLIST,
"bar2", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"t", EC_NODE_ENDLIST,
"toto", "titi", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"to", EC_NODE_ENDLIST,
"toto", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"x", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
ec_node_free(node);
- return ret;
+ return testres;
}
/* LCOV_EXCL_STOP */
EC_LOG(EC_LOG_ERR, "%s:%d: error: " fmt "\n", \
__FILE__, __LINE__, ##__VA_ARGS__); \
-/* XXX this is not an assert, it does not abort */
-// XXX use it instead of ec_log to have the file:line
-// XXX set test result?
-#define EC_TEST_ASSERT_STR(cond, fmt, ...) \
- do { \
- if (!(cond)) \
- EC_TEST_ERR("assert failure: (" #cond ") " fmt, \
- ##__VA_ARGS__); \
- } while (0)
-
-#define EC_TEST_ASSERT(cond) EC_TEST_ASSERT_STR(cond, "")
+#define EC_TEST_CHECK(cond, fmt, ...) ({ \
+ int ret_ = 0; \
+ if (!(cond)) { \
+ EC_TEST_ERR("(" #cond ") is wrong. " \
+ ##__VA_ARGS__); \
+ ret_ = -1; \
+ } \
+ ret_; \
+})
/* node, input, [expected1, expected2, ...] */
#define EC_TEST_CHECK_PARSE(node, args...) ({ \