save
[protos/libecoli.git] / lib / ecoli_test.c
index 134fefa..efe4c04 100644 (file)
@@ -35,6 +35,9 @@
 #include <ecoli_test.h>
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
+#include <ecoli_parsed.h>
+#include <ecoli_completed.h>
+#include <ecoli_parsed.h>
 
 static struct ec_test_list test_list = TAILQ_HEAD_INITIALIZER(test_list);
 
@@ -71,8 +74,7 @@ int ec_test_check_parse(struct ec_node *tk, int expected, ...)
        }
 
        p = ec_node_parse_strvec(tk, vec);
-       /* XXX only for debug */
-       ec_parsed_dump(stdout, p);
+       ec_parsed_dump(stdout, p); /* XXX only for debug */
        if (p == NULL) {
                ec_log(EC_LOG_ERR, "parsed is NULL\n");
        }
@@ -99,7 +101,6 @@ out:
 int ec_test_check_complete(struct ec_node *tk, ...)
 {
        struct ec_completed *c = NULL;
-       struct ec_completed_elt *elt;
        struct ec_strvec *vec = NULL;
        const char *s, *expected;
        int ret = 0;
@@ -129,28 +130,36 @@ int ec_test_check_complete(struct ec_node *tk, ...)
                goto out;
        }
 
+       /* for each expected completion, check it is there */
        for (s = va_arg(ap, const char *);
             s != EC_NODE_ENDLIST;
             s = va_arg(ap, const char *)) {
+               struct ec_completed_iter *iter;
+               const struct ec_completed_match *item;
+
                if (s == NULL) {
                        ret = -1;
                        goto out;
                }
 
                count++;
-               TAILQ_FOREACH(elt, &c->elts, next) {
-                       /* only check matching completions */
-                       if (elt->add != NULL && strcmp(elt->add, s) == 0)
+
+               /* only check matching completions */
+               iter = ec_completed_iter(c, EC_MATCH);
+               while ((item = ec_completed_iter_next(iter)) != NULL) {
+                       if (item->add != NULL && strcmp(item->add, s) == 0)
                                break;
                }
 
-               if (elt == NULL) {
+               if (item == NULL) {
                        ec_log(EC_LOG_ERR,
                                "completion <%s> not in list\n", s);
                        ret = -1;
                }
+               ec_completed_iter_free(iter);
        }
 
+       /* check if we have more completions (or less) than expected */
        if (count != ec_completed_count(c, EC_MATCH)) {
                ec_log(EC_LOG_ERR,
                        "nb_completion (%d) does not match (%d)\n",
@@ -159,7 +168,7 @@ int ec_test_check_complete(struct ec_node *tk, ...)
                ret = -1;
        }
 
-
+       /* check the expected smallest start */
        expected = va_arg(ap, const char *);
        s = ec_completed_smallest_start(c);
        if (strcmp(s, expected)) {
@@ -199,8 +208,10 @@ static int launch_test(const char *name)
                }
        }
 
-       if (name != NULL && count == 0)
+       if (name != NULL && count == 0) {
                ec_log(EC_LOG_WARNING, "== test %s not found\n", name);
+               ret = -1;
+       }
 
        return ret;
 }