]> git.ipfire.org Git - pakfire.git/commitdiff
tests: Make the context accessible
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 Oct 2023 08:47:17 +0000 (08:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 Oct 2023 08:47:17 +0000 (08:47 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/testsuite.c
tests/testsuite.h

index 209693831959ede1882fecb4a824ce1cf25a4ee8..52c419eded7e28664a5b7e32a8f152a445759ab3 100644 (file)
@@ -34,7 +34,6 @@
 struct testsuite ts;
 
 static int test_run(int i, struct test* t) {
-       struct pakfire_ctx* ctx = NULL;
        struct pakfire* p = NULL;
        FILE* c = NULL;
 
@@ -51,17 +50,17 @@ static int test_run(int i, struct test* t) {
        LOG("running %s (%s)\n", t->name, root);
 
        // Create a new context
-       r = pakfire_ctx_create(&ctx, NULL);
+       r = pakfire_ctx_create(&t->ctx, NULL);
        if (r) {
                LOG("Could not create context: %m\n");
                goto ERROR;
        }
 
        // Set the log level to DEBUG
-       pakfire_ctx_set_log_level(ctx, LOG_DEBUG);
+       pakfire_ctx_set_log_level(t->ctx, LOG_DEBUG);
 
        // Log everything to the console
-       pakfire_ctx_set_log_callback(ctx, pakfire_log_stderr, NULL);
+       pakfire_ctx_set_log_callback(t->ctx, pakfire_log_stderr, NULL);
 
        // Open the configuration file
        c = fopen(TEST_SRC_PATH "/pakfire.conf", "r");
@@ -72,7 +71,7 @@ static int test_run(int i, struct test* t) {
        }
 
        // Create a pakfire instance
-       r = pakfire_create(&t->pakfire, ctx, root, NULL, c, 0);
+       r = pakfire_create(&t->pakfire, t->ctx, root, NULL, c, 0);
        if (r) {
                LOG("ERROR: Could not initialize pakfire: %m\n");
                goto ERROR;
@@ -111,8 +110,8 @@ ERROR:
                t->pakfire = NULL;
        }
 
-       if (ctx)
-               pakfire_ctx_unref(ctx);
+       if (t->ctx)
+               pakfire_ctx_unref(t->ctx);
 
        // Close the configuration file
        if (c)
index 4661ea168c96458ce9b4225774687a491228de48..7581bd0ccdc34beb1405dce51be1bedaf4402b5c 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <string.h>
 
+#include <pakfire/ctx.h>
 #include <pakfire/pakfire.h>
 
 #define MAX_TESTS 128
 struct test {
        const char* name;
        int (*func)(const struct test* t);
+
+       // Pakfire Context
+       struct pakfire_ctx* ctx;
+
+       // Pakfire
        struct pakfire* pakfire;
 };