OSDN Git Service

Add test
authorHiroshi Miura <miurahr@linux.com>
Fri, 29 Apr 2016 13:34:00 +0000 (22:34 +0900)
committerHiroshi Miura <miurahr@linux.com>
Fri, 29 Apr 2016 13:42:45 +0000 (22:42 +0900)
Signed-off-by: Hiroshi Miura <miurahr@linux.com>
CHANGELOG.md
dictzip-lib/src/test/java/org/dict/zip/DictZipInputStreamTest.java

index cb1e9f0..6beff30 100644 (file)
@@ -6,8 +6,11 @@ All notable changes to this project will be documented in this file.
 
 ### Changed
 
+
+## [0.8.1] - 2015-4-29
 ### Fixed
 - Gradle: github and bintray release error.
+- [#21] fixed unexpected EOFException when readFully() called after seek().
 
 ## [0.8.0] - 2015-4-29
 ### Add
@@ -92,7 +95,8 @@ All notable changes to this project will be documented in this file.
 ### Added
 - Start project.
 
-[Unreleased]: https://github.com/miurahr/dictzip-java/compare/v0.8.0...HEAD
+[Unreleased]: https://github.com/miurahr/dictzip-java/compare/v0.8.1...HEAD
+[0.8.1]: https://github.com/miurahr/dictzip-java/compare/v0.8.0...v0.8.1
 [0.8.0]: https://github.com/miurahr/dictzip-java/compare/v0.7.0...v0.8.0
 [0.7.0]: https://github.com/miurahr/dictzip-java/compare/v0.6.1...v0.7.0
 [0.6.1]: https://github.com/miurahr/dictzip-java/compare/v0.6.0...v0.6.1
index 3a701df..42fc811 100644 (file)
@@ -43,9 +43,11 @@ import org.testng.SkipException;
 import org.testng.annotations.*;
 
 import java.io.EOFException;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.Arrays;
 
+import static tokyo.northside.io.IOUtils2.contentEquals;
 
 /**
  * Test of DictZipInputStream.
@@ -95,9 +97,10 @@ public class DictZipInputStreamTest {
      * Test close of stream.
      * @throws Exception if I/O error occurred.
      */
-    @Test (dependsOnGroups = { "test" })
+    @Test (groups = "exit", dependsOnGroups = { "test" })
     public void testClose() throws Exception {
         din.close();
+        din = null;
     }
 
     /**
@@ -177,8 +180,7 @@ public class DictZipInputStreamTest {
         int len = 512;
         byte[] buf = new byte[len];
         int size = din.read(buf, 0, 0);
-        throw new SkipException("Unknown bug.");
-        //assertEquals(size, 0);
+        assertEquals(size, 0);
     }
 
     /**
@@ -289,5 +291,64 @@ public class DictZipInputStreamTest {
         assertEquals(din.getFilename(), "results.dict");
     }
 
+   /**
+     * Test readFully with large seek
+     */
+    @Test (groups = "test", dependsOnMethods = { "testConstructor" })
+    public void testReadFully_seek2() throws Exception {
+        System.out.println("readFully_seek2");
+        int start = 56003;
+        int len = 195;
+        try {
+            din.seek(start);
+        } catch (IOException ioe) {
+            fail("Unexpected IOException");
+        }
+        byte[] buf = new byte[len];
+        try {
+            din.readFully(buf);
+        } catch (EOFException eofe) {
+            fail("Unexpected EOF");
+        }
+    }
 
+   /**
+     * Test with large  seek
+     */
+    @Test (groups = "test", dependsOnMethods = { "testConstructor" })
+    public void testRead_seek2() throws Exception {
+        System.out.println("read_seek2");
+        int start = 56003;
+        int len = 195;
+        try {
+            din.seek(start);
+        } catch (IOException ioe) {
+            fail("Unexpected IOException");
+        }
+        byte[] buf = new byte[len];
+        int result=0;
+        try {
+            result = din.read(buf, 0, len);
+        } catch (EOFException eofe) {
+            fail("Unexpected EOF");
+        }
+        assertEquals(result, len);
+    }
+    /**
+     * Test with large seek comparison content
+     */
+    @Test (groups = "test", dependsOnMethods = { "testConstructor"})
+    public void testRead_seek3() throws Exception {
+         System.out.println("read_seek2");
+        int start = 56003;
+        int len = 195;
+        try {
+            din.seek(start);
+        } catch (IOException ioe) {
+            fail("Unexpected IOException");
+        }
+        FileInputStream in2 = new FileInputStream(this.getClass().getResource("/test.dict.expected").getFile());
+        in2.skip(start);
+        assertTrue(contentEquals(din, in2, 0, len));
+    }
 }