1 /* Unit tests for the utils.c file.
3 Copyright (C) 2018-2024 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/selftest.h"
27 test_substitute_path_component ()
29 auto test
= [] (std::string s
, const char *from
, const char *to
,
32 char *temp
= xstrdup (s
.c_str ());
33 substitute_path_component (&temp
, from
, to
);
34 SELF_CHECK (strcmp (temp
, expected
) == 0);
38 test ("/abc/$def/g", "abc", "xyz", "/xyz/$def/g");
39 test ("abc/$def/g", "abc", "xyz", "xyz/$def/g");
40 test ("/abc/$def/g", "$def", "xyz", "/abc/xyz/g");
41 test ("/abc/$def/g", "g", "xyz", "/abc/$def/xyz");
42 test ("/abc/$def/g", "ab", "xyz", "/abc/$def/g");
43 test ("/abc/$def/g", "def", "xyz", "/abc/$def/g");
44 test ("/abc/$def/g", "abc", "abc", "/abc/$def/g");
45 test ("/abc/$def/g", "abc", "", "//$def/g");
46 test ("/abc/$def/g", "abc/$def", "xyz", "/xyz/g");
47 test ("/abc/$def/abc", "abc", "xyz", "/xyz/$def/xyz");
53 void _initialize_utils_selftests ();
55 _initialize_utils_selftests ()
57 selftests::register_test ("substitute_path_component",
58 selftests::utils::test_substitute_path_component
);