]> git.ipfire.org Git - pakfire.git/commitdiff
tests: libpakfire: Test pakfire_basename/dirname
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 10 Jun 2019 15:39:59 +0000 (16:39 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 10 Jun 2019 15:39:59 +0000 (16:39 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
.gitignore
Makefile.am
src/libpakfire/libpakfire.sym
tests/libpakfire/util.c [new file with mode: 0644]

index a89182f4a79b522a07e8f024858c0228ce6a50ce..97eb45d2d2f66a3e68b0eb57a2ace464eeba1e78 100644 (file)
@@ -15,6 +15,7 @@
 /tests/libpakfire/main
 /tests/libpakfire/makefile
 /tests/libpakfire/parser
+/tests/libpakfire/util
 /tmp
 *.py[co]
 /*.tar.bz2
index 02120535dcc1e6511db75d33d16877727e54d37e..28f900c16fc60f993506a04e494d3f95bd73a0ad 100644 (file)
@@ -354,7 +354,8 @@ check_PROGRAMS += \
        tests/libpakfire/archive \
        tests/libpakfire/key \
        tests/libpakfire/makefile \
-       tests/libpakfire/parser
+       tests/libpakfire/parser \
+       tests/libpakfire/util
 
 dist_tests_libpakfire_main_SOURCES = \
        tests/libpakfire/main.c
@@ -409,6 +410,16 @@ tests_libpakfire_parser_LDADD = \
        $(TESTSUITE_LDADD) \
        $(PAKFIRE_LIBS)
 
+dist_tests_libpakfire_util_SOURCES = \
+       tests/libpakfire/util.c
+
+tests_libpakfire_util_CPPFLAGS = \
+       $(TESTSUITE_CPPFLAGS)
+
+tests_libpakfire_util_LDADD = \
+       $(TESTSUITE_LDADD) \
+       $(PAKFIRE_LIBS)
+
 # ------------------------------------------------------------------------------
 
 lib_LTLIBRARIES += \
index 206b3d74b6a8f16d42dc190f3a4edb79c90f8182..efb78b24503a1be0ddb8385ea5b66fd798248530 100644 (file)
@@ -354,6 +354,8 @@ global:
 
        # util
        pakfire_access;
+       pakfire_basename;
+       pakfire_dirname;
        pakfire_free;
        pakfire_get_errno;
        pakfire_partition_string;
diff --git a/tests/libpakfire/util.c b/tests/libpakfire/util.c
new file mode 100644 (file)
index 0000000..a4bd542
--- /dev/null
@@ -0,0 +1,57 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2019 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 <string.h>
+
+#include <pakfire/parser.h>
+#include <pakfire/util.h>
+
+#include "../testsuite.h"
+
+int test_basename(const test_t* t) {
+       const char* dir = "/a/b/c";
+
+       char* output = pakfire_basename(dir);
+       assert_compare(output, "c", EXIT_FAILURE);
+       pakfire_free(output);
+
+       return EXIT_SUCCESS;
+}
+
+int test_dirname(const test_t* t) {
+       const char* dir = "/a/b/c";
+
+       char* output = pakfire_dirname(dir);
+       assert_compare(output, "/a/b", EXIT_FAILURE);
+       pakfire_free(output);
+
+       return EXIT_SUCCESS;
+}
+
+int main(int argc, char** argv) {
+       testsuite_init();
+
+       testsuite_t* ts = testsuite_create(2);
+
+       testsuite_add_test(ts, "test_basename", test_basename);
+       testsuite_add_test(ts, "test_dirname", test_dirname);
+
+       return testsuite_run(ts);
+}