]> git.ozlabs.org Git - petitboot/blobdiff - test/parser/utils.c
test/parser: Add test_set_conf_source()
[petitboot] / test / parser / utils.c
index 68fc3debb333baf36cc2560dc8668393d0effe3e..f1604e06a30c0dedd8f3dcbbdd8de4f80fab9ca1 100644 (file)
@@ -32,6 +32,14 @@ void __register_parser(struct parser *parser)
        list_add(&parsers, &i->list);
 }
 
+static void __attribute__((destructor)) __cleanup_parsers(void)
+{
+       struct p_item *item, *tmp;
+
+       list_for_each_entry_safe(&parsers, item, tmp, list)
+               talloc_free(item);
+}
+
 static struct discover_device *test_create_device_simple(
                struct discover_context *ctx)
 {
@@ -78,7 +86,7 @@ struct parser_test *test_init(void)
        struct parser_test *test;
 
        test = talloc_zero(NULL, struct parser_test);
-       test->handler = device_handler_init(NULL, 0);
+       test->handler = device_handler_init(NULL, NULL, 0);
        test->ctx = test_create_context(test);
 
        return test;
@@ -125,6 +133,12 @@ void test_read_conf_file(struct parser_test *test, const char *filename)
        talloc_free(path);
 }
 
+void test_set_conf_source(struct parser_test *test, const char *url)
+{
+       test->ctx->conf_url = pb_url_parse(test, url);
+       assert(test->ctx->conf_url);
+}
+
 int test_run_parser(struct parser_test *test, const char *parser_name)
 {
        struct p_item* i;
@@ -282,3 +296,10 @@ void __check_unresolved_resource(struct resource *res,
        if (res->resolved)
                errx(EXIT_FAILURE, "%s:%d: Resource is resolved", file, line);
 }
+
+void __check_not_present_resource(struct resource *res,
+               const char *file, int line)
+{
+       if (res)
+               errx(EXIT_FAILURE, "%s:%d: Resource present", file, line);
+}