]>
git.ipfire.org Git - people/ms/pakfire.git/blob - tests/libpakfire/path.c
1 /*#############################################################################
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2019 Pakfire development team #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 #############################################################################*/
23 #include <pakfire/path.h>
24 #include <pakfire/string.h>
26 #include "../testsuite.h"
28 static int test_path_normalize(const struct test
* t
) {
31 ASSERT_SUCCESS(pakfire_string_set(path
, "/usr/bin/bash"));
32 ASSERT_SUCCESS(pakfire_path_normalize(path
));
33 ASSERT_STRING_EQUALS(path
, "/usr/bin/bash");
35 ASSERT_SUCCESS(pakfire_string_set(path
, "/"));
36 ASSERT_SUCCESS(pakfire_path_normalize(path
));
37 ASSERT_STRING_EQUALS(path
, "/");
39 ASSERT_SUCCESS(pakfire_string_set(path
, "/.."));
40 ASSERT_SUCCESS(pakfire_path_normalize(path
));
41 ASSERT_STRING_EQUALS(path
, "/");
43 ASSERT_SUCCESS(pakfire_string_set(path
, "/../.."));
44 ASSERT_SUCCESS(pakfire_path_normalize(path
));
45 ASSERT_STRING_EQUALS(path
, "/");
47 ASSERT_SUCCESS(pakfire_string_set(path
, "/usr/bin/bash"));
48 ASSERT_SUCCESS(pakfire_path_normalize(path
));
49 ASSERT_STRING_EQUALS(path
, "/usr/bin/bash");
51 ASSERT_SUCCESS(pakfire_string_set(path
, "/usr/bin/sh/../bash"));
52 ASSERT_SUCCESS(pakfire_path_normalize(path
));
53 ASSERT_STRING_EQUALS(path
, "/usr/bin/bash");
61 static int test_path_append(const struct test
* t
) {
64 ASSERT_SUCCESS(pakfire_path_append(path
, "/usr/bin", "bash"));
65 ASSERT_STRING_EQUALS(path
, "/usr/bin/bash");
67 ASSERT_SUCCESS(pakfire_path_append(path
, "/usr/bin", "/bash"));
68 ASSERT_STRING_EQUALS(path
, "/usr/bin/bash");
70 ASSERT_SUCCESS(pakfire_path_append(path
, "/usr/bin/sh", "../bash"));
71 ASSERT_STRING_EQUALS(path
, "/usr/bin/bash");
79 static int test_path_merge(const struct test
* t
) {
82 ASSERT_SUCCESS(pakfire_path_merge(path
, "/usr/bin/sh", "bash"));
83 ASSERT_STRING_EQUALS(path
, "/usr/bin/bash");
85 ASSERT_SUCCESS(pakfire_path_merge(path
, "/usr/bin", "/bash"));
86 ASSERT_STRING_EQUALS(path
, "/bash");
88 ASSERT_SUCCESS(pakfire_path_merge(path
, "/usr/bin/sh", "../bin/bash"));
89 ASSERT_STRING_EQUALS(path
, "/usr/bin/bash");
97 static int test_path_dirname(const struct test
* t
) {
100 ASSERT_SUCCESS(pakfire_path_dirname(path
, "/usr/bin/bash"));
101 ASSERT_STRING_EQUALS(path
, "/usr/bin");
109 int main(int argc
, const char* argv
[]) {
110 testsuite_add_test(test_path_normalize
);
111 testsuite_add_test(test_path_append
);
112 testsuite_add_test(test_path_merge
);
113 testsuite_add_test(test_path_dirname
);
115 return testsuite_run(argc
, argv
);