harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r587111 [2/2] - in /harmony/enhanced/classlib/trunk/modules/pack200/src: main/java/org/apache/harmony/pack200/ main/java/org/apache/harmony/pack200/bytecode/ test/java/org/apache/harmony/pack200/tests/ test/resources/org/apache/harmony/pack...
Date Mon, 22 Oct 2007 14:31:35 GMT
Added: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ClassBandsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ClassBandsTest.java?rev=587111&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ClassBandsTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ClassBandsTest.java
Mon Oct 22 07:31:32 2007
@@ -0,0 +1,144 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.harmony.pack200.tests;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import org.apache.harmony.pack200.ClassBands;
+import org.apache.harmony.pack200.Codec;
+import org.apache.harmony.pack200.CpBands;
+import org.apache.harmony.pack200.Pack200Exception;
+import org.apache.harmony.pack200.Segment;
+
+/**
+ *
+ */
+public class ClassBandsTest extends AbstractBandsTestCase {
+    
+    private String[] cpClasses;
+    private String[] cpDescriptor;
+    
+    public class MockCpBands extends CpBands {
+
+        public MockCpBands(Segment segment) {
+            super(segment);
+        }
+        
+        public String[] getCpClass() {
+            return cpClasses;
+        }
+        
+        public String[] getCpDescriptor() {
+            return cpDescriptor;
+        }
+
+    }
+
+    public class MockSegment extends AbstractBandsTestCase.MockSegment {
+        protected CpBands getCpBands() {
+            return new MockCpBands(this);
+        }       
+        
+    }
+    
+    
+    
+    ClassBands classBands = new ClassBands(new MockSegment());
+    
+    public void testSimple() throws IOException, Pack200Exception {
+        cpClasses = new String[] { "Class1", "Class2", "Class3", "Interface1", "Interface2"
};
+        byte[] classThis = Codec.DELTA5.encode(1, 0);
+        byte[] classSuper = Codec.DELTA5.encode(2, 0);
+        byte[] classInterfaceCount = Codec.DELTA5.encode(2, 0);
+        byte[] classInterfaceRef1 = classBands.encodeBandLong(new long[] {3, 4}, Codec.DELTA5);
+        byte[] classFieldCount = Codec.DELTA5.encode(0, 0);
+        byte[] classMethodCount = Codec.DELTA5.encode(0, 0);
+        byte[] classFlags = Codec.UNSIGNED5.encode(0, 0);
+        byte[][] allArrays = new byte[][] { classThis, classSuper,
+                classInterfaceCount, classInterfaceRef1, classFieldCount,
+                classMethodCount, classFlags };
+        int total = classThis.length + classSuper.length
+                + classInterfaceCount.length + classInterfaceRef1.length
+                + classFieldCount.length + classMethodCount.length
+                + classFlags.length;
+        byte[] bytes = new byte[total];
+        int index = 0;
+        for (int i = 0; i < allArrays.length; i++) {
+            for (int j = 0; j < allArrays[i].length; j++) {
+                bytes[index] = allArrays[i][j];
+                index++;
+            }
+        }
+        ByteArrayInputStream in = new ByteArrayInputStream(bytes);
+        classBands.unpack(in);
+        assertEquals(cpClasses[1], classBands.getClassThis()[0]);
+        assertEquals(cpClasses[2], classBands.getClassSuper()[0]);
+        assertEquals(1, classBands.getClassInterfaces().length);
+        assertEquals(2, classBands.getClassInterfaces()[0].length);
+        assertEquals(cpClasses[3], classBands.getClassInterfaces()[0][0]);
+        assertEquals(cpClasses[4], classBands.getClassInterfaces()[0][1]);
+        cpClasses = null;
+    }
+    
+    public void testWithMethods() throws Pack200Exception, IOException {
+        cpClasses = new String[] { "Class1", "Class2", "Class3" };
+        cpDescriptor = new String[] {"method1", "method2", "method3"};
+        byte[] classThis = Codec.DELTA5.encode(1, 0);
+        byte[] classSuper = Codec.DELTA5.encode(2, 0);
+        byte[] classInterfaceCount = Codec.DELTA5.encode(0, 0);
+        byte[] classFieldCount = Codec.DELTA5.encode(0, 0);
+        byte[] classMethodCount = Codec.DELTA5.encode(3, 0);
+        byte[] methodDescr = classBands.encodeBandLong(new long[]{0, 1, 2}, Codec.MDELTA5);
+        byte[] methodFlagsLo = classBands.encodeBandLong(new long[]{0, 0, 0}, Codec.UNSIGNED5);
+        byte[] classFlags = Codec.UNSIGNED5.encode(0, 0);
+        byte[][] allArrays = new byte[][] { classThis, classSuper,
+                classInterfaceCount, classFieldCount, classMethodCount, 
+                methodDescr, methodFlagsLo, classFlags, };
+        int total = 0;
+        for (int i = 0; i < allArrays.length; i++) {
+            total += allArrays[i].length;
+        }
+        byte[] bytes = new byte[total];
+        int index = 0;
+        for (int i = 0; i < allArrays.length; i++) {
+            for (int j = 0; j < allArrays[i].length; j++) {
+                bytes[index] = allArrays[i][j];
+                index++;
+            }
+        }
+        ByteArrayInputStream in = new ByteArrayInputStream(bytes);
+        classBands.unpack(in);
+        assertEquals(cpClasses[1], classBands.getClassThis()[0]);
+        assertEquals(cpClasses[2], classBands.getClassSuper()[0]);
+        assertEquals(1, classBands.getMethodDescr().length);
+        assertEquals(3, classBands.getMethodDescr()[0].length);
+        assertEquals(cpDescriptor[0], classBands.getMethodDescr()[0][0]);
+        assertEquals(cpDescriptor[1], classBands.getMethodDescr()[0][1]);
+        assertEquals(cpDescriptor[2], classBands.getMethodDescr()[0][2]);
+        
+        cpClasses = null;
+        cpDescriptor = null;
+    }
+    
+    public void testWithFields() {
+        
+    }
+    
+    
+    
+}

