]> git.ipfire.org Git - pakfire.git/commitdiff
test: Add simple dependency pasing tests
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 5 Oct 2021 14:50:11 +0000 (14:50 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 5 Oct 2021 15:20:53 +0000 (15:20 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
.gitignore
Makefile.am
tests/libpakfire/dependencies.c [new file with mode: 0644]

index 4079771e617d3e5d31921c7bb5d5fdf192034473..343cc95c5b839bc57325fd6ce5365cea48bfa044 100644 (file)
@@ -19,6 +19,7 @@
 /tests/libpakfire/compress
 /tests/libpakfire/config
 /tests/libpakfire/db
+/tests/libpakfire/dependencies
 /tests/libpakfire/downloader
 /tests/libpakfire/execute
 /tests/libpakfire/key
index 3f9fa5e589ebfc0c33f666e495366f56b052d62d..001aa25f9f0d58aa176ff493217fcfe3552c5f69 100644 (file)
@@ -362,6 +362,7 @@ check_PROGRAMS += \
        tests/libpakfire/compress \
        tests/libpakfire/config \
        tests/libpakfire/db \
+       tests/libpakfire/dependencies \
        tests/libpakfire/downloader \
        tests/libpakfire/execute \
        tests/libpakfire/key \
@@ -436,6 +437,15 @@ tests_libpakfire_db_CPPFLAGS = \
 tests_libpakfire_db_LDADD = \
        $(TESTSUITE_LDADD)
 
+dist_tests_libpakfire_dependencies_SOURCES = \
+       tests/libpakfire/dependencies.c
+
+tests_libpakfire_dependencies_CPPFLAGS = \
+       $(TESTSUITE_CPPFLAGS)
+
+tests_libpakfire_dependencies_LDADD = \
+       $(TESTSUITE_LDADD)
+
 dist_tests_libpakfire_downloader_SOURCES = \
        tests/libpakfire/downloader.c
 
diff --git a/tests/libpakfire/dependencies.c b/tests/libpakfire/dependencies.c
new file mode 100644 (file)
index 0000000..673ff71
--- /dev/null
@@ -0,0 +1,99 @@
+/*#############################################################################
+#                                                                             #
+# 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 <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <pakfire/parser.h>
+#include <pakfire/util.h>
+
+#include "../testsuite.h"
+
+static const char* relations[] = {
+       // Simple packages
+       "beep",
+       "bash",
+       "kernel-devel",
+
+       // Packages with a specific version
+       "beep = 1",
+       "bash = 2",
+       "kernel-devel = 3",
+
+       // Packages with version and release
+       "beep = 1-1.ip3",
+       "bash = 2-2.ip3",
+       "kernel-devel = 3-3.ip3",
+
+       // Packages with version, release and arch
+       "beep = 1-1.ip3.x86_64",
+       "bash = 2-2.ip3.aarch64",
+       "kernel-devel = 3-3.x86_64",
+
+       // Packages with a version greater/smaller/greater or equal/smaller or equal than
+       "beep > 1",
+       "bash > 2",
+       "kernel-devel > 3",
+       "beep < 1",
+       "bash < 2",
+       "kernel-devel < 3",
+       "beep >= 1",
+       "bash >= 2",
+       "kernel-devel >= 3",
+       "beep >= 1",
+       "bash >= 2",
+       "kernel-devel >= 3",
+
+       // Namespaces
+       "pakfire(test)",
+
+       NULL,
+};
+
+static int test_dependencies(const struct test* t) {
+       Id dep = 0;
+       const char* result = NULL;
+
+       for (const char** relation = relations; *relation; relation++) {
+               printf("Parsing '%s'...\n", *relation);
+
+               // Parse relation
+               dep = pakfire_str2dep(t->pakfire, *relation);
+
+               // Convert it back to string
+               result = pakfire_dep2str(t->pakfire, dep);
+               ASSERT(result);
+
+               // Check if the output matches the input
+               ASSERT_STRING_EQUALS(*relation, result);
+       }
+
+       return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_FAILURE;
+}
+
+int main(int argc, char** argv) {
+       testsuite_add_test(test_dependencies);
+
+       return testsuite_run();
+}