child-path-selftests.c revision 1.1.1.4 1 /* Self tests for child_path for GDB, the GNU debugger.
2
3 Copyright (C) 2019-2024 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "gdbsupport/pathstuff.h"
21 #include "gdbsupport/selftest.h"
22
23 namespace selftests {
24 namespace child_path {
25
26 /* Verify the result of a single child_path test. */
27
28 static bool
29 child_path_check (const char *parent, const char *child, const char *expected)
30 {
31 const char *result = ::child_path (parent, child);
32 if (result == NULL || expected == NULL)
33 return result == expected;
34 return strcmp (result, expected) == 0;
35 }
36
37 /* Test child_path. */
38
39 static void
40 test ()
41 {
42 SELF_CHECK (child_path_check ("/one", "/two", NULL));
43 SELF_CHECK (child_path_check ("/one", "/one", NULL));
44 SELF_CHECK (child_path_check ("/one", "/one/", NULL));
45 SELF_CHECK (child_path_check ("/one", "/one//", NULL));
46 SELF_CHECK (child_path_check ("/one", "/one/two", "two"));
47 SELF_CHECK (child_path_check ("/one/", "/two", NULL));
48 SELF_CHECK (child_path_check ("/one/", "/one", NULL));
49 SELF_CHECK (child_path_check ("/one/", "/one/", NULL));
50 SELF_CHECK (child_path_check ("/one/", "/one//", NULL));
51 SELF_CHECK (child_path_check ("/one/", "/one/two", "two"));
52 SELF_CHECK (child_path_check ("/one/", "/one//two", "two"));
53 SELF_CHECK (child_path_check ("/one/", "/one//two/", "two/"));
54 SELF_CHECK (child_path_check ("/one", "/onetwo", NULL));
55 SELF_CHECK (child_path_check ("/one", "/onetwo/three", NULL));
56 }
57
58 }
59 }
60
61 void _initialize_child_path_selftests ();
62 void
63 _initialize_child_path_selftests ()
64 {
65 selftests::register_test ("child_path",
66 selftests::child_path::test);
67 }
68
69