def GetPixelErrorLimit(self): """Returns a Size denoting the expected error limit for pixel-based resizing tests. For xterm, there are two cases for pixel-based resizing: a) WINOP_RESIZE_PIXELS, which requests that the (inner) text-window be resize, and b) the various "maximize" operations, which operate directly on the (outer) shell window. They both run into the same constraint: xterm uses window manager hints to request that the window manager keep the size of the text window an multiple of the character cell-size. Most window managers ignore those hints when asked to maximize a window, and will produce a window with cut-off rows/columns. While it is "always" true that one can use xwininfo with xterm's $WINDOWID to obtain the dimensions of the shell-window, xterm patch 333 adds a control sequence which returns this information.""" if escargs.args.expected_terminal in ["xterm"]: cells = 3 if CanQueryShellSize() == 2: cells = 1 frame = GetFrameSizePixels() chars = GetCharSizePixels() return Size(frame.width() + cells * chars.width(), frame.height() + cells * chars.height()) else: return Size(20, 20)
def GetCharErrorLimit(self): """Returns a Size denoting the expected error limit for character- based resizing tests.""" if escargs.args.expected_terminal == "xterm": return Size(2, 2) else: return Size(0, 0)
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_ResizeChars_BothParameters(self): """Resize the window to a character size, giving both parameters.""" desired_size = Size(20, 21) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_CHARS, desired_size.height(), desired_size.width()) AssertEQ(GetScreenSize(), desired_size)
def test_XtermWinops_ResizeChars_ZeroHeight(self): """Resize the window to a character size, setting one param to 0 (max size in that direction).""" max_size = GetDisplaySize() desired_size = Size(20, max_size.height()) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_CHARS, 0, desired_size.width()) AssertEQ(GetScreenSize(), desired_size)
def CheckAnySize(self, desired_size, actual_size, limit): """After resizing a window, check if its actual size is within the test's limits of the desired size.""" self.DebugSize("actual size ", actual_size) self.DebugSize("desired size ", desired_size) error = Size(abs(actual_size.width() - desired_size.width()), abs(actual_size.height() - desired_size.height())) self.DebugSize("error limit ", limit) self.DebugSize("actual error ", error) AssertTrue(error.width() <= (limit.width())) AssertTrue(error.height() <= (limit.height()), "actual size=%s, desired size=%s, error limit=%s, actual error=%s" % (str(actual_size), str(desired_size), str(limit), str(error)))
def test_XtermWinops_DECSLPP(self): """Resize to n lines of height.""" esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_CHARS, 10, 90) AssertEQ(GetScreenSize(), Size(90, 10)) esccmd.XTERM_WINOPS(24) AssertEQ(GetScreenSize(), Size(90, 24)) esccmd.XTERM_WINOPS(30) AssertEQ(GetScreenSize(), Size(90, 30))
def test_XtermWinops_ResizePixels_ZeroHeight(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(self.AverageWidth(maximum_size, original_size), maximum_size.height()) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, 0, desired_size.width()) self.DelayAfterResize() self.CheckActualSizePixels(desired_size) # See if the height 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.height() - screen_size.height()) < 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_width = 400 esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, 0, desired_width) # Make sure the height changed as requested. max_error = 20 actual_size = GetWindowSizePixels() AssertTrue(abs(actual_size.width() - desired_width) < max_error) # See if the height 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.height() - screen_size.height()) < max_error) # Restore to original size. esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, original_size.height(), original_size.width())
def test_XtermWinops_MaximizeWindow_Vertically(self): desired_size = Size(GetScreenSize().width(), GetDisplaySize().height()) esccmd.XTERM_WINOPS(esccmd.WINOP_MAXIMIZE, esccmd.WINOP_MAXIMIZE_V) self.DelayAfterResize() actual_size = GetScreenSize() esccmd.XTERM_WINOPS(esccmd.WINOP_MAXIMIZE, esccmd.WINOP_MAXIMIZE_EXIT) self.DelayAfterResize() if escargs.args.expected_terminal == "xterm": error_limit = Size(0, 5) else: error_limit = Size(0, 0) self.CheckAnySize(desired_size, actual_size, Size(0, 5))
def test_XtermWinops_MaximizeWindow_HorizontallyAndVertically(self): esccmd.XTERM_WINOPS(esccmd.WINOP_MAXIMIZE, esccmd.WINOP_MAXIMIZE_HV) self.DelayAfterResize() actual_size = GetScreenSize() desired_size = GetDisplaySize() esccmd.XTERM_WINOPS(esccmd.WINOP_MAXIMIZE, esccmd.WINOP_MAXIMIZE_EXIT) self.DelayAfterResize() if escargs.args.expected_terminal == "xterm": error_limit = Size(3, 3) else: error_limit = Size(0, 0) self.CheckAnySize(desired_size, actual_size, error_limit)
def GetWindowSizePixels(): """Returns a Size giving the window's size in pixels.""" esccmd.XTERM_WINOPS(esccmd.WINOP_REPORT_WINDOW_SIZE_PIXELS) params = escio.ReadCSI("t") AssertTrue(params[0] == 4) AssertTrue(len(params) >= 3) return Size(params[2], params[1])
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 GetCharSizePixels(): """Returns a Size giving the font's character-size in pixels. While xterm can be told to change its font, none of these tests exercise that feature. We cache a value to improve performance. """ global gCharSizePixels if gCharSizePixels.height() == 0: esccmd.XTERM_WINOPS(esccmd.WINOP_REPORT_CHAR_SIZE_PIXELS) params = escio.ReadCSI("t") AssertTrue(params[0] == 6) AssertTrue(len(params) >= 3) gCharSizePixels = Size(params[2], params[1]) LogDebug("size of CHARS " + str(gCharSizePixels.height()) + "x" + str(gCharSizePixels.width())) return gCharSizePixels
def test_XtermWinops_Fullscreen(self): original_size = GetScreenSize() display_size = GetDisplaySize() # Enter fullscreen esccmd.XTERM_WINOPS(esccmd.WINOP_FULLSCREEN, esccmd.WINOP_FULLSCREEN_ENTER) self.DelayAfterResize() actual_size = GetScreenSize() self.CheckAnySize(display_size, actual_size, Size(3, 3)) self.CheckForShrinkage(original_size, actual_size) # Exit fullscreen esccmd.XTERM_WINOPS(esccmd.WINOP_FULLSCREEN, esccmd.WINOP_FULLSCREEN_EXIT) self.DelayAfterResize() self.CheckForShrinkage(original_size, GetScreenSize()) # Toggle in esccmd.XTERM_WINOPS(esccmd.WINOP_FULLSCREEN, esccmd.WINOP_FULLSCREEN_TOGGLE) self.DelayAfterResize() self.CheckForShrinkage(original_size, GetScreenSize()) # Toggle out esccmd.XTERM_WINOPS(esccmd.WINOP_FULLSCREEN, esccmd.WINOP_FULLSCREEN_TOGGLE) self.DelayAfterResize() self.CheckForShrinkage(original_size, GetScreenSize())
def GetScreenSize(): """Return the terminal's screen-size in characters. The size is reported for the terminal's character-cell window, which is smaller than the shell-window.""" esccmd.XTERM_WINOPS(esccmd.WINOP_REPORT_TEXT_AREA_CHARS) params = escio.ReadCSI("t") return Size(params[2], params[1])
def GetFrameSizePixels(): """Returns a Size giving the terminal's border/title frame size. The frame size is used to adjust the expected error in window-resizing tests which modify the shell window's size. """ global gFrameSizePixels if gFrameSizePixels.height() == 0: GetCharSizePixels() outer = GetWindowSizePixels() inner = GetScreenSize() gFrameSizePixels = Size( outer.height() - (inner.height() * gCharSizePixels.height()), outer.width() - (inner.width() * gCharSizePixels.width())) LogDebug("size of FRAME " + str(gFrameSizePixels.height()) + "x" + str(gFrameSizePixels.width())) return gFrameSizePixels
def test_XtermWinops_ResizePixels_OmittedHeight(self): """Resize the window to a pixel size, omitting one parameter. The size should not change in the direction of the omitted parameter.""" maximum_size = GetScreenSizePixels() original_size = GetWindowSizePixels() if escargs.args.expected_terminal == "xterm": desired_size = Size(maximum_size.width(), original_size.height()) else: desired_size = Size(400, original_size.height()) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, None, desired_size.width()) self.DelayAfterResize() self.CheckActualSizePixels(desired_size) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, original_size.height(), original_size.width()) self.DelayAfterResize()
def test_XtermWinops_ResizePixels_BothParameters(self): """Resize the window to a pixel size, giving both parameters.""" original_size = GetWindowSizePixels() desired_size = Size(400, 200) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, desired_size.height(), desired_size.width()) # See if we're within 20px of the desired size on each dimension. It won't # be exact because most terminals snap to grid. actual_size = GetWindowSizePixels() error = Size(abs(actual_size.width() - desired_size.width()), abs(actual_size.height() - desired_size.height())) max_error = 20 AssertTrue(error.width() <= max_error) AssertTrue(error.height() <= max_error) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, original_size.height(), original_size.width())
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_XtermWinops_ResizePixels_OmittedWidth(self): """Resize the window to a pixel size, omitting one parameter. The size should not change in the direction of the omitted parameter.""" original_size = GetWindowSizePixels() desired_size = Size(original_size.width(), 200) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, desired_size.height()) # See if we're within 20px of the desired size. It won't be exact because # most terminals snap to grid. actual_size = GetWindowSizePixels() error = Size(abs(actual_size.width() - desired_size.width()), abs(actual_size.height() - desired_size.height())) max_error = 20 AssertTrue(error.width() <= max_error) AssertTrue(error.height() <= max_error) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, original_size.height(), original_size.width())
def test_XtermWinops_ResizeChars_DefaultHeight(self): original_size = GetScreenSize() display_size = GetDisplaySize() if escargs.args.expected_terminal == "xterm": desired_size = Size(self.AverageWidth(original_size, display_size), original_size.height()) else: desired_size = Size(20, original_size.height()) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_CHARS, None, desired_size.width()) self.DelayAfterResize() self.CheckActualSizeChars(desired_size, Size(0, 0))
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 CanQueryShellSize(): """Determine if the terminal responds to a request for shell-window size vs text-window size. xterm has two windows of interest: a) the text-window b) the shell-window (i.e., outer window). The shell-window includes the title and other decorations. Unless those are suppressed (an option in some window managers), it will be larger than the terminal's character-cell window. In any case, it also has a border which is normally present. The window operations report for the window-size in pixels was added to xterm to provide an alternate way to measure the text-window (and indirectly, the font size). That is the default operation. Alternatively, the size of the shell window can be returned.""" global gCanQueryShellSize if gCanQueryShellSize < 0: gCanQueryShellSize = 0 # check for the default operation esccmd.XTERM_WINOPS(esccmd.WINOP_REPORT_WINDOW_SIZE_PIXELS) params = escio.ReadCSI("t") if params[0] == 4 and len(params) >= 3: # TODO: compare size_1 with result from text-window size # If it is larger, then that's a special case. size_1 = Size(params[2], params[1]) gCanQueryShellSize = 1 # check for the window-shell operation esccmd.XTERM_WINOPS(esccmd.WINOP_REPORT_WINDOW_SIZE_PIXELS, 2) params = escio.ReadCSI("t") if params[0] == 4 and len(params) >= 3: size_2 = Size(params[2], params[1]) if size_2.height() > size_1.height() and \ size_2.width() > size_1.width(): gCanQueryShellSize = 2 return gCanQueryShellSize
def test_XtermWinops_ResizePixels_BothParameters(self): """Resize the window to a pixel size, giving both parameters.""" maximum_size = GetScreenSizePixels() original_size = GetWindowSizePixels() 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(400, 200) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, desired_size.height(), desired_size.width()) self.DelayAfterResize() self.CheckActualSizePixels(desired_size) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, original_size.height(), original_size.width()) self.DelayAfterResize()
def GetScreenSizePixels(): """Returns a Size giving the screen's size in pixels. The "screen" refers to the X display on which xterm is running. Because that does not change as a result of these tests, we cache a value to help with performance.""" global gScreenSizePixels if gScreenSizePixels.height() == 0: if escargs.args.expected_terminal == "xterm": esccmd.XTERM_WINOPS(esccmd.WINOP_REPORT_SCREEN_SIZE_PIXELS) params = escio.ReadCSI("t") AssertTrue(params[0] == 5) AssertTrue(len(params) >= 3) gScreenSizePixels = Size(params[2], params[1]) else: # iTerm2 doesn't support esccmd.WINOP_REPORT_SCREEN_SIZE_PIXELS so just fake it. gScreenSizePixels = Size(1024, 768) LogDebug("size of SCREEN " + str(gScreenSizePixels.height()) + "x" + str(gScreenSizePixels.width())) return gScreenSizePixels
def GetScreenSize(): esccmd.XTERM_WINOPS(esccmd.WINOP_REPORT_TEXT_AREA_CHARS) params = escio.ReadCSI("t") return Size(params[2], params[1])
import functools import traceback import esc import escargs import esccmd import escio from esclog import LogInfo, LogDebug import esctypes from esctypes import Point, Size, Rect gNextId = 1 gHaveAsserted = False gCharSizePixels = Size(0, 0) gFrameSizePixels = Size(0, 0) gScreenSizePixels = Size(0, 0) gCanQueryShellSize = -1 KNOWN_BUG_TERMINALS = "known_bug_terminals" def Raise(e): if not escargs.args.force: raise e def AssertGE(actual, expected): global gHaveAsserted gHaveAsserted = True if actual < expected:
def GetDisplaySize(): esccmd.XTERM_WINOPS(esccmd.WINOP_REPORT_SCREEN_SIZE_CHARS) params = escio.ReadCSI("t") return Size(params[2], params[1])