1"""
2Test that the 'gui' displays long lines/names correctly without overruns.
3"""
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test.lldbpexpect import PExpectTest
9
10class GuiViewLargeCommandTest(PExpectTest):
11
12    # PExpect uses many timeouts internally and doesn't play well
13    # under ASAN on a loaded machine..
14    @skipIfAsan
15    @skipIfCursesSupportMissing
16    @skipIfRemote # "run" command will not work correctly for remote debug
17    @expectedFailureNetBSD
18    @skipIf(oslist=["linux"], archs=["arm", "aarch64"])
19    def test_gui(self):
20        self.build()
21
22        # Limit columns to 80, so that long lines will not be displayed completely.
23        self.launch(executable=self.getBuildArtifact("a.out"), dimensions=(100,80))
24        self.expect('br set -f main.c -p "// Break here"', substrs=["Breakpoint 1", "address ="])
25        self.expect("run", substrs=["stop reason ="])
26
27        escape_key = chr(27).encode()
28        left_key = chr(27)+'OD' # for vt100 terminal (lldbexpect sets TERM=vt100)
29        right_key = chr(27)+'OC'
30        ctrl_l = chr(12)
31
32        # Start the GUI.
33        self.child.sendline("gui")
34
35        # Check the sources window.
36        self.child.expect_exact("Sources")
37        # The string is copy&pasted from a 80-columns terminal. It will be followed by some
38        # kind of an escape sequence (color, frame, etc.).
39        self.child.expect_exact("int a_variable_with_a_very_looooooooooooooooooooooooooo"+chr(27))
40        # The escape here checks that there's no content drawn by the previous line.
41        self.child.expect_exact("int shortvar = 1;"+chr(27))
42        # Check the triggered breakpoint marker on a long line.
43        self.child.expect_exact("<<< Thread 1: breakpoint 1.1"+chr(27))
44
45        # Check the variable window.
46        self.child.expect_exact("Variables")
47        self.child.expect_exact("(int) a_variable_with_a_very_looooooooooooooooooooooooooooooo"+chr(27))
48        self.child.expect_exact("(int) shortvar = 1"+chr(27))
49
50        # Scroll the sources view twice to the right.
51        self.child.send(right_key)
52        self.child.send(right_key)
53        # Force a redraw, otherwise curses will optimize the drawing to not draw all 'o'.
54        self.child.send(ctrl_l)
55        # The source code is indented by two spaces, so there'll be just two extra 'o' on the right.
56        self.child.expect_exact("int a_variable_with_a_very_looooooooooooooooooooooooooooo"+chr(27))
57
58        # And scroll back to the left.
59        self.child.send(left_key)
60        self.child.send(left_key)
61        self.child.send(ctrl_l)
62        self.child.expect_exact("int a_variable_with_a_very_looooooooooooooooooooooooooo"+chr(27))
63
64        # Press escape to quit the gui
65        self.child.send(escape_key)
66
67        self.expect_prompt()
68        self.quit()
69