1*56bb7041Schristos# Copyright 2019-2020 Free Software Foundation, Inc.
2*56bb7041Schristos
3*56bb7041Schristos# This program is free software; you can redistribute it and/or modify
4*56bb7041Schristos# it under the terms of the GNU General Public License as published by
5*56bb7041Schristos# the Free Software Foundation; either version 3 of the License, or
6*56bb7041Schristos# (at your option) any later version.
7*56bb7041Schristos#
8*56bb7041Schristos# This program is distributed in the hope that it will be useful,
9*56bb7041Schristos# but WITHOUT ANY WARRANTY; without even the implied warranty of
10*56bb7041Schristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11*56bb7041Schristos# GNU General Public License for more details.
12*56bb7041Schristos#
13*56bb7041Schristos# You should have received a copy of the GNU General Public License
14*56bb7041Schristos# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15*56bb7041Schristos
16*56bb7041Schristos# Basic TUI tests.
17*56bb7041Schristos
18*56bb7041Schristostuiterm_env
19*56bb7041Schristos
20*56bb7041Schristosstandard_testfile tui-layout.c
21*56bb7041Schristos
22*56bb7041Schristosif {[build_executable "failed to prepare" ${testfile} ${srcfile}] == -1} {
23*56bb7041Schristos    return -1
24*56bb7041Schristos}
25*56bb7041Schristos
26*56bb7041SchristosTerm::clean_restart 24 80 $testfile
27*56bb7041Schristosif {![Term::enter_tui]} {
28*56bb7041Schristos    unsupported "TUI not supported"
29*56bb7041Schristos    return
30*56bb7041Schristos}
31*56bb7041Schristos
32*56bb7041Schristosset text [Term::get_all_lines]
33*56bb7041Schristosgdb_assert {![string match "No Source Available" $text]} \
34*56bb7041Schristos    "initial source listing"
35*56bb7041Schristos
36*56bb7041SchristosTerm::command "list main"
37*56bb7041SchristosTerm::check_contents "list main" "21 *return 0"
38*56bb7041Schristos
39*56bb7041Schristos# Get the first source line.
40*56bb7041Schristosset line [Term::get_line 1]
41*56bb7041Schristos# Send an up arrow.
42*56bb7041Schristossend_gdb "\033\[A"
43*56bb7041Schristos# Wait for a redraw and check that the first line changed.
44*56bb7041Schristosif {[Term::wait_for [string_to_regexp $line]] \
45*56bb7041Schristos	&& [Term::get_line 1] != $line\
46*56bb7041Schristos	&& [Term::get_line 2] == $line} {
47*56bb7041Schristos    pass "scroll up"
48*56bb7041Schristos} else {
49*56bb7041Schristos    fail "scroll up"
50*56bb7041Schristos}
51*56bb7041Schristos
52*56bb7041Schristos# Check the horizontal scrolling.  First confirm that 'main ()' is
53*56bb7041Schristos# where we expect it to be.  This relies on the current way we
54*56bb7041Schristos# position source code on the screen, which might change in the
55*56bb7041Schristos# future.  The important part of this test is detecting the left/right
56*56bb7041Schristos# scrolling, not which line main is actually on.
57*56bb7041Schristosset line_num 6
58*56bb7041Schristosset line [Term::get_line $line_num]
59*56bb7041Schristosgdb_assert {[regexp -- "19\[\\t \]+main \\(\\)" $line]} \
60*56bb7041Schristos    "check main is where we expect on the screen"
61*56bb7041Schristosset regexp "19\[\\t \]+ain \\(\\)"
62*56bb7041Schristos# Send a right arrow.
63*56bb7041Schristossend_gdb "\033\[C"
64*56bb7041Schristosif {[Term::wait_for $regexp]} {
65*56bb7041Schristos    pass "scroll right"
66*56bb7041Schristos} else {
67*56bb7041Schristos    fail "scroll right"
68*56bb7041Schristos}
69*56bb7041Schristosset line [Term::get_line $line_num]
70*56bb7041Schristos# Send a down arrow.
71*56bb7041Schristossend_gdb "\033\[B"
72*56bb7041Schristosif {[Term::wait_for $regexp] \
73*56bb7041Schristos	&& [Term::get_line [expr {$line_num - 1}]] == $line} {
74*56bb7041Schristos    pass "scroll down"
75*56bb7041Schristos} else {
76*56bb7041Schristos    fail "scroll down"
77*56bb7041Schristos}
78*56bb7041Schristos
79*56bb7041SchristosTerm::check_box "source box" 0 0 80 15
80*56bb7041Schristos
81*56bb7041SchristosTerm::command "layout asm"
82*56bb7041SchristosTerm::check_contents "asm window shows main" "$hex <main>"
83*56bb7041Schristos
84*56bb7041SchristosTerm::check_box "asm box" 0 0 80 15
85*56bb7041Schristos
86*56bb7041SchristosTerm::command "layout split"
87*56bb7041SchristosTerm::check_contents "split layout contents" "21 *return 0.*$hex <main>"
88*56bb7041Schristos
89*56bb7041SchristosTerm::check_box "source box in split layout" 0 0 80 7
90*56bb7041SchristosTerm::check_box "asm box in split layout" 0 6 80 9
91