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 24 namespace selftests { 25 namespace file { 26 27 static void 28 check_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 35 static void 36 run_tests () 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 56 void _initialize_ui_file_selftest (); 57 void 58 _initialize_ui_file_selftest () 59 { 60 selftests::register_test ("ui-file", 61 selftests::file::run_tests); 62 } 63