From: Michael Tremer Date: Sun, 10 Jan 2021 16:12:19 +0000 (+0000) Subject: libpakfire: arch: Add tests X-Git-Tag: 0.9.28~1285^2~907 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=10ad6f16079d76433cddad64b9265c75ee3b1a42;p=pakfire.git libpakfire: arch: Add tests Signed-off-by: Michael Tremer --- diff --git a/.gitignore b/.gitignore index 288961565..a9a2f0f73 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ /src/scripts/extract-debuginfo /src/systemd/*.service /tests/.root +/tests/libpakfire/arch /tests/libpakfire/archive /tests/libpakfire/execute /tests/libpakfire/key diff --git a/Makefile.am b/Makefile.am index b2ecd1d1d..8667a337e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -351,6 +351,7 @@ EXTRA_DIST += \ check_PROGRAMS += \ tests/libpakfire/main \ + tests/libpakfire/arch \ tests/libpakfire/archive \ tests/libpakfire/execute \ tests/libpakfire/key \ @@ -369,6 +370,16 @@ tests_libpakfire_main_LDADD = \ $(TESTSUITE_LDADD) \ $(PAKFIRE_LIBS) +tests_libpakfire_arch_SOURCES = \ + tests/libpakfire/arch.c + +tests_libpakfire_arch_CPPFLAGS = \ + $(TESTSUITE_CPPFLAGS) + +tests_libpakfire_arch_LDADD = \ + $(TESTSUITE_LDADD) \ + $(PAKFIRE_LIBS) + tests_libpakfire_archive_SOURCES = \ tests/libpakfire/archive.c diff --git a/tests/libpakfire/arch.c b/tests/libpakfire/arch.c new file mode 100644 index 000000000..d6005c810 --- /dev/null +++ b/tests/libpakfire/arch.c @@ -0,0 +1,106 @@ +/*############################################################################# +# # +# 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 . # +# # +#############################################################################*/ + +#include + +#include +#include + +#include "../testsuite.h" + +int test_native(const test_t* t) { + // First call + const char* arch1 = pakfire_arch_native(); + assert_return(arch1, EXIT_FAILURE); + + // Second call + const char* arch2 = pakfire_arch_native(); + assert_return(arch2, EXIT_FAILURE); + + // Must be the same pointer + assert_return(arch1 == arch2, EXIT_FAILURE); + + return EXIT_SUCCESS; +} + +int test_supported(const test_t* t) { + int r; + + r = pakfire_arch_supported("x86_64"); + assert_return(r, EXIT_FAILURE); + + r = pakfire_arch_supported("i686"); + assert_return(r, EXIT_FAILURE); + + // Check non-existant architecture + r = pakfire_arch_supported("ABC"); + assert_return(!r, EXIT_FAILURE); + + return EXIT_SUCCESS; +} + +int test_compatible(const test_t* t) { + int r; + + // x86_64 can build i686 + r = pakfire_arch_is_compatible("x86_64", "i686"); + assert_return(r, EXIT_FAILURE); + + // i686 can NOT build i686 + r = pakfire_arch_is_compatible("i686", "x86_64"); + assert_return(!r, EXIT_FAILURE); + + // x86_64 can build itself + r = pakfire_arch_is_compatible("x86_64", "x86_64"); + assert_return(r, EXIT_FAILURE); + + // x86_64 can NOT build a non-existant architecture + r = pakfire_arch_is_compatible("x86_64", "ABC"); + assert_return(!r, EXIT_FAILURE); + + // A non-existant architecture cannot build anything + r = pakfire_arch_is_compatible("ABC", "x86_64"); + assert_return(!r, EXIT_FAILURE); + + return EXIT_SUCCESS; +} + +int test_machine(const test_t* t) { + char* machine; + + machine = pakfire_arch_machine("x86_64", "ipfire"); + assert_compare(machine, "x86_64-ipfire-linux-gnu", EXIT_FAILURE); + + machine = pakfire_arch_machine("x86_64", "IPFIRE"); + assert_compare(machine, "x86_64-ipfire-linux-gnu", EXIT_FAILURE); + + return EXIT_SUCCESS; +} + +int main(int argc, char** argv) { + testsuite_t* ts = testsuite_create(4); + + testsuite_add_test(ts, "test_native", test_native); + testsuite_add_test(ts, "test_supported", test_supported); + testsuite_add_test(ts, "test_compatible", test_compatible); + testsuite_add_test(ts, "test_machine", test_machine); + + return testsuite_run(ts); +} diff --git a/tests/testsuite.h b/tests/testsuite.h index 9254b94fd..0d5b9eb23 100644 --- a/tests/testsuite.h +++ b/tests/testsuite.h @@ -23,6 +23,7 @@ #include #include +#include #include