]> git.ipfire.org Git - pakfire.git/commitdiff
tests: Add some basic tests for files
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Aug 2022 11:45:02 +0000 (11:45 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Aug 2022 11:45:02 +0000 (11:45 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
.gitignore
Makefile.am
tests/libpakfire/file.c [new file with mode: 0644]

index 2baa3d327d7a522fcc4b7c526aade490b153954e..62da71d581b63d09ad6c9c848240d261a7c7bef1 100644 (file)
@@ -23,6 +23,7 @@
 /tests/libpakfire/dependencies
 /tests/libpakfire/downloader
 /tests/libpakfire/execute
+/tests/libpakfire/file
 /tests/libpakfire/jail
 /tests/libpakfire/key
 /tests/libpakfire/main
index 4290355450085c7fa6530db7df63bd9300255509..2182053fc2eafdd82610cabd46086da87c5c8aa7 100644 (file)
@@ -381,6 +381,7 @@ check_PROGRAMS += \
        tests/libpakfire/db \
        tests/libpakfire/dependencies \
        tests/libpakfire/downloader \
+       tests/libpakfire/file \
        tests/libpakfire/jail \
        tests/libpakfire/key \
        tests/libpakfire/makefile \
@@ -512,6 +513,18 @@ tests_libpakfire_downloader_CFLAGS = \
 tests_libpakfire_downloader_LDADD = \
        $(TESTSUITE_LDADD)
 
+dist_tests_libpakfire_file_SOURCES = \
+       tests/libpakfire/file.c
+
+tests_libpakfire_file_CPPFLAGS = \
+       $(TESTSUITE_CPPFLAGS)
+
+tests_libpakfire_file_CFLAGS = \
+       $(TESTSUITE_CFLAGS)
+
+tests_libpakfire_file_LDADD = \
+       $(TESTSUITE_LDADD)
+
 dist_tests_libpakfire_jail_SOURCES = \
        tests/libpakfire/jail.c
 
diff --git a/tests/libpakfire/file.c b/tests/libpakfire/file.c
new file mode 100644 (file)
index 0000000..6565ec2
--- /dev/null
@@ -0,0 +1,72 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2022 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/file.h>
+
+#include "../testsuite.h"
+
+static int test_create(const struct test* t) {
+       struct pakfire_file* file = NULL;
+
+       // Create a new file
+       ASSERT_SUCCESS(pakfire_file_create(&file, t->pakfire));
+
+       // Set path & check
+       ASSERT_SUCCESS(pakfire_file_set_path(file, "/abc"));
+       ASSERT_STRING_EQUALS(pakfire_file_get_path(file), "/abc");
+
+       // Destroy it
+       ASSERT_NULL(pakfire_file_unref(file));
+
+       return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_FAILURE;
+}
+
+static int test_create_invalid(const struct test* t) {
+       struct pakfire_file* file = NULL;
+
+       // Create a new file
+       ASSERT_SUCCESS(pakfire_file_create(&file, t->pakfire));
+
+       // Set path
+       ASSERT_ERRNO(pakfire_file_set_path(file, NULL), EINVAL);
+
+       // It should not be possible to set relative paths
+       ASSERT_ERRNO(pakfire_file_set_path(file, "abc/abc"), EINVAL);
+       ASSERT_ERRNO(pakfire_file_set_abspath(file, "abc/abc"), EINVAL);
+
+       // Destroy it
+       ASSERT_NULL(pakfire_file_unref(file));
+
+       return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_FAILURE;
+}
+
+
+int main(int argc, const char* argv[]) {
+       testsuite_add_test(test_create);
+       testsuite_add_test(test_create_invalid);
+
+       return testsuite_run(argc, argv);
+}