Index: /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AttributeLayoutMapTest.java =================================================================== --- /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AttributeLayoutMapTest.java (revision 0) +++ /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AttributeLayoutMapTest.java (revision 0) @@ -0,0 +1,50 @@ +/* + * 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.archive.tests.internal.pack200; +//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.archive.internal.pack200.AttributeLayout; +import org.apache.harmony.archive.internal.pack200.AttributeLayoutMap; +import org.apache.harmony.archive.internal.pack200.Pack200Exception; + +public class AttributeLayoutMapTest extends TestCase { + public void testRepeatable() throws Pack200Exception { + // Check we can retrieve a default layout + AttributeLayoutMap a = new AttributeLayoutMap(); + AttributeLayout layout = a.getAttributeLayout("SourceFile", AttributeLayout.CONTEXT_CLASS); + assertNotNull(layout); + assertEquals("RUNH",layout.getLayout()); + // and that we can change it + a.add(new AttributeLayout("SourceFile",AttributeLayout.CONTEXT_CLASS,"FROG",15)); + layout = a.getAttributeLayout("SourceFile", AttributeLayout.CONTEXT_CLASS); + assertNotNull(layout); + assertEquals("FROG",layout.getLayout()); + assertTrue(layout.matches(1<<15)); + assertFalse(layout.matches(1<<16)); + assertTrue(layout.matches(-1)); + assertFalse(layout.matches(0)); + // and that changes don't affect subsequent defaults + AttributeLayoutMap b = new AttributeLayoutMap(); + layout = b.getAttributeLayout("SourceFile", AttributeLayout.CONTEXT_CLASS); + assertNotNull(layout); + assertEquals("RUNH",layout.getLayout()); + + } +} Index: /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AttributeLayoutTest.java =================================================================== --- /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AttributeLayoutTest.java (revision 0) +++ /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AttributeLayoutTest.java (revision 0) @@ -0,0 +1,91 @@ +/* + * 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.archive.tests.internal.pack200; +//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.archive.internal.pack200.AttributeLayout; +import org.apache.harmony.archive.internal.pack200.Pack200Exception; +import org.apache.harmony.archive.internal.pack200.Segment; + +public class AttributeLayoutTest extends TestCase { + public class TestSegment extends Segment { + public SegmentConstantPool getConstantPool() { + final Object[][] data = new Object[][] { + { }, // ALL + { "Zero", "One" }, // UTF-8 + { "Ein", "Zwei" }, // Signature + }; + return new SegmentConstantPool() { + public Object getValue(int cp, long index) { + if (index == -1) + return null; + return data[cp][(int)index]; + } + + }; + } + } + public void testBadData() { + assertTrue(throwsException(null,AttributeLayout.CONTEXT_CLASS,"")); + assertTrue(throwsException("",AttributeLayout.CONTEXT_CLASS,"")); + assertTrue(!throwsException("name",AttributeLayout.CONTEXT_CLASS,"")); + assertTrue(!throwsException("name",AttributeLayout.CONTEXT_METHOD,"")); + assertTrue(!throwsException("name",AttributeLayout.CONTEXT_FIELD,"")); + assertTrue(!throwsException("name",AttributeLayout.CONTEXT_CODE,"")); + assertTrue(throwsException("name",-1,"")); + assertTrue(throwsException("name",1234,"")); + } + public void testLayoutRU() throws Pack200Exception { + AttributeLayout layout = new AttributeLayout("RU",AttributeLayout.CONTEXT_CLASS,"RU", 1); + Segment segment = new TestSegment(); + assertNull(layout.getValue(-1, segment)); + assertEquals("Zero",layout.getValue(0, segment)); + assertEquals("One",layout.getValue(1, segment)); + } + public void testLayoutRUN() throws Pack200Exception { + AttributeLayout layout = new AttributeLayout("RUN",AttributeLayout.CONTEXT_CLASS,"RUN", 1); + Segment segment = new TestSegment(); + assertNull(layout.getValue(0, segment)); + assertEquals("Zero",layout.getValue(1, segment)); + assertEquals("One",layout.getValue(2, segment)); + } + public void testLayoutRS() throws Pack200Exception { + AttributeLayout layout = new AttributeLayout("RS",AttributeLayout.CONTEXT_CLASS,"RS", 1); + Segment segment = new TestSegment(); + assertNull(layout.getValue(-1, segment)); + assertEquals("Ein",layout.getValue(0, segment)); + assertEquals("Zwei",layout.getValue(1, segment)); + } + public void testLayoutRSN() throws Pack200Exception { + AttributeLayout layout = new AttributeLayout("RSN",AttributeLayout.CONTEXT_CLASS,"RSN", 1); + Segment segment = new TestSegment(); + assertNull(layout.getValue(0, segment)); + assertEquals("Ein",layout.getValue(1, segment)); + assertEquals("Zwei",layout.getValue(2, segment)); + } + public boolean throwsException(String name, int context, String layout) { + try { + new AttributeLayout(name,context,layout,-1); + return false; + } catch (Pack200Exception e) { + return true; + } + } +} Index: /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/SegmentTest.java =================================================================== --- /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/SegmentTest.java (revision 464090) +++ /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/SegmentTest.java (working copy) @@ -15,7 +15,9 @@ * limitations under the License. */ package org.apache.harmony.archive.tests.internal.pack200; - +//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 org.apache.harmony.archive.internal.pack200.Segment; import junit.framework.TestCase; Index: /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/CodecEncodingTest.java =================================================================== --- /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/CodecEncodingTest.java (revision 464090) +++ /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/CodecEncodingTest.java (working copy) @@ -15,7 +15,9 @@ * limitations under the License. */ package org.apache.harmony.archive.tests.internal.pack200; - +//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; @@ -36,7 +38,7 @@ 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(); + Map map = new HashMap(); // These are the canonical encodings specified by the Pack200 spec map.put(new Integer(1), "(1,256)"); map.put(new Integer(2), "(1,256,1)"); Index: /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/PopulationCodecTest.java =================================================================== --- /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/PopulationCodecTest.java (revision 464090) +++ /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/PopulationCodecTest.java (working copy) @@ -15,7 +15,9 @@ * limitations under the License. */ package org.apache.harmony.archive.tests.internal.pack200; - +//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; Index: /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/HelloWorld.java =================================================================== --- /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/HelloWorld.java (revision 464090) +++ /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/HelloWorld.java (working copy) @@ -15,7 +15,9 @@ * limitations under the License. */ package org.apache.harmony.archive.tests.internal.pack200; - +//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 Index: /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AllTests.java =================================================================== --- /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AllTests.java (revision 464090) +++ /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AllTests.java (working copy) @@ -1,25 +1,25 @@ -/* - * 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 - * +/* + * 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. + * + * 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.archive.tests.internal.pack200; - +// 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.Test; import junit.framework.TestSuite; - /** * Test suite for org.apache.harmony.archive.internal.pack200 package. */ @@ -33,6 +33,8 @@ TestSuite suite = new TestSuite( "Suite org.apache.harmony.archive.tests.internal.pack200"); // $JUnit-BEGIN$ + suite.addTestSuite(AttributeLayoutMapTest.class); + suite.addTestSuite(AttributeLayoutTest.class); suite.addTestSuite(CodecEncodingTest.class); suite.addTestSuite(CodecTest.class); suite.addTestSuite(PopulationCodecTest.class); Index: /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/CodecTest.java =================================================================== --- /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/CodecTest.java (revision 464090) +++ /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/CodecTest.java (working copy) @@ -15,7 +15,9 @@ * limitations under the License. */ package org.apache.harmony.archive.tests.internal.pack200; - +//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; Index: /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/SegmentOptionsTest.java =================================================================== --- /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/SegmentOptionsTest.java (revision 464090) +++ /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/SegmentOptionsTest.java (working copy) @@ -15,7 +15,9 @@ * limitations under the License. */ package org.apache.harmony.archive.tests.internal.pack200; - +//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.archive.internal.pack200.Pack200Exception;