OSDN Git Service

Add header getExtraFlag mothod
authorHiroshi Miura <miurahr@linux.com>
Sat, 9 Apr 2016 06:41:58 +0000 (15:41 +0900)
committerHiroshi Miura <miurahr@linux.com>
Sat, 9 Apr 2016 06:41:58 +0000 (15:41 +0900)
Signed-off-by: Hiroshi Miura <miurahr@linux.com>
CHANGELOG.md
dictzip-lib/src/main/java/org/dict/zip/DictZipHeader.java
dictzip-lib/src/test/java/org/dict/zip/DictZipHeaderTest.java
dictzip-lib/src/test/resources/best.dict.dz [new file with mode: 0644]
dictzip-lib/src/test/resources/fast.dict.dz [new file with mode: 0644]

index d57f84b..4e93fe6 100644 (file)
@@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
 - gradle.properties.template
   You need to copy to gradle.properties and edit its configuration.
 - [#8] Support -# --fast --best option in CLI.
+- DictZipHeader.getExtraFlag() method.
 
 ### Changed
 - We have now dictzip-lib and dictzip-cli subprojects.
index 7c70599..5477dec 100644 (file)
@@ -528,6 +528,14 @@ public class DictZipHeader {
     }
 
     /**
+     * Get extra flag.
+     * @return flag compression level.
+     */
+    public CompressionLevel getExtraFlag() {
+        return extraFlag;
+    }
+
+    /**
      * Set mtime field.
      * @param mtime modification time.
      */
index 4b68792..11b13d5 100644 (file)
@@ -33,9 +33,7 @@ import java.io.IOException;
  */
 public class DictZipHeaderTest {
 
-    private final String dataFile = this.getClass().getResource("/test.dict.dz").getFile();
-
-    private String expResult() {
+    private String toStringExpResult() {
         return "\nHeader length = 49" +
                 "\nSubfield ID = RA" +
                 "\nSubfield length = 20" +
@@ -47,23 +45,24 @@ public class DictZipHeaderTest {
     /**
      * Test of readHeader method, of class DictZipHeader.
      *
-     * @throws java.lang.Exception if file I/O error occurd.
+     * @throws java.lang.Exception if file I/O error occurred.
      */
     @Test
     public void testReadHeader_String() throws Exception {
         System.out.println("readHeader");
+        String dataFile = this.getClass().getResource("/test.dict.dz").getFile();
         DictZipHeader result = DictZipHeader.readHeader(dataFile);
-        assertEquals(expResult(), result.toString());
+        assertEquals(toStringExpResult(), result.toString());
     }
 
     /**
      * Test of readHeader method, of class DictZipHeader.
      *
-     * @throws java.lang.Exception if file I/O error occurd.
+     * @throws java.lang.Exception if file I/O error occurred.
      */
     @Test
     public void testReadHeader_NonGZip() throws Exception {
-        System.out.println("readHeader");
+        System.out.println("readHeader / not dictzip file");
         byte b[] = {3, 5, 2, 'r', 'g', 'e', 'f', 'd', 'e', 'w'};
         File testFile = File.createTempFile("DictZipOutCon", ".txt.dz");
         FileOutputStream outFile = new FileOutputStream(testFile);
@@ -77,16 +76,17 @@ public class DictZipHeaderTest {
             r = true;
         }
         assertTrue(r, "IOException Expected and got");
+        testFile.deleteOnExit();
     }
 
     /**
      * Test of readHeader method, of class DictZipHeader.
      *
-     * @throws java.lang.Exception if file I/O error occurd.
+     * @throws java.lang.Exception if file I/O error occurred.
      */
     @Test
     public void testReadHeader_GZipMagic() throws Exception {
-        System.out.println("readHeader");
+        System.out.println("readHeader / wrong gzip magic");
         byte b[] = {(byte) 0x1f, (byte) 0x8b, 2, 'r', 'g', 'e', 'f', 'd', 'e', 'w'};
         File testFile = File.createTempFile("DictZipOutCon", ".txt.dz");
         FileOutputStream outFile = new FileOutputStream(testFile);
@@ -100,5 +100,32 @@ public class DictZipHeaderTest {
             r = true;
         }
         assertTrue(r, "IOException Expected and got");
+        testFile.deleteOnExit();
+    }
+
+    /**
+     * Test of readHeader method on fast_compression level file.
+     *
+     * @throws java.lang.Exception if file I/O error occurred.
+     */
+    @Test
+    public void testReaderHeader_FastCompression() throws Exception {
+        System.out.println("readHeader of fast compression");
+        String dataFile = this.getClass().getResource("/fast.dict.dz").getFile();
+        DictZipHeader result = DictZipHeader.readHeader(dataFile);
+        assertEquals(result.getExtraFlag(), DictZipHeader.CompressionLevel.BEST_SPEED);
+    }
+
+    /**
+     * Test of readHeader method on best_compression level file.
+     *
+     * @throws java.lang.Exception if file I/O error occurred.
+     */
+    @Test
+    public void testReaderHeader_BestCompression() throws Exception {
+        System.out.println("readHeader of best compression");
+        String dataFile = this.getClass().getResource("/best.dict.dz").getFile();
+        DictZipHeader result = DictZipHeader.readHeader(dataFile);
+        assertEquals(result.getExtraFlag(), DictZipHeader.CompressionLevel.BEST_COMPRESSION);
     }
 }
diff --git a/dictzip-lib/src/test/resources/best.dict.dz b/dictzip-lib/src/test/resources/best.dict.dz
new file mode 100644 (file)
index 0000000..3e63240
Binary files /dev/null and b/dictzip-lib/src/test/resources/best.dict.dz differ
diff --git a/dictzip-lib/src/test/resources/fast.dict.dz b/dictzip-lib/src/test/resources/fast.dict.dz
new file mode 100644 (file)
index 0000000..e872bf1
Binary files /dev/null and b/dictzip-lib/src/test/resources/fast.dict.dz differ