GDB (xrefs)
Loading...
Searching...
No Matches
ui-file-selftests.c
Go to the documentation of this file.
1/* Self tests for ui_file
2
3 Copyright (C) 2022-2023 Free Software Foundation, Inc.
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 "gdbsupport/selftest.h"
22#include "ui-file.h"
23
24namespace selftests {
25namespace file {
26
27static void
28check_one (const char *str, int quoter, const char *result)
29{
30 string_file out;
31 out.putstr (str, quoter);
32 SELF_CHECK (out.string () == result);
33}
34
35static void
37{
38 check_one ("basic stuff: \\", '\\',
39 "basic stuff: \\\\");
40 check_one ("more basic stuff: \\Q", 'Q',
41 "more basic stuff: \\\\\\Q");
42 check_one ("more basic stuff: \\Q", '\0',
43 "more basic stuff: \\Q");
44
45 check_one ("weird stuff: \x1f\x90\n\b\t\f\r\033\007", '\\',
46 "weird stuff: \\037\\220\\n\\b\\t\\f\\r\\e\\a");
47
48 scoped_restore save_7 = make_scoped_restore (&sevenbit_strings, true);
49 check_one ("more weird stuff: \xa5", '\\',
50 "more weird stuff: \\245");
51}
52
53} /* namespace file*/
54} /* namespace selftests */
55
57void
59{
60 selftests::register_test ("ui-file",
62}
const std::string & string()
Definition ui-file.h:198
void void putstr(const char *str, int quoter)
Definition ui-file.c:50
static void check_one(const char *str, int quoter, const char *result)
static void run_tests()
void _initialize_ui_file_selftest()
bool sevenbit_strings
Definition utils.c:108