]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.tui/tui-focus.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.tui / tui-focus.exp
1 # Copyright 2023-2024 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 # Testcase that just checks the tui 'focus' command works as expected.
17
18 require allow_tui_tests
19
20 tuiterm_env
21 load_lib gdb-python.exp
22
23 standard_testfile
24
25 if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile}]} {
26 return -1
27 }
28
29 # Run a series of tests based on various test specifications.
30 #
31 # Each test specification is a tuple where the first item is the name of a
32 # window, and the second item is a boolean indicating if we expect that
33 # window to be present in the default (src) layout.
34 foreach spec {{src true} {cmd true} {status true} {regs false} \
35 {asm false} {unknown false}} {
36 lassign $spec window valid_p
37 with_test_prefix "window=$window" {
38
39 Term::clean_restart 24 80 $binfile
40 if {![Term::prepare_for_tui]} {
41 unsupported "TUI not supported"
42 return
43 }
44
45 Term::command_no_prompt_prefix "focus $window"
46
47 if {$valid_p} {
48 # The 'status' window is special, it's present in the
49 # default (src) layout, but is not focusable.
50 if {$window == "status"} {
51 Term::check_region_contents "check focus error" 0 16 80 1 \
52 "^Window \"$window\" cannot be focused\\s*"
53 } else {
54 Term::check_region_contents "check focus message" 0 16 80 1 \
55 "^Focus set to $window window\\.\\s*"
56 }
57 } else {
58 if {$window == "unknown"} {
59 Term::check_region_contents "check focus error" 0 16 80 1 \
60 "^Unrecognized window name \"$window\"\\s*"
61 } else {
62 Term::check_region_contents "check focus error" 0 16 80 1 \
63 "^Window \"$window\" is not in the current layout\\s*"
64 }
65 }
66
67 Term::check_box "check src box" 0 0 80 15
68
69 # At one point the following 'focus prev' command would trigger a
70 # crash in GDB, GDB was allowing users to set focus to the 'status'
71 # window, and 'focus prev' would then trigger an assert.
72 Term::command "focus prev"
73 }
74 }
75
76 # Use the Python TUI API to exercise some of the ambigous window name
77 # handling parts of the 'focus' command.
78 Term::clean_restart 24 80 $binfile
79 if {[allow_python_tests]} {
80 # Create a very simple tui window.
81 gdb_py_test_silent_cmd \
82 [multi_line_input \
83 "python" \
84 "class TestWindow:" \
85 " def __init__(self, win):" \
86 " pass" \
87 "" \
88 " def render(self):" \
89 " pass" \
90 "end"] \
91 "setup dummy window class" \
92 true
93
94 # Register the window with a set of similar names.
95 gdb_test_no_output "python gdb.register_window_type(\"test1\", TestWindow)"
96 gdb_test_no_output "python gdb.register_window_type(\"test2\", TestWindow)"
97 gdb_test_no_output "python gdb.register_window_type(\"test3\", TestWindow)"
98
99 # Create a layout containing just one of the above windows.
100 gdb_test_no_output "tui new-layout example1 test2 1 status 1 cmd 1"
101
102 # Create a layout containing two of the above windows.
103 gdb_test_no_output "tui new-layout example2 test1 1 test2 1 status 1 cmd 1"
104
105 if {![Term::prepare_for_tui]} {
106 unsupported "TUI not supported"
107 return
108 }
109
110 # Try to focus using an ambiguous, partial window name. This
111 # should fail as the default layout (src) doesn't include any
112 # windows matching this name.
113 Term::command_no_prompt_prefix "focus test"
114 Term::check_region_contents "check no matching window focus message" \
115 0 16 80 1 \
116 "^No windows matching \"test\" in the current layout\\s*"
117
118 # Now select a layout that includes a single window that matches
119 # the ambiguous, partial name 'test', and disable tui mode.
120 Term::command "layout example1"
121 send_gdb "tui disable\n"
122
123 # Reactivate tui mode and try to set focus using the ambiguous,
124 # partial window name. This should succeed though, as, within the
125 # current layout, the partial name is not actually ambiguous.
126 send_gdb "focus test\n"
127 gdb_assert [Term::wait_for_region_contents 0 19 80 1 \
128 "^Focus set to test2 window\\.\\s*"] \
129 "check test2 focus message"
130
131 # Now select a layout that includes two windows that matches the
132 # ambiguous, partial name 'test', and disable tui mode.
133 Term::command "layout example2"
134 send_gdb "tui disable\n"
135
136 # Reactivate tui mode and try to set focus using the ambiguous,
137 # partial window name. This will fail as now the layout includes
138 # multiple windows that match 'test'.
139 send_gdb "focus test\n"
140 gdb_assert [Term::wait_for_region_contents 0 22 80 1 \
141 "^Window name \"test\" is ambiguous\\s*"] \
142 "check ambiguous focus message"
143 }