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 465556) +++ /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AllTests.java (working copy) @@ -18,6 +18,9 @@ // 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.tests.internal.pack200.bytecode.ClassFileEntryTest; +import org.apache.harmony.archive.tests.internal.pack200.bytecode.ConstantPoolTest; + import junit.framework.Test; import junit.framework.TestSuite; /** @@ -35,8 +38,10 @@ // $JUnit-BEGIN$ suite.addTestSuite(AttributeLayoutMapTest.class); suite.addTestSuite(AttributeLayoutTest.class); + suite.addTestSuite(ClassFileEntryTest.class); suite.addTestSuite(CodecEncodingTest.class); suite.addTestSuite(CodecTest.class); + suite.addTestSuite(ConstantPoolTest.class); suite.addTestSuite(PopulationCodecTest.class); suite.addTestSuite(SegmentOptionsTest.class); suite.addTestSuite(SegmentTest.class); Index: /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/bytecode/ConstantPoolTest.java =================================================================== --- /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/bytecode/ConstantPoolTest.java (revision 0) +++ /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/bytecode/ConstantPoolTest.java (revision 0) @@ -0,0 +1,37 @@ +package org.apache.harmony.archive.tests.internal.pack200.bytecode; + +import junit.framework.TestCase; + +import org.apache.harmony.archive.internal.pack200.bytecode.CPField; +import org.apache.harmony.archive.internal.pack200.bytecode.CPUTF8; +import org.apache.harmony.archive.internal.pack200.bytecode.ClassConstantPool; + +public class ConstantPoolTest extends TestCase { + private ClassConstantPool pool; + + public void setUp() { + pool = new ClassConstantPool(); + } + public void testDuplicateUTF8() { + CPUTF8 u1 = new CPUTF8("thing"); + CPUTF8 u2 = new CPUTF8("thing"); + pool.add(u1); + pool.add(u2); + assertEquals(1,pool.size()); + } + public void testDuplicateField() { + CPField cp1 = new CPField("name:I",0,null); + pool.add(cp1); + assertEquals(3,pool.size()); + CPField cp2 = new CPField("name:I",0,null); + pool.add(cp2); + assertEquals(3,pool.size()); + } + public void testIndex() { + pool.add(new CPUTF8("OtherThing")); + CPUTF8 u1 = new CPUTF8("thing"); + pool.add(u1); + pool.resolve(); + assertTrue(pool.indexOf(u1) > 0); + } +} Index: /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/bytecode/ClassFileEntryTest.java =================================================================== --- /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/bytecode/ClassFileEntryTest.java (revision 0) +++ /Users/alex/Documents/Harmony/Workspace/Pack200/src/test/java/org/apache/harmony/archive/tests/internal/pack200/bytecode/ClassFileEntryTest.java (revision 0) @@ -0,0 +1,47 @@ +package org.apache.harmony.archive.tests.internal.pack200.bytecode; + +import junit.framework.TestCase; + +import org.apache.harmony.archive.internal.pack200.bytecode.CPField; +import org.apache.harmony.archive.internal.pack200.bytecode.CPInteger; +import org.apache.harmony.archive.internal.pack200.bytecode.CPUTF8; +import org.apache.harmony.archive.internal.pack200.bytecode.SourceFileAttribute; + +public class ClassFileEntryTest extends TestCase { + public void testUTF8() { + CPUTF8 u1 = new CPUTF8(new String("thing")); //$NON-NLS-1$ + CPUTF8 u2 = new CPUTF8(new String("thing")); //$NON-NLS-1$ + CPUTF8 u3 = new CPUTF8(new String("otherthing")); //$NON-NLS-1$ + checkEquality(u1, u2, "thing", u3); + } + private void checkEquality(Object equal1, Object equal2, String toString, Object unequal) { + assertEquals(equal1,equal2); + assertEquals(equal1.hashCode(),equal2.hashCode()); + assertTrue(equal1.toString().indexOf(toString)>=0); //$NON-NLS-1$ + assertFalse(equal1.equals(unequal)); + assertFalse(equal2.equals(unequal)); + assertFalse(unequal.equals(equal1)); + assertFalse(unequal.equals(equal2)); + } + public void testSourceAttribute() { + SourceFileAttribute sfa1 = new SourceFileAttribute(new String("Thing.java")); //$NON-NLS-1$ + SourceFileAttribute sfa2 = new SourceFileAttribute(new String("Thing.java")); //$NON-NLS-1$ + SourceFileAttribute sfa3 = new SourceFileAttribute(new String("OtherThing.java")); //$NON-NLS-1$ + checkEquality(sfa1,sfa2,"Thing.java",sfa3); //$NON-NLS-1$ + } + public void testCPInteger() { + CPInteger cp1 = new CPInteger(new Integer(3)); + CPInteger cp2 = new CPInteger(new Integer(3)); + CPInteger cp3 = new CPInteger(new Integer(5)); + checkEquality(cp1,cp2,"3",cp3); //$NON-NLS-1$ + } + public void testCPField() { + CPField cp1 = new CPField("Name:I", 0, null); + CPField cp2 = new CPField("Name:I", 0, null); + CPField cp3 = new CPField("Name:Z", 0, null); + CPField cp4 = new CPField("GName:I", 0, null); + checkEquality(cp1,cp2,"Name",cp3); //$NON-NLS-1$ + checkEquality(cp1,cp2,"I",cp4); //$NON-NLS-1$ + } + +}