child-path-selftests.c revision 1.1.1.4 1 1.1 christos /* Self tests for child_path for GDB, the GNU debugger.
2 1.1 christos
3 1.1.1.4 christos Copyright (C) 2019-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.1.2 christos #include "gdbsupport/pathstuff.h"
21 1.1.1.2 christos #include "gdbsupport/selftest.h"
22 1.1 christos
23 1.1 christos namespace selftests {
24 1.1 christos namespace child_path {
25 1.1 christos
26 1.1 christos /* Verify the result of a single child_path test. */
27 1.1 christos
28 1.1 christos static bool
29 1.1 christos child_path_check (const char *parent, const char *child, const char *expected)
30 1.1 christos {
31 1.1 christos const char *result = ::child_path (parent, child);
32 1.1 christos if (result == NULL || expected == NULL)
33 1.1 christos return result == expected;
34 1.1 christos return strcmp (result, expected) == 0;
35 1.1 christos }
36 1.1 christos
37 1.1 christos /* Test child_path. */
38 1.1 christos
39 1.1 christos static void
40 1.1 christos test ()
41 1.1 christos {
42 1.1 christos SELF_CHECK (child_path_check ("/one", "/two", NULL));
43 1.1 christos SELF_CHECK (child_path_check ("/one", "/one", NULL));
44 1.1 christos SELF_CHECK (child_path_check ("/one", "/one/", NULL));
45 1.1 christos SELF_CHECK (child_path_check ("/one", "/one//", NULL));
46 1.1 christos SELF_CHECK (child_path_check ("/one", "/one/two", "two"));
47 1.1 christos SELF_CHECK (child_path_check ("/one/", "/two", NULL));
48 1.1 christos SELF_CHECK (child_path_check ("/one/", "/one", NULL));
49 1.1 christos SELF_CHECK (child_path_check ("/one/", "/one/", NULL));
50 1.1 christos SELF_CHECK (child_path_check ("/one/", "/one//", NULL));
51 1.1 christos SELF_CHECK (child_path_check ("/one/", "/one/two", "two"));
52 1.1 christos SELF_CHECK (child_path_check ("/one/", "/one//two", "two"));
53 1.1 christos SELF_CHECK (child_path_check ("/one/", "/one//two/", "two/"));
54 1.1 christos SELF_CHECK (child_path_check ("/one", "/onetwo", NULL));
55 1.1 christos SELF_CHECK (child_path_check ("/one", "/onetwo/three", NULL));
56 1.1 christos }
57 1.1 christos
58 1.1 christos }
59 1.1 christos }
60 1.1 christos
61 1.1.1.2 christos void _initialize_child_path_selftests ();
62 1.1 christos void
63 1.1 christos _initialize_child_path_selftests ()
64 1.1 christos {
65 1.1 christos selftests::register_test ("child_path",
66 1.1 christos selftests::child_path::test);
67 1.1 christos }
68 1.1 christos
69