return r;
}
+int pakfire_config_read_path(struct pakfire_config* config, const char* path) {
+ FILE* f = NULL;
+ int r;
+
+ // Open the file
+ f = fopen(path, "r");
+ if (!f)
+ return -errno;
+
+ // Read the configuration
+ r = pakfire_config_read(config, f);
+
+ // Close the file
+ fclose(f);
+
+ return r;
+}
+
int pakfire_config_parse(struct pakfire_config* config, const char* s, ssize_t length) {
FILE* f = NULL;
int r;
int pakfire_config_has_section(struct pakfire_config* config, const char* section);
int pakfire_config_read(struct pakfire_config* config, FILE* f);
+int pakfire_config_read_path(struct pakfire_config* config, const char* path);
int pakfire_config_parse(struct pakfire_config* config, const char* s, ssize_t length);
int pakfire_config_dump(struct pakfire_config* config, FILE* f);
struct pakfire_build* build = NULL;
// Create a new build
- ASSERT_SUCCESS(pakfire_build_create(&build, t->pakfire, NULL, 0));
+ ASSERT_SUCCESS(pakfire_build_create(&build, t->ctx, NULL, NULL, 0));
// Check if build actually got allocated
ASSERT(build);
struct pakfire_build* build = NULL;
// Try to create a build with an invalid UUID
- ASSERT(pakfire_build_create(&build, t->pakfire, "ABC", 0) == -EINVAL);
+ ASSERT(pakfire_build_create(&build, t->ctx, NULL, "ABC", 0) == -EINVAL);
// Try to create a build with an empty UUID
- ASSERT(pakfire_build_create(&build, t->pakfire, "", 0) == -EINVAL);
+ ASSERT(pakfire_build_create(&build, t->ctx, NULL, "", 0) == -EINVAL);
return EXIT_SUCCESS;
}
int main(int argc, const char* argv[]) {
- testsuite_add_test(test_create_and_free, TEST_WANTS_PAKFIRE);
- testsuite_add_test(test_create_with_invalid_ids, TEST_WANTS_PAKFIRE);
+ testsuite_add_test(test_create_and_free, 0);
+ testsuite_add_test(test_create_with_invalid_ids, 0);
return testsuite_run(argc, argv);
}
ASSERT(pakfire_create(&pakfire, t->ctx, NULL, NULL, NULL, 0) == -EINVAL);
// Invalid architecture
- ASSERT(pakfire_create(&pakfire, t->ctx, NULL, "arch", NULL, 0) == -ENOTSUP);
+ ASSERT(pakfire_create(&pakfire, t->ctx, NULL, NULL, "arch", 0) == -ENOTSUP);
// Invalid path (must be absolute)
- ASSERT(pakfire_create(&pakfire, t->ctx, "path", NULL, NULL, 0) == -EINVAL);
+ ASSERT(pakfire_create(&pakfire, t->ctx, NULL, "path", NULL, 0) == -EINVAL);
// Cannot use snapshots with a path
- ASSERT(pakfire_create(&pakfire, t->ctx, PAKFIRE_TMP_DIR "/test",
- NULL, NULL, PAKFIRE_USE_SNAPSHOT) == -EINVAL);
+ ASSERT(pakfire_create(&pakfire, t->ctx, NULL, PAKFIRE_TMP_DIR "/test",
+ NULL, PAKFIRE_USE_SNAPSHOT) == -EINVAL);
return EXIT_SUCCESS;
#include "testsuite.h"
+#include <pakfire/config.h>
#include <pakfire/logging.h>
#include <pakfire/mount.h>
#include <pakfire/pakfire.h>
struct testsuite ts;
static int test_run(int i, struct test* t) {
+ struct pakfire_config* config = NULL;
struct pakfire_ctx* ctx = NULL;
struct pakfire* p = NULL;
- FILE* c = NULL;
int r;
LOG("running %s\n", t->name);
// Log everything to the console
pakfire_ctx_set_log_callback(t->ctx, pakfire_log_stderr, NULL);
- // Open the configuration file
- c = fopen(TEST_SRC_PATH "/pakfire.conf", "r");
- if (!c) {
- LOG("Could not open configuration file: %m\n");
- r = 1;
- goto ERROR;
- }
-
// Create a pakfire instance (if requested)
if (t->flags & TEST_WANTS_PAKFIRE) {
- r = pakfire_create(&t->pakfire, t->ctx, TEST_STUB_ROOT, NULL, c, 0);
+ // Create a configuration object
+ r = pakfire_config_create(&config);
+ if (r < 0) {
+ LOG("Could not create configuration object: %s\n", strerror(-r));
+ goto ERROR;
+ }
+
+ // Read the configuration file
+ r = pakfire_config_read_path(config, TEST_SRC_PATH "/pakfire.conf");
+ if (r < 0) {
+ LOG("Could not read the configuration: %s\n", strerror(-r));
+ goto ERROR;
+ }
+
+ r = pakfire_create(&t->pakfire, t->ctx, config, TEST_STUB_ROOT, NULL, 0);
if (r < 0) {
LOG("ERROR: Could not initialize pakfire: %s\n", strerror(-r));
goto ERROR;
t->ctx = NULL;
}
- // Close the configuration file
- if (c)
- fclose(c);
+ if (config)
+ pakfire_config_unref(config);
return r;
}