def test_REP_ExplicitParam(self): escio.Write("a") esccmd.REP(2) AssertScreenCharsInRectEqual(Rect(1, 1, 4, 1), ["aaa" + empty()])
def AssertScreenCharsInRectEqual(rect, expected_lines): global gHaveAsserted gHaveAsserted = True AssertVTLevel(4, "checksum") if rect.height() != len(expected_lines): raise esctypes.InternalError( "Height of rect (%d) does not match number of expected lines (%d)" % (rect.height(), len(expected_lines))) # Check each point individually. The dumb checksum algorithm can't distinguish # "ab" from "ba", so equivalence of two multiple-character rects means nothing. # |actual| and |expected| will form human-readable arrays of lines actual = [] expected = [] # Additional information about mismatches. errorLocations = [] for point in rect.points(): y = point.y() - rect.top() x = point.x() - rect.left() expected_line = expected_lines[y] if rect.width() != len(expected_line): fmt = ( "Width of rect (%d) does not match number of characters in expected line " + "index %d, coordinate %d (its length is %d)") raise esctypes.InternalError( fmt % (rect.width(), y, point.y(), len(expected_lines[y]))) expected_checksum = ord(expected_line[x]) actual_checksum = GetChecksumOfRect( Rect(left=point.x(), top=point.y(), right=point.x(), bottom=point.y())) # esctest is only asking for one cell at a time, which simplifies things. if escargs.args.expected_terminal == "xterm": if escargs.args.xterm_checksum < 279: actual_checksum = 0x10000 - actual_checksum # DEC terminals trim trailing blanks if expected_checksum == 0 and actual_checksum == 32: actual_checksum = 0 if len(actual) <= y: actual.append("") if actual_checksum == 0: actual[y] += '.' else: actual[y] += chr(actual_checksum) if len(expected) <= y: expected.append("") if expected_checksum == 0: expected[y] += '.' else: expected[y] += chr(expected_checksum) if expected_checksum != actual_checksum: errorLocations.append( "At %s expected '%c' (0x%02x) but got '%c' (0x%02x)" % (str(point), chr(expected_checksum), expected_checksum, chr(actual_checksum), actual_checksum)) if len(errorLocations) > 0: Raise(esctypes.ChecksumException(errorLocations, actual, expected))
def test_SD_ExplicitParam(self): """SD should scroll the screen down by the number of lines given in the parameter.""" self.prepare() esccmd.SD(2) expected_lines = [NUL * 5, NUL * 5, "abcde", "fghij", "klmno"] AssertScreenCharsInRectEqual(Rect(1, 1, 5, 5), expected_lines)
def test_REP_DefaultParam(self): escio.Write("a") esccmd.REP() AssertScreenCharsInRectEqual(Rect(1, 1, 3, 1), ["aa" + empty()])
def test_DECSEL_0(self): """Should erase to right of cursor.""" self.prepare() esccmd.DECSEL(0) AssertScreenCharsInRectEqual(Rect(1, 1, 10, 1), ["abcd" + 6 * empty()])
def test_SU_DefaultParam(self): """SU with no parameter should scroll the screen contents up one line.""" self.prepare() esccmd.SU() expected_lines = ["fghij", "klmno", "pqrst", "uvwxy", empty() * 5] AssertScreenCharsInRectEqual(Rect(1, 1, 5, 5), expected_lines)
def test_DCH_DefaultParam(self): """DCH with no parameter should delete one character at the cursor.""" escio.Write("abcd") esccmd.CUP(Point(2, 1)) esccmd.DCH() AssertScreenCharsInRectEqual(Rect(1, 1, 4, 1), [ "acd" + NUL ]);
def doAltBuftest(self, code, altGetsClearedBeforeToMain, cursorSaved, movesCursorOnEnter=False): """|code| is the code to test with, either 47 or 1047.""" # Scribble in main screen escio.Write("abc" + CR + LF + "abc") # Switch from main to alt. Cursor should not move. If |cursorSaved| is set, # record the position first to verify that it's restored after DECRESET. if cursorSaved: mainCursorPosition = GetCursorPosition() before = GetCursorPosition() esccmd.DECSET(code) after = GetCursorPosition() if not movesCursorOnEnter: # 1049 moves the cursor on enter AssertEQ(before.x(), after.x()) AssertEQ(before.y(), after.y()) # Scribble in alt screen, clearing it first since who knows what might have # been there. esccmd.ED(2) esccmd.CUP(Point(1, 2)) escio.Write("def" + CR + LF + "def") # Make sure abc is gone AssertScreenCharsInRectEqual(Rect(1, 1, 3, 3), [empty() * 3, "def", "def"]) # Switch to main. Cursor should not move. before = GetCursorPosition() esccmd.DECRESET(code) after = GetCursorPosition() if cursorSaved: AssertEQ(mainCursorPosition.x(), after.x()) AssertEQ(mainCursorPosition.y(), after.y()) else: AssertEQ(before.x(), after.x()) AssertEQ(before.y(), after.y()) # def should be gone, abc should be back. AssertScreenCharsInRectEqual(Rect(1, 1, 3, 3), ["abc", "abc", empty() * 3]) # Switch to alt before = GetCursorPosition() esccmd.DECSET(code) after = GetCursorPosition() if not movesCursorOnEnter: # 1049 moves the cursor on enter AssertEQ(before.x(), after.x()) AssertEQ(before.y(), after.y()) if altGetsClearedBeforeToMain: AssertScreenCharsInRectEqual( Rect(1, 1, 3, 3), [empty() * 3, empty() * 3, empty() * 3]) else: AssertScreenCharsInRectEqual(Rect(1, 1, 3, 3), [empty() * 3, "def", "def"])
def test_ED_2(self): """Erase whole screen.""" self.prepare() esccmd.ED(2) AssertScreenCharsInRectEqual(Rect( 1, 1, 3, 5), [NUL * 3, NUL * 3, NUL * 3, NUL * 3, NUL * 3])
def test_DCH_ExplicitParam(self): """DCH deletes the specified number of parameters.""" escio.Write("abcd") esccmd.CUP(Point(2, 1)) esccmd.DCH(2) AssertScreenCharsInRectEqual(Rect(1, 1, 4, 1), [ "ad" + NUL * 2 ]);
def test_ECH_DefaultParam(self): """Should erase the character under the cursor.""" escio.Write("abc") esccmd.CUP(Point(1, 1)) esccmd.ECH() AssertScreenCharsInRectEqual(Rect(1, 1, 3, 1), [blank() + "bc"])
def test_ECH_ExplicitParam(self): """Should erase N characters starting at the cursor.""" escio.Write("abc") esccmd.CUP(Point(1, 1)) esccmd.ECH(2) AssertScreenCharsInRectEqual(Rect(1, 1, 3, 1), [blank() * 2 + "c"])
def test_SU_ExplicitParam(self): """SU should scroll the screen up by the number of lines given in the parameter.""" self.prepare() esccmd.SU(2) expected_lines = ["klmno", "pqrst", "uvwxy", empty() * 5, empty() * 5] AssertScreenCharsInRectEqual(Rect(1, 1, 5, 5), expected_lines)
def test_IL_DefaultParam(self): """Should insert a single line below the cursor.""" self.prepare_wide() esccmd.IL() AssertScreenCharsInRectEqual(Rect(1, 1, 5, 4), ["abcde", "fghij", NUL * 5, "klmno"])
def test_EL_Default(self): """Should erase to right of cursor.""" self.prepare() esccmd.EL() AssertScreenCharsInRectEqual(Rect(1, 1, 10, 1), [ "abcd" + 6 * NUL ])
def test_IL_ExplicitParam(self): """Should insert two lines below the cursor.""" self.prepare_wide() esccmd.IL(2) AssertScreenCharsInRectEqual(Rect( 1, 1, 5, 5), ["abcde", "fghij", NUL * 5, NUL * 5, "klmno"])
def test_EL_2(self): """Should erase whole line.""" self.prepare() esccmd.EL(2) AssertScreenCharsInRectEqual(Rect(1, 1, 10, 1), [ 10 * NUL ])
def test_RIS_ClearsScreen(self): escio.Write("x") esccmd.RIS() AssertScreenCharsInRectEqual(Rect(1, 1, 1, 1), [empty()])
def test_SD_DefaultParam(self): """SD with no parameter should scroll the screen contents down one line.""" self.prepare() esccmd.SD() expected_lines = [NUL * 5, "abcde", "fghij", "klmno", "pqrst"] AssertScreenCharsInRectEqual(Rect(1, 1, 5, 5), expected_lines)
def test_DECSEL_1(self): """Should erase to left of cursor.""" self.prepare() esccmd.DECSEL(1) AssertScreenCharsInRectEqual(Rect(1, 1, 10, 1), [5 * blank() + "fghij"])
def test_DCS_Unrecognized(self): """An unrecognized DCS code should be swallowed""" escio.WriteDCS("z", "0") AssertScreenCharsInRectEqual(Rect(1, 1, 1, 1), NUL)