]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.tui/tuiterm.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.tui / tuiterm.exp
CommitLineData
213516ef 1# Copyright 2022-2023 Free Software Foundation, Inc.
e5f7752a
SM
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# Unit-test Term, the testsuite's terminal implementation that is used to test
17# the TUI.
18
19tuiterm_env
20
21# Validate the cursor position.
22#
23# EXPECTED_CUR_COL and EXPECTED_CUR_ROW are the expected cursor column and row
24# positions.
25
26proc check_cursor_position { test expected_cur_col expected_cur_row } {
27 with_test_prefix $test {
28 gdb_assert {$expected_cur_col == ${Term::_cur_col}} "column"
29 gdb_assert {$expected_cur_row == ${Term::_cur_row}} "row"
30 }
31}
32
33# Validate the terminal contents and cursor position.
34#
35# EXPECTED_CONTENTS must be a list of strings, one element for each terminal
36# line.
37#
38# EXPECTED_CUR_COL and EXPECTED_CUR_ROW are passed to check_cursor_position.
39
40proc check { test expected_contents expected_cur_col expected_cur_row } {
41 with_test_prefix $test {
42 # Check term contents.
43 set regexp "^"
44
45 foreach line $expected_contents {
46 append regexp $line
47 append regexp "\n"
48 }
49
50 append regexp "$"
51 Term::check_contents "contents" $regexp
52 }
53
54 check_cursor_position $test $expected_cur_col $expected_cur_row
55}
56
57proc setup_terminal { cols rows } {
58 setenv TERM ansi
59 Term::_setup $rows $cols
60}
61
62# Most tests are fine with a small terminal. This proc initializes the terminal
63# with 8 columns and 4 rows, with the following content:
64#
65# abcdefgh
66# ijklmnop
67# qrstuvwx
68# yz01234
69#
70# The bottom right cell is left blank: trying to write to it using _insert
71# would move the cursor past the screen, causing a scroll, but scrolling is
72# not implemented at the moment.
73
74proc setup_small {} {
75 setup_terminal 8 4
76
77 Term::_insert "abcdefgh"
78 Term::_insert "ijklmnop"
79 Term::_insert "qrstuvwx"
80 Term::_insert "yz01234"
81
82 check "check after setup" {
83 "abcdefgh"
84 "ijklmnop"
85 "qrstuvwx"
86 "yz01234 "
87 } 7 3
88}
89
90# Some tests require a larger terminal. This proc initializes the terminal with
91# 80 columns and 25 rows, but leaves the content empty.
92
93proc setup_large {} {
94 setup_terminal 80 25
95}
96
97# Each proc below tests a control character or sequence individually.
98
99proc test_backspace {} {
100 # Note: the backspace (BS) control character only moves the cursor left,
101 # it does not delete characters.
102
103 Term::_move_cursor 1 2
104
105 Term::_ctl_0x08
106 check "backspace one" {
107 "abcdefgh"
108 "ijklmnop"
109 "qrstuvwx"
110 "yz01234 "
111 } 0 2
112
113 # Cursor should not move if it is already at column 0.
114 Term::_ctl_0x08
115 check "backspace 2" {
116 "abcdefgh"
117 "ijklmnop"
118 "qrstuvwx"
119 "yz01234 "
120 } 0 2
121}
122
123proc test_linefeed { } {
124 Term::_move_cursor 1 2
125 Term::_ctl_0x0a
126 check "linefeed" {
127 "abcdefgh"
128 "ijklmnop"
129 "qrstuvwx"
130 "yz01234 "
131 } 1 3
132}
133
134proc test_carriage_return { } {
135 Term::_move_cursor 1 2
136 Term::_ctl_0x0d
137 check "carriage return 1" {
138 "abcdefgh"
139 "ijklmnop"
140 "qrstuvwx"
141 "yz01234 "
142 } 0 2
143
144 Term::_ctl_0x0d
145 check "carriage return 2" {
146 "abcdefgh"
147 "ijklmnop"
148 "qrstuvwx"
149 "yz01234 "
150 } 0 2
151}
152
153proc test_insert_characters { } {
154 Term::_move_cursor 1 2
155
156 Term::_csi_@
157 check "insert characters 1" {
158 "abcdefgh"
159 "ijklmnop"
160 "q rstuvw"
161 "yz01234 "
162 } 1 2
163
164 Term::_csi_@ 20
165 check "insert characters 2" {
166 "abcdefgh"
167 "ijklmnop"
168 "q "
169 "yz01234 "
170 } 1 2
171
172 Term::_move_cursor 0 1
173 Term::_csi_@ 6
174 check "insert characters 3" {
175 "abcdefgh"
176 " ij"
177 "q "
178 "yz01234 "
179 } 0 1
180}
181
fd46a69e
AB
182proc test_pan_down { } {
183 Term::_move_cursor 1 2
184 Term::_csi_S
185 check "pan down, default arg" {
186 "ijklmnop"
187 "qrstuvwx"
188 "yz01234 "
189 " "
190 } 1 2
191
192 Term::_csi_S 2
193 check "pan down, explicit arg" {
194 "yz01234 "
195 " "
196 " "
197 " "
198 } 1 2
199
200 Term::_csi_S 100
201 check "pan down, excessive arg" {
202 " "
203 " "
204 " "
205 " "
206 } 1 2
207}
208
209proc test_pan_up { } {
210 Term::_move_cursor 1 2
211 Term::_csi_T
212 check "pan down, default arg" {
213 " "
214 "abcdefgh"
215 "ijklmnop"
216 "qrstuvwx"
217 } 1 2
218
219 Term::_csi_T 2
220 check "pan down, explicit arg" {
221 " "
222 " "
223 " "
224 "abcdefgh"
225 } 1 2
226
227 Term::_csi_T 100
228 check "pan down, excessive arg" {
229 " "
230 " "
231 " "
232 " "
233 } 1 2
234}
235
e5f7752a
SM
236proc test_cursor_up { } {
237 Term::_move_cursor 2 3
238
239 Term::_csi_A
240 check "cursor up 1" {
241 "abcdefgh"
242 "ijklmnop"
243 "qrstuvwx"
244 "yz01234 "
245 } 2 2
246
247 Term::_csi_A 2
248 check "cursor up 2" {
249 "abcdefgh"
250 "ijklmnop"
251 "qrstuvwx"
252 "yz01234 "
253 } 2 0
254
255 Term::_csi_A 1
256 check "cursor up 3" {
257 "abcdefgh"
258 "ijklmnop"
259 "qrstuvwx"
260 "yz01234 "
261 } 2 0
262}
263
264proc test_cursor_down { } {
265 Term::_move_cursor 1 0
266
267 Term::_csi_B
268 check "cursor down 1" {
269 "abcdefgh"
270 "ijklmnop"
271 "qrstuvwx"
272 "yz01234 "
273 } 1 1
274
275 Term::_csi_B 2
276 check "cursor down 2" {
277 "abcdefgh"
278 "ijklmnop"
279 "qrstuvwx"
280 "yz01234 "
281 } 1 3
282
283 Term::_csi_B 1
284 check "cursor down 3" {
285 "abcdefgh"
286 "ijklmnop"
287 "qrstuvwx"
288 "yz01234 "
289 } 1 3
290}
291
292proc test_cursor_forward { } {
293 Term::_move_cursor 0 1
294
295 Term::_csi_C
296 check "cursor forward 1" {
297 "abcdefgh"
298 "ijklmnop"
299 "qrstuvwx"
300 "yz01234 "
301 } 1 1
302
303 Term::_csi_C 6
304 check "cursor forward 2" {
305 "abcdefgh"
306 "ijklmnop"
307 "qrstuvwx"
308 "yz01234 "
309 } 7 1
310
311 Term::_csi_C 1
312 check "cursor forward 3" {
313 "abcdefgh"
314 "ijklmnop"
315 "qrstuvwx"
316 "yz01234 "
317 } 7 1
318}
319
320proc test_cursor_backward { } {
321 Term::_move_cursor 7 1
322
323 Term::_csi_D
324 check "cursor backward 1" {
325 "abcdefgh"
326 "ijklmnop"
327 "qrstuvwx"
328 "yz01234 "
329 } 6 1
330
331 Term::_csi_D 6
332 check "cursor backward 2" {
333 "abcdefgh"
334 "ijklmnop"
335 "qrstuvwx"
336 "yz01234 "
337 } 0 1
338
339 Term::_csi_D 1
340 check "cursor backward 3" {
341 "abcdefgh"
342 "ijklmnop"
343 "qrstuvwx"
344 "yz01234 "
345 } 0 1
346}
347
348proc test_cursor_next_line { } {
349 Term::_move_cursor 2 0
350
351 Term::_csi_E
352 check "cursor next line 1" {
353 "abcdefgh"
354 "ijklmnop"
355 "qrstuvwx"
356 "yz01234 "
357 } 0 1
358
359 Term::_move_cursor 2 1
360 Term::_csi_E 2
361 check "cursor next line 2" {
362 "abcdefgh"
363 "ijklmnop"
364 "qrstuvwx"
365 "yz01234 "
366 } 0 3
367
368 Term::_move_cursor 2 3
369 Term::_csi_E 1
370 check "cursor next line 3" {
371 "abcdefgh"
372 "ijklmnop"
373 "qrstuvwx"
374 "yz01234 "
375 } 0 3
376}
377
378proc test_cursor_previous_line { } {
379 Term::_move_cursor 2 3
380
381 Term::_csi_F
382 check "cursor previous line 1" {
383 "abcdefgh"
384 "ijklmnop"
385 "qrstuvwx"
386 "yz01234 "
387 } 0 2
388
389 Term::_move_cursor 2 2
390 Term::_csi_F 2
391 check "cursor previous line 2" {
392 "abcdefgh"
393 "ijklmnop"
394 "qrstuvwx"
395 "yz01234 "
396 } 0 0
397
398 Term::_move_cursor 2 0
399 Term::_csi_F 1
400 check "cursor previous line 3" {
401 "abcdefgh"
402 "ijklmnop"
403 "qrstuvwx"
404 "yz01234 "
405 } 0 0
406}
407
408proc test_horizontal_absolute { } {
409 Term::_move_cursor 2 2
410 Term::_csi_G
411 check "cursor horizontal absolute 1" {
412 "abcdefgh"
413 "ijklmnop"
414 "qrstuvwx"
415 "yz01234 "
416 } 0 2
417
418 Term::_move_cursor 2 2
419 Term::_csi_G 4
420 check "cursor horizontal absolute 2" {
421 "abcdefgh"
422 "ijklmnop"
423 "qrstuvwx"
424 "yz01234 "
425 } 3 2
426}
427
428proc test_cursor_position { } {
429 Term::_move_cursor 1 1
430
431 Term::_csi_H 3 5
432 check "cursor horizontal absolute 2" {
433 "abcdefgh"
434 "ijklmnop"
435 "qrstuvwx"
436 "yz01234 "
437 } 4 2
438}
439
440proc test_cursor_horizontal_forward_tabulation { } {
441 Term::_move_cursor 5 2
442 Term::_csi_I
443 check_cursor_position "default param" 8 2
444
445 Term::_csi_I 2
446 check_cursor_position "explicit param" 24 2
447
448 Term::_move_cursor 77 2
449 Term::_csi_I 5
450 check_cursor_position "try to go past the end" 79 2
451}
452
453proc test_erase_in_display { } {
454 Term::_move_cursor 5 2
455 Term::_csi_J
456 check "erase in display, cursor to end with default param" {
457 "abcdefgh"
458 "ijklmnop"
459 "qrstu "
460 " "
461 } 5 2
462
463 Term::_move_cursor 3 2
464 Term::_csi_J 0
465 check "erase in display, cursor to end with explicit param" {
466 "abcdefgh"
467 "ijklmnop"
468 "qrs "
469 " "
470 } 3 2
471
472 Term::_move_cursor 2 1
473 Term::_csi_J 1
474 check "erase in display, beginning to cursor" {
475 " "
476 " lmnop"
477 "qrs "
478 " "
479 } 2 1
480
481 Term::_move_cursor 5 1
482 Term::_csi_J 2
483 check "erase in display, entire display" {
484 " "
485 " "
486 " "
487 " "
488 } 5 1
489}
490
491proc test_erase_in_line { } {
492 Term::_move_cursor 5 2
493 Term::_csi_K
494 check "erase in line, cursor to end with default param" {
495 "abcdefgh"
496 "ijklmnop"
497 "qrstu "
498 "yz01234 "
499 } 5 2
500
501 Term::_move_cursor 3 2
502 Term::_csi_K 0
503 check "erase in line, cursor to end with explicit param" {
504 "abcdefgh"
505 "ijklmnop"
506 "qrs "
507 "yz01234 "
508 } 3 2
509
510 Term::_move_cursor 3 1
511 Term::_csi_K 1
512 check "erase in line, beginning to cursor" {
513 "abcdefgh"
514 " mnop"
515 "qrs "
516 "yz01234 "
517 } 3 1
518
519 Term::_move_cursor 3 0
520 Term::_csi_K 2
521 check "erase in line, entire line" {
522 " "
523 " mnop"
524 "qrs "
525 "yz01234 "
526 } 3 0
527}
528
529proc test_delete_line { } {
530 Term::_move_cursor 3 2
531 Term::_csi_M
532 check "delete line, default param" {
533 "abcdefgh"
534 "ijklmnop"
535 "yz01234 "
536 " "
537 } 3 2
538
539 Term::_move_cursor 3 0
540 Term::_csi_M 2
541 check "delete line, explicit param" {
542 "yz01234 "
543 " "
544 " "
545 " "
546 } 3 0
547}
548
7820b634
SM
549proc test_delete_character { } {
550 Term::_move_cursor 2 1
551
552 Term::_csi_P
553 check "delete character, default param" {
554 "abcdefgh"
555 "ijlmnop "
556 "qrstuvwx"
557 "yz01234 "
558 } 2 1
559
560 Term::_csi_P 3
561 check "delete character, explicit param" {
562 "abcdefgh"
563 "ijop "
564 "qrstuvwx"
565 "yz01234 "
566 } 2 1
567
568 Term::_csi_P 12
569 check "delete character, more than number of columns" {
570 "abcdefgh"
571 "ij "
572 "qrstuvwx"
573 "yz01234 "
574 } 2 1
575}
576
e5f7752a
SM
577proc test_erase_character { } {
578 Term::_move_cursor 3 2
579 Term::_csi_X
580 check "erase character, default param" {
581 "abcdefgh"
582 "ijklmnop"
583 "qrs uvwx"
584 "yz01234 "
585 } 3 2
586
587 Term::_move_cursor 1 3
588 Term::_csi_X 4
589 check "erase character, explicit param" {
590 "abcdefgh"
591 "ijklmnop"
592 "qrs uvwx"
593 "y 34 "
594 } 1 3
595}
596
597proc test_cursor_backward_tabulation { } {
598 Term::_move_cursor 77 2
599 Term::_csi_Z
600 check_cursor_position "default param" 72 2
601
602 Term::_csi_Z 2
603 check_cursor_position "explicit param" 56 2
604
605 Term::_move_cursor 6 2
606 Term::_csi_Z 12
607 check_cursor_position "try to go past the beginning" 0 2
608}
609
610proc test_repeat { } {
611 Term::_move_cursor 2 1
612 set Term::_last_char X
613
614 Term::_csi_b 3
615 check "repeat" {
616 "abcdefgh"
617 "ijXXXnop"
618 "qrstuvwx"
619 "yz01234 "
620 } 5 1
621}
622
623proc test_vertical_line_position_absolute { } {
624 Term::_move_cursor 2 1
625
626 Term::_csi_d
627 check "default param" {
628 "abcdefgh"
629 "ijklmnop"
630 "qrstuvwx"
631 "yz01234 "
632 } 2 0
633
634 Term::_csi_d 3
635 check "explicit param" {
636 "abcdefgh"
637 "ijklmnop"
638 "qrstuvwx"
639 "yz01234 "
640 } 2 2
641
642 Term::_csi_d 100
643 check "try to move off-display" {
644 "abcdefgh"
645 "ijklmnop"
646 "qrstuvwx"
647 "yz01234 "
648 } 2 3
649}
650
fd46a69e
AB
651proc test_insert_line { } {
652 Term::_move_cursor 2 1
653 Term::_csi_L
654 check "insert line, default param" {
655 "abcdefgh"
656 " "
657 "ijklmnop"
658 "qrstuvwx"
659 } 2 1
660
661 Term::_move_cursor 2 0
662 Term::_csi_L 2
663 check "insert line, explicit param" {
664 " "
665 " "
666 "abcdefgh"
667 " "
668 } 2 0
669
670 Term::_csi_L 12
671 check "insert line, insert more lines than display has" {
672 " "
673 " "
674 " "
675 " "
676 } 2 0
677}
678
e5f7752a
SM
679# Run proc TEST_PROC_NAME with a "small" terminal.
680
681proc run_one_test_small { test_proc_name } {
682 save_vars { env(TERM) stty_init } {
683 setup_small
684 eval $test_proc_name
685 }
686}
687
688# Run proc TEST_PROC_NAME with a "large" terminal.
689
690proc run_one_test_large { test_proc_name } {
691 save_vars { env(TERM) stty_init } {
692 setup_large
693 eval $test_proc_name
694 }
695}
696
697foreach_with_prefix test {
698 test_backspace
699 test_linefeed
700 test_carriage_return
701 test_insert_characters
702 test_cursor_up
703 test_cursor_down
704 test_cursor_forward
705 test_cursor_backward
706 test_cursor_next_line
707 test_cursor_previous_line
708 test_horizontal_absolute
709 test_cursor_position
710 test_erase_in_display
711 test_erase_in_line
712 test_delete_line
7820b634 713 test_delete_character
e5f7752a
SM
714 test_erase_character
715 test_repeat
716 test_vertical_line_position_absolute
fd46a69e
AB
717 test_insert_line
718 test_pan_up
719 test_pan_down
e5f7752a
SM
720} {
721 run_one_test_small $test
722}
723
724foreach_with_prefix test {
725 test_cursor_horizontal_forward_tabulation
726 test_cursor_backward_tabulation
727} {
728 run_one_test_large $test
729}