]> git.ipfire.org Git - pakfire.git/commitdiff
testsuite: Add simple test that opens an archive
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Nov 2017 13:04:19 +0000 (14:04 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Nov 2017 13:04:19 +0000 (14:04 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
.gitignore
Makefile.am
src/libpakfire/libpakfire.sym
tests/libpakfire/archive.c [new file with mode: 0644]
tests/testsuite.c
tests/testsuite.h

index 8b8ec923e9818daa68d9d6eae850f397b7a6f248..18cdfcb87486256e38f72ce50ccc992e49e49dc4 100644 (file)
@@ -10,6 +10,7 @@
 /src/scripts/extract-debuginfo
 /src/systemd/*.service
 /tests/.data
+/tests/libpakfire/archive
 /tests/libpakfire/key
 /tests/libpakfire/main
 /tmp
index 9e23f7742884ff5657f5e8ab1a7b790952b574c9..6be3a5223a68b77c50d80947940912736f843dbe 100644 (file)
@@ -323,6 +323,7 @@ EXTRA_DIST += \
 
 check_PROGRAMS += \
        tests/libpakfire/main \
+       tests/libpakfire/archive \
        tests/libpakfire/key
 
 dist_tests_libpakfire_main_SOURCES = \
@@ -335,6 +336,16 @@ tests_libpakfire_main_LDADD = \
        $(TESTSUITE_LDADD) \
        $(PAKFIRE_LIBS)
 
+tests_libpakfire_archive_SOURCES = \
+       tests/libpakfire/archive.c
+
+tests_libpakfire_archive_CPPFLAGS = \
+       $(TESTSUITE_CPPFLAGS)
+
+tests_libpakfire_archive_LDADD = \
+       $(TESTSUITE_LDADD) \
+       $(PAKFIRE_LIBS)
+
 tests_libpakfire_key_SOURCES = \
        tests/libpakfire/key.c \
        tests/libpakfire/key.h
@@ -490,7 +501,8 @@ tests_libtestsuite_la_SOURCES = \
 
 tests_libtestsuite_la_CPPFLAGS = \
        $(TESTSUITE_CPPFLAGS) \
-       -DABS_TOP_BUILDDIR=\"$(abs_top_builddir)\"
+       -DABS_TOP_BUILDDIR=\"$(abs_top_builddir)\" \
+       -DABS_TOP_SRCDIR=\"$(abs_top_srcdir)\"
 
 TESTSUITE_CPPFLAGS = \
        $(AM_CPPFLAGS) \
@@ -510,3 +522,8 @@ TESTS_ENVIRONMENT = \
 TESTS = \
        $(check_PROGRAMS) \
        $(dist_check_SCRIPTS)
+
+# Some test data to run tests
+EXTRA_DIST += \
+       tests/data/726D8B0B0889B04E.key \
+       tests/data/beep-1.3-2.ip3.x86_64.pfm
index addb0a66bccdb5851bd90b994c05b9ef95fd430c..6e0bfc675af0150a38546c5acf4842e864a61b3d 100644 (file)
@@ -322,6 +322,7 @@ global:
        # util
        pakfire_free;
        pakfire_get_errno;
+       pakfire_path_join;
 
 local:
        *;
diff --git a/tests/libpakfire/archive.c b/tests/libpakfire/archive.c
new file mode 100644 (file)
index 0000000..d4d51e5
--- /dev/null
@@ -0,0 +1,51 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2017 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/archive.h>
+#include <pakfire/util.h>
+
+#include "../testsuite.h"
+
+static const char* TEST_PKG1_PATH = "data/beep-1.3-2.ip3.x86_64.pfm";
+
+int test_open(const test_t* t) {
+    char* path = pakfire_path_join(TEST_SRC_PATH, TEST_PKG1_PATH);
+    LOG("Trying to open %s\n", path);
+
+    // Open the archive
+    PakfireArchive archive = pakfire_archive_open(t->pakfire, path);
+    assert_return(archive, EXIT_FAILURE);
+
+    pakfire_archive_unref(archive);
+
+    pakfire_free(path);
+
+    return EXIT_SUCCESS;
+}
+
+int main(int argc, char** argv) {
+       testsuite_init();
+
+       testsuite_t* ts = testsuite_create(1);
+
+       testsuite_add_test(ts, "test_open", test_open);
+
+       return testsuite_run(ts);
+}
index 031b77b3abc8cba75b37adc05c4f98e2e9f3909c..64d4f27d2b0b8b29c790cc75eb9ac9de844f65fe 100644 (file)
@@ -23,6 +23,7 @@
 #include <pakfire/logging.h>
 #include <pakfire/pakfire.h>
 
+const char* TEST_SRC_PATH = ABS_TOP_SRCDIR "/tests";
 const char* TEST_PATH = ABS_TOP_BUILDDIR "/tests/.data";
 
 int testsuite_init() {
index 1388266c35f65415f5288875cc4d36a1d11cf766..13f540df486ad783dcfa43d8358f4363122a1a58 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <pakfire/pakfire.h>
 
+extern const char* TEST_SRC_PATH;
 extern const char* TEST_PATH;
 
 // Forward declaration