-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathByteQueueTest.java
More file actions
54 lines (43 loc) · 1.58 KB
/
Copy pathByteQueueTest.java
File metadata and controls
54 lines (43 loc) · 1.58 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
54
package com.termux.terminal;
import junit.framework.TestCase;
public class ByteQueueTest extends TestCase {
private static void assertArrayEquals(byte[] expected, byte[] actual) {
if (expected.length != actual.length) {
fail("Difference array length");
}
for (int i = 0; i < expected.length; i++) {
if (expected[i] != actual[i]) {
fail("Inequals at index=" + i + ", expected=" + (int) expected[i] + ", actual=" + (int) actual[i]);
}
}
}
public void testCompleteWrites() throws Exception {
ByteQueue q = new ByteQueue(10);
assertTrue(q.write(new byte[]{1, 2, 3}, 0, 3));
byte[] arr = new byte[10];
assertEquals(3, q.read(arr, true));
assertArrayEquals(new byte[]{1, 2, 3}, new byte[]{arr[0], arr[1], arr[2]});
assertTrue(q.write(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 0, 10));
assertEquals(10, q.read(arr, true));
assertArrayEquals(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, arr);
}
public void testQueueWraparound() throws Exception {
ByteQueue q = new ByteQueue(10);
byte[] origArray = new byte[]{1, 2, 3, 4, 5, 6};
byte[] readArray = new byte[origArray.length];
for (int i = 0; i < 20; i++) {
q.write(origArray, 0, origArray.length);
assertEquals(origArray.length, q.read(readArray, true));
assertArrayEquals(origArray, readArray);
}
}
public void testWriteNotesClosing() throws Exception {
ByteQueue q = new ByteQueue(10);
q.close();
assertFalse(q.write(new byte[]{1, 2, 3}, 0, 3));
}
public void testReadNonBlocking() throws Exception {
ByteQueue q = new ByteQueue(10);
assertEquals(0, q.read(new byte[128], false));
}
}