commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject svn commit: r1592433 - /commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/ProviderReadTests.java
Date Mon, 05 May 2014 00:05:08 GMT
Author: ecki
Date: Mon May  5 00:05:08 2014
New Revision: 1592433

URL: http://svn.apache.org/r1592433
Log:
[tests] Test EOF condition handling in providers.
(merges (with modifications) https://github.com/apache/commons-vfs/pull/3)

Modified:
    commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/ProviderReadTests.java

Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/ProviderReadTests.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/ProviderReadTests.java?rev=1592433&r1=1592432&r2=1592433&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/ProviderReadTests.java
(original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/ProviderReadTests.java
Mon May  5 00:05:08 2014
@@ -266,6 +266,58 @@ public class ProviderReadTests extends A
     }
 
     /**
+     * Tests can read multiple time end of stream of empty file
+     */
+    public void testReadEmptyMultipleEOF() throws Exception
+    {
+        final FileObject file = getReadFolder().resolveFile("empty.txt");
+        assertTrue(file.exists());
+
+        // Start reading from the file
+        final InputStream instr = file.getContent().getInputStream();
+        try
+        {
+            assertEquals("read() from empty file should return EOF", -1, instr.read());
+
+            for(int i=0;i<5;i++)
+            {
+                assertEquals("multiple read() at EOF should return EOF", -1, instr.read());
+            }
+        }
+        finally
+        {
+            instr.close();
+        }
+    }
+
+    /**
+     * Tests can read multiple time end of stream
+     */
+    public void testReadFileEOFMultiple() throws Exception
+    {
+        final FileObject file = getReadFolder().resolveFile("file1.txt");
+        assertTrue(file.exists());
+        assertEquals("Expecting 20 bytes test-data file1.txt", 20, file.getContent().getSize());
+
+        // Start reading from the file
+        final InputStream instr = file.getContent().getInputStream();
+        try
+        {
+            byte[] buf = new byte[25];
+            assertEquals(20, instr.read(buf));
+
+            for(int i=0;i<5;i++)
+            {
+                assertEquals("multiple read(byte[]) at EOF should return EOF", -1, instr.read(buf));
+            }
+        }
+        finally
+        {
+            instr.close();
+        }
+    }
+
+    /**
      * Tests can perform operations on a folder while reading from a different files.
      */
     public void testConcurrentReadFolder() throws Exception



Mime
View raw message