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    mydir = TestBase.compute_mydir(__file__)
13
14    # PExpect uses many timeouts internally and doesn't play well
15    # under ASAN on a loaded machine..
16    @skipIfAsan
17    @skipIfCursesSupportMissing
18    @skipIfRemote # "run" command will not work correctly for remote debug
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 and close the welcome window.
33        self.child.sendline("gui")
34        self.child.send(escape_key)
35
36        # Check the sources window.
37        self.child.expect_exact("Sources")
38        # The string is copy&pasted from a 80-columns terminal. It will be followed by some
39        # kind of an escape sequence (color, frame, etc.).
40        self.child.expect_exact("int a_variable_with_a_very_looooooooooooooooooooooooooo"+chr(27))
41        # The escape here checks that there's no content drawn by the previous line.
42        self.child.expect_exact("int shortvar = 1;"+chr(27))
43        # Check the triggered breakpoint marker on a long line.
44        self.child.expect_exact("<<< Thread 1: breakpoint 1.1"+chr(27))
45
46        # Check the variable window.
47        self.child.expect_exact("Variables")
48        self.child.expect_exact("(int) a_variable_with_a_very_looooooooooooooooooooooooooooooo"+chr(27))
49        self.child.expect_exact("(int) shortvar = 1"+chr(27))
50
51        # Scroll the sources view twice to the right.
52        self.child.send(right_key)
53        self.child.send(right_key)
54        # Force a redraw, otherwise curses will optimize the drawing to not draw all 'o'.
55        self.child.send(ctrl_l)
56        # The source code is indented by two spaces, so there'll be just two extra 'o' on the right.
57        self.child.expect_exact("int a_variable_with_a_very_looooooooooooooooooooooooooooo"+chr(27))
58
59        # And scroll back to the left.
60        self.child.send(left_key)
61        self.child.send(left_key)
62        self.child.send(ctrl_l)
63        self.child.expect_exact("int a_variable_with_a_very_looooooooooooooooooooooooooo"+chr(27))
64
65        # Press escape to quit the gui
66        self.child.send(escape_key)
67
68        self.expect_prompt()
69        self.quit()
70