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