You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2010/06/01 17:19:53 UTC

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

Author: sebb
Date: Tue Jun  1 15:19:53 2010
New Revision: 950111

URL: http://svn.apache.org/viewvc?rev=950111&view=rev
Log:
Fixup tests - should only allow at most 11 octal digits in 12-byte buffer

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

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java?rev=950111&r1=950110&r2=950111&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java (original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java Tue Jun  1 15:19:53 2010
@@ -39,30 +39,20 @@ public class TarUtilsTest extends TestCa
         assertEquals(sb1, sb2);
     }
     
-    private void fillBuff(byte []buffer, String input) throws Exception{
-        for(int i=0; i<buffer.length;i++){
-            buffer[i]=0;
-        }
-        System.arraycopy(input.getBytes("UTF-8"),0,buffer,0,Math.min(buffer.length,input.length()));        
-    }
-
     public void testParseOctal() throws Exception{
-        byte [] buffer = new byte[20];
-        fillBuff(buffer,"777777777777 ");
         long value; 
-        value = TarUtils.parseOctal(buffer,0, 11);
-        assertEquals(077777777777L, value);
-        value = TarUtils.parseOctal(buffer,0, 12);
-        assertEquals(0777777777777L, value);
-        buffer[11]=' ';
-        value = TarUtils.parseOctal(buffer,0, 11);
-        assertEquals(077777777777L, value);
-        buffer[11]=0;
-        value = TarUtils.parseOctal(buffer,0, 11);
-        assertEquals(077777777777L, value);
-        fillBuff(buffer, "abcdef"); // Invalid input
+        byte [] buffer;
+        final long MAX_OCTAL  = 077777777777L; // Allowed 11 digits
+        final String maxOctal = "77777777777 "; // Maximum valid octal
+        buffer = maxOctal.getBytes("UTF-8");
+        value = TarUtils.parseOctal(buffer,0, buffer.length);
+        assertEquals(MAX_OCTAL, value);
+        buffer[buffer.length-1]=0;
+        value = TarUtils.parseOctal(buffer,0, buffer.length);
+        assertEquals(MAX_OCTAL, value);
+        buffer = "abcdef".getBytes("UTF-8"); // Invalid input
         try {
-            value = TarUtils.parseOctal(buffer,0, 11);
+            TarUtils.parseOctal(buffer,0, buffer.length);
             fail("Expected IllegalArgumentException");
         } catch (IllegalArgumentException expected) {
         }