]> git.ipfire.org Git - pakfire.git/commitdiff
db: Add test for add_package()
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 7 Feb 2021 17:03:12 +0000 (17:03 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 7 Feb 2021 17:03:12 +0000 (17:03 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/libpakfire/db.c

index 65b98eed1223ee14f78bad0df3c3bbda2fc9e0b9..05922ff2607751a3b911ac62f7deba8c1b62aeca 100644 (file)
 #                                                                             #
 #############################################################################*/
 
+#include <pakfire/archive.h>
 #include <pakfire/db.h>
+#include <pakfire/package.h>
+#include <pakfire/repo.h>
 #include <pakfire/util.h>
 
 #include "../testsuite.h"
@@ -59,10 +62,44 @@ static int test_check(const struct test* t) {
        return 0;
 }
 
+static int test_add_package(const struct test* t) {
+       struct pakfire_db* db;
+
+       PakfireRepo repo = pakfire_repo_create(t->pakfire, "dummy");
+       ASSERT(repo);
+
+       int r = pakfire_db_open(&db, t->pakfire, PAKFIRE_DB_READWRITE);
+       ASSERT(!r);
+
+       char* path = pakfire_path_join(TEST_SRC_PATH, "data/beep-1.3-2.ip3.x86_64.pfm");
+
+       // Open archive
+       PakfireArchive archive = pakfire_archive_open(t->pakfire, path);
+       ASSERT(archive);
+
+       // Get package
+       PakfirePackage pkg = pakfire_archive_make_package(archive, repo);
+       ASSERT(pkg);
+
+       // Try to add the package to the database
+       r = pakfire_db_add_package(db, pkg, archive);
+       ASSERT(r == 0);
+
+       // Cleanup
+       pakfire_archive_unref(archive);
+       pakfire_db_unref(db);
+       pakfire_package_unref(pkg);
+       pakfire_repo_unref(repo);
+       free(path);
+
+       return 0;
+}
+
 int main(int argc, char** argv) {
        testsuite_add_test(test_open_ro);
        testsuite_add_test(test_open_rw);
        testsuite_add_test(test_check);
+       testsuite_add_test(test_add_package);
 
        return testsuite_run();
 }