diff options
author | Robin Stocker <robin@nibor.org> | 2013-04-18 21:55:35 +0200 |
---|---|---|
committer | Chris Aniszczyk <zx@twitter.com> | 2013-04-18 14:58:51 -0500 |
commit | 78fca8a099bd2efc88eb44a0b491dd8aecc222b0 (patch) | |
tree | 61bb9377fff13fd82622a5becc944da827a8454c /org.eclipse.jgit.test/tst/org/eclipse/jgit/util | |
parent | fa1bc6abb76cdd0abfe536d838035f94c3dfaeeb (diff) | |
download | jgit-78fca8a099bd2efc88eb44a0b491dd8aecc222b0.tar.gz jgit-78fca8a099bd2efc88eb44a0b491dd8aecc222b0.zip |
Improve test coverage of AutoCRLF(In|Out)putStream
Bug: 405672
Change-Id: I3894e98617fcee16dc2ac9853c203c62eb30c3ab
Signed-off-by: Chris Aniszczyk <zx@twitter.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/util')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java | 11 | ||||
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java | 40 |
2 files changed, 33 insertions, 18 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java index 754c9fc435..5975d37871 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java @@ -64,6 +64,17 @@ public class AutoCRLFInputStreamTest { 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 { + for (int i = AutoCRLFInputStream.BUFFER_SIZE - 10; i < AutoCRLFInputStream.BUFFER_SIZE + 10; i++) { + String s1 = AutoCRLFOutputStreamTest.repeat("a", i); + assertNoCrLf(s1, s1); + String s2 = AutoCRLFOutputStreamTest.repeat("\0", i); + assertNoCrLf(s2, s2); + } } private void assertNoCrLf(String string, String string2) throws IOException { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java index df175196fd..6cb31050f4 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java @@ -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)); } } |