You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by eb...@apache.org on 2013/08/07 11:17:35 UTC

svn commit: r1511218 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java

Author: ebourg
Date: Wed Aug  7 09:17:34 2013
New Revision: 1511218

URL: http://svn.apache.org/r1511218
Log:
Added tests for the ERROR and TRUNCATE long file modes of TarArchiveOutputStream

Modified:
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java?rev=1511218&r1=1511217&r2=1511218&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java (original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java Wed Aug  7 09:17:34 2013
@@ -372,6 +372,46 @@ public class TarArchiveOutputStreamTest 
         tin.close();
     }
 
+    public void testWriteLongDirectoryNameErrorMode() throws Exception {
+        String n = "01234567890123456789012345678901234567890123456789"
+                + "01234567890123456789012345678901234567890123456789"
+                + "01234567890123456789012345678901234567890123456789/";
+
+        try {
+            TarArchiveEntry t = new TarArchiveEntry(n);
+            ByteArrayOutputStream bos = new ByteArrayOutputStream();
+            TarArchiveOutputStream tos = new TarArchiveOutputStream(bos, "ASCII");
+            tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_ERROR);
+            tos.putArchiveEntry(t);
+            tos.closeArchiveEntry();
+            tos.close();
+            
+            fail("Truncated name didn't throw an exception");
+        } catch (RuntimeException e) {
+            // expected
+        }
+    }
+
+    public void testWriteLongDirectoryNameTruncateMode() throws Exception {
+        String n = "01234567890123456789012345678901234567890123456789"
+            + "01234567890123456789012345678901234567890123456789"
+            + "01234567890123456789012345678901234567890123456789/";
+        TarArchiveEntry t = new TarArchiveEntry(n);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        TarArchiveOutputStream tos = new TarArchiveOutputStream(bos, "ASCII");
+        tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_TRUNCATE);
+        tos.putArchiveEntry(t);
+        tos.closeArchiveEntry();
+        tos.close();
+        byte[] data = bos.toByteArray();
+        TarArchiveInputStream tin =
+            new TarArchiveInputStream(new ByteArrayInputStream(data));
+        TarArchiveEntry e = tin.getNextTarEntry();
+        assertEquals("Entry name", n.substring(0, TarConstants.NAMELEN) + "/", e.getName());
+        assertTrue("The entry is not a directory", e.isDirectory());
+        tin.close();
+    }
+
     /**
      * @see "https://issues.apache.org/jira/browse/COMPRESS-203"
      */