james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mwiederk...@apache.org
Subject svn commit: r778457 [9/13] - in /james/mime4j/trunk: benchmark/src/main/java/org/apache/james/mime4j/ core/src/main/java/org/apache/james/mime4j/ core/src/main/java/org/apache/james/mime4j/codec/ core/src/main/java/org/apache/james/mime4j/descriptor/ c...
Date Mon, 25 May 2009 17:20:52 GMT
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/Base64InputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/Base64InputStreamTest.java?rev=778457&r1=778456&r2=778457&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/Base64InputStreamTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/Base64InputStreamTest.java Mon May 25 17:20:48 2009
@@ -1,293 +1,293 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mime4j.codec;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.Random;
-
-import org.apache.commons.io.output.NullOutputStream;
-import org.apache.log4j.BasicConfigurator;
-
-import junit.framework.TestCase;
-
-public class Base64InputStreamTest extends TestCase {
-
-    @Override
-    public void setUp() {
-        BasicConfigurator.resetConfiguration();
-        BasicConfigurator.configure();
-    }
-    
-    public void testDecode() throws IOException {
-        ByteArrayInputStream bis = null;
-        Base64InputStream decoder = null;
-        byte[] bytes = null;
-        
-        /*
-         * Simple initial test.
-         */
-        bis = new ByteArrayInputStream(
-                fromString("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlIQ=="));
-        decoder = new Base64InputStream(bis);
-        assertEquals("This is the plain text message!", toString(read(decoder)));
-        
-        /*
-         * Test encoded text padded once, twice and not at all.
-         */
-        bis = new ByteArrayInputStream(
-                fromString("VGhpcyBpcyBhIHRleHQgd2hpY2ggaGFzIHRvIGJl"
-                        + "IHBhZGRlZCBvbmNlLi4="));
-        decoder = new Base64InputStream(bis);
-        assertEquals("This is a text which has to be padded once..", toString(read(decoder)));
-        bis = new ByteArrayInputStream(
-                fromString("VGhpcyBpcyBhIHRleHQgd2hpY2ggaGFzIHRvIGJl"
-                        + "IHBhZGRlZCB0d2ljZQ=="));
-        decoder = new Base64InputStream(bis);
-        assertEquals("This is a text which has to be padded twice", toString(read(decoder)));
-        bis = new ByteArrayInputStream(
-                fromString("VGhpcyBpcyBhIHRleHQgd2hpY2ggd2lsbCBub3Qg"
-                        + "YmUgcGFkZGVk"));
-        decoder = new Base64InputStream(bis);
-        assertEquals("This is a text which will not be padded", toString(read(decoder)));
-        
-        /*
-         * Test that non base64 characters are ignored.
-         */
-        bis = new ByteArrayInputStream(
-                fromString(" &% VGhp\r\ncyBp\r\ncyB0aGUgcGxhaW4g "
-                        + " \tdGV4dCBtZ?!XNzY*WdlIQ=="));
-        decoder = new Base64InputStream(bis);
-        assertEquals("This is the plain text message!", toString(read(decoder)));
-        
-        /*
-         * Test that the bytes 0-255 shifted 0, 1 and 2 positions are
-         * decoded properly.
-         */
-        String s1 = "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCU"
-                  + "mJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0"
-                  + "xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3Bxc"
-                  + "nN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeY"
-                  + "mZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6"
-                  + "/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5O"
-                  + "Xm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==";
-        
-        String s2 = "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSY"
-                  + "nKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE"
-                  + "1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2hpamtsbW5vcHFyc"
-                  + "3R1dnd4eXp7fH1+f4CBgoOEhYaHiImKi4yNjo+QkZKTlJWWl5iZ"
-                  + "mpucnZ6foKGio6SlpqeoqaqrrK2ur7CxsrO0tba3uLm6u7y9vr/"
-                  + "AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3+Dh4uPk5e"
-                  + "bn6Onq6+zt7u/w8fLz9PX29/j5+vv8/f7/AA==";
-        
-        String s3 = "AgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fICEiIyQlJic"
-                  + "oKSorLC0uLzAxMjM0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSktMTU"
-                  + "5PUFFSU1RVVldYWVpbXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzd"
-                  + "HV2d3h5ent8fX5/gIGCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJma"
-                  + "m5ydnp+goaKjpKWmp6ipqqusra6vsLGys7S1tre4ubq7vL2+v8D"
-                  + "BwsPExcbHyMnKy8zNzs/Q0dLT1NXW19jZ2tvc3d7f4OHi4+Tl5u"
-                  + "fo6err7O3u7/Dx8vP09fb3+Pn6+/z9/v8AAQ==";
-        
-        bis = new ByteArrayInputStream(fromString(s1));
-        decoder = new Base64InputStream(bis);
-        bytes = read(decoder);
-        
-        for (int i = 0; i < bytes.length; i++) {
-            assertEquals("Position " + i, bytes[i], (byte) i);
-        }
-        
-        bis = new ByteArrayInputStream(fromString(s2));
-        decoder = new Base64InputStream(bis);
-        bytes = read(decoder);
-        
-        for (int i = 0; i < bytes.length; i++) {
-            assertEquals("Position " + i, bytes[i], (byte) (i + 1));
-        }
-        
-        bis = new ByteArrayInputStream(fromString(s3));
-        decoder = new Base64InputStream(bis);
-        bytes = read(decoder);
-        
-        for (int i = 0; i < bytes.length; i++) {
-            assertEquals("Position " + i, bytes[i], (byte) (i + 2));
-        }
-    }
-
-    public void testDecodePrematureClose() throws IOException {
-        ByteArrayInputStream bis = null;
-        Base64InputStream decoder = null;
-        
-        bis = new ByteArrayInputStream(
-                fromString("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlIQ=="));
-        decoder = new Base64InputStream(bis);
-        assertEquals('T', decoder.read());
-        assertEquals('h', decoder.read());
-        decoder.close();
-        
-        try {
-            decoder.read();
-            fail();
-        } catch (IOException expected) {
-        }
-    }
-
-    public void testRoundtripWithVariousBufferSizes() throws Exception {
-        byte[] data = new byte[3719];
-        new Random(0).nextBytes(data);
-
-        ByteArrayOutputStream eOut = new ByteArrayOutputStream();
-        CodecUtil.encodeBase64(new ByteArrayInputStream(data), eOut);
-        byte[] encoded = eOut.toByteArray();
-
-        for (int bufferSize = 1; bufferSize <= 1009; bufferSize++) {
-            ByteArrayInputStream bis = new ByteArrayInputStream(encoded);
-            Base64InputStream decoder = new Base64InputStream(bis);
-            ByteArrayOutputStream dOut = new ByteArrayOutputStream();
-
-            final byte[] buffer = new byte[bufferSize];
-            int inputLength;
-            while (-1 != (inputLength = decoder.read(buffer))) {
-                dOut.write(buffer, 0, inputLength);
-            }
-
-            byte[] decoded = dOut.toByteArray();
-
-            assertEquals(data.length, decoded.length);
-            for (int i = 0; i < data.length; i++) {
-                assertEquals(data[i], decoded[i]);
-            }
-        }
-    }
-
-    /**
-     * Tests {@link InputStream#read()}
-     */
-    public void testReadInt() throws Exception {
-        ByteArrayInputStream bis = new ByteArrayInputStream(
-                fromString("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlIQ=="));
-        Base64InputStream decoder = new Base64InputStream(bis);
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-
-        while (true) {
-            int x = decoder.read();
-            if (x == -1)
-                break;
-            out.write(x);
-        }
-
-        assertEquals("This is the plain text message!", toString(out
-                .toByteArray()));
-    }
-
-    /**
-     * Tests {@link InputStream#read(byte[], int, int)} with various offsets
-     */
-    public void testReadOffset() throws Exception {
-        ByteArrayInputStream bis = new ByteArrayInputStream(
-                fromString("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlIQ=="));
-        Base64InputStream decoder = new Base64InputStream(bis);
-
-        byte[] data = new byte[36];
-        for (int i = 0;;) {
-            int bytes = decoder.read(data, i, 5);
-            if (bytes == -1)
-                break;
-            i += bytes;
-        }
-
-        assertEquals("This is the plain text message!\0\0\0\0\0",
-                toString(data));
-    }
-
-    public void testStrictUnexpectedEof() throws Exception {
-        ByteArrayInputStream bis = new ByteArrayInputStream(
-                fromString("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlI"));
-        Base64InputStream decoder = new Base64InputStream(bis, true);
-        try {
-            CodecUtil.copy(decoder, new NullOutputStream());
-            fail();
-        } catch (IOException expected) {
-            assertTrue(expected.getMessage().toLowerCase().contains(
-                    "end of file"));
-        }
-    }
-
-    public void testLenientUnexpectedEof() throws Exception {
-        ByteArrayInputStream bis = new ByteArrayInputStream(
-                fromString("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlI"));
-        Base64InputStream decoder = new Base64InputStream(bis, false);
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        CodecUtil.copy(decoder, out);
-        assertEquals("This is the plain text message", toString(out
-                .toByteArray()));
-    }
-
-    public void testStrictUnexpectedPad() throws Exception {
-        ByteArrayInputStream bis = new ByteArrayInputStream(
-                fromString("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlI="));
-        Base64InputStream decoder = new Base64InputStream(bis, true);
-        try {
-            CodecUtil.copy(decoder, new NullOutputStream());
-            fail();
-        } catch (IOException expected) {
-            assertTrue(expected.getMessage().toLowerCase().contains("pad"));
-        }
-    }
-
-    public void testLenientUnexpectedPad() throws Exception {
-        ByteArrayInputStream bis = new ByteArrayInputStream(
-                fromString("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlI="));
-        Base64InputStream decoder = new Base64InputStream(bis, false);
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        CodecUtil.copy(decoder, out);
-        assertEquals("This is the plain text message", toString(out
-                .toByteArray()));
-    }
-        
-    private byte[] read(InputStream is) throws IOException {
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        int b;
-        while ((b = is.read()) != -1) {
-            bos.write(b);
-        }
-        return bos.toByteArray();
-    }
-    
-    private byte[] fromString(String s) {
-        try {
-            return s.getBytes("US-ASCII");
-        } catch (UnsupportedEncodingException e) {
-            fail(e.getMessage());
-            return null;
-        }
-    }
-    
-    private String toString(byte[] b) {
-        try {
-            return new String(b, "US-ASCII");
-        } catch (UnsupportedEncodingException e) {
-            fail(e.getMessage());
-            return null;
-        }
-    }
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.codec;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.Random;
+
+import org.apache.commons.io.output.NullOutputStream;
+import org.apache.log4j.BasicConfigurator;
+
+import junit.framework.TestCase;
+
+public class Base64InputStreamTest extends TestCase {
+
+    @Override
+    public void setUp() {
+        BasicConfigurator.resetConfiguration();
+        BasicConfigurator.configure();
+    }
+    
+    public void testDecode() throws IOException {
+        ByteArrayInputStream bis = null;
+        Base64InputStream decoder = null;
+        byte[] bytes = null;
+        
+        /*
+         * Simple initial test.
+         */
+        bis = new ByteArrayInputStream(
+                fromString("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlIQ=="));
+        decoder = new Base64InputStream(bis);
+        assertEquals("This is the plain text message!", toString(read(decoder)));
+        
+        /*
+         * Test encoded text padded once, twice and not at all.
+         */
+        bis = new ByteArrayInputStream(
+                fromString("VGhpcyBpcyBhIHRleHQgd2hpY2ggaGFzIHRvIGJl"
+                        + "IHBhZGRlZCBvbmNlLi4="));
+        decoder = new Base64InputStream(bis);
+        assertEquals("This is a text which has to be padded once..", toString(read(decoder)));
+        bis = new ByteArrayInputStream(
+                fromString("VGhpcyBpcyBhIHRleHQgd2hpY2ggaGFzIHRvIGJl"
+                        + "IHBhZGRlZCB0d2ljZQ=="));
+        decoder = new Base64InputStream(bis);
+        assertEquals("This is a text which has to be padded twice", toString(read(decoder)));
+        bis = new ByteArrayInputStream(
+                fromString("VGhpcyBpcyBhIHRleHQgd2hpY2ggd2lsbCBub3Qg"
+                        + "YmUgcGFkZGVk"));
+        decoder = new Base64InputStream(bis);
+        assertEquals("This is a text which will not be padded", toString(read(decoder)));
+        
+        /*
+         * Test that non base64 characters are ignored.
+         */
+        bis = new ByteArrayInputStream(
+                fromString(" &% VGhp\r\ncyBp\r\ncyB0aGUgcGxhaW4g "
+                        + " \tdGV4dCBtZ?!XNzY*WdlIQ=="));
+        decoder = new Base64InputStream(bis);
+        assertEquals("This is the plain text message!", toString(read(decoder)));
+        
+        /*
+         * Test that the bytes 0-255 shifted 0, 1 and 2 positions are
+         * decoded properly.
+         */
+        String s1 = "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCU"
+                  + "mJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0"
+                  + "xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3Bxc"
+                  + "nN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeY"
+                  + "mZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6"
+                  + "/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5O"
+                  + "Xm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==";
+        
+        String s2 = "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSY"
+                  + "nKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE"
+                  + "1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2hpamtsbW5vcHFyc"
+                  + "3R1dnd4eXp7fH1+f4CBgoOEhYaHiImKi4yNjo+QkZKTlJWWl5iZ"
+                  + "mpucnZ6foKGio6SlpqeoqaqrrK2ur7CxsrO0tba3uLm6u7y9vr/"
+                  + "AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3+Dh4uPk5e"
+                  + "bn6Onq6+zt7u/w8fLz9PX29/j5+vv8/f7/AA==";
+        
+        String s3 = "AgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fICEiIyQlJic"
+                  + "oKSorLC0uLzAxMjM0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSktMTU"
+                  + "5PUFFSU1RVVldYWVpbXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzd"
+                  + "HV2d3h5ent8fX5/gIGCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJma"
+                  + "m5ydnp+goaKjpKWmp6ipqqusra6vsLGys7S1tre4ubq7vL2+v8D"
+                  + "BwsPExcbHyMnKy8zNzs/Q0dLT1NXW19jZ2tvc3d7f4OHi4+Tl5u"
+                  + "fo6err7O3u7/Dx8vP09fb3+Pn6+/z9/v8AAQ==";
+        
+        bis = new ByteArrayInputStream(fromString(s1));
+        decoder = new Base64InputStream(bis);
+        bytes = read(decoder);
+        
+        for (int i = 0; i < bytes.length; i++) {
+            assertEquals("Position " + i, bytes[i], (byte) i);
+        }
+        
+        bis = new ByteArrayInputStream(fromString(s2));
+        decoder = new Base64InputStream(bis);
+        bytes = read(decoder);
+        
+        for (int i = 0; i < bytes.length; i++) {
+            assertEquals("Position " + i, bytes[i], (byte) (i + 1));
+        }
+        
+        bis = new ByteArrayInputStream(fromString(s3));
+        decoder = new Base64InputStream(bis);
+        bytes = read(decoder);
+        
+        for (int i = 0; i < bytes.length; i++) {
+            assertEquals("Position " + i, bytes[i], (byte) (i + 2));
+        }
+    }
+
+    public void testDecodePrematureClose() throws IOException {
+        ByteArrayInputStream bis = null;
+        Base64InputStream decoder = null;
+        
+        bis = new ByteArrayInputStream(
+                fromString("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlIQ=="));
+        decoder = new Base64InputStream(bis);
+        assertEquals('T', decoder.read());
+        assertEquals('h', decoder.read());
+        decoder.close();
+        
+        try {
+            decoder.read();
+            fail();
+        } catch (IOException expected) {
+        }
+    }
+
+    public void testRoundtripWithVariousBufferSizes() throws Exception {
+        byte[] data = new byte[3719];
+        new Random(0).nextBytes(data);
+
+        ByteArrayOutputStream eOut = new ByteArrayOutputStream();
+        CodecUtil.encodeBase64(new ByteArrayInputStream(data), eOut);
+        byte[] encoded = eOut.toByteArray();
+
+        for (int bufferSize = 1; bufferSize <= 1009; bufferSize++) {
+            ByteArrayInputStream bis = new ByteArrayInputStream(encoded);
+            Base64InputStream decoder = new Base64InputStream(bis);
+            ByteArrayOutputStream dOut = new ByteArrayOutputStream();
+
+            final byte[] buffer = new byte[bufferSize];
+            int inputLength;
+            while (-1 != (inputLength = decoder.read(buffer))) {
+                dOut.write(buffer, 0, inputLength);
+            }
+
+            byte[] decoded = dOut.toByteArray();
+
+            assertEquals(data.length, decoded.length);
+            for (int i = 0; i < data.length; i++) {
+                assertEquals(data[i], decoded[i]);
+            }
+        }
+    }
+
+    /**
+     * Tests {@link InputStream#read()}
+     */
+    public void testReadInt() throws Exception {
+        ByteArrayInputStream bis = new ByteArrayInputStream(
+                fromString("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlIQ=="));
+        Base64InputStream decoder = new Base64InputStream(bis);
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+        while (true) {
+            int x = decoder.read();
+            if (x == -1)
+                break;
+            out.write(x);
+        }
+
+        assertEquals("This is the plain text message!", toString(out
+                .toByteArray()));
+    }
+
+    /**
+     * Tests {@link InputStream#read(byte[], int, int)} with various offsets
+     */
+    public void testReadOffset() throws Exception {
+        ByteArrayInputStream bis = new ByteArrayInputStream(
+                fromString("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlIQ=="));
+        Base64InputStream decoder = new Base64InputStream(bis);
+
+        byte[] data = new byte[36];
+        for (int i = 0;;) {
+            int bytes = decoder.read(data, i, 5);
+            if (bytes == -1)
+                break;
+            i += bytes;
+        }
+
+        assertEquals("This is the plain text message!\0\0\0\0\0",
+                toString(data));
+    }
+
+    public void testStrictUnexpectedEof() throws Exception {
+        ByteArrayInputStream bis = new ByteArrayInputStream(
+                fromString("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlI"));
+        Base64InputStream decoder = new Base64InputStream(bis, true);
+        try {
+            CodecUtil.copy(decoder, new NullOutputStream());
+            fail();
+        } catch (IOException expected) {
+            assertTrue(expected.getMessage().toLowerCase().contains(
+                    "end of file"));
+        }
+    }
+
+    public void testLenientUnexpectedEof() throws Exception {
+        ByteArrayInputStream bis = new ByteArrayInputStream(
+                fromString("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlI"));
+        Base64InputStream decoder = new Base64InputStream(bis, false);
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        CodecUtil.copy(decoder, out);
+        assertEquals("This is the plain text message", toString(out
+                .toByteArray()));
+    }
+
+    public void testStrictUnexpectedPad() throws Exception {
+        ByteArrayInputStream bis = new ByteArrayInputStream(
+                fromString("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlI="));
+        Base64InputStream decoder = new Base64InputStream(bis, true);
+        try {
+            CodecUtil.copy(decoder, new NullOutputStream());
+            fail();
+        } catch (IOException expected) {
+            assertTrue(expected.getMessage().toLowerCase().contains("pad"));
+        }
+    }
+
+    public void testLenientUnexpectedPad() throws Exception {
+        ByteArrayInputStream bis = new ByteArrayInputStream(
+                fromString("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlI="));
+        Base64InputStream decoder = new Base64InputStream(bis, false);
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        CodecUtil.copy(decoder, out);
+        assertEquals("This is the plain text message", toString(out
+                .toByteArray()));
+    }
+        
+    private byte[] read(InputStream is) throws IOException {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        int b;
+        while ((b = is.read()) != -1) {
+            bos.write(b);
+        }
+        return bos.toByteArray();
+    }
+    
+    private byte[] fromString(String s) {
+        try {
+            return s.getBytes("US-ASCII");
+        } catch (UnsupportedEncodingException e) {
+            fail(e.getMessage());
+            return null;
+        }
+    }
+    
+    private String toString(byte[] b) {
+        try {
+            return new String(b, "US-ASCII");
+        } catch (UnsupportedEncodingException e) {
+            fail(e.getMessage());
+            return null;
+        }
+    }
+}

Propchange: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/Base64InputStreamTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/CodecUtilTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/DecoderUtilTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/DecoderUtilTest.java?rev=778457&r1=778456&r2=778457&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/DecoderUtilTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/DecoderUtilTest.java Mon May 25 17:20:48 2009
@@ -1,105 +1,105 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mime4j.codec;
-
-import java.io.UnsupportedEncodingException;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.BasicConfigurator;
-
-public class DecoderUtilTest extends TestCase {
-
-    @Override
-    public void setUp() {
-        BasicConfigurator.resetConfiguration();
-        BasicConfigurator.configure();
-    }
-    /*
-    public void testDecodeEncodedWords() {
-        String s = "=?ISO-2022-JP?B?GyRCTCQbKEobJEI+NRsoShskQkJ6GyhKGyRCOS0bKEo=?= "
-                 + "=?ISO-2022-JP?B?GyRCOXAbKEobJEIiKBsoShskQiU1GyhKGyRCJSQbKEo=?= "
-                 + "=?ISO-2022-JP?B?GyRCJUkbKEobJEIlUxsoShskQiU4GyhKGyRCJU0bKEo=?= "  
-                 + "=?ISO-2022-JP?B?GyRCJTkbKEobJEIkThsoShskQjdoGyhKGyRCRGobKEo=?= "
-                 + "=?ISO-2022-JP?B?GyRCSEcbKEobJEIkRxsoShskQiQ5GyhKGyRCISobKEo=?=";      
-        
-        s = DecoderUtil.decodeEncodedWords(s);
-        System.out.println(s);
-    }*/
-    
-    public void testDecodeB() throws UnsupportedEncodingException {
-        String s = DecoderUtil.decodeB("VGhpcyBpcyB0aGUgcGxhaW4gd"
-                    + "GV4dCBtZXNzYWdlIQ==", "ISO8859-1");
-        assertEquals("This is the plain text message!", s);
-    }
-    
-
-    public void testDecodeQ() throws UnsupportedEncodingException {
-        String s = DecoderUtil.decodeQ("=e1_=e2=09=E3_=E4_", 
-                                                         "ISO8859-1");
-        assertEquals("\u00e1 \u00e2\t\u00e3 \u00e4 ", s);
-    }
-    
-    public void testDecodeEncodedWords() {
-        assertEquals("", DecoderUtil.decodeEncodedWords(""));
-        assertEquals("Yada yada", DecoderUtil.decodeEncodedWords("Yada yada"));
-        assertEquals("  \u00e1\u00e2\u00e3\t\u00e4", 
-                DecoderUtil.decodeEncodedWords("=?iso-8859-1?Q?_=20=e1=e2=E3=09=E4?="));
-        assertEquals("Word 1 '  \u00e2\u00e3\t\u00e4'. Word 2 '  \u00e2\u00e3\t\u00e4'", 
-                DecoderUtil.decodeEncodedWords("Word 1 '=?iso-8859-1?Q?_=20=e2=E3=09=E4?="
-                        + "'. Word 2 '=?iso-8859-1?q?_=20=e2=E3=09=E4?='"));
-        assertEquals("=?iso-8859-YADA?Q?_=20=t1=e2=E3=09=E4?=", 
-                DecoderUtil.decodeEncodedWords("=?iso-8859-YADA?Q?_=20=t1=e2=E3=09=E4?="));
-        assertEquals("A short text", 
-                DecoderUtil.decodeEncodedWords("=?US-ASCII?B?QSBzaG9ydCB0ZXh0?="));
-        assertEquals("A short text again!", 
-                DecoderUtil.decodeEncodedWords("=?US-ASCII?b?QSBzaG9ydCB0ZXh0IGFnYWluIQ==?="));
-
-        // invalid encoded words should be returned unchanged
-        assertEquals("=?iso8859-1?Q?=", DecoderUtil.decodeEncodedWords("=?iso8859-1?Q?="));
-        assertEquals("=?iso8859-1?b?=", DecoderUtil.decodeEncodedWords("=?iso8859-1?b?="));
-        assertEquals("=?ISO-8859-1?Q?", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?"));
-        assertEquals("=?ISO-8859-1?R?abc?=", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?R?abc?="));
-
-        // encoded-text requires at least one character according to rfc 2047
-        assertEquals("=?ISO-8859-1?Q??=", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q??="));
-        assertEquals("=?ISO-8859-1?B??=", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?B??="));
-        
-        // white space between encoded words should be removed (MIME4J-104)
-        assertEquals("a", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?="));
-        assertEquals("a b", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?= b"));
-        assertEquals("ab", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?="));
-        assertEquals("ab", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?=  =?ISO-8859-1?Q?b?="));
-        assertEquals("ab", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?=\r\n  =?ISO-8859-1?Q?b?="));
-        assertEquals("a b", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a_b?="));
-        assertEquals("a b", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?= =?ISO-8859-2?Q?_b?="));
-
-        // non white space between encoded words should be retained
-        assertEquals("a b c", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?= b =?ISO-8859-1?Q?c?="));
-
-        // text before and after encoded words should be retained
-        assertEquals(" a b c ", DecoderUtil.decodeEncodedWords(" =?ISO-8859-1?Q?a?= b =?ISO-8859-1?Q?c?= "));
-        assertEquals("! a b c !", DecoderUtil.decodeEncodedWords("! =?ISO-8859-1?Q?a?= b =?ISO-8859-1?Q?c?= !"));
-        
-        // Bug detected on June 7, 2005. Decoding the following string caused
-        // OutOfMemoryError.
-        assertEquals("=3?!!\\=?\"!g6P\"!Xp:\"!", DecoderUtil.decodeEncodedWords("=3?!!\\=?\"!g6P\"!Xp:\"!"));
-    }    
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.codec;
+
+import java.io.UnsupportedEncodingException;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.BasicConfigurator;
+
+public class DecoderUtilTest extends TestCase {
+
+    @Override
+    public void setUp() {
+        BasicConfigurator.resetConfiguration();
+        BasicConfigurator.configure();
+    }
+    /*
+    public void testDecodeEncodedWords() {
+        String s = "=?ISO-2022-JP?B?GyRCTCQbKEobJEI+NRsoShskQkJ6GyhKGyRCOS0bKEo=?= "
+                 + "=?ISO-2022-JP?B?GyRCOXAbKEobJEIiKBsoShskQiU1GyhKGyRCJSQbKEo=?= "
+                 + "=?ISO-2022-JP?B?GyRCJUkbKEobJEIlUxsoShskQiU4GyhKGyRCJU0bKEo=?= "  
+                 + "=?ISO-2022-JP?B?GyRCJTkbKEobJEIkThsoShskQjdoGyhKGyRCRGobKEo=?= "
+                 + "=?ISO-2022-JP?B?GyRCSEcbKEobJEIkRxsoShskQiQ5GyhKGyRCISobKEo=?=";      
+        
+        s = DecoderUtil.decodeEncodedWords(s);
+        System.out.println(s);
+    }*/
+    
+    public void testDecodeB() throws UnsupportedEncodingException {
+        String s = DecoderUtil.decodeB("VGhpcyBpcyB0aGUgcGxhaW4gd"
+                    + "GV4dCBtZXNzYWdlIQ==", "ISO8859-1");
+        assertEquals("This is the plain text message!", s);
+    }
+    
+
+    public void testDecodeQ() throws UnsupportedEncodingException {
+        String s = DecoderUtil.decodeQ("=e1_=e2=09=E3_=E4_", 
+                                                         "ISO8859-1");
+        assertEquals("\u00e1 \u00e2\t\u00e3 \u00e4 ", s);
+    }
+    
+    public void testDecodeEncodedWords() {
+        assertEquals("", DecoderUtil.decodeEncodedWords(""));
+        assertEquals("Yada yada", DecoderUtil.decodeEncodedWords("Yada yada"));
+        assertEquals("  \u00e1\u00e2\u00e3\t\u00e4", 
+                DecoderUtil.decodeEncodedWords("=?iso-8859-1?Q?_=20=e1=e2=E3=09=E4?="));
+        assertEquals("Word 1 '  \u00e2\u00e3\t\u00e4'. Word 2 '  \u00e2\u00e3\t\u00e4'", 
+                DecoderUtil.decodeEncodedWords("Word 1 '=?iso-8859-1?Q?_=20=e2=E3=09=E4?="
+                        + "'. Word 2 '=?iso-8859-1?q?_=20=e2=E3=09=E4?='"));
+        assertEquals("=?iso-8859-YADA?Q?_=20=t1=e2=E3=09=E4?=", 
+                DecoderUtil.decodeEncodedWords("=?iso-8859-YADA?Q?_=20=t1=e2=E3=09=E4?="));
+        assertEquals("A short text", 
+                DecoderUtil.decodeEncodedWords("=?US-ASCII?B?QSBzaG9ydCB0ZXh0?="));
+        assertEquals("A short text again!", 
+                DecoderUtil.decodeEncodedWords("=?US-ASCII?b?QSBzaG9ydCB0ZXh0IGFnYWluIQ==?="));
+
+        // invalid encoded words should be returned unchanged
+        assertEquals("=?iso8859-1?Q?=", DecoderUtil.decodeEncodedWords("=?iso8859-1?Q?="));
+        assertEquals("=?iso8859-1?b?=", DecoderUtil.decodeEncodedWords("=?iso8859-1?b?="));
+        assertEquals("=?ISO-8859-1?Q?", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?"));
+        assertEquals("=?ISO-8859-1?R?abc?=", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?R?abc?="));
+
+        // encoded-text requires at least one character according to rfc 2047
+        assertEquals("=?ISO-8859-1?Q??=", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q??="));
+        assertEquals("=?ISO-8859-1?B??=", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?B??="));
+        
+        // white space between encoded words should be removed (MIME4J-104)
+        assertEquals("a", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?="));
+        assertEquals("a b", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?= b"));
+        assertEquals("ab", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?="));
+        assertEquals("ab", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?=  =?ISO-8859-1?Q?b?="));
+        assertEquals("ab", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?=\r\n  =?ISO-8859-1?Q?b?="));
+        assertEquals("a b", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a_b?="));
+        assertEquals("a b", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?= =?ISO-8859-2?Q?_b?="));
+
+        // non white space between encoded words should be retained
+        assertEquals("a b c", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?a?= b =?ISO-8859-1?Q?c?="));
+
+        // text before and after encoded words should be retained
+        assertEquals(" a b c ", DecoderUtil.decodeEncodedWords(" =?ISO-8859-1?Q?a?= b =?ISO-8859-1?Q?c?= "));
+        assertEquals("! a b c !", DecoderUtil.decodeEncodedWords("! =?ISO-8859-1?Q?a?= b =?ISO-8859-1?Q?c?= !"));
+        
+        // Bug detected on June 7, 2005. Decoding the following string caused
+        // OutOfMemoryError.
+        assertEquals("=3?!!\\=?\"!g6P\"!Xp:\"!", DecoderUtil.decodeEncodedWords("=3?!!\\=?\"!g6P\"!Xp:\"!"));
+    }    
+}

Propchange: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/DecoderUtilTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/EncoderUtilTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableEncodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java?rev=778457&r1=778456&r2=778457&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java Mon May 25 17:20:48 2009
@@ -1,97 +1,97 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mime4j.codec;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.BasicConfigurator;
-
-public class QuotedPrintableInputStreamTest extends TestCase {
-
-    @Override
-    public void setUp() {
-        BasicConfigurator.resetConfiguration();
-        BasicConfigurator.configure();
-    }
-    
-    public void testDecode() throws IOException, UnsupportedEncodingException {
-        ByteArrayInputStream bis = null;
-        QuotedPrintableInputStream decoder = null;
-
-        bis = new ByteArrayInputStream("=e1=e2=E3=E4\r\n".getBytes("US-ASCII"));
-        decoder = new QuotedPrintableInputStream(bis);
-        assertEquals("\u00e1\u00e2\u00e3\u00e4\r\n", new String(read(decoder), "ISO8859-1"));
-        
-        bis = new ByteArrayInputStream("=e1=g2=E3=E4\r\n".getBytes("US-ASCII"));
-        decoder = new QuotedPrintableInputStream(bis);
-        assertEquals("\u00e1=g2\u00e3\u00e4\r\n", new String(read(decoder), "ISO8859-1"));
-        
-        bis = new ByteArrayInputStream("   =e1 =e2  =E3\t=E4  \t \t    \r\n".getBytes("US-ASCII"));
-        decoder = new QuotedPrintableInputStream(bis);
-        assertEquals("   \u00e1 \u00e2  \u00e3\t\u00e4\r\n", new String(read(decoder), "ISO8859-1"));
-        
-        /*
-         * Test soft line breaks.
-         */
-        bis = new ByteArrayInputStream("Soft line   = \t \r\nHard line   \r\n".getBytes("US-ASCII"));
-        decoder = new QuotedPrintableInputStream(bis);
-        assertEquals("Soft line   Hard line\r\n", new String(read(decoder), "ISO8859-1"));
-        
-        /*
-         * This isn't valid qp (==) but it is known to occur in certain
-         * messages, especially spam.
-         */
-        bis = new ByteArrayInputStream("width==\r\n340 height=3d200\r\n".getBytes("US-ASCII"));
-        decoder = new QuotedPrintableInputStream(bis);
-        assertEquals("width=340 height=200\r\n", new String(read(decoder), "ISO8859-1"));
-    }
-
-    public void testDecodePrematureClose() throws IOException, UnsupportedEncodingException {
-        ByteArrayInputStream bis = null;
-        QuotedPrintableInputStream decoder = null;
-
-        bis = new ByteArrayInputStream("=e1=e2=E3=E4\r\n".getBytes("US-ASCII"));
-        decoder = new QuotedPrintableInputStream(bis);
-        assertEquals('\u00e1', decoder.read());
-        assertEquals('\u00e2', decoder.read());
-        decoder.close();
-        
-        try {
-            decoder.read();
-            fail();
-        } catch (IOException expected) {
-        }
-    }
-    
-    private byte[] read(InputStream is) throws IOException {
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        int b;
-        while ((b = is.read()) != -1) {
-            bos.write(b);
-        }
-        return bos.toByteArray();
-    }
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.codec;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.BasicConfigurator;
+
+public class QuotedPrintableInputStreamTest extends TestCase {
+
+    @Override
+    public void setUp() {
+        BasicConfigurator.resetConfiguration();
+        BasicConfigurator.configure();
+    }
+    
+    public void testDecode() throws IOException, UnsupportedEncodingException {
+        ByteArrayInputStream bis = null;
+        QuotedPrintableInputStream decoder = null;
+
+        bis = new ByteArrayInputStream("=e1=e2=E3=E4\r\n".getBytes("US-ASCII"));
+        decoder = new QuotedPrintableInputStream(bis);
+        assertEquals("\u00e1\u00e2\u00e3\u00e4\r\n", new String(read(decoder), "ISO8859-1"));
+        
+        bis = new ByteArrayInputStream("=e1=g2=E3=E4\r\n".getBytes("US-ASCII"));
+        decoder = new QuotedPrintableInputStream(bis);
+        assertEquals("\u00e1=g2\u00e3\u00e4\r\n", new String(read(decoder), "ISO8859-1"));
+        
+        bis = new ByteArrayInputStream("   =e1 =e2  =E3\t=E4  \t \t    \r\n".getBytes("US-ASCII"));
+        decoder = new QuotedPrintableInputStream(bis);
+        assertEquals("   \u00e1 \u00e2  \u00e3\t\u00e4\r\n", new String(read(decoder), "ISO8859-1"));
+        
+        /*
+         * Test soft line breaks.
+         */
+        bis = new ByteArrayInputStream("Soft line   = \t \r\nHard line   \r\n".getBytes("US-ASCII"));
+        decoder = new QuotedPrintableInputStream(bis);
+        assertEquals("Soft line   Hard line\r\n", new String(read(decoder), "ISO8859-1"));
+        
+        /*
+         * This isn't valid qp (==) but it is known to occur in certain
+         * messages, especially spam.
+         */
+        bis = new ByteArrayInputStream("width==\r\n340 height=3d200\r\n".getBytes("US-ASCII"));
+        decoder = new QuotedPrintableInputStream(bis);
+        assertEquals("width=340 height=200\r\n", new String(read(decoder), "ISO8859-1"));
+    }
+
+    public void testDecodePrematureClose() throws IOException, UnsupportedEncodingException {
+        ByteArrayInputStream bis = null;
+        QuotedPrintableInputStream decoder = null;
+
+        bis = new ByteArrayInputStream("=e1=e2=E3=E4\r\n".getBytes("US-ASCII"));
+        decoder = new QuotedPrintableInputStream(bis);
+        assertEquals('\u00e1', decoder.read());
+        assertEquals('\u00e2', decoder.read());
+        decoder.close();
+        
+        try {
+            decoder.read();
+            fail();
+        } catch (IOException expected) {
+        }
+    }
+    
+    private byte[] read(InputStream is) throws IOException {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        int b;
+        while ((b = is.read()) != -1) {
+            bos.write(b);
+        }
+        return bos.toByteArray();
+    }
+}

Propchange: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableTextEncodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/descriptor/BaseTestForBodyDescriptors.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/descriptor/BaseTestForBodyDescriptors.java?rev=778457&r1=778456&r2=778457&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/descriptor/BaseTestForBodyDescriptors.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/descriptor/BaseTestForBodyDescriptors.java Mon May 25 17:20:48 2009
@@ -1,237 +1,237 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mime4j.descriptor;
-
-import junit.framework.TestCase;
-
-import org.apache.james.mime4j.parser.Field;
-import org.apache.james.mime4j.util.ByteSequence;
-
-public abstract class BaseTestForBodyDescriptors extends TestCase {
-
-    protected abstract MutableBodyDescriptor newBodyDescriptor();
-
-    protected abstract MutableBodyDescriptor newBodyDescriptor(BodyDescriptor parent);
-    
-    public void testGetParameters() {
-        MutableBodyDescriptor bd = null;
-        
-        bd = newBodyDescriptor();
-        bd.addField(new TestField("Content-Type ", "text/plain; charset=ISO-8859-1; "
-                + "boundary=foo; param1=value1; param2=value2; param3=value3"));
-        assertEquals(3, bd.getContentTypeParameters().size());
-        assertEquals("value1", bd.getContentTypeParameters().get("param1"));
-        assertEquals("value2", bd.getContentTypeParameters().get("param2"));
-        assertEquals("value3", bd.getContentTypeParameters().get("param3"));
-        
-        bd = newBodyDescriptor();
-        bd.addField(new TestField("Content-Type ", "text/plain; param1=value1; param2=value2;"
-                     + " param3=value3"));
-        assertEquals(3, bd.getContentTypeParameters().size());
-        assertEquals("value1", bd.getContentTypeParameters().get("param1"));
-        assertEquals("value2", bd.getContentTypeParameters().get("param2"));
-        assertEquals("value3", bd.getContentTypeParameters().get("param3"));
-        
-        bd = newBodyDescriptor();
-        bd.addField(new TestField("Content-Type ", "text/plain; "
-                + "param1= \" value with\tspaces \" ; "
-                + "param2=\"\\\"value4 with escaped \\\" \\\"\";"));
-        assertEquals(2, bd.getContentTypeParameters().size());
-        assertEquals(" value with\tspaces ", bd.getContentTypeParameters().get("param1"));
-        assertEquals("\"value4 with escaped \" \"", bd.getContentTypeParameters().get("param2"));
-        
-        /*
-         * Make sure escaped characters (except ") are still escaped.
-         * The parameter value should be \n\"
-         */
-        bd = newBodyDescriptor();
-        bd.addField(new TestField("Content-Type ", "text/plain; param=\"\\n\\\\\\\"\""));
-        assertEquals(1, bd.getContentTypeParameters().size());
-        assertEquals("\\n\\\"", bd.getContentTypeParameters().get("param"));
-    }
-    
-    public void testAddField() {
-        MutableBodyDescriptor bd = null;
-        
-        /*
-         * Make sure that only the first Content-Type header added is used.
-         */
-        bd = newBodyDescriptor();
-        bd.addField(new TestField("Content-Type ", "text/plain; charset=ISO-8859-1"));
-        assertEquals("text/plain", bd.getMimeType());
-        assertEquals("iso-8859-1", bd.getCharset());
-        bd.addField(new TestField("Content-Type ", "text/html; charset=us-ascii"));
-        assertEquals("text/plain", bd.getMimeType());
-        assertEquals("iso-8859-1", bd.getCharset());
-    }
-    
-    public void testGetMimeType() {
-        MutableBodyDescriptor bd = null;
-        
-        bd = newBodyDescriptor();
-        bd.addField(new TestField("Content-Type ", "text/PLAIN"));
-        assertEquals("text/plain", bd.getMimeType());
-        
-        bd = newBodyDescriptor();
-        bd.addField(new TestField("Content-Type ", "text/PLAIN;"));
-        assertEquals("text/plain", bd.getMimeType());
-        
-        bd = newBodyDescriptor();
-        bd.addField(new TestField("content-type", "   TeXt / html   "));
-        assertEquals("text/html", bd.getMimeType());
-        
-        bd = newBodyDescriptor();
-        bd.addField(new TestField("CONTENT-TYPE", "   x-app/yada ;  param = yada"));
-        assertEquals("x-app/yada", bd.getMimeType());
-        
-        bd = newBodyDescriptor();
-        bd.addField(new TestField("CONTENT-TYPE", "   yada"));
-        assertEquals("text/plain", bd.getMimeType());
-        
-        /*
-         * Make sure that only the first Content-Type header added is used.
-         */
-        bd = newBodyDescriptor();
-        bd.addField(new TestField("Content-Type ", "text/plain"));
-        assertEquals("text/plain", bd.getMimeType());
-        bd.addField(new TestField("Content-Type ", "text/html"));
-        assertEquals("text/plain", bd.getMimeType());
-        
-        /*
-         * Implicit mime types.
-         */
-        MutableBodyDescriptor child = null;
-        MutableBodyDescriptor parent = null;
-        
-        parent = newBodyDescriptor();
-        parent.addField(new TestField("Content-Type", "mutlipart/alternative; boundary=foo"));
-        
-        child = newBodyDescriptor(parent);
-        assertEquals("text/plain", child.getMimeType());
-        child.addField(new TestField("Content-Type", " child/type"));
-        assertEquals("child/type", child.getMimeType());
-        
-        parent = newBodyDescriptor();
-        parent.addField(new TestField("Content-Type", "multipart/digest; boundary=foo"));
-        
-        child = newBodyDescriptor(parent);
-        assertEquals("message/rfc822", child.getMimeType());
-        child.addField(new TestField("Content-Type", " child/type"));
-        assertEquals("child/type", child.getMimeType());
-        
-    }
-    
-    public void testParameters() {
-        MutableBodyDescriptor bd = null;
-
-        /*
-         * Test charset.
-         */
-        bd = newBodyDescriptor();
-        assertEquals("us-ascii", bd.getCharset());
-        bd.addField(new TestField("Content-Type ", "text/type; charset=ISO-8859-1"));
-        assertEquals("iso-8859-1", bd.getCharset());
-        
-        bd = newBodyDescriptor();
-        assertEquals("us-ascii", bd.getCharset());
-        bd.addField(new TestField("Content-Type ", "text/type"));
-        assertEquals("us-ascii", bd.getCharset());
-        
-        /*
-         * Test boundary.
-         */
-        bd = newBodyDescriptor();
-        bd.addField(new TestField("Content-Type", "text/html; boundary=yada yada"));
-        assertNull(bd.getBoundary());
-
-        bd = newBodyDescriptor();
-        bd.addField(new TestField("Content-Type", "multipart/yada; boundary=yada"));
-        assertEquals("yada", bd.getBoundary());
-
-        /*
-         * Test some weird parameters.
-         */
-        bd = newBodyDescriptor();
-        bd.addField(new TestField("Content-Type", "multipart/yada; boundary=yada yada"));
-        assertEquals("yada", bd.getBoundary());
-        
-        bd = newBodyDescriptor();
-        bd.addField(new TestField("Content-Type", "multipart/yada; boUNdarY= ya:*da; \tcharset\t =  big5"));
-        assertEquals("ya:*da", bd.getBoundary());
-        assertEquals("big5", bd.getCharset());
-        
-        bd = newBodyDescriptor();
-        bd.addField(new TestField("Content-Type", "multipart/yada; boUNdarY= \"ya \\\"\\\"\tda \\\"\"; "
-                            + "\tcharset\t =  \"\\\"hepp\\\"  =us\t-ascii\""));
-        assertEquals("ya \"\"\tda \"", bd.getBoundary());
-        assertEquals("\"hepp\"  =us\t-ascii", bd.getCharset());
-        
-    }
-    
-    public void testGetContentLength() throws Exception {
-        MutableBodyDescriptor bd = null;
-
-        bd = newBodyDescriptor();
-        assertEquals(-1, bd.getContentLength());
-
-        bd.addField(new TestField("Content-Length", "9901"));
-        assertEquals(9901, bd.getContentLength());
-
-        // only the first content-length counts
-        bd.addField(new TestField("Content-Length", "1239901"));
-        assertEquals(9901, bd.getContentLength());
-    }
-    
-    public void testDoDefaultToUsAsciiWhenUntyped() throws Exception {
-        MutableBodyDescriptor descriptor = newBodyDescriptor();
-        descriptor.addField(new TestField("To", "me@example.org"));
-        assertEquals("us-ascii", descriptor.getCharset());
-    }
-
-    public void testDoNotDefaultToUsAsciiForNonTextTypes() throws Exception {
-        MutableBodyDescriptor descriptor = newBodyDescriptor();
-        descriptor.addField(new TestField("Content-Type", "image/png; name=blob.png"));
-        assertNull(descriptor.getCharset());
-    }
-    
-    private static final class TestField implements Field {
-
-        private final String name;
-        private final String body;
-
-        public TestField(String name, String body){
-            this.name = name;
-            this.body = body;
-        }
-        
-        public String getName() {
-            return name;
-        }
-
-        public String getBody() {
-            return body;
-        }
-
-        public ByteSequence getRaw() {
-            throw new UnsupportedOperationException();
-        }
-        
-    }
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.descriptor;
+
+import junit.framework.TestCase;
+
+import org.apache.james.mime4j.parser.Field;
+import org.apache.james.mime4j.util.ByteSequence;
+
+public abstract class BaseTestForBodyDescriptors extends TestCase {
+
+    protected abstract MutableBodyDescriptor newBodyDescriptor();
+
+    protected abstract MutableBodyDescriptor newBodyDescriptor(BodyDescriptor parent);
+    
+    public void testGetParameters() {
+        MutableBodyDescriptor bd = null;
+        
+        bd = newBodyDescriptor();
+        bd.addField(new TestField("Content-Type ", "text/plain; charset=ISO-8859-1; "
+                + "boundary=foo; param1=value1; param2=value2; param3=value3"));
+        assertEquals(3, bd.getContentTypeParameters().size());
+        assertEquals("value1", bd.getContentTypeParameters().get("param1"));
+        assertEquals("value2", bd.getContentTypeParameters().get("param2"));
+        assertEquals("value3", bd.getContentTypeParameters().get("param3"));
+        
+        bd = newBodyDescriptor();
+        bd.addField(new TestField("Content-Type ", "text/plain; param1=value1; param2=value2;"
+                     + " param3=value3"));
+        assertEquals(3, bd.getContentTypeParameters().size());
+        assertEquals("value1", bd.getContentTypeParameters().get("param1"));
+        assertEquals("value2", bd.getContentTypeParameters().get("param2"));
+        assertEquals("value3", bd.getContentTypeParameters().get("param3"));
+        
+        bd = newBodyDescriptor();
+        bd.addField(new TestField("Content-Type ", "text/plain; "
+                + "param1= \" value with\tspaces \" ; "
+                + "param2=\"\\\"value4 with escaped \\\" \\\"\";"));
+        assertEquals(2, bd.getContentTypeParameters().size());
+        assertEquals(" value with\tspaces ", bd.getContentTypeParameters().get("param1"));
+        assertEquals("\"value4 with escaped \" \"", bd.getContentTypeParameters().get("param2"));
+        
+        /*
+         * Make sure escaped characters (except ") are still escaped.
+         * The parameter value should be \n\"
+         */
+        bd = newBodyDescriptor();
+        bd.addField(new TestField("Content-Type ", "text/plain; param=\"\\n\\\\\\\"\""));
+        assertEquals(1, bd.getContentTypeParameters().size());
+        assertEquals("\\n\\\"", bd.getContentTypeParameters().get("param"));
+    }
+    
+    public void testAddField() {
+        MutableBodyDescriptor bd = null;
+        
+        /*
+         * Make sure that only the first Content-Type header added is used.
+         */
+        bd = newBodyDescriptor();
+        bd.addField(new TestField("Content-Type ", "text/plain; charset=ISO-8859-1"));
+        assertEquals("text/plain", bd.getMimeType());
+        assertEquals("iso-8859-1", bd.getCharset());
+        bd.addField(new TestField("Content-Type ", "text/html; charset=us-ascii"));
+        assertEquals("text/plain", bd.getMimeType());
+        assertEquals("iso-8859-1", bd.getCharset());
+    }
+    
+    public void testGetMimeType() {
+        MutableBodyDescriptor bd = null;
+        
+        bd = newBodyDescriptor();
+        bd.addField(new TestField("Content-Type ", "text/PLAIN"));
+        assertEquals("text/plain", bd.getMimeType());
+        
+        bd = newBodyDescriptor();
+        bd.addField(new TestField("Content-Type ", "text/PLAIN;"));
+        assertEquals("text/plain", bd.getMimeType());
+        
+        bd = newBodyDescriptor();
+        bd.addField(new TestField("content-type", "   TeXt / html   "));
+        assertEquals("text/html", bd.getMimeType());
+        
+        bd = newBodyDescriptor();
+        bd.addField(new TestField("CONTENT-TYPE", "   x-app/yada ;  param = yada"));
+        assertEquals("x-app/yada", bd.getMimeType());
+        
+        bd = newBodyDescriptor();
+        bd.addField(new TestField("CONTENT-TYPE", "   yada"));
+        assertEquals("text/plain", bd.getMimeType());
+        
+        /*
+         * Make sure that only the first Content-Type header added is used.
+         */
+        bd = newBodyDescriptor();
+        bd.addField(new TestField("Content-Type ", "text/plain"));
+        assertEquals("text/plain", bd.getMimeType());
+        bd.addField(new TestField("Content-Type ", "text/html"));
+        assertEquals("text/plain", bd.getMimeType());
+        
+        /*
+         * Implicit mime types.
+         */
+        MutableBodyDescriptor child = null;
+        MutableBodyDescriptor parent = null;
+        
+        parent = newBodyDescriptor();
+        parent.addField(new TestField("Content-Type", "mutlipart/alternative; boundary=foo"));
+        
+        child = newBodyDescriptor(parent);
+        assertEquals("text/plain", child.getMimeType());
+        child.addField(new TestField("Content-Type", " child/type"));
+        assertEquals("child/type", child.getMimeType());
+        
+        parent = newBodyDescriptor();
+        parent.addField(new TestField("Content-Type", "multipart/digest; boundary=foo"));
+        
+        child = newBodyDescriptor(parent);
+        assertEquals("message/rfc822", child.getMimeType());
+        child.addField(new TestField("Content-Type", " child/type"));
+        assertEquals("child/type", child.getMimeType());
+        
+    }
+    
+    public void testParameters() {
+        MutableBodyDescriptor bd = null;
+
+        /*
+         * Test charset.
+         */
+        bd = newBodyDescriptor();
+        assertEquals("us-ascii", bd.getCharset());
+        bd.addField(new TestField("Content-Type ", "text/type; charset=ISO-8859-1"));
+        assertEquals("iso-8859-1", bd.getCharset());
+        
+        bd = newBodyDescriptor();
+        assertEquals("us-ascii", bd.getCharset());
+        bd.addField(new TestField("Content-Type ", "text/type"));
+        assertEquals("us-ascii", bd.getCharset());
+        
+        /*
+         * Test boundary.
+         */
+        bd = newBodyDescriptor();
+        bd.addField(new TestField("Content-Type", "text/html; boundary=yada yada"));
+        assertNull(bd.getBoundary());
+
+        bd = newBodyDescriptor();
+        bd.addField(new TestField("Content-Type", "multipart/yada; boundary=yada"));
+        assertEquals("yada", bd.getBoundary());
+
+        /*
+         * Test some weird parameters.
+         */
+        bd = newBodyDescriptor();
+        bd.addField(new TestField("Content-Type", "multipart/yada; boundary=yada yada"));
+        assertEquals("yada", bd.getBoundary());
+        
+        bd = newBodyDescriptor();
+        bd.addField(new TestField("Content-Type", "multipart/yada; boUNdarY= ya:*da; \tcharset\t =  big5"));
+        assertEquals("ya:*da", bd.getBoundary());
+        assertEquals("big5", bd.getCharset());
+        
+        bd = newBodyDescriptor();
+        bd.addField(new TestField("Content-Type", "multipart/yada; boUNdarY= \"ya \\\"\\\"\tda \\\"\"; "
+                            + "\tcharset\t =  \"\\\"hepp\\\"  =us\t-ascii\""));
+        assertEquals("ya \"\"\tda \"", bd.getBoundary());
+        assertEquals("\"hepp\"  =us\t-ascii", bd.getCharset());
+        
+    }
+    
+    public void testGetContentLength() throws Exception {
+        MutableBodyDescriptor bd = null;
+
+        bd = newBodyDescriptor();
+        assertEquals(-1, bd.getContentLength());
+
+        bd.addField(new TestField("Content-Length", "9901"));
+        assertEquals(9901, bd.getContentLength());
+
+        // only the first content-length counts
+        bd.addField(new TestField("Content-Length", "1239901"));
+        assertEquals(9901, bd.getContentLength());
+    }
+    
+    public void testDoDefaultToUsAsciiWhenUntyped() throws Exception {
+        MutableBodyDescriptor descriptor = newBodyDescriptor();
+        descriptor.addField(new TestField("To", "me@example.org"));
+        assertEquals("us-ascii", descriptor.getCharset());
+    }
+
+    public void testDoNotDefaultToUsAsciiForNonTextTypes() throws Exception {
+        MutableBodyDescriptor descriptor = newBodyDescriptor();
+        descriptor.addField(new TestField("Content-Type", "image/png; name=blob.png"));
+        assertNull(descriptor.getCharset());
+    }
+    
+    private static final class TestField implements Field {
+
+        private final String name;
+        private final String body;
+
+        public TestField(String name, String body){
+            this.name = name;
+            this.body = body;
+        }
+        
+        public String getName() {
+            return name;
+        }
+
+        public String getBody() {
+            return body;
+        }
+
+        public ByteSequence getRaw() {
+            throw new UnsupportedOperationException();
+        }
+        
+    }
+}

Propchange: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/descriptor/BaseTestForBodyDescriptors.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/descriptor/DefaultBodyDescriptorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/descriptor/MaximalBodyDescriptorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/field/ContentDispositionFieldTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/field/ContentDispositionFieldTest.java?rev=778457&r1=778456&r2=778457&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/field/ContentDispositionFieldTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/field/ContentDispositionFieldTest.java Mon May 25 17:20:48 2009
@@ -1,209 +1,209 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mime4j.field;
-
-import java.util.Date;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.BasicConfigurator;
-
-public class ContentDispositionFieldTest extends TestCase {
-
-    @Override
-    public void setUp() {
-        BasicConfigurator.resetConfiguration();
-        BasicConfigurator.configure();
-    }
-
-    public void testDispositionTypeWithSemiColonNoParams() throws Exception {
-        ContentDispositionField f = null;
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: inline;");
-        assertEquals("inline", f.getDispositionType());
-    }
-
-    public void testGetDispositionType() throws Exception {
-        ContentDispositionField f = null;
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: attachment");
-        assertEquals("attachment", f.getDispositionType());
-
-        f = (ContentDispositionField) AbstractField
-                .parse("content-disposition:   InLiNe   ");
-        assertEquals("inline", f.getDispositionType());
-
-        f = (ContentDispositionField) AbstractField
-                .parse("CONTENT-DISPOSITION:   x-yada ;" + "  param = yada");
-        assertEquals("x-yada", f.getDispositionType());
-
-        f = (ContentDispositionField) AbstractField.parse("CONTENT-DISPOSITION:   ");
-        assertEquals("", f.getDispositionType());
-    }
-
-    public void testGetParameter() throws Exception {
-        ContentDispositionField f = null;
-
-        f = (ContentDispositionField) AbstractField
-                .parse("CONTENT-DISPOSITION:   inline ;"
-                        + "  filename=yada yada");
-        assertEquals("yada", f.getParameter("filename"));
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: x-yada;"
-                        + "  fileNAme= \"ya:\\\"*da\"; " + "\tSIZE\t =  1234");
-        assertEquals("ya:\"*da", f.getParameter("filename"));
-        assertEquals("1234", f.getParameter("size"));
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: x-yada;  "
-                        + "fileNAme= \"ya \\\"\\\"\tda \\\"\"; "
-                        + "\tx-Yada\t =  \"\\\"hepp\\\"  =us\t-ascii\"");
-        assertEquals("ya \"\"\tda \"", f.getParameter("filename"));
-        assertEquals("\"hepp\"  =us\t-ascii", f.getParameter("x-yada"));
-    }
-
-    public void testIsDispositionType() throws Exception {
-        ContentDispositionField f = null;
-
-        f = (ContentDispositionField) AbstractField.parse("Content-Disposition:INline");
-        assertTrue(f.isDispositionType("InLiNe"));
-        assertFalse(f.isDispositionType("NiLiNe"));
-        assertTrue(f.isInline());
-        assertFalse(f.isAttachment());
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: attachment");
-        assertTrue(f.isDispositionType("ATTACHMENT"));
-        assertFalse(f.isInline());
-        assertTrue(f.isAttachment());
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: x-something");
-        assertTrue(f.isDispositionType("x-SomeThing"));
-        assertFalse(f.isInline());
-        assertFalse(f.isAttachment());
-    }
-
-    public void testGetFilename() throws Exception {
-        ContentDispositionField f = null;
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: inline; filename=yada.txt");
-        assertEquals("yada.txt", f.getFilename());
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: inline; filename=yada yada.txt");
-        assertEquals("yada", f.getFilename());
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: inline; filename=\"yada yada.txt\"");
-        assertEquals("yada yada.txt", f.getFilename());
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: inline");
-        assertNull(f.getFilename());
-    }
-
-    public void testGetCreationDate() throws Exception {
-        ContentDispositionField f = null;
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: inline; "
-                        + "creation-date=\"Tue, 01 Jan 1970 00:00:00 +0000\"");
-        assertEquals(new Date(0), f.getCreationDate());
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: inline; "
-                        + "creation-date=Tue, 01 Jan 1970 00:00:00 +0000");
-        assertNull(f.getCreationDate());
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: attachment");
-        assertNull(f.getCreationDate());
-    }
-
-    public void testGetModificationDate() throws Exception {
-        ContentDispositionField f = null;
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: inline; "
-                        + "modification-date=\"Tue, 01 Jan 1970 00:00:00 +0000\"");
-        assertEquals(new Date(0), f.getModificationDate());
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: inline; "
-                        + "modification-date=\"Wed, 12 Feb 1997 16:29:51 -0500\"");
-        assertEquals(new Date(855782991000l), f.getModificationDate());
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: inline; "
-                        + "modification-date=yesterday");
-        assertNull(f.getModificationDate());
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: attachment");
-        assertNull(f.getModificationDate());
-    }
-
-    public void testGetReadDate() throws Exception {
-        ContentDispositionField f = null;
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: inline; "
-                        + "read-date=\"Tue, 01 Jan 1970 00:00:00 +0000\"");
-        assertEquals(new Date(0), f.getReadDate());
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: inline; read-date=");
-        assertNull(f.getReadDate());
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: attachment");
-        assertNull(f.getReadDate());
-    }
-
-    public void testGetSize() throws Exception {
-        ContentDispositionField f = null;
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: attachment; size=0");
-        assertEquals(0, f.getSize());
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: attachment; size=matters");
-        assertEquals(-1, f.getSize());
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: attachment");
-        assertEquals(-1, f.getSize());
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: attachment; size=-12");
-        assertEquals(-1, f.getSize());
-
-        f = (ContentDispositionField) AbstractField
-                .parse("Content-Disposition: attachment; size=12");
-        assertEquals(12, f.getSize());
-    }
-
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.field;
+
+import java.util.Date;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.BasicConfigurator;
+
+public class ContentDispositionFieldTest extends TestCase {
+
+    @Override
+    public void setUp() {
+        BasicConfigurator.resetConfiguration();
+        BasicConfigurator.configure();
+    }
+
+    public void testDispositionTypeWithSemiColonNoParams() throws Exception {
+        ContentDispositionField f = null;
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: inline;");
+        assertEquals("inline", f.getDispositionType());
+    }
+
+    public void testGetDispositionType() throws Exception {
+        ContentDispositionField f = null;
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: attachment");
+        assertEquals("attachment", f.getDispositionType());
+
+        f = (ContentDispositionField) AbstractField
+                .parse("content-disposition:   InLiNe   ");
+        assertEquals("inline", f.getDispositionType());
+
+        f = (ContentDispositionField) AbstractField
+                .parse("CONTENT-DISPOSITION:   x-yada ;" + "  param = yada");
+        assertEquals("x-yada", f.getDispositionType());
+
+        f = (ContentDispositionField) AbstractField.parse("CONTENT-DISPOSITION:   ");
+        assertEquals("", f.getDispositionType());
+    }
+
+    public void testGetParameter() throws Exception {
+        ContentDispositionField f = null;
+
+        f = (ContentDispositionField) AbstractField
+                .parse("CONTENT-DISPOSITION:   inline ;"
+                        + "  filename=yada yada");
+        assertEquals("yada", f.getParameter("filename"));
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: x-yada;"
+                        + "  fileNAme= \"ya:\\\"*da\"; " + "\tSIZE\t =  1234");
+        assertEquals("ya:\"*da", f.getParameter("filename"));
+        assertEquals("1234", f.getParameter("size"));
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: x-yada;  "
+                        + "fileNAme= \"ya \\\"\\\"\tda \\\"\"; "
+                        + "\tx-Yada\t =  \"\\\"hepp\\\"  =us\t-ascii\"");
+        assertEquals("ya \"\"\tda \"", f.getParameter("filename"));
+        assertEquals("\"hepp\"  =us\t-ascii", f.getParameter("x-yada"));
+    }
+
+    public void testIsDispositionType() throws Exception {
+        ContentDispositionField f = null;
+
+        f = (ContentDispositionField) AbstractField.parse("Content-Disposition:INline");
+        assertTrue(f.isDispositionType("InLiNe"));
+        assertFalse(f.isDispositionType("NiLiNe"));
+        assertTrue(f.isInline());
+        assertFalse(f.isAttachment());
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: attachment");
+        assertTrue(f.isDispositionType("ATTACHMENT"));
+        assertFalse(f.isInline());
+        assertTrue(f.isAttachment());
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: x-something");
+        assertTrue(f.isDispositionType("x-SomeThing"));
+        assertFalse(f.isInline());
+        assertFalse(f.isAttachment());
+    }
+
+    public void testGetFilename() throws Exception {
+        ContentDispositionField f = null;
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: inline; filename=yada.txt");
+        assertEquals("yada.txt", f.getFilename());
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: inline; filename=yada yada.txt");
+        assertEquals("yada", f.getFilename());
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: inline; filename=\"yada yada.txt\"");
+        assertEquals("yada yada.txt", f.getFilename());
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: inline");
+        assertNull(f.getFilename());
+    }
+
+    public void testGetCreationDate() throws Exception {
+        ContentDispositionField f = null;
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: inline; "
+                        + "creation-date=\"Tue, 01 Jan 1970 00:00:00 +0000\"");
+        assertEquals(new Date(0), f.getCreationDate());
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: inline; "
+                        + "creation-date=Tue, 01 Jan 1970 00:00:00 +0000");
+        assertNull(f.getCreationDate());
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: attachment");
+        assertNull(f.getCreationDate());
+    }
+
+    public void testGetModificationDate() throws Exception {
+        ContentDispositionField f = null;
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: inline; "
+                        + "modification-date=\"Tue, 01 Jan 1970 00:00:00 +0000\"");
+        assertEquals(new Date(0), f.getModificationDate());
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: inline; "
+                        + "modification-date=\"Wed, 12 Feb 1997 16:29:51 -0500\"");
+        assertEquals(new Date(855782991000l), f.getModificationDate());
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: inline; "
+                        + "modification-date=yesterday");
+        assertNull(f.getModificationDate());
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: attachment");
+        assertNull(f.getModificationDate());
+    }
+
+    public void testGetReadDate() throws Exception {
+        ContentDispositionField f = null;
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: inline; "
+                        + "read-date=\"Tue, 01 Jan 1970 00:00:00 +0000\"");
+        assertEquals(new Date(0), f.getReadDate());
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: inline; read-date=");
+        assertNull(f.getReadDate());
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: attachment");
+        assertNull(f.getReadDate());
+    }
+
+    public void testGetSize() throws Exception {
+        ContentDispositionField f = null;
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: attachment; size=0");
+        assertEquals(0, f.getSize());
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: attachment; size=matters");
+        assertEquals(-1, f.getSize());
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: attachment");
+        assertEquals(-1, f.getSize());
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: attachment; size=-12");
+        assertEquals(-1, f.getSize());
+
+        f = (ContentDispositionField) AbstractField
+                .parse("Content-Disposition: attachment; size=12");
+        assertEquals(12, f.getSize());
+    }
+
+}

Propchange: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/field/ContentDispositionFieldTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message