From: Michael Tremer Date: Tue, 5 Oct 2021 14:50:11 +0000 (+0000) Subject: test: Add simple dependency pasing tests X-Git-Tag: 0.9.28~896 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ff5b32572c64bd96905b15d9796cef96ec44c23;p=pakfire.git test: Add simple dependency pasing tests Signed-off-by: Michael Tremer --- diff --git a/.gitignore b/.gitignore index 4079771e6..343cc95c5 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Makefile.am b/Makefile.am index 3f9fa5e58..001aa25f9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 000000000..673ff71a6 --- /dev/null +++ b/tests/libpakfire/dependencies.c @@ -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 . # +# # +#############################################################################*/ + +#include +#include +#include + +#include +#include + +#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(); +}