diff --git a/test/build.xml b/test/build.xml index 0ebe61fdf03c21d93ccdcf9eb7c960d8864374c8..8426d3499102f16ee10d4508b8215d2d2b980d52 100644 --- a/test/build.xml +++ b/test/build.xml @@ -161,7 +161,6 @@ - diff --git a/test/conform/annotations.xml b/test/conform/annotations.xml deleted file mode 100644 index 791ac99693fe094d0caa9028d7c6b2620eaff27a..0000000000000000000000000000000000000000 --- a/test/conform/annotations.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/test/conform/org/objectweb/asm/AnnotationsTest.java b/test/conform/org/objectweb/asm/AnnotationVisitorTest.java similarity index 70% rename from test/conform/org/objectweb/asm/AnnotationsTest.java rename to test/conform/org/objectweb/asm/AnnotationVisitorTest.java index c1772bad8f81b16db6bd3ec40a08960510192b0b..bba45296cff21eaeb23c4d339282c32128e38d0b 100644 --- a/test/conform/org/objectweb/asm/AnnotationsTest.java +++ b/test/conform/org/objectweb/asm/AnnotationVisitorTest.java @@ -27,33 +27,46 @@ // THE POSSIBILITY OF SUCH DAMAGE. package org.objectweb.asm; -import junit.framework.TestSuite; +import java.util.Collection; + +import org.junit.Test; +import org.junit.runners.Parameterized.Parameters; +import org.objectweb.asm.test.AsmTest; /** - * Annotations tests. + * AnnotationVisitor tests. * * @author Eric Bruneton */ -public class AnnotationsTest extends AbstractTest { +public class AnnotationVisitorTest extends AsmTest { - public static TestSuite suite() throws Exception { - return new AnnotationsTest().getSuite(); + /** @return test parameters to test all the precompiled classes with all the apis. */ + @Parameters(name = NAME) + public static Collection data() { + return data(Api.ASM4, Api.ASM5, Api.ASM6); } - @Override - public void test() throws Exception { - ClassReader cr = new ClassReader(is); - ClassWriter cw1 = new ClassWriter(0); - ClassWriter cw2 = new ClassWriter(0); - cr.accept(new RemoveAnnotationsAdapter1(cw1), 0); - cr.accept(new RemoveAnnotationsAdapter2(cw2), 0); - assertEquals(new ClassReader(cw2.toByteArray()), new ClassReader(cw1.toByteArray())); + /** + * Tests that ClassReader accepts visitor which return null AnnotationVisitor, and that returning + * null AnnotationVisitor is equivalent to returning an EmptyAnnotationVisitor. + */ + @Test + public void testRemoveOrDelete() { + ClassReader classReader = new ClassReader(classParameter.getBytes()); + ClassWriter classWriter1 = new ClassWriter(0); + ClassWriter classWriter2 = new ClassWriter(0); + if (classParameter.isMoreRecentThan(apiParameter)) { + thrown.expect(RuntimeException.class); + } + classReader.accept(new RemoveAnnotationsAdapter(apiParameter.value(), classWriter1), 0); + classReader.accept(new DeleteAnnotationsAdapter(apiParameter.value(), classWriter2), 0); + assertThatClass(classWriter1.toByteArray()).isEqualTo(classWriter2.toByteArray()); } static class EmptyAnnotationVisitor extends AnnotationVisitor { - public EmptyAnnotationVisitor() { - super(Opcodes.ASM5); + public EmptyAnnotationVisitor(final int api) { + super(api); } @Override @@ -67,21 +80,21 @@ public class AnnotationsTest extends AbstractTest { } } - static class RemoveAnnotationsAdapter1 extends ClassVisitor { + static class RemoveAnnotationsAdapter extends ClassVisitor { - public RemoveAnnotationsAdapter1(final ClassVisitor cv) { - super(Opcodes.ASM5, cv); + public RemoveAnnotationsAdapter(final int api, final ClassVisitor cv) { + super(api, cv); } @Override public AnnotationVisitor visitAnnotation(final String desc, final boolean visible) { - return new EmptyAnnotationVisitor(); + return new EmptyAnnotationVisitor(api); } @Override public AnnotationVisitor visitTypeAnnotation( int typeRef, TypePath typePath, String desc, boolean visible) { - return new EmptyAnnotationVisitor(); + return new EmptyAnnotationVisitor(api); } @Override @@ -91,41 +104,40 @@ public class AnnotationsTest extends AbstractTest { final String desc, final String signature, final String[] exceptions) { - return new MethodVisitor( - Opcodes.ASM5, cv.visitMethod(access, name, desc, signature, exceptions)) { + return new MethodVisitor(api, cv.visitMethod(access, name, desc, signature, exceptions)) { @Override public AnnotationVisitor visitAnnotationDefault() { - return new EmptyAnnotationVisitor(); + return new EmptyAnnotationVisitor(api); } @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { - return new EmptyAnnotationVisitor(); + return new EmptyAnnotationVisitor(api); } @Override public AnnotationVisitor visitTypeAnnotation( int typeRef, TypePath typePath, String desc, boolean visible) { - return new EmptyAnnotationVisitor(); + return new EmptyAnnotationVisitor(api); } @Override public AnnotationVisitor visitParameterAnnotation( int parameter, String desc, boolean visible) { - return new EmptyAnnotationVisitor(); + return new EmptyAnnotationVisitor(api); } @Override public AnnotationVisitor visitInsnAnnotation( int typeRef, TypePath typePath, String desc, boolean visible) { - return new EmptyAnnotationVisitor(); + return new EmptyAnnotationVisitor(api); } @Override public AnnotationVisitor visitTryCatchAnnotation( int typeRef, TypePath typePath, String desc, boolean visible) { - return new EmptyAnnotationVisitor(); + return new EmptyAnnotationVisitor(api); } @Override @@ -137,16 +149,16 @@ public class AnnotationsTest extends AbstractTest { int[] index, String desc, boolean visible) { - return new EmptyAnnotationVisitor(); + return new EmptyAnnotationVisitor(api); } }; } } - static class RemoveAnnotationsAdapter2 extends ClassVisitor { + static class DeleteAnnotationsAdapter extends ClassVisitor { - public RemoveAnnotationsAdapter2(final ClassVisitor cv) { - super(Opcodes.ASM5, cv); + public DeleteAnnotationsAdapter(final int api, final ClassVisitor cv) { + super(api, cv); } @Override @@ -167,8 +179,7 @@ public class AnnotationsTest extends AbstractTest { final String desc, final String signature, final String[] exceptions) { - return new MethodVisitor( - Opcodes.ASM5, cv.visitMethod(access, name, desc, signature, exceptions)) { + return new MethodVisitor(api, cv.visitMethod(access, name, desc, signature, exceptions)) { @Override public AnnotationVisitor visitAnnotationDefault() { diff --git a/test/conform/unit.xml b/test/conform/unit.xml index a20726554d61e0f834f7a8803726d2cac7090d53..9b9f060d39d2d9577435ba0d9fe5172f535d4eac 100644 --- a/test/conform/unit.xml +++ b/test/conform/unit.xml @@ -37,6 +37,7 @@ failureproperty="test.failed"> +