diff options
author | Robin Rosenberg <robin.rosenberg@dewire.com> | 2012-03-09 15:52:11 -0500 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2012-03-09 15:52:11 -0500 |
commit | 9a9877da4e8c366287ad0bf090bb3c153b06d8ef (patch) | |
tree | a7383a39257990f47ca04778754ac00302d51bd6 /org.eclipse.jgit.test/tst/org | |
parent | d725ecb80ed0bfc430e1959fcc666931d61e83cd (diff) | |
parent | 7df17e57d4e736336de6b95810daf076e9b7dded (diff) | |
download | jgit-9a9877da4e8c366287ad0bf090bb3c153b06d8ef.tar.gz jgit-9a9877da4e8c366287ad0bf090bb3c153b06d8ef.zip |
Merge "EolCanonicalizingInputStream: binary detection should be optional"
Diffstat (limited to 'org.eclipse.jgit.test/tst/org')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/EolCanonicalizingInputStreamTest.java | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/EolCanonicalizingInputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/EolCanonicalizingInputStreamTest.java index 960ca62411..52ad0139c6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/EolCanonicalizingInputStreamTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/EolCanonicalizingInputStreamTest.java @@ -57,35 +57,46 @@ public class EolCanonicalizingInputStreamTest { @Test public void testLF() throws IOException { final byte[] bytes = asBytes("1\n2\n3"); - test(bytes, bytes); + test(bytes, bytes, false); } @Test public void testCR() throws IOException { final byte[] bytes = asBytes("1\r2\r3"); - test(bytes, bytes); + test(bytes, bytes, false); } @Test public void testCRLF() throws IOException { - test(asBytes("1\r\n2\r\n3"), asBytes("1\n2\n3")); + test(asBytes("1\r\n2\r\n3"), asBytes("1\n2\n3"), false); } @Test public void testLFCR() throws IOException { final byte[] bytes = asBytes("1\n\r2\n\r3"); - test(bytes, bytes); + test(bytes, bytes, false); } @Test public void testEmpty() throws IOException { final byte[] bytes = asBytes(""); - test(bytes, bytes); + test(bytes, bytes, false); } - private void test(byte[] input, byte[] expected) throws IOException { + @Test + public void testBinaryDetect() throws IOException { + final byte[] bytes = asBytes("1\r\n2\r\n3\0"); + test(bytes, bytes, true); + } + + @Test + public void testBinaryDontDetect() throws IOException { + test(asBytes("1\r\n2\r\n3\0"), asBytes("1\n2\n3\0"), false); + } + + private void test(byte[] input, byte[] expected, boolean detectBinary) throws IOException { final InputStream bis1 = new ByteArrayInputStream(input); - final InputStream cis1 = new EolCanonicalizingInputStream(bis1); + final InputStream cis1 = new EolCanonicalizingInputStream(bis1, detectBinary); int index1 = 0; for (int b = cis1.read(); b != -1; b = cis1.read()) { assertEquals(expected[index1], (byte) b); @@ -97,7 +108,7 @@ public class EolCanonicalizingInputStreamTest { for (int bufferSize = 1; bufferSize < 10; bufferSize++) { final byte[] buffer = new byte[bufferSize]; final InputStream bis2 = new ByteArrayInputStream(input); - final InputStream cis2 = new EolCanonicalizingInputStream(bis2); + final InputStream cis2 = new EolCanonicalizingInputStream(bis2, detectBinary); int read = 0; for (int readNow = cis2.read(buffer, 0, buffer.length); readNow != -1 |