Propchange: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ClassBandsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecEncodingTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecEncodingTest.java?rev=587111&r1=587110&r2=587111&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecEncodingTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecEncodingTest.java
Mon Oct 22 07:31:32 2007
@@ -15,9 +15,7 @@
  *  limitations under the License.
  */
 package org.apache.harmony.pack200.tests;
-//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
-//NOTE: Do not extract strings as messages; this code is still a work-in-progress
-//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
+
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.util.HashMap;
@@ -31,11 +29,11 @@
 import org.apache.harmony.pack200.Pack200Exception;
 
 /**
- * @author Alex Blewitt
- * @version $Revision: $
+ * 
  */
 public class CodecEncodingTest extends TestCase {
-	public void testCanonicalEncodings() throws IOException, Pack200Exception { 
+	
+    public void testCanonicalEncodings() throws IOException, Pack200Exception { 
 		Codec defaultCodec = new BHSDCodec(2,16,0,0);
 		assertEquals(defaultCodec,CodecEncoding.getCodec(0,null, defaultCodec));
 		Map map = new HashMap();
@@ -164,4 +162,5 @@
 		assertEquals("(5,128,2,1)",CodecEncoding.getCodec(116,new ByteArrayInputStream(new byte[]
{ 0x25, (byte)0x7F}), null).toString());
 		assertEquals("(2,128,1,1)",CodecEncoding.getCodec(116,new ByteArrayInputStream(new byte[]
{ 0x0B, (byte)0x7F}), null).toString());
 	}
+    
 }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecTest.java?rev=587111&r1=587110&r2=587111&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecTest.java
Mon Oct 22 07:31:32 2007
@@ -15,9 +15,7 @@
  *  limitations under the License.
  */
 package org.apache.harmony.pack200.tests;
-//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
-//NOTE: Do not extract strings as messages; this code is still a work-in-progress
-//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
+
 import java.io.ByteArrayInputStream;
 import java.io.EOFException;
 import java.io.IOException;
@@ -31,8 +29,7 @@
 
 
 /**
- * @author Alex Blewitt
- * @version $Revision: $
+ *
  */
 public class CodecTest extends TestCase {
 

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/HelloWorld.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/HelloWorld.java?rev=587111&r1=587110&r2=587111&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/HelloWorld.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/HelloWorld.java
Mon Oct 22 07:31:32 2007
@@ -15,13 +15,9 @@
  *  limitations under the License.
  */
 package org.apache.harmony.pack200.tests;
-//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
-//NOTE: Do not extract strings as messages; this code is still a work-in-progress
-//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
+
 /**
  * This is intended to be used as a test class for unpacking a packed Jar file.
- * @author Alex Blewitt
- * @version $Revision: $
  */
 public class HelloWorld {
 	int i=97,j=42,k=12345;

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/PopulationCodecTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/PopulationCodecTest.java?rev=587111&r1=587110&r2=587111&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/PopulationCodecTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/PopulationCodecTest.java
Mon Oct 22 07:31:32 2007
@@ -15,9 +15,7 @@
  *  limitations under the License.
  */
 package org.apache.harmony.pack200.tests;
-//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
-//NOTE: Do not extract strings as messages; this code is still a work-in-progress
-//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
+
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentOptionsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentOptionsTest.java?rev=587111&r1=587110&r2=587111&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentOptionsTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentOptionsTest.java
Mon Oct 22 07:31:32 2007
@@ -15,20 +15,18 @@
  *  limitations under the License.
  */
 package org.apache.harmony.pack200.tests;
-//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
-//NOTE: Do not extract strings as messages; this code is still a work-in-progress
-//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
+
 import junit.framework.TestCase;
 
 import org.apache.harmony.pack200.Pack200Exception;
 import org.apache.harmony.pack200.SegmentOptions;
 
 /**
- * @author Alex Blewitt
- * @version $Revision: $
+ * 
  */
 public class SegmentOptionsTest extends TestCase {
-	public void testUnused() {
+	
+    public void testUnused() {
 		int[] unused = new int[] { 3, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
 				23, 24, 25, 26, 27, 28, 29, 30, 31 };
 		for (int i = 0; i < unused.length; i++) {

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentTest.java?rev=587111&r1=587110&r2=587111&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentTest.java
Mon Oct 22 07:31:32 2007
@@ -16,10 +16,15 @@
  */
 package org.apache.harmony.pack200.tests;
 
-import org.apache.harmony.pack200.Segment;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.util.jar.JarOutputStream;
 
 import junit.framework.TestCase;
 
+import org.apache.harmony.pack200.Segment;
+
 /**
  * Tests for org.apache.harmony.pack200.Segment, which is the main class for pack200.
  */
@@ -31,9 +36,11 @@
 	}
 
 	public void testJustResources() throws Exception {
-		assertNotNull(Segment
-				.parse(Segment.class
-						.getResourceAsStream("/org/apache/harmony/pack200/tests/JustResources.pack")));
+        InputStream in = Segment.class
+            .getResourceAsStream("/org/apache/harmony/pack200/tests/JustResources.pack");
+        Segment segment = Segment.parse(in);
+		assertNotNull(segment);
+        segment.writeJar(new JarOutputStream(new FileOutputStream(File.createTempFile("just",
"Resources.jar"))), in);
 	}
 
 	public void testJustResourcesGZip() throws Exception {
@@ -41,11 +48,28 @@
 				.parse(Segment.class
 						.getResourceAsStream("/org/apache/harmony/pack200/tests/JustResources.pack.gz")));
 	}
-
+    
+    // Test with an archive containing Harmony's SQL module, packed with -E1
+    public void testWithSqlE1() throws Exception {
+        assertNotNull(Segment
+                .parse(Segment.class
+                        .getResourceAsStream("/org/apache/harmony/pack200/tests/sql-e1.pack.gz")));
+    
+    }
+    
+    // Test with an archive containing Harmony's Pack200 module, packed with -E1
+    public void testWithPack200E1() throws Exception {
+        assertNotNull(Segment
+                .parse(Segment.class
+                        .getResourceAsStream("/org/apache/harmony/pack200/tests/pack200-e1.pack.gz")));
+    
+    }
+ 
     public void testInterfaceOnly() throws Exception {
         assertNotNull(Segment
                 .parse(Segment.class
                         .getResourceAsStream("/org/apache/harmony/pack200/tests/InterfaceOnly.pack")));
     }
+
 
 }

Added: harmony/enhanced/classlib/trunk/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/pack200-e1.pack.gz
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/pack200-e1.pack.gz?rev=587111&view=auto
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/classlib/trunk/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/pack200-e1.pack.gz
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: harmony/enhanced/classlib/trunk/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/sql-e1.pack.gz
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/sql-e1.pack.gz?rev=587111&view=auto
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/classlib/trunk/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/sql-e1.pack.gz
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message