]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/unittests/child-path-selftests.c
2ed83faed66b868a650a6f6da7a4cc9ecd457b78
[thirdparty/binutils-gdb.git] / gdb / unittests / child-path-selftests.c
1 /* Self tests for child_path for GDB, the GNU debugger.
2
3 Copyright (C) 2019 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 "defs.h"
21 #include "gdbsupport/pathstuff.h"
22 #include "gdbsupport/selftest.h"
23
24 namespace selftests {
25 namespace child_path {
26
27 /* Verify the result of a single child_path test. */
28
29 static bool
30 child_path_check (const char *parent, const char *child, const char *expected)
31 {
32 const char *result = ::child_path (parent, child);
33 if (result == NULL || expected == NULL)
34 return result == expected;
35 return strcmp (result, expected) == 0;
36 }
37
38 /* Test child_path. */
39
40 static void
41 test ()
42 {
43 SELF_CHECK (child_path_check ("/one", "/two", 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//", NULL));
47 SELF_CHECK (child_path_check ("/one", "/one/two", "two"));
48 SELF_CHECK (child_path_check ("/one/", "/two", 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//", NULL));
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/", "/one//two/", "two/"));
55 SELF_CHECK (child_path_check ("/one", "/onetwo", NULL));
56 SELF_CHECK (child_path_check ("/one", "/onetwo/three", NULL));
57 }
58
59 }
60 }
61
62 void
63 _initialize_child_path_selftests ()
64 {
65 selftests::register_test ("child_path",
66 selftests::child_path::test);
67 }
68