aboutsummaryrefslogtreecommitdiffstats
path: root/tests/java5/ataspectj
diff options
context:
space:
mode:
authoravasseur <avasseur>2005-04-28 09:05:44 +0000
committeravasseur <avasseur>2005-04-28 09:05:44 +0000
commitfd380fe072d2444995109658c38b1ecae390f900 (patch)
tree6dbb0ccec776447df8913b4f57ef8ef6523c1d9e /tests/java5/ataspectj
parentd8bfe7324600e51511051a9db49a2ad7e4e9d7a7 (diff)
downloadaspectj-fd380fe072d2444995109658c38b1ecae390f900.tar.gz
aspectj-fd380fe072d2444995109658c38b1ecae390f900.zip
inlining of around for @AJ works unless non public member accessed from within the advice
splitted ajc150 xml test file
Diffstat (limited to 'tests/java5/ataspectj')
-rw-r--r--tests/java5/ataspectj/ataspectj/BindingTest.java103
1 files changed, 103 insertions, 0 deletions
diff --git a/tests/java5/ataspectj/ataspectj/BindingTest.java b/tests/java5/ataspectj/ataspectj/BindingTest.java
index e88bead39..c4114f020 100644
--- a/tests/java5/ataspectj/ataspectj/BindingTest.java
+++ b/tests/java5/ataspectj/ataspectj/BindingTest.java
@@ -17,10 +17,13 @@ import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.Aspects;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
+import java.security.PrivilegedAction;
+
/**
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
@@ -43,6 +46,10 @@ public class BindingTest extends TestCase {
return i*3;//see x3 here
}
+ public int echo(int i) {
+ return i;
+ }
+
public void testAroundArgs() {
int res = substract(3, 2);// should be 2 without around advice
assertEquals(1, res);
@@ -54,6 +61,35 @@ public class BindingTest extends TestCase {
callWithinStatic();
}
+ public void testProceedInInner() {
+ int res = echo(3);//advice will x2 using an inner
+ assertEquals(6, res);
+ }
+
+ public void testNoProceed() {
+ int res = echo(3);//advice will return 0 and not proceed
+ assertEquals(0, res);
+ }
+
+ public void testDoubleProceed() {
+ int res = echo(3);//advice will proceed twice and add the returned values
+ assertEquals(6, res);
+ }
+
+ public void testDoubleProceedOneInner() {
+ int res = echo(3);//advice will proceed twice with one in inner and add the returned values
+ assertEquals(6, res);
+ }
+
+ public void testAccessAspectState() {
+ //TestAspect_1 aspect = (TestAspect_1) Aspects.aspectOf(TestAspect_1.class);
+ //aspect.m_count = 0;
+ int res = echo(3);
+ res += echo(3);
+ assertEquals(6, res);
+ //assertEquals(2, aspect.m_count);
+ }
+
private static void callWithinStatic() {
int res = dup((3+1));
assertEquals(6, res);
@@ -62,9 +98,12 @@ public class BindingTest extends TestCase {
@Aspect
public static class TestAspect_1 {
+ private int m_count = 0;
+
@Pointcut("call(int substract(int, int)) && within(ataspectj.BindingTest) && args(arg1, arg2)")
void pc(int arg2, int arg1) {}// see rather fancy ordering here..
+ // see return int here.
@Around("pc(argAdvice2, argAdvice1) && target(t)")//see here ordering remade consistent
public int aaround(ProceedingJoinPoint jp, BindingTest t, int argAdvice1, int argAdvice2) throws Throwable {
int res = ((Integer)jp.proceed()).intValue();
@@ -79,5 +118,69 @@ public class BindingTest extends TestCase {
int res = ((Integer)jp.proceed(new Object[]{new Integer(argAdvice1-1)})).intValue();
return new Integer(res/3*2);
}
+
+ @Around("call(int echo(int)) && withincode(void ataspectj.BindingTest.testProceedInInner()) && args(i)")
+ public int aaround3(int i, final ProceedingJoinPoint jp) throws Throwable {
+ final StringBuffer sb = new StringBuffer();
+ Runnable r = new Runnable() {
+ public void run() {
+ try {
+ int res = ((Integer)jp.proceed()).intValue();
+ sb.append(res);
+ } catch (Throwable t) {
+ fail(t.toString());
+ }
+ }
+ };
+ Thread t = new Thread(r);
+ t.start();
+ t.join();
+ assertEquals(i, Integer.parseInt(sb.toString()));
+ return Integer.parseInt(sb.toString())*2;
+ }
+
+ @Around("call(int echo(int)) && withincode(void ataspectj.BindingTest.testNoProceed()) && args(i)")
+ public int aaround4(int i, final ProceedingJoinPoint jp) throws Throwable {
+ // since no proceed() is call, this advice won't be inlined
+ return 0;
+ }
+
+ @Around("call(int echo(int)) && withincode(void ataspectj.BindingTest.testDoubleProceed()) && args(i)")
+ public int aaround5(int i, final ProceedingJoinPoint jp) throws Throwable {
+ int i1 = ((Integer)jp.proceed()).intValue();
+ int i2 = ((Integer)jp.proceed()).intValue();
+ return i1 + i2;
+ }
+
+ @Around("call(int echo(int)) && withincode(void ataspectj.BindingTest.testDoubleProceedOneInner()) && args(i)")
+ public int aaround6(int i, final ProceedingJoinPoint jp) throws Throwable {
+ int i1 = ((Integer)jp.proceed()).intValue();
+ Object io2 = new PrivilegedAction() {
+ public Object run() {
+ try {
+ return jp.proceed();
+ } catch (Throwable t) {
+ fail(t.toString());
+ return null;
+ }
+ }
+ }.run();
+ if (io2 == null) {
+ // since inlining occured, proceed was never called
+ fail("should not happen - advice was probably inlined while it must not be");
+ return i1 * 2;
+ } else {
+ int i2 = ((Integer)io2).intValue();
+ return i1 + i2;
+ }
+ }
+
+ @Around("call(int echo(int)) && withincode(void ataspectj.BindingTest.testAccessAspectState()) && args(i)")
+ public Object aaround7(int i, final ProceedingJoinPoint jp) throws Throwable {
+ //m_count++;// what if inlined ?
+ return jp.proceed();
+ }
+
}
+
}