diff options
Diffstat (limited to 'tests')
4 files changed, 159 insertions, 3 deletions
diff --git a/tests/java5/ataspectj/ajc-ant.xml b/tests/java5/ataspectj/ajc-ant.xml index 8381b6135..393b92f30 100644 --- a/tests/java5/ataspectj/ajc-ant.xml +++ b/tests/java5/ataspectj/ajc-ant.xml @@ -7,10 +7,11 @@ value="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"/> <target name="compile:javac"> - <!-- compile only javac compilable stuff --> + <!-- compile only javac compilable stuff, exclude the one that needs other dependencies --> <javac destdir="${aj.sandbox}" classpathref="aj.path" srcdir="${basedir}" includes="ataspectj/*" + excludes="ataspectj/UnweavableTest.java" debug="true"> </javac> </target> @@ -101,4 +102,24 @@ <jvmarg value="-Daj5.def=ataspectj/ltwlog/aop-verboseandshow.xml"/> </java> </target> + + <target name="ltw.Unweavable"> + <javac destdir="${aj.sandbox}" + srcdir="${basedir}" + includes="ataspectj/UnweavableTest.java, ataspectj/TestHelper.java" + debug="true"> + <classpath> + <path refid="aj.path"/> + <pathelement path="${aj.root}/lib/asm/asm-2.0.jar"/> + </classpath> + </javac> + <java fork="yes" classname="ataspectj.UnweavableTest" failonerror="yes"> + <classpath> + <path refid="aj.path"/> + <pathelement path="${aj.root}/lib/asm/asm-2.0.jar"/> + </classpath> + <jvmarg value="-javaagent:${aj.root}/lib/test/loadtime5.jar"/> + <jvmarg value="-Daj5.def=ataspectj/aop-unweavabletest.xml"/> + </java> + </target> </project>
\ No newline at end of file diff --git a/tests/java5/ataspectj/ataspectj/UnweavableTest.java b/tests/java5/ataspectj/ataspectj/UnweavableTest.java new file mode 100644 index 000000000..4ce689723 --- /dev/null +++ b/tests/java5/ataspectj/ataspectj/UnweavableTest.java @@ -0,0 +1,128 @@ +/******************************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexandre Vasseur initial implementation + *******************************************************************************/ +package ataspectj; + +import junit.framework.TestCase; + +import java.lang.reflect.Proxy; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.security.ProtectionDomain; + +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.AnnotationVisitor; + +/** + * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a> + */ +public class UnweavableTest extends TestCase { + + public void testUnweavableProxy() { + TestAspect.I = 0; + ISome some = getProxy(); + some.giveOne(); + assertEquals(1, TestAspect.I); + } + + static interface ISome { + public int giveOne(); + } + + ISome getProxy() { + return (ISome) Proxy.newProxyInstance( + ISome.class.getClassLoader(), + new Class[]{ISome.class}, + new InvocationHandler() { + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + return new Integer(1); + } + } + ); + } + + @Aspect + public static class TestAspect { + + static int I = 0; + + @Before("execution(* ataspectj.UnweavableTest.ISome+.giveOne())") + public void before() { + I++; + } + } + + public void testJit() { + TestAspect.I = 0; + TestAspect2.I = 0; + ISome some = getJit(); + assertNotNull(some.getClass().getAnnotation(ASome.class)); + assertEquals(2, some.giveOne()); + assertEquals(1, TestAspect.I); + assertEquals(1, TestAspect2.I); + } + + @Retention(RetentionPolicy.RUNTIME) + static @interface ASome {} + + ISome getJit() { + ClassWriter cw = new ClassWriter(true, true); + cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, "ataspectj/ISomeGen", null, "java/lang/Object", new String[]{"ataspectj/UnweavableTest$ISome"}); + AnnotationVisitor av = cw.visitAnnotation("Lataspectj/UnweavableTest$ASome;", true); + av.visitEnd(); + + MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, new String[0]); + mv.visitVarInsn(Opcodes.ALOAD, 0); + mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); + mv.visitInsn(Opcodes.RETURN); + mv.visitMaxs(0, 0); + mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "giveOne", "()I", null, new String[0]); + mv.visitInsn(Opcodes.ICONST_2); + mv.visitInsn(Opcodes.IRETURN); + mv.visitMaxs(0, 0); + cw.visitEnd(); + + try { + ClassLoader loader = this.getClass().getClassLoader(); + Method def = ClassLoader.class.getDeclaredMethod("defineClass", new Class[]{String.class, byte[].class, int.class, int.class}); + def.setAccessible(true); + Class gen = (Class) def.invoke(loader, "ataspectj.ISomeGen", cw.toByteArray(), 0, cw.toByteArray().length); + return (ISome) gen.newInstance(); + } catch (Throwable t) { + fail(t.toString()); + return null; + } + } + + @Aspect + public static class TestAspect2 { + static int I = 0; + @Before("execution(* @ataspectj.UnweavableTest$ASome ataspectj..*.giveOne())") + public void before() { + I++; + } + } + + public static void main(String args[]) throws Throwable { + TestHelper.runAndThrowOnFailure(suite()); + } + + public static junit.framework.Test suite() { + return new junit.framework.TestSuite(UnweavableTest.class); + } + +} diff --git a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjLTWTests.java b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjLTWTests.java index e414c63b4..a9f9afda4 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjLTWTests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjLTWTests.java @@ -36,8 +36,7 @@ public class AtAjLTWTests extends XMLBasedAjcTestCase { public void testAjcLTWPerClauseTest_XnoWeave() { runTest("AjcLTW PerClauseTest -XnoWeave"); } -//FIXME AV - fails with ?? ataspectj\PerClauseTestAspects.java::0 the parameter jp is not bound in [all branches of] pointcut -// + public void testAjcLTWPerClauseTest_Xreweavable() { runTest("AjcLTW PerClauseTest -Xreweavable"); } @@ -78,4 +77,9 @@ public class AtAjLTWTests extends XMLBasedAjcTestCase { runTest("LTW Log"); } + public void testLTWUnweavable() { + // actually test that we do LTW proxy and jit classes + runTest("LTW Unweavable"); + } + } diff --git a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/ltw.xml b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/ltw.xml index af74f5b81..fda448c22 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/ltw.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/ltw.xml @@ -98,5 +98,8 @@ <ant file="ajc-ant.xml" target="ltwlog.LTWLog" verbose="true"/> </ajc-test> + <ajc-test dir="java5/ataspectj" title="LTW Unweavable"> + <ant file="ajc-ant.xml" target="ltw.Unweavable" verbose="true"/> + </ajc-test> </suite>
\ No newline at end of file |