Introduce basic_safe_range
[deliverable/binutils-gdb.git] / gdb / unittests / utils-selftests.c
CommitLineData
03afa6ef
SM
1/* Unit tests for the utils.c file.
2
42a4f53d 3 Copyright (C) 2018-2019 Free Software Foundation, Inc.
03afa6ef
SM
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 "utils.h"
268a13a5 22#include "gdbsupport/selftest.h"
03afa6ef
SM
23
24namespace selftests {
25namespace utils {
26
27static void
28test_substitute_path_component ()
29{
30 auto test = [] (std::string s, const char *from, const char *to,
31 const char *expected)
32 {
33 char *temp = xstrdup (s.c_str ());
34 substitute_path_component (&temp, from, to);
35 SELF_CHECK (strcmp (temp, expected) == 0);
36 xfree (temp);
37 };
38
39 test ("/abc/$def/g", "abc", "xyz", "/xyz/$def/g");
40 test ("abc/$def/g", "abc", "xyz", "xyz/$def/g");
41 test ("/abc/$def/g", "$def", "xyz", "/abc/xyz/g");
42 test ("/abc/$def/g", "g", "xyz", "/abc/$def/xyz");
43 test ("/abc/$def/g", "ab", "xyz", "/abc/$def/g");
44 test ("/abc/$def/g", "def", "xyz", "/abc/$def/g");
45 test ("/abc/$def/g", "abc", "abc", "/abc/$def/g");
46 test ("/abc/$def/g", "abc", "", "//$def/g");
47 test ("/abc/$def/g", "abc/$def", "xyz", "/xyz/g");
48 test ("/abc/$def/abc", "abc", "xyz", "/xyz/$def/xyz");
49}
50
51}
52}
53
54void
55_initialize_utils_selftests ()
56{
57 selftests::register_test ("substitute_path_component",
58 selftests::utils::test_substitute_path_component);
59}
This page took 0.418066 seconds and 4 git commands to generate.