]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: arch: Add tests
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 10 Jan 2021 16:12:19 +0000 (16:12 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 10 Jan 2021 16:12:19 +0000 (16:12 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
.gitignore
Makefile.am
tests/libpakfire/arch.c [new file with mode: 0644]
tests/testsuite.h

index 2889615655c6537409ca873360f312e74f84bcbe..a9a2f0f73d2e4d2a7296585b3d17d857042e754f 100644 (file)
@@ -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
index b2ecd1d1d8e43ac09a1f81602f3cc27090f14b00..8667a337e8e6d71846cf61f803fe988d7526ae21 100644 (file)
@@ -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 (file)
index 0000000..d6005c8
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include <unistd.h>
+
+#include <pakfire/arch.h>
+#include <pakfire/util.h>
+
+#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);
+}
index 9254b94fd7b33c6d4cdbcc0124764c89d0f9a39f..0d5b9eb23ffdc587d8f47e17e5192e15ffab9a26 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
 
 #include <pakfire/pakfire.h>