From 799d60911e7988fec9e2b3a068e483e5eaf786e7 Mon Sep 17 00:00:00 2001 From: mguessan Date: Tue, 22 Feb 2011 20:44:26 +0000 Subject: [PATCH] POP: test new double dot implementation git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1629 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../exchange/TestDoubleDotInputStream.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/test/davmail/exchange/TestDoubleDotInputStream.java b/src/test/davmail/exchange/TestDoubleDotInputStream.java index 2bcc8ceb..91c881b9 100644 --- a/src/test/davmail/exchange/TestDoubleDotInputStream.java +++ b/src/test/davmail/exchange/TestDoubleDotInputStream.java @@ -40,6 +40,14 @@ public class TestDoubleDotInputStream extends TestCase { return new String(baos.toByteArray()); } + protected String doubleDotWrite(String value) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DoubleDotOutputStream doubleDotOutputStream = new DoubleDotOutputStream(baos); + doubleDotOutputStream.write(value.getBytes()); + doubleDotOutputStream.close(); + return new String(baos.toByteArray()); + } + public void testSimple() throws IOException { String value = "simple test"; assertEquals(value, doubleDotRead(value + END_OF_STREAM)); @@ -59,9 +67,41 @@ public class TestDoubleDotInputStream extends TestCase { String value = "simple test\r\n..\r\nsecond line"; assertEquals(value.replaceAll("\\.\\.", "."), doubleDotRead(value+END_OF_STREAM)); } + public void testDoubleDotEnd() throws IOException { String value = "simple test\r\n.."; assertEquals(value.replaceAll("\\.\\.", "."), doubleDotRead(value+END_OF_STREAM)); assertEquals("..", doubleDotRead(".."+END_OF_STREAM)); } + + public void testWriteCRLF() throws IOException { + String value = "simple test\r\n.\r\nsecond line"; + assertEquals(value.replaceAll("\\.", "..")+END_OF_STREAM, doubleDotWrite(value)); + } + + public void testEndsWithCRLF() throws IOException { + String value = "simple test\r\n"; + assertEquals("simple test"+END_OF_STREAM, doubleDotWrite(value)); + } + + public void testEndsWithLF() throws IOException { + String value = "simple test\n"; + assertEquals("simple test\n"+END_OF_STREAM, doubleDotWrite(value)); + } + + public void testWriteOSXCR() throws IOException { + String value = "simple test\r.\rsecond line"; + assertEquals(value.replaceAll("\\.", "..")+END_OF_STREAM, doubleDotWrite(value)); + } + + public void testWriteUnixLF() throws IOException { + String value = "simple test\n.\nsecond line"; + assertEquals(value.replaceAll("\\.", "..")+END_OF_STREAM, doubleDotWrite(value)); + } + + public void testAnotherTest() throws IOException { + String value = "foo\r\n..bar"; + assertEquals(value, doubleDotRead(value)); + } + }