def test_XtermWinops_ResizeChars_DefaultHeight(self): size = GetScreenSize() desired_size = Size(20, size.height()) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_CHARS, None, desired_size.width()) 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 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_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 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_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_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 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_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_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 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 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.""" 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