1 /* Self tests for child_path for GDB, the GNU debugger.
3 Copyright (C) 2019-2022 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
21 #include "gdbsupport/pathstuff.h"
22 #include "gdbsupport/selftest.h"
25 namespace child_path
{
27 /* Verify the result of a single child_path test. */
30 child_path_check (const char *parent
, const char *child
, const char *expected
)
32 const char *result
= ::child_path (parent
, child
);
33 if (result
== NULL
|| expected
== NULL
)
34 return result
== expected
;
35 return strcmp (result
, expected
) == 0;
38 /* Test child_path. */
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
));
62 void _initialize_child_path_selftests ();
64 _initialize_child_path_selftests ()
66 selftests::register_test ("child_path",
67 selftests::child_path::test
);