You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ni...@apache.org on 2006/10/13 02:56:19 UTC

svn commit: r463537 - in /jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io: IOUtilsCopyTestCase.java input/CountingInputStreamTest.java output/CountingOutputStreamTest.java

Author: niallp
Date: Thu Oct 12 17:56:18 2006
New Revision: 463537

URL: http://svn.apache.org/viewvc?view=rev&rev=463537
Log:
IO-84 - add tests for files > 2GB to IOUtils.copy(), CountingInputStream and CountingOutputStream

Modified:
    jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/IOUtilsCopyTestCase.java
    jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/input/CountingInputStreamTest.java
    jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/output/CountingOutputStreamTest.java

Modified: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/IOUtilsCopyTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/IOUtilsCopyTestCase.java?view=diff&rev=463537&r1=463536&r2=463537
==============================================================================
--- jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/IOUtilsCopyTestCase.java (original)
+++ jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/IOUtilsCopyTestCase.java Thu Oct 12 17:56:18 2006
@@ -21,6 +21,7 @@
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
+import java.io.IOException;
 import java.io.Reader;
 import java.io.Writer;
 import java.util.Arrays;
@@ -29,7 +30,11 @@
 import junit.framework.TestSuite;
 import junit.textui.TestRunner;
 
+import org.apache.commons.io.input.NullInputStream;
+import org.apache.commons.io.input.NullReader;
 import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.commons.io.output.NullOutputStream;
+import org.apache.commons.io.output.NullWriter;
 import org.apache.commons.io.testtools.FileBasedTestCase;
 import org.apache.commons.io.testtools.YellOnCloseInputStream;
 import org.apache.commons.io.testtools.YellOnFlushAndCloseOutputStream;
@@ -111,6 +116,29 @@
         } catch (NullPointerException ex) {}
     }
 
+    /**
+     * Test Copying file > 2GB  - see issue# IO-84
+     */
+    public void testCopy_inputStreamToOutputStream_IO84() throws Exception {
+        long size = (long)Integer.MAX_VALUE + (long)1;
+        InputStream  in  = new NullInputStream(size);
+        OutputStream out = new NullOutputStream();
+
+        // Test copy() method
+        try {
+            IOUtils.copy(in, out);
+            fail("Expected copy() to throw an ArithmeticException");
+        } catch (ArithmeticException ae) {
+            // expected result
+        }
+
+        // reset the input
+        in.close();
+
+        // Test copyLarge() method
+        assertEquals("copyLarge()", size, IOUtils.copyLarge(in, out));
+    }
+
     //-----------------------------------------------------------------------
     public void testCopy_inputStreamToWriter() throws Exception {
         InputStream in = new ByteArrayInputStream(inData);
@@ -330,6 +358,30 @@
             IOUtils.copy(reader, (Writer) null);
             fail();
         } catch (NullPointerException ex) {}
+    }
+
+    /**
+     * Test Copying file > 2GB  - see issue# IO-84
+     */
+    public void testCopy_readerToWriter_IO84() throws Exception {
+        long size = (long)Integer.MAX_VALUE + (long)1;
+        Reader reader = new NullReader(size);
+        Writer writer = new NullWriter();
+
+        // Test copy() method
+        try {
+            IOUtils.copy(reader, writer);
+            fail("Expected copy() to throw an ArithmeticException");
+        } catch (ArithmeticException ae) {
+            // expected result
+        }
+
+        // reset the input
+        reader.close();
+
+        // Test copyLarge() method
+        assertEquals("copyLarge()", size, IOUtils.copyLarge(reader, writer));
+
     }
 
 }

Modified: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/input/CountingInputStreamTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/input/CountingInputStreamTest.java?view=diff&rev=463537&r1=463536&r2=463537
==============================================================================
--- jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/input/CountingInputStreamTest.java (original)
+++ jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/input/CountingInputStreamTest.java Thu Oct 12 17:56:18 2006
@@ -17,9 +17,12 @@
 package org.apache.commons.io.input;
 
 import java.io.ByteArrayInputStream;
+import java.io.OutputStream;
 import java.io.IOException;
 
 import junit.framework.TestCase;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.output.NullOutputStream;
 
 /**
  * Tests the CountingInputStream.
@@ -65,6 +68,39 @@
         // trim to get rid of the 6 empty values
         String textResult = new String(result).trim();
         assertEquals(textResult, text);
+    }
+
+
+    /**
+     * Test for files > 2GB in size - see issue IO-84
+     */
+    public void testLargeFiles_IO84() throws Exception {
+        long size = (long)Integer.MAX_VALUE + (long)1;
+        NullInputStream mock    = new NullInputStream(size);
+        CountingInputStream cis = new CountingInputStream(mock);
+        OutputStream out        = new NullOutputStream();
+
+        // Test integer methods
+        IOUtils.copyLarge(cis, out);
+        try {
+            cis.getCount();
+            fail("Expected getCount() to throw an ArithmeticException");
+        } catch (ArithmeticException ae) {
+            // expected result
+        }
+        try {
+            cis.resetCount();
+            fail("Expected resetCount() to throw an ArithmeticException");
+        } catch (ArithmeticException ae) {
+            // expected result
+        }
+
+        mock.close();
+
+        // Test long methods
+        IOUtils.copyLarge(cis, out);
+        assertEquals("getByteCount()",   size, cis.getByteCount());
+        assertEquals("resetByteCount()", size, cis.resetByteCount());
     }
 
     public void testResetting() throws Exception {

Modified: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/output/CountingOutputStreamTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/output/CountingOutputStreamTest.java?view=diff&rev=463537&r1=463536&r2=463537
==============================================================================
--- jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/output/CountingOutputStreamTest.java (original)
+++ jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/output/CountingOutputStreamTest.java Thu Oct 12 17:56:18 2006
@@ -17,10 +17,13 @@
 package org.apache.commons.io.output;
 
 
+import java.io.OutputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 
 import junit.framework.TestCase;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.input.NullInputStream;
 
 
 /**
@@ -68,6 +71,39 @@
         assertByteArrayEquals("CountingOutputStream.write(int)", baos.toByteArray(), 35, 45);
         assertEquals("CountingOutputStream.getCount()", cos.getCount(), 10);
 
+    }
+
+    /**
+     * Test for files > 2GB in size - see issue IO-84
+     */
+    public void testLargeFiles_IO84() throws Exception {
+        long size = (long)Integer.MAX_VALUE + (long)1;
+
+        NullInputStream mock     = new NullInputStream(size);
+        OutputStream nos         = new NullOutputStream();
+        CountingOutputStream cos = new CountingOutputStream(nos);
+
+        // Test integer methods
+        IOUtils.copyLarge(mock, cos);
+        try {
+            cos.getCount();
+            fail("Expected getCount() to throw an ArithmeticException");
+        } catch (ArithmeticException ae) {
+            // expected result
+        }
+        try {
+            cos.resetCount();
+            fail("Expected resetCount() to throw an ArithmeticException");
+        } catch (ArithmeticException ae) {
+            // expected result
+        }
+
+        mock.close();
+
+        // Test long methods
+        IOUtils.copyLarge(mock, cos);
+        assertEquals("getByteCount()",   size, cos.getByteCount());
+        assertEquals("resetByteCount()", size, cos.resetByteCount());
     }
 
     private void assertByteArrayEquals(String msg, byte[] array, int start, int end) {



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org