|
|
|
@ -66,29 +66,25 @@ public class AutoCRLFOutputStreamTest {
|
|
|
|
|
assertNoCrLf("\r\n\r\r", "\r\n\r\r"); |
|
|
|
|
assertNoCrLf("\r\n\r\n", "\r\n\r\n"); |
|
|
|
|
assertNoCrLf("\r\n\r\n\r", "\n\r\n\r"); |
|
|
|
|
assertNoCrLf("\0\n", "\0\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testBoundary() throws IOException { |
|
|
|
|
assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE - 5); |
|
|
|
|
assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE - 4); |
|
|
|
|
assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE - 3); |
|
|
|
|
assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE - 2); |
|
|
|
|
assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE - 1); |
|
|
|
|
assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE); |
|
|
|
|
assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE + 1); |
|
|
|
|
assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE + 2); |
|
|
|
|
assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE + 3); |
|
|
|
|
assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE + 4); |
|
|
|
|
assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE + 5); |
|
|
|
|
for (int i = AutoCRLFOutputStream.BUFFER_SIZE - 10; i < AutoCRLFOutputStream.BUFFER_SIZE + 10; i++) { |
|
|
|
|
String s1 = repeat("a", i); |
|
|
|
|
assertNoCrLf(s1, s1); |
|
|
|
|
String s2 = repeat("\0", i); |
|
|
|
|
assertNoCrLf(s2, s2); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void assertBoundaryCorrect(int size) throws IOException { |
|
|
|
|
StringBuilder sb = new StringBuilder(size); |
|
|
|
|
public static String repeat(String input, int size) { |
|
|
|
|
StringBuilder sb = new StringBuilder(input.length() * size); |
|
|
|
|
for (int i = 0; i < size; i++) |
|
|
|
|
sb.append('a'); |
|
|
|
|
sb.append(input); |
|
|
|
|
String s = sb.toString(); |
|
|
|
|
assertNoCrLf(s, s); |
|
|
|
|
return s; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void assertNoCrLf(String string, String string2) throws IOException { |
|
|
|
@ -105,8 +101,9 @@ public class AutoCRLFOutputStreamTest {
|
|
|
|
|
throws IOException { |
|
|
|
|
byte[] inbytes = input.getBytes(); |
|
|
|
|
byte[] expectBytes = expect.getBytes(); |
|
|
|
|
for (int i = 0; i < 5; ++i) { |
|
|
|
|
byte[] buf = new byte[i]; |
|
|
|
|
for (int i = -4; i < 5; ++i) { |
|
|
|
|
int size = Math.abs(i); |
|
|
|
|
byte[] buf = new byte[size]; |
|
|
|
|
InputStream in = new ByteArrayInputStream(inbytes); |
|
|
|
|
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
|
|
|
|
OutputStream out = new AutoCRLFOutputStream(bos); |
|
|
|
@ -115,6 +112,13 @@ public class AutoCRLFOutputStreamTest {
|
|
|
|
|
while ((n = in.read(buf)) >= 0) { |
|
|
|
|
out.write(buf, 0, n); |
|
|
|
|
} |
|
|
|
|
} else if (i < 0) { |
|
|
|
|
int n; |
|
|
|
|
while ((n = in.read(buf)) >= 0) { |
|
|
|
|
byte[] b = new byte[n]; |
|
|
|
|
System.arraycopy(buf, 0, b, 0, n); |
|
|
|
|
out.write(b); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
int c; |
|
|
|
|
while ((c = in.read()) != -1) |
|
|
|
@ -124,7 +128,7 @@ public class AutoCRLFOutputStreamTest {
|
|
|
|
|
in.close(); |
|
|
|
|
out.close(); |
|
|
|
|
byte[] actualBytes = bos.toByteArray(); |
|
|
|
|
Assert.assertEquals("bufsize=" + i, encode(expectBytes), |
|
|
|
|
Assert.assertEquals("bufsize=" + size, encode(expectBytes), |
|
|
|
|
encode(actualBytes)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|