def test_DECIC_ScrollEntirelyOffRightEdge(self): """Test DECIC behavior when pushing text off the right edge. """ width = GetScreenSize().width() esccmd.CUP(Point(1, 1)) escio.Write("x" * width) esccmd.CUP(Point(1, 2)) escio.Write("x" * width) esccmd.CUP(Point(1, 1)) esccmd.DECIC(width) expectedLine = blank() * width AssertScreenCharsInRectEqual(Rect(1, 1, width, 2), [expectedLine, expectedLine]) # Ensure there is no wrap-around. AssertScreenCharsInRectEqual(Rect(1, 2, 1, 3), [blank(), blank()])
def test_SD_CanClearScreen(self): """An SD equal to the height of the screen clears it.""" # Fill the screen with 0001, 0002, ..., height. Fill expected_lines with empty rows. height = GetScreenSize().height() expected_lines = [] for i in xrange(height): y = i + 1 esccmd.CUP(Point(1, y)) escio.Write("%04d" % y) expected_lines.append(NUL * 4) # Scroll by |height| esccmd.SD(height) # Ensure the screen is empty AssertScreenCharsInRectEqual(Rect(1, 1, 4, height), expected_lines)
def test_XtermWinops_ResizeChars_BothParameters(self): """Resize the window to a character size, giving both parameters.""" maximum_size = GetDisplaySize() # In characters original_size = GetScreenSize() # In characters if escargs.args.expected_terminal == "xterm": desired_size = Size(self.AverageWidth(maximum_size, original_size), self.AverageHeight(maximum_size, original_size)) else: desired_size = Size(20, 21) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_CHARS, desired_size.height(), desired_size.width()) self.DelayAfterResize() self.CheckActualSizeChars(desired_size, self.GetCharErrorLimit())
def test_DL_DeleteMoreThanVisible(self): """Test passing a too-big parameter to DL.""" # Set up the screen with 0001, 0002, ..., height self.prepare() # Delete more than the height of the screen. height = GetScreenSize().height() esccmd.DL(height * 2) # Build an array of 0001 followed by height-1 empty lines. y = 1 expected_lines = ["0001"] for i in xrange(height - 1): expected_lines.append(empty() * 4) AssertScreenCharsInRectEqual(Rect(1, 1, 4, height), expected_lines)
def test_CUF_StopsAtRightMarginInScrollRegion(self): """When the cursor starts within the scroll region, CUF moves it right to the right margin but no farther.""" # Set a scroll region. esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(5, 10) # Position the cursor inside the scroll region esccmd.CUP(Point(7, 3)) # Move it right by a lot width = GetScreenSize().width() esccmd.CUF(width) # Ensure it stopped at the right edge of the screen AssertEQ(GetCursorPosition().x(), 10)
def test_XtermWinops_ResizeChars_ZeroHeight(self): """Resize the window to a character size, setting one param to 0 (max size in that direction).""" maximum_size = GetDisplaySize() original_size = GetScreenSize() if escargs.args.expected_terminal == "xterm": desired_size = Size(original_size.width(), maximum_size.height()) else: desired_size = Size(20, maximum_size.height()) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_CHARS, 0, desired_size.width()) self.DelayAfterResize() limit = self.GetCharErrorLimit() limit = Size(0, limit.height()) self.CheckActualSizeChars(desired_size, limit)
def test_DECDC_DeleteAll(self): """Test DECDC behavior when deleting more columns than are available.""" width = GetScreenSize().width() s = "abcdefg" startX = width - len(s) + 1 esccmd.CUP(Point(startX, 1)) escio.Write(s) esccmd.CUP(Point(startX, 2)) escio.Write(s.upper()) esccmd.CUP(Point(startX + 1, 1)) esccmd.DECDC(width + 10) AssertScreenCharsInRectEqual(Rect(startX, 1, width, 2), ["a" + empty() * 6, "A" + empty() * 6]) # Ensure there is no wrap-around. AssertScreenCharsInRectEqual(Rect(1, 2, 1, 3), [empty(), empty()])
def test_DECSET_DECAWM(self): """Auto-wrap mode.""" size = GetScreenSize() esccmd.CUP(Point(size.width() - 1, 1)) esccmd.DECSET(esccmd.DECAWM) escio.Write("abc") AssertScreenCharsInRectEqual(Rect(1, 2, 1, 2), ["c"]) esccmd.CUP(Point(size.width() - 1, 1)) esccmd.DECRESET(esccmd.DECAWM) escio.Write("ABC") AssertScreenCharsInRectEqual( Rect(size.width() - 1, 1, size.width(), 1), ["AC"]) AssertScreenCharsInRectEqual(Rect(1, 2, 1, 2), ["c"])
def test_DECIC_ScrollOffRightEdge(self): """Test DECIC behavior when pushing text off the right edge. """ width = GetScreenSize().width() s = "abcdefg" startX = width - len(s) + 1 esccmd.CUP(Point(startX, 1)) escio.Write(s) esccmd.CUP(Point(startX, 2)) escio.Write(s.upper()) esccmd.CUP(Point(startX + 1, 1)) esccmd.DECIC() AssertScreenCharsInRectEqual( Rect(startX, 1, width, 2), ["a" + blank() + "bcdef", "A" + blank() + "BCDEF"]) # Ensure there is no wrap-around. AssertScreenCharsInRectEqual(Rect(1, 2, 1, 3), [NUL, NUL])
def test_CUF_StopsAtRightEdgeWhenBegunRightOfScrollRegion(self): """When the cursor starts right of the scroll region, CUF moves it right to the edge of the screen.""" # Set a scroll region. esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(5, 10) # Position the cursor right of the scroll region esccmd.CUP(Point(12, 3)) AssertEQ(GetCursorPosition().x(), 12) # Move it right by a lot width = GetScreenSize().width() esccmd.CUF(width) # Ensure it stopped at the right edge of the screen AssertEQ(GetCursorPosition().x(), width)
def test_DECSET_DECCOLM(self): """DECNCSM - No Clearing Screen On Column Change""" # Ensure this is reset from other tests. Otherwise DECCOLM will not # erase the screen. esccmd.DECRESET(esccmd.DECNCSM) """Set 132 column mode.""" # From the docs: # When the terminal receives the sequence, the screen is erased and the # cursor moves to the home position. This also sets the scrolling region # for full screen # Enable DECCOLM. esccmd.DECSET(esccmd.Allow80To132) # Write something to verify that it gets erased esccmd.CUP(Point(5, 5)) escio.Write("xyz") # Set left-right and top-bottom margins to ensure they're removed. esccmd.DECSTBM(1, 2) esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(1, 2) # Enter 132-column mode. esccmd.DECSET(esccmd.DECCOLM) # Check that the screen got resized AssertEQ(GetScreenSize().width(), 132) # Make sure the cursor is at the origin position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 1) # Write to make sure the scroll regions are gone escio.Write(CR + LF) escio.Write("Hello") escio.Write(CR + LF) escio.Write("World") esccmd.DECSTBM() esccmd.DECRESET(esccmd.DECLRMM) AssertScreenCharsInRectEqual(Rect(1, 2, 5, 3), ["Hello", "World"]) AssertScreenCharsInRectEqual(Rect(5, 5, 5, 5), [empty()])
def test_XtermSave_SaveSetState(self): # Turn on auto-wrap esccmd.DECSET(esccmd.DECAWM) # Save the setting esccmd.XTERM_SAVE(esccmd.DECAWM) # Turn off auto-wrap esccmd.DECRESET(esccmd.DECAWM) # Restore the setting esccmd.XTERM_RESTORE(esccmd.DECAWM) # Verify that auto-wrap is on size = GetScreenSize() esccmd.CUP(Point(size.width() - 1, 1)) escio.Write("xxx") AssertEQ(GetCursorPosition().x(), 2)
def test_IL_ScrollsOffBottom(self): """Lines should be scrolled off the bottom of the screen.""" height = GetScreenSize().height() for i in xrange(height): esccmd.CUP(Point(1, i + 1)) escio.Write("%04d" % (i + 1)) esccmd.CUP(Point(1, 2)) esccmd.IL() expected = 1 for i in xrange(height): y = i + 1 if y == 2: AssertScreenCharsInRectEqual(Rect(1, y, 4, y), [NUL * 4]) else: AssertScreenCharsInRectEqual(Rect(1, y, 4, y), ["%04d" % expected]) expected += 1
def test_CPL_StopsAtTopLineWhenBegunAboveScrollRegion(self): """When the cursor starts above the scroll region, CPL moves it up to the top of the screen.""" # Set a scroll region. This must be done first because DECSTBM moves the cursor to the origin. esccmd.DECSTBM(4, 5) esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(5, 10) # Position the cursor below the scroll region esccmd.CUP(Point(7, 3)) # Move it up by a lot height = GetScreenSize().height() esccmd.CPL(height) # Ensure it stopped at the top of the screen position = GetCursorPosition() AssertEQ(position.y(), 1) AssertEQ(position.x(), 5)
def test_CNL_StopsAtBottomLineWhenBegunBelowScrollRegion(self): """When the cursor starts below the scroll region, CNL moves it down to the bottom of the screen.""" # Set a scroll region. This must be done first because DECSTBM moves the cursor to the origin. esccmd.DECSTBM(4, 5) esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(5, 10) # Position the cursor below the scroll region esccmd.CUP(Point(7, 6)) # Move it down by a lot height = GetScreenSize().height() esccmd.CNL(height) # Ensure it stopped at the bottom of the screen position = GetCursorPosition() AssertEQ(position.y(), height) AssertEQ(position.x(), 5)
def test_DECSET_MoreFix(self): """xterm supports DECSET 41 to enable a fix for a bug in curses where it would draw to the end of a row and then insert a tab. When 41 is set, the tab is drawn.""" # With MoreFix on, test that writing N x'es followed by a tab leaves the # cursor at the first tab stop. esccmd.DECSET(esccmd.MoreFix) self.fillLineAndWriteTab() AssertEQ(GetCursorPosition().x(), 9) escio.Write("1") AssertScreenCharsInRectEqual(Rect(9, 3, 9, 3), ["1"]) # With MoreFix off, test that writing N x'es followed by a tab leaves the cursor at # the right margin esccmd.DECRESET(esccmd.MoreFix) self.fillLineAndWriteTab() AssertEQ(GetCursorPosition().x(), GetScreenSize().width()) escio.Write("2") AssertScreenCharsInRectEqual(Rect(1, 5, 1, 5), ["2"])
def test_DECSTBM_BottomOfZeroIsBottomOfScreen(self): """A zero value for the bottom arg gives the bottom of the screen.""" # Write "x" at line 3 esccmd.CUP(Point(1, 3)) escio.Write("x") # Set the scroll bottom to below the screen. size = GetScreenSize() esccmd.DECSTBM(2, 0) # Move the cursor to the last line and write a newline. esccmd.CUP(Point(1, size.height())) escio.Write(CR + LF) # Verify that line 3 scrolled up to line 2. AssertScreenCharsInRectEqual(Rect(1, 2, 1, 3), ["x", empty()]) # Verify the cursor is at the last line on the page. AssertEQ(GetCursorPosition().y(), size.height())
def test_DECALN_FillsScreen(self): """Makes sure DECALN fills the screen with the letter E (could be anything, but xterm uses E). Testing the whole screen would be slow so we just check the corners and center.""" esccmd.DECALN() size = GetScreenSize() AssertScreenCharsInRectEqual(Rect(1, 1, 1, 1), ["E"]) AssertScreenCharsInRectEqual(Rect(size.width(), 1, size.width(), 1), ["E"]) AssertScreenCharsInRectEqual(Rect(1, size.height(), 1, size.height()), ["E"]) AssertScreenCharsInRectEqual( Rect(size.width(), size.height(), size.width(), size.height()), ["E"]) AssertScreenCharsInRectEqual( Rect(size.width() / 2, size.height() / 2, size.width() / 2, size.height() / 2), ["E"])
def test_DL_DefaultParam(self): """DL with no parameter should delete a single line.""" # Set up the screen with 0001, 0002, ..., height self.prepare() # Delete the second line, moving subsequent lines up. esccmd.DL() # Build an array of 0001, 0003, 0004, ..., height height = GetScreenSize().height() y = 1 expected_lines = [] for i in xrange(height): if y != 2: expected_lines.append("%04d" % y) y += 1 # The last line should be blank expected_lines.append(NUL * 4) AssertScreenCharsInRectEqual(Rect(1, 1, 4, height), expected_lines)
def fillRectangle_overlyLargeSourceClippedToScreenSize(self): size = GetScreenSize() # Put ab, cX in the bottom right esccmd.CUP(Point(size.width() - 1, size.height() - 1)) escio.Write("ab") esccmd.CUP(Point(size.width() - 1, size.height())) escio.Write("cd") # Fill a 2x2 block starting at the d. self.fill(top=size.height(), left=size.width(), bottom=size.height() + 10, right=size.width() + 10) AssertScreenCharsInRectEqual(Rect(size.width() - 1, size.height() - 1, size.width(), size.height()), ["ab", "c" + self.characters(Point(size.width(), size.height()), 1)])
def test_DECSTBM_TopBelowBottom(self): """The value of the top margin (Pt) must be less than the bottom margin (Pb).""" size = GetScreenSize() esccmd.DECSTBM(3, 3) for i in xrange(size.height()): escio.Write("%04d" % i) y = i + 1 if y != size.height(): escio.Write(CR + LF) for i in xrange(size.height()): y = i + 1 AssertScreenCharsInRectEqual(Rect(1, y, 4, y), ["%04d" % i]) esccmd.CUP(Point(1, size.height())) escio.Write(LF) for i in xrange(size.height() - 1): y = i + 1 AssertScreenCharsInRectEqual(Rect(1, y, 4, y), ["%04d" % (i + 1)]) y = size.height() AssertScreenCharsInRectEqual(Rect(1, y, 4, y), [NUL * 4])
def test_VT_StopsAtBottomLineWhenBegunBelowScrollRegion(self): """When the cursor starts below the scroll region, index moves it down to the bottom of the screen but won't scroll.""" # Set a scroll region. This must be done first because DECSTBM moves the cursor to the origin. esccmd.DECSTBM(4, 5) # Position the cursor below the scroll region esccmd.CUP(Point(1, 6)) escio.Write("x") # Move it down by a lot height = GetScreenSize().height() for i in xrange(height): escio.Write(VT) # Ensure it stopped at the bottom of the screen AssertEQ(GetCursorPosition().y(), height) # Ensure no scroll AssertScreenCharsInRectEqual(Rect(1, 6, 1, 6), ["x"])
def fillRectangle_defaultArgs(self): """Write a value at each corner, run fill with no args, and verify the corners have all been replaced with self.character.""" size = GetScreenSize() points = [Point(1, 1), Point(size.width(), 1), Point(size.width(), size.height()), Point(1, size.height())] n = 1 for point in points: esccmd.CUP(point) escio.Write(str(n)) n += 1 self.fill() for point in points: AssertScreenCharsInRectEqual( Rect(point.x(), point.y(), point.x(), point.y()), [self.characters(point, 1)])
def test_SD_CanClearScreen(self): """An SD equal to the height of the screen clears it. Some older versions of xterm failed this test, due to an incorrect fix for debugging-assertions in patch #318. That was corrected in #332. """ # Fill the screen with 0001, 0002, ..., height. Fill expected_lines with empty rows. height = GetScreenSize().height() expected_lines = [] for i in xrange(height): y = i + 1 esccmd.CUP(Point(1, y)) escio.Write("%04d" % y) expected_lines.append(empty() * 4) # Scroll by |height| esccmd.SD(height) # Ensure the screen is empty AssertScreenCharsInRectEqual(Rect(1, 1, 4, height), expected_lines)
def test_DECSET_Allow80To132(self): """DECCOLM only has an effect if Allow80To132 is on.""" # There are four tests: # Allowed Not allowed # 80->132 1 3 # 132->80 2 4 # Test 1: 80->132, allowed # Allow 80 to 132. esccmd.DECSET(esccmd.Allow80To132) if GetScreenSize().width() == 132: # Enter 80 columns so the test can proceed. esccmd.DECRESET(esccmd.DECCOLM) AssertEQ(GetScreenSize().width(), 80) # Enter 132 esccmd.DECSET(esccmd.DECCOLM) AssertEQ(GetScreenSize().width(), 132) # Test 2: 132->80, allowed esccmd.DECRESET(esccmd.DECCOLM) AssertEQ(GetScreenSize().width(), 80) # Test 3: 80->132 # Disallow 80 to 132 esccmd.DECRESET(esccmd.Allow80To132) # Try to enter 132 - should do nothing. esccmd.DECSET(esccmd.DECCOLM) AssertEQ(GetScreenSize().width(), 80) # Allow 80 to 132 esccmd.DECSET(esccmd.Allow80To132) # Enter 132 esccmd.DECSET(esccmd.DECCOLM) AssertEQ(GetScreenSize().width(), 132) # Disallow 80 to 132 esccmd.DECRESET(esccmd.Allow80To132) # Try to enter 80 - should do nothing. esccmd.DECRESET(esccmd.DECCOLM) AssertEQ(GetScreenSize().width(), 132)
def test_RI_StopsAtTopLineWhenBegunAboveScrollRegion(self): """When the cursor starts above the scroll region, reverse index moves it up to the top of the screen but won't scroll.""" # Set a scroll region. This must be done first because DECSTBM moves the # cursor to the origin. esccmd.DECSTBM(4, 5) # Position the cursor above the scroll region esccmd.CUP(Point(1, 3)) escio.Write("x") # Move it up by a lot height = GetScreenSize().height() for _ in xrange(height): esccmd.RI() # Ensure it stopped at the top of the screen AssertEQ(GetCursorPosition().y(), 1) # Ensure no scroll AssertScreenCharsInRectEqual(Rect(1, 3, 1, 3), ["x"])
def test_DECCRA_overlyLargeSourceClippedToScreenSize(self): size = GetScreenSize() # Put ab, cX in the bottom right esccmd.CUP(Point(size.width() - 1, size.height() - 1)) escio.Write("ab") esccmd.CUP(Point(size.width() - 1, size.height())) escio.Write("cX") # Copy a 2x2 block starting at the X to the a esccmd.DECCRA(source_top=size.height(), source_left=size.width(), source_bottom=size.height() + 1, source_right=size.width() + 1, source_page=1, dest_top=size.height() - 1, dest_left=size.width() - 1, dest_page=1) AssertScreenCharsInRectEqual( Rect(size.width() - 1, size.height() - 1, size.width(), size.height()), ["Xb", "cX"])
def test_DL_ExplicitParam(self): """DL should delete the given number of lines.""" # Set up the screen with 0001, 0002, ..., height self.prepare() # Delete two lines starting at the second line, moving subsequent lines up. esccmd.DL(2) # Build an array of 0001, 0004, ..., height height = GetScreenSize().height() y = 1 expected_lines = [] for i in xrange(height): if y < 2 or y > 3: expected_lines.append("%04d" % y) y += 1 # The last two lines should be blank expected_lines.append(NUL * 4) expected_lines.append(NUL * 4) AssertScreenCharsInRectEqual(Rect(1, 1, 4, height), expected_lines)
def test_FF_Scrolls(self): """FF scrolls when it hits the bottom.""" height = GetScreenSize().height() # Put a and b on the last two lines. esccmd.CUP(Point(2, height - 1)) escio.Write("a") esccmd.CUP(Point(2, height)) escio.Write("b") # Move to penultimate line. esccmd.CUP(Point(2, height - 1)) # Move down, ensure no scroll yet. escio.Write(FF) AssertEQ(GetCursorPosition().y(), height) AssertScreenCharsInRectEqual(Rect(2, height - 2, 2, height), [ NUL, "a", "b" ]) # Move down, ensure scroll. escio.Write(FF) AssertEQ(GetCursorPosition().y(), height) AssertScreenCharsInRectEqual(Rect(2, height - 2, 2, height), [ "a", "b", NUL ])
def test_DECSET_DECAWM_CursorAtRightMargin(self): """If you start at column 1 and write N+1 characters (where N is the width of the window) the cursor's position should go: 1, 2, ..., N, N, 2.""" esccmd.DECSET(esccmd.DECAWM) size = GetScreenSize() # 1, 2, ... N - 2 AssertEQ(GetCursorPosition().x(), 1) for _ in xrange(size.width() - 2): escio.Write("x") AssertEQ(GetCursorPosition().x(), size.width() - 1) # Write the N-1th character, cursor enters the right margin. escio.Write("x") AssertEQ(GetCursorPosition().x(), size.width()) # Nth: cursor still at right margin! escio.Write("x") AssertEQ(GetCursorPosition().x(), size.width()) # N+1th: cursor wraps around to second position. escio.Write("x") AssertEQ(GetCursorPosition().x(), 2)