+
+/* LCOV_EXCL_START */
+static int ec_comp_testcase(void)
+{
+ struct ec_node *node = NULL;
+ struct ec_comp *c = NULL;
+ struct ec_comp_iter *iter = NULL;
+ struct ec_comp_item *item;
+ FILE *f = NULL;
+ char *buf = NULL;
+ size_t buflen = 0;
+ int testres = 0;
+
+ node = ec_node_sh_lex(EC_NO_ID,
+ EC_NODE_OR(EC_NO_ID,
+ ec_node_str("id_x", "xx"),
+ ec_node_str("id_y", "yy")));
+ if (node == NULL)
+ goto fail;
+
+ c = ec_node_complete(node, "xcdscds");
+ testres |= EC_TEST_CHECK(
+ c != NULL && ec_comp_count(c, EC_COMP_ALL) == 0,
+ "complete count should is not 0\n");
+ ec_comp_free(c);
+
+ c = ec_node_complete(node, "x");
+ testres |= EC_TEST_CHECK(
+ c != NULL && ec_comp_count(c, EC_COMP_ALL) == 1,
+ "complete count should is not 1\n");
+ ec_comp_free(c);
+
+ c = ec_node_complete(node, "");
+ testres |= EC_TEST_CHECK(
+ c != NULL && ec_comp_count(c, EC_COMP_ALL) == 2,
+ "complete count should is not 2\n");
+
+ f = open_memstream(&buf, &buflen);
+ if (f == NULL)
+ goto fail;
+ ec_comp_dump(f, NULL);
+ fclose(f);
+ f = NULL;
+
+ testres |= EC_TEST_CHECK(
+ strstr(buf, "no completion"), "bad dump\n");
+ free(buf);
+ buf = NULL;
+
+ f = open_memstream(&buf, &buflen);
+ if (f == NULL)
+ goto fail;
+ ec_comp_dump(f, c);
+ fclose(f);
+ f = NULL;
+
+ testres |= EC_TEST_CHECK(
+ strstr(buf, "comp=<xx>"), "bad dump\n");
+ testres |= EC_TEST_CHECK(
+ strstr(buf, "comp=<yy>"), "bad dump\n");
+ free(buf);
+ buf = NULL;
+
+ iter = ec_comp_iter(c, EC_COMP_ALL);
+ item = ec_comp_iter_next(iter);
+ if (item == NULL)
+ goto fail;
+
+ testres |= EC_TEST_CHECK(
+ !strcmp(ec_comp_item_get_display(item), "xx"),
+ "bad item display\n");
+ testres |= EC_TEST_CHECK(
+ ec_comp_item_get_type(item) == EC_COMP_FULL,
+ "bad item type\n");
+ testres |= EC_TEST_CHECK(
+ !strcmp(ec_node_id(ec_comp_item_get_node(item)), "id_x"),
+ "bad item node\n");
+
+ item = ec_comp_iter_next(iter);
+ if (item == NULL)
+ goto fail;
+
+ testres |= EC_TEST_CHECK(
+ !strcmp(ec_comp_item_get_display(item), "yy"),
+ "bad item display\n");
+ testres |= EC_TEST_CHECK(
+ ec_comp_item_get_type(item) == EC_COMP_FULL,
+ "bad item type\n");
+ testres |= EC_TEST_CHECK(
+ !strcmp(ec_node_id(ec_comp_item_get_node(item)), "id_y"),
+ "bad item node\n");
+
+ item = ec_comp_iter_next(iter);
+ testres |= EC_TEST_CHECK(item == NULL, "should be the last item\n");
+
+ ec_comp_iter_free(iter);
+ ec_comp_free(c);
+ ec_node_free(node);
+
+ return testres;
+
+fail:
+ ec_comp_iter_free(iter);
+ ec_comp_free(c);
+ ec_node_free(node);
+ if (f != NULL)
+ fclose(f);
+ free(buf);
+
+ return -1;
+}
+/* LCOV_EXCL_STOP */
+
+static struct ec_test ec_comp_test = {
+ .name = "comp",
+ .test = ec_comp_testcase,
+};
+
+EC_TEST_REGISTER(ec_comp_test);