path-join-selftests.c revision 1.1.1.2 1 1.1 christos /* Self tests for path_join for GDB, the GNU debugger.
2 1.1 christos
3 1.1.1.2 christos Copyright (C) 2022-2024 Free Software Foundation, Inc.
4 1.1 christos
5 1.1 christos This file is part of GDB.
6 1.1 christos
7 1.1 christos This program is free software; you can redistribute it and/or modify
8 1.1 christos it under the terms of the GNU General Public License as published by
9 1.1 christos the Free Software Foundation; either version 3 of the License, or
10 1.1 christos (at your option) any later version.
11 1.1 christos
12 1.1 christos This program is distributed in the hope that it will be useful,
13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 christos GNU General Public License for more details.
16 1.1 christos
17 1.1 christos You should have received a copy of the GNU General Public License
18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 1.1 christos
20 1.1 christos #include "gdbsupport/pathstuff.h"
21 1.1 christos #include "gdbsupport/selftest.h"
22 1.1 christos
23 1.1 christos namespace selftests {
24 1.1 christos namespace path_join {
25 1.1 christos
26 1.1 christos template <typename ...Args>
27 1.1 christos static void
28 1.1 christos test_one (const char *expected, Args... paths)
29 1.1 christos {
30 1.1 christos std::string actual = ::path_join (paths...);
31 1.1 christos
32 1.1 christos SELF_CHECK (actual == expected);
33 1.1 christos }
34 1.1 christos
35 1.1 christos /* Test path_join. */
36 1.1 christos
37 1.1 christos static void
38 1.1 christos test ()
39 1.1 christos {
40 1.1 christos test_one ("/foo/bar", "/foo", "bar");
41 1.1 christos test_one ("/bar", "/", "bar");
42 1.1 christos test_one ("foo/bar/", "foo", "bar", "");
43 1.1 christos test_one ("foo", "", "foo");
44 1.1 christos test_one ("foo/bar", "foo", "", "bar");
45 1.1 christos test_one ("foo/", "foo", "");
46 1.1 christos test_one ("foo/", "foo/", "");
47 1.1 christos
48 1.1 christos test_one ("D:/foo/bar", "D:/foo", "bar");
49 1.1 christos test_one ("D:/foo/bar", "D:/foo/", "bar");
50 1.1 christos
51 1.1 christos #if defined(_WIN32)
52 1.1 christos /* The current implementation doesn't recognize backslashes as directory
53 1.1 christos separators on Unix-like systems, so only run these tests on Windows. If
54 1.1 christos we ever switch our implementation to use std::filesystem::path, they
55 1.1 christos should work anywhere, in theory. */
56 1.1 christos test_one ("D:\\foo/bar", "D:\\foo", "bar");
57 1.1 christos test_one ("D:\\foo\\bar", "D:\\foo\\", "bar");
58 1.1 christos test_one ("\\\\server\\dir\\file", "\\\\server\\dir\\", "file");
59 1.1 christos test_one ("\\\\server\\dir/file", "\\\\server\\dir", "file");
60 1.1 christos #endif /* _WIN32 */
61 1.1 christos }
62 1.1 christos
63 1.1 christos }
64 1.1 christos }
65 1.1 christos
66 1.1 christos void _initialize_path_join_selftests ();
67 1.1 christos void
68 1.1 christos _initialize_path_join_selftests ()
69 1.1 christos {
70 1.1 christos selftests::register_test ("path_join",
71 1.1 christos selftests::path_join::test);
72 1.1 christos }
73