aboutsummaryrefslogtreecommitdiff
path: root/gdb/unittests
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-12-31 10:40:02 -0700
committerTom Tromey <tom@tromey.com>2022-01-05 11:01:02 -0700
commitd53fd721a18f8c827aa69ffbd15abd99641b5e20 (patch)
tree436641845129a7eb9eb38733a456656da9312366 /gdb/unittests
parent28a4e64dd1b17b0d9f267c3466d7da3e8a41afd8 (diff)
downloadbinutils-d53fd721a18f8c827aa69ffbd15abd99641b5e20.zip
binutils-d53fd721a18f8c827aa69ffbd15abd99641b5e20.tar.gz
binutils-d53fd721a18f8c827aa69ffbd15abd99641b5e20.tar.bz2
Implement putstr and putstrn in ui_file
In my tour of the ui_file subsystem, I found that fputstr and fputstrn can be simplified. The _filtered forms are never used (and IMO unlikely to ever be used) and so can be removed. And, the interface can be simplified by removing a callback function and moving the implementation directly to ui_file. A new self-test is included. Previously, I think nothing was testing this code. Regression tested on x86-64 Fedora 34.
Diffstat (limited to 'gdb/unittests')
-rw-r--r--gdb/unittests/ui-file-selftests.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/gdb/unittests/ui-file-selftests.c b/gdb/unittests/ui-file-selftests.c
new file mode 100644
index 0000000..5585438
--- /dev/null
+++ b/gdb/unittests/ui-file-selftests.c
@@ -0,0 +1,62 @@
+/* Self tests for ui_file
+
+ Copyright (C) 2022 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "defs.h"
+#include "gdbsupport/selftest.h"
+#include "ui-file.h"
+
+namespace selftests {
+namespace file {
+
+static void
+check_one (const char *str, int quoter, const char *result)
+{
+ string_file out;
+ out.putstr (str, quoter);
+ SELF_CHECK (out.string () == result);
+}
+
+static void
+run_tests ()
+{
+ check_one ("basic stuff: \\", '\\',
+ "basic stuff: \\\\");
+ check_one ("more basic stuff: \\Q", 'Q',
+ "more basic stuff: \\\\\\Q");
+ check_one ("more basic stuff: \\Q", '\0',
+ "more basic stuff: \\Q");
+
+ check_one ("weird stuff: \x1f\x90\n\b\t\f\r\033\007", '\\',
+ "weird stuff: \\037\\220\\n\\b\\t\\f\\r\\e\\a");
+
+ scoped_restore save_7 = make_scoped_restore (&sevenbit_strings, true);
+ check_one ("more weird stuff: \xa5", '\\',
+ "more weird stuff: \\245");
+}
+
+} /* namespace file*/
+} /* namespace selftests */
+
+void _initialize_ui_file_selftest ();
+void
+_initialize_ui_file_selftest ()
+{
+ selftests::register_test ("ui-file",
+ selftests::file::run_tests);
+}