def test_HVP_OutOfBoundsParams(self): """With overly large parameters, HVP moves as far as possible down and right.""" size = GetScreenSize() esccmd.HVP(Point(size.width() + 10, size.height() + 10)) position = GetCursorPosition() AssertEQ(position.x(), size.width()) AssertEQ(position.y(), size.height())
def test_DECSET_DECAWM_TabDoesNotWrapAround(self): """In auto-wrap mode, tabs to not wrap to the next line.""" esccmd.DECSET(esccmd.DECAWM) size = GetScreenSize() for i in xrange(size.width() / 8 + 2): escio.Write(TAB) AssertEQ(GetCursorPosition().x(), size.width()) AssertEQ(GetCursorPosition().y(), 1)
def test_DECSET_ReverseWraparound_Multi(self): size = GetScreenSize() esccmd.CUP(Point(size.width() - 1, 1)) escio.Write("abcd") esccmd.DECSET(esccmd.ReverseWraparound) esccmd.DECSET(esccmd.DECAWM) esccmd.CUB(4) AssertEQ(GetCursorPosition().x(), size.width() - 1)
def test_CUP_OutOfBoundsParams(self): """With overly large parameters, CUP moves as far as possible down and right.""" size = GetScreenSize() esccmd.CUP(Point(size.width() + 10, size.height() + 10)) position = GetCursorPosition() AssertEQ(position.x(), size.width()) AssertEQ(position.y(), size.height())
def test_DECSET_ReverseWraparound_Multi(self): size = GetScreenSize() esccmd.CUP(Point(size.width() - 1, 1)) escio.Write("abcd") esccmd.DECSET(esccmd.ReverseWraparound) esccmd.DECSET(esccmd.DECAWM) esccmd.CUB(4) AssertEQ(GetCursorPosition().x(), size.width() - 1)
def test_DECFI_WholeScreenScrolls(self): """Starting with the cursor at the right edge of the page (outside the margins), verify that DECFI is ignored.""" size = GetScreenSize() esccmd.CUP(Point(size.width(), 1)) escio.Write("x") esccmd.DECFI() AssertScreenCharsInRectEqual( Rect(size.width() - 1, 1, size.width(), 1), ["x" + empty()])
def test_BS_CursorStartsInDoWrapPosition(self): """Cursor is right of right edge of screen.""" size = GetScreenSize() esccmd.CUP(Point(size.width() - 1, 1)) escio.Write("ab") escio.Write(esc.BS) escio.Write("X") AssertScreenCharsInRectEqual( Rect(size.width() - 1, 1, size.width(), 1), ["Xb"])
def test_DECSET_DECAWM_TabDoesNotWrapAround(self): """In auto-wrap mode, tabs to not wrap to the next line.""" esccmd.DECSET(esccmd.DECAWM) size = GetScreenSize() for i in xrange(size.width() / 8 + 2): escio.Write(TAB) AssertEQ(GetCursorPosition().x(), size.width()) AssertEQ(GetCursorPosition().y(), 1) escio.Write("X")
def test_BS_CursorStartsInDoWrapPosition(self): """Cursor is right of right edge of screen.""" size = GetScreenSize() esccmd.CUP(Point(size.width() - 1, 1)) escio.Write("ab") escio.Write(esc.BS) escio.Write("X") AssertScreenCharsInRectEqual(Rect(size.width() - 1, 1, size.width(), 1), [ "Xb" ])
def test_DECFI_WholeScreenScrolls(self): """The spec is confusing and contradictory. It first says "If the cursor is at the right margin, then all screen data within the margin moves one column to the left" and then says "DECFI is not affected by the margins." I don't know what they could mean by the second part.""" size = GetScreenSize() esccmd.CUP(Point(size.width(), 1)) escio.Write("x") esccmd.DECFI() AssertScreenCharsInRectEqual(Rect(size.width() - 1, 1, size.width(), 1), [ "x" + NUL ])
def test_XtermWinops_ResizePixels_ZeroWidth(self): """Resize the window to a pixel size, setting one parameter to 0. The window should maximize in the direction of the 0 parameter.""" if escargs.args.expected_terminal == "xterm": maximum_size = GetScreenSizePixels() original_size = GetWindowSizePixels() # Set height and maximize width. desired_size = Size(maximum_size.width(), self.AverageHeight(maximum_size, original_size)) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, desired_size.height(), 0) self.DelayAfterResize() self.CheckActualSizePixels(desired_size) # See if the width is about as big as the display (only measurable in # characters, not pixels). display_size = GetDisplaySize() # In characters screen_size = GetScreenSize() # In characters max_error = 5 AssertTrue(abs(display_size.width() - screen_size.width()) < max_error) # Restore to original size. esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, original_size.height(), original_size.width()) self.DelayAfterResize() else: original_size = GetWindowSizePixels() # Set height and maximize width. desired_height = 200 esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, desired_height, 0) # Make sure the height changed as requested. max_error = 20 actual_size = GetWindowSizePixels() AssertTrue(abs(actual_size.height() - desired_height) < max_error) # See if the width is about as big as the display (only measurable in # characters, not pixels). display_size = GetDisplaySize() # In characters screen_size = GetScreenSize() # In characters max_error = 5 AssertTrue(abs(display_size.width() - screen_size.width()) < max_error) # Restore to original size. esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, original_size.height(), original_size.width())
def test_SM_IRM_DoesNotWrapUnlessCursorAtMargin(self): """Insert mode does not cause wrapping.""" size = GetScreenSize() escio.Write("a" * (size.width() - 1)) escio.Write("b") esccmd.CUP(Point(1, 1)) esccmd.SM(esccmd.IRM) AssertScreenCharsInRectEqual(Rect(1, 2, 1, 2), [empty()]) escio.Write("X") AssertScreenCharsInRectEqual(Rect(1, 2, 1, 2), [empty()]) esccmd.CUP(Point(size.width(), 1)) escio.Write("YZ") AssertScreenCharsInRectEqual(Rect(1, 2, 1, 2), ["Z"])
def test_DECSET_ReverseWraparoundLastCol_BS(self): """If the cursor is in the last column and a character was just output and reverse-wraparound is on then backspace by 1 has no effect.""" esccmd.DECSET(esccmd.ReverseWraparound) esccmd.DECSET(esccmd.DECAWM) size = GetScreenSize() esccmd.CUP(Point(size.width() - 1, 1)) escio.Write("a") AssertEQ(GetCursorPosition().x(), size.width()) escio.Write("b") AssertEQ(GetCursorPosition().x(), size.width()) escio.Write(BS) AssertEQ(GetCursorPosition().x(), size.width())
def test_HPR_StopsAtRightEdge(self): """HPR won't go past the right edge.""" # Position on 6th row esccmd.CUP(Point(5, 6)) # Try to move 10 past the right edge size = GetScreenSize() esccmd.HPR(size.width() + 10) # Ensure at the right edge on same row position = GetCursorPosition() AssertEQ(position.x(), size.width()) AssertEQ(position.y(), 6)
def test_HPA_StopsAtRightEdge(self): """HPA won't go past the right edge.""" # Position on 6th row esccmd.CUP(Point(5, 6)) # Try to move 10 past the right edge size = GetScreenSize() esccmd.HPA(size.width() + 10) # Ensure at the right edge on same row position = GetCursorPosition() AssertEQ(position.x(), size.width()) AssertEQ(position.y(), 6)
def test_SM_IRM_DoesNotWrapUnlessCursorAtMargin(self): """Insert mode does not cause wrapping.""" size = GetScreenSize() escio.Write("a" * (size.width() - 1)) escio.Write("b") esccmd.CUP(Point(1, 1)) esccmd.SM(esccmd.IRM) AssertScreenCharsInRectEqual(Rect(1, 2, 1, 2), [ NUL ]) escio.Write("X") AssertScreenCharsInRectEqual(Rect(1, 2, 1, 2), [ NUL ]) esccmd.CUP(Point(size.width(), 1)) escio.Write("YZ") AssertScreenCharsInRectEqual(Rect(1, 2, 1, 2), [ "Z" ])
def test_DECSET_ReverseWraparoundLastCol_BS(self): """If the cursor is in the last column and a character was just output and reverse-wraparound is on then backspace by 1 has no effect.""" esccmd.DECSET(esccmd.ReverseWraparound) esccmd.DECSET(esccmd.DECAWM) size = GetScreenSize() esccmd.CUP(Point(size.width() - 1, 1)) escio.Write("a") AssertEQ(GetCursorPosition().x(), size.width()) escio.Write("b") AssertEQ(GetCursorPosition().x(), size.width()) escio.Write(BS) AssertEQ(GetCursorPosition().x(), size.width())
def test_XtermWinops_ResizeChars_DefaultWidth(self): original_size = GetScreenSize() display_size = GetDisplaySize() if escargs.args.expected_terminal == "xterm": desired_size = Size( original_size.width(), self.AverageHeight(original_size, display_size)) else: desired_size = Size(original_size.width(), 21) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_CHARS, desired_size.height()) self.DelayAfterResize() self.CheckActualSizeChars(desired_size, Size(0, 0))
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_DECCRA_destinationPartiallyOffscreen(self): self.prepare() size = GetScreenSize() esccmd.DECCRA(source_top=2, source_left=2, source_bottom=4, source_right=4, 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()), ["jk", "rs"])
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_XtermWinops_MaximizeWindow_Vertically(self): display_size = GetDisplaySize() original_size = GetScreenSize() expected_size = Size(width=original_size.width(), height=display_size.height()) esccmd.XTERM_WINOPS(esccmd.WINOP_MAXIMIZE, esccmd.WINOP_MAXIMIZE_V) AssertEQ(GetScreenSize(), expected_size)
def test_XtermWinops_ResizeChars_DefaultWidth(self): size = GetScreenSize() desired_size = Size(size.width(), 21) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_CHARS, desired_size.height()) AssertEQ(GetScreenSize(), desired_size)
def test_XtermWinops_ResizePixels_ZeroWidth(self): """Resize the window to a pixel size, setting one parameter to 0. The window should maximize in the direction of the 0 parameter.""" original_size = GetWindowSizePixels() # Set height and maximize width. desired_height = 200 esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, desired_height, 0) # Make sure the height changed as requested. max_error = 20 actual_size = GetWindowSizePixels() AssertTrue(abs(actual_size.height() - desired_height) < max_error) # See if the width is about as big as the display (only measurable in # characters, not pixels). display_size = GetDisplaySize() # In characters screen_size = GetScreenSize() # In characters max_error = 5 AssertTrue(abs(display_size.width() - screen_size.width()) < max_error) # Restore to original size. esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, original_size.height(), original_size.width())
def test_BS_WrapsInWraparoundMode(self): esccmd.DECSET(esccmd.DECAWM) esccmd.DECSET(esccmd.ReverseWraparound) esccmd.CUP(Point(1, 3)) escio.Write(esc.BS) size = GetScreenSize() AssertEQ(GetCursorPosition(), Point(size.width(), 2))
def test_BS_WrapsInWraparoundMode(self): esccmd.DECSET(esccmd.DECAWM) esccmd.DECSET(esccmd.ReverseWraparound) esccmd.CUP(Point(1, 3)) escio.Write(esc.BS) size = GetScreenSize() AssertEQ(GetCursorPosition(), Point(size.width(), 2))
def test_DECCRA_destinationPartiallyOffscreen(self): self.prepare() size = GetScreenSize() esccmd.DECCRA(source_top=2, source_left=2, source_bottom=4, source_right=4, 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()), [ "jk", "rj" ])
def test_XtermSave_SaveResetState(self): # Turn off auto-wrap esccmd.DECRESET(esccmd.DECAWM) # Save the setting esccmd.XTERM_SAVE(esccmd.DECAWM) # Turn on auto-wrap esccmd.DECSET(esccmd.DECAWM) # Restore the setting esccmd.XTERM_RESTORE(esccmd.DECAWM) # Verify that auto-wrap is of size = GetScreenSize() esccmd.CUP(Point(size.width() - 1, 1)) escio.Write("xxx") AssertEQ(GetCursorPosition().x(), size.width())
def test_XtermSave_SaveResetState(self): # Turn off auto-wrap esccmd.DECRESET(esccmd.DECAWM) # Save the setting esccmd.XTERM_SAVE(esccmd.DECAWM) # Turn on auto-wrap esccmd.DECSET(esccmd.DECAWM) # Restore the setting esccmd.XTERM_RESTORE(esccmd.DECAWM) # Verify that auto-wrap is of size = GetScreenSize() esccmd.CUP(Point(size.width() - 1, 1)) escio.Write("xxx") AssertEQ(GetCursorPosition().x(), size.width())
def test_XtermWinops_Fullscreen(self): original_size = GetScreenSize() display_size = GetDisplaySize() # Enter fullscreen esccmd.XTERM_WINOPS(esccmd.WINOP_FULLSCREEN, esccmd.WINOP_FULLSCREEN_ENTER) time.sleep(1) actual_size = GetScreenSize() AssertTrue(actual_size.width() >= display_size.width()) AssertTrue(actual_size.height() >= display_size.height()) AssertTrue(actual_size.width() >= original_size.width()) AssertTrue(actual_size.height() >= original_size.height()) # Exit fullscreen esccmd.XTERM_WINOPS(esccmd.WINOP_FULLSCREEN, esccmd.WINOP_FULLSCREEN_EXIT) AssertEQ(GetScreenSize(), original_size) # Toggle in esccmd.XTERM_WINOPS(esccmd.WINOP_FULLSCREEN, esccmd.WINOP_FULLSCREEN_TOGGLE) AssertTrue(actual_size.width() >= display_size.width()) AssertTrue(actual_size.height() >= display_size.height()) AssertTrue(actual_size.width() >= original_size.width()) AssertTrue(actual_size.height() >= original_size.height()) # Toggle out esccmd.XTERM_WINOPS(esccmd.WINOP_FULLSCREEN, esccmd.WINOP_FULLSCREEN_TOGGLE) AssertEQ(GetScreenSize(), original_size)
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 i 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)
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)
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 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 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_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 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 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_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_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_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 fillLineAndWriteTab(self): escio.Write(CR + LF) size = GetScreenSize() for _ in xrange(size.width()): escio.Write("x") escio.Write(TAB)
def fillLineAndWriteTab(self): escio.Write(CR + LF) size = GetScreenSize() for i in xrange(size.width()): escio.Write("x") escio.Write(TAB)
def test_DECFI_NoWrapOnRightEdge(self): size = GetScreenSize() esccmd.CUP(Point(size.width(), 2)) esccmd.DECFI() AssertEQ(GetCursorPosition(), Point(size.width(), 2))