commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1149128 - in /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip: ExtraFieldUtilsTest.java ZipArchiveEntryTest.java
Date Thu, 21 Jul 2011 11:29:27 GMT
Author: bodewig
Date: Thu Jul 21 11:29:26 2011
New Revision: 1149128

URL: http://svn.apache.org/viewvc?rev=1149128&view=rev
Log:
extra field header id 1 is the zip 64 extra information field which will soon be supported,
so don't use it as 'unknown' placeholder

Modified:
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtilsTest.java
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtilsTest.java?rev=1149128&r1=1149127&r2=1149128&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtilsTest.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtilsTest.java
Thu Jul 21 11:29:26 2011
@@ -29,6 +29,14 @@ public class ExtraFieldUtilsTest extends
         super(name);
     }
 
+    /**
+     * Header-ID of a ZipExtraField not supported by Commons Compress.
+     *
+     * <p>Used to be ZipShort(1) but this is the ID of the Zip64 extra
+     * field.</p>
+     */
+    static final ZipShort UNRECOGNIZED_HEADER = new ZipShort(0x5555);
+
     private AsiExtraField a;
     private UnrecognizedExtraField dummy;
     private byte[] data;
@@ -39,7 +47,7 @@ public class ExtraFieldUtilsTest extends
         a.setMode(0755);
         a.setDirectory(true);
         dummy = new UnrecognizedExtraField();
-        dummy.setHeaderId(new ZipShort(1));
+        dummy.setHeaderId(UNRECOGNIZED_HEADER);
         dummy.setLocalFileDataData(new byte[] {0});
         dummy.setCentralDirectoryData(new byte[] {0});
 
@@ -167,7 +175,8 @@ public class ExtraFieldUtilsTest extends
 
     public void testMergeWithUnparseableData() throws Exception {
         ZipExtraField d = new UnparseableExtraFieldData();
-        d.parseFromLocalFileData(new byte[] {1, 0, 1, 0}, 0, 4);
+        byte[] b = UNRECOGNIZED_HEADER.getBytes();
+        d.parseFromLocalFileData(new byte[] {b[0], b[1], 1, 0}, 0, 4);
         byte[] local =
             ExtraFieldUtils.mergeLocalFileDataData(new ZipExtraField[] {a, d});
         assertEquals("local length", data.length - 1, local.length);

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java?rev=1149128&r1=1149127&r2=1149128&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java
Thu Jul 21 11:29:26 2011
@@ -38,7 +38,7 @@ public class ZipArchiveEntryTest extends
         a.setDirectory(true);
         a.setMode(0755);
         UnrecognizedExtraField u = new UnrecognizedExtraField();
-        u.setHeaderId(new ZipShort(1));
+        u.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
         u.setLocalFileDataData(new byte[0]);
 
         ZipArchiveEntry ze = new ZipArchiveEntry("test/");
@@ -50,7 +50,7 @@ public class ZipArchiveEntryTest extends
         assertSame(u, result[1]);
 
         UnrecognizedExtraField u2 = new UnrecognizedExtraField();
-        u2.setHeaderId(new ZipShort(1));
+        u2.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
         u2.setLocalFileDataData(new byte[] {1});
 
         ze.addExtraField(u2);
@@ -68,7 +68,7 @@ public class ZipArchiveEntryTest extends
         result = ze.getExtraFields();
         assertEquals("third pass", 3, result.length);
 
-        ze.removeExtraField(new ZipShort(1));
+        ze.removeExtraField(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
         byte[] data3 = ze.getExtra();
         result = ze.getExtraFields();
         assertEquals("fourth pass", 2, result.length);
@@ -77,7 +77,7 @@ public class ZipArchiveEntryTest extends
         assertEquals("length fourth pass", data2.length, data3.length);
 
         try {
-            ze.removeExtraField(new ZipShort(1));
+            ze.removeExtraField(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
             fail("should be no such element");
         } catch (java.util.NoSuchElementException nse) {
         }
@@ -91,7 +91,7 @@ public class ZipArchiveEntryTest extends
         a.setDirectory(true);
         a.setMode(0755);
         UnrecognizedExtraField u = new UnrecognizedExtraField();
-        u.setHeaderId(new ZipShort(1));
+        u.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
         u.setLocalFileDataData(new byte[0]);
 
         ZipArchiveEntry ze = new ZipArchiveEntry("test/");
@@ -99,12 +99,14 @@ public class ZipArchiveEntryTest extends
 
         // merge
         // Header-ID 1 + length 1 + one byte of data
-        ze.setCentralDirectoryExtra(new byte[] {1, 0, 1, 0, 127});
+        byte[] b = ExtraFieldUtilsTest.UNRECOGNIZED_HEADER.getBytes();
+        ze.setCentralDirectoryExtra(new byte[] {b[0], b[1], 1, 0, 127});
 
         ZipExtraField[] result = ze.getExtraFields();
         assertEquals("first pass", 2, result.length);
         assertSame(a, result[0]);
-        assertEquals(new ZipShort(1), result[1].getHeaderId());
+        assertEquals(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER,
+                     result[1].getHeaderId());
         assertEquals(new ZipShort(0), result[1].getLocalFileDataLength());
         assertEquals(new ZipShort(1), result[1].getCentralDirectoryLength());
 
@@ -135,7 +137,7 @@ public class ZipArchiveEntryTest extends
         a.setDirectory(true);
         a.setMode(0755);
         UnrecognizedExtraField u = new UnrecognizedExtraField();
-        u.setHeaderId(new ZipShort(1));
+        u.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
         u.setLocalFileDataData(new byte[0]);
 
         ZipArchiveEntry ze = new ZipArchiveEntry("test/");
@@ -143,7 +145,7 @@ public class ZipArchiveEntryTest extends
         byte[] data1 = ze.getExtra();
 
         UnrecognizedExtraField u2 = new UnrecognizedExtraField();
-        u2.setHeaderId(new ZipShort(1));
+        u2.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
         u2.setLocalFileDataData(new byte[] {1});
 
         ze.addAsFirstExtraField(u2);



Mime
View raw message