-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeviceControlStringTest.java
More file actions
53 lines (46 loc) · 2.08 KB
/
Copy pathDeviceControlStringTest.java
File metadata and controls
53 lines (46 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.termux.terminal;
/**
* "\033P" is a device control string.
*/
public class DeviceControlStringTest extends TerminalTestCase {
private static String hexEncode(String s) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < s.length(); i++)
result.append(String.format("%02X", (int) s.charAt(i)));
return result.toString();
}
private void assertCapabilityResponse(String cap, String expectedResponse) {
String input = "\033P+q" + hexEncode(cap) + "\033\\";
assertEnteringStringGivesResponse(input, "\033P1+r" + hexEncode(cap) + "=" + hexEncode(expectedResponse) + "\033\\");
}
public void testReportColorsAndName() {
// Request Termcap/Terminfo String. The string following the "q" is a list of names encoded in
// hexadecimal (2 digits per character) separated by ; which correspond to termcap or terminfo key
// names.
// Two special features are also recognized, which are not key names: Co for termcap colors (or colors
// for terminfo colors), and TN for termcap name (or name for terminfo name).
// xterm responds with DCS 1 + r P t ST for valid requests, adding to P t an = , and the value of the
// corresponding string that xterm would send, or DCS 0 + r P t ST for invalid requests. The strings are
// encoded in hexadecimal (2 digits per character).
withTerminalSized(3, 3).enterString("A");
assertCapabilityResponse("Co", "256");
assertCapabilityResponse("colors", "256");
assertCapabilityResponse("TN", "xterm");
assertCapabilityResponse("name", "xterm");
enterString("B").assertLinesAre("AB ", " ", " ");
}
public void testReportKeys() {
withTerminalSized(3, 3);
assertCapabilityResponse("kB", "\033[Z");
}
public void testReallyLongDeviceControlString() {
withTerminalSized(3, 3).enterString("\033P");
for (int i = 0; i < 10000; i++) {
enterString("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
}
// The terminal should ignore the overlong DCS sequence and continue printing "aaa." and fill at least the first two lines with
// them:
assertLineIs(0, "aaa");
assertLineIs(1, "aaa");
}
}