]> git.ipfire.org Git - pakfire.git/commitdiff
tests: Add some tests for database
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 22 Jan 2021 18:10:59 +0000 (18:10 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 22 Jan 2021 18:10:59 +0000 (18:10 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
.gitignore
Makefile.am
tests/libpakfire/db.c [new file with mode: 0644]

index a9a2f0f73d2e4d2a7296585b3d17d857042e754f..a4fe5de2b218132bc137618730438ca07a9e4820 100644 (file)
@@ -12,6 +12,7 @@
 /tests/.root
 /tests/libpakfire/arch
 /tests/libpakfire/archive
+/tests/libpakfire/db
 /tests/libpakfire/execute
 /tests/libpakfire/key
 /tests/libpakfire/main
index 79c0d697ae6c77ddfcd4a7fae9ff4e107a21833f..8732f8584adba9aa4af9041f0d9be9f5f70800b5 100644 (file)
@@ -357,6 +357,7 @@ check_PROGRAMS += \
        tests/libpakfire/main \
        tests/libpakfire/arch \
        tests/libpakfire/archive \
+       tests/libpakfire/db \
        tests/libpakfire/execute \
        tests/libpakfire/key \
        tests/libpakfire/makefile \
@@ -394,6 +395,16 @@ tests_libpakfire_archive_LDADD = \
        $(TESTSUITE_LDADD) \
        $(PAKFIRE_LIBS)
 
+tests_libpakfire_db_SOURCES = \
+       tests/libpakfire/db.c
+
+tests_libpakfire_db_CPPFLAGS = \
+       $(TESTSUITE_CPPFLAGS)
+
+tests_libpakfire_db_LDADD = \
+       $(TESTSUITE_LDADD) \
+       $(PAKFIRE_LIBS)
+
 tests_libpakfire_execute_SOURCES = \
        tests/libpakfire/execute.c
 
diff --git a/tests/libpakfire/db.c b/tests/libpakfire/db.c
new file mode 100644 (file)
index 0000000..e0c324e
--- /dev/null
@@ -0,0 +1,53 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2021 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include <pakfire/db.h>
+#include <pakfire/util.h>
+
+#include "../testsuite.h"
+
+static int test_open_ro(const struct test* t) {
+       struct pakfire_db* db;
+
+       int r = pakfire_db_open(&db, t->pakfire, PAKFIRE_DB_READONLY);
+       ASSERT(!r);
+
+       pakfire_db_unref(db);
+
+       return 0;
+}
+
+static int test_open_rw(const struct test* t) {
+       struct pakfire_db* db;
+
+       int r = pakfire_db_open(&db, t->pakfire, PAKFIRE_DB_READWRITE);
+       ASSERT(!r);
+
+       pakfire_db_unref(db);
+
+       return 0;
+}
+
+int main(int argc, char** argv) {
+       testsuite_add_test(test_open_ro);
+       testsuite_add_test(test_open_rw);
+
+       return testsuite_run();
+}