diff options
author | aclement <aclement> | 2005-02-17 09:10:50 +0000 |
---|---|---|
committer | aclement <aclement> | 2005-02-17 09:10:50 +0000 |
commit | 3534aad5edf1adc9d3167c5f70c141e1fbeafc94 (patch) | |
tree | a7f3ed0561e3cf14886854d18eec71037ed6aeb0 /tests | |
parent | 200fd222d63578de1dc891fa211b7bcf03c7655d (diff) | |
download | aspectj-3534aad5edf1adc9d3167c5f70c141e1fbeafc94.tar.gz aspectj-3534aad5edf1adc9d3167c5f70c141e1fbeafc94.zip |
Testcases for @within() and @withincode() binding.
Diffstat (limited to 'tests')
5 files changed, 171 insertions, 0 deletions
diff --git a/tests/java5/annotations/binding/WithinBinding1.aj b/tests/java5/annotations/binding/WithinBinding1.aj new file mode 100644 index 000000000..68b617c0d --- /dev/null +++ b/tests/java5/annotations/binding/WithinBinding1.aj @@ -0,0 +1,44 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +@interface Colored { String color();} + +@Colored(color="red") +public class WithinBinding1 { + + void mRed() {System.out.println("red"); } + + void mBlue() {System.out.println("blue");} + + void mGreen() {System.out.println("green");} + + WithinBinding1() { + System.out.println("yellow"); + } + + public static void main(String[]argv) { + WithinBinding1 instance = new WithinBinding1(); + instance.mRed(); + instance.mBlue(); + instance.mGreen(); + X.verifyRun(); + } +} + +aspect X { + + static int maxruns = 21; // there are 21 join points in a run of WithinBinding1.main() + + static int i = 0; // Count of advice executions + + before(Colored c): @within(c) { + System.err.println(thisJoinPoint+" color="+c.color()); + if (!c.color().equals("red")) throw new RuntimeException("not red? "+c.color()); + i++; + } + + public static void verifyRun() { + if (X.i != maxruns) + throw new RuntimeException("Expected "+maxruns+" advice runs but did "+X.i); + } +} diff --git a/tests/java5/annotations/binding/WithinBinding2.aj b/tests/java5/annotations/binding/WithinBinding2.aj new file mode 100644 index 000000000..8881a26b4 --- /dev/null +++ b/tests/java5/annotations/binding/WithinBinding2.aj @@ -0,0 +1,46 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +@interface Colored { String color();} + +@Colored(color="red") class RedClass { + public void m() { System.err.println("RedClass.m() running"); } +} + +@Colored(color="green") class GreenClass { + public GreenClass() { System.err.println("GreenClass.ctor() running"); } + public void m() { System.err.println("GreenClass.m() running"); } +} + +class NormalClass { + public void m() { System.err.println("NormalClass.m() running"); } +} + + +public class WithinBinding2 { + public static void main(String[]argv) { + new RedClass().m(); + new NormalClass().m(); + new GreenClass().m(); + X.verifyRun(); + } +} + +aspect X { + + static int red = 0; + static int green=0; + + before(Colored c): @within(c) { + System.err.println(thisJoinPoint+" color="+c.color()); + if (c.color().startsWith("r")) red++; + else if (c.color().startsWith("g")) green++; + else throw new RuntimeException("Didn't expect this color: "+c.color()); + } + + public static void verifyRun() { + System.err.println(red+" "+green); + if (red!=7) throw new RuntimeException("Expected 7 red join points but got "+red); + if (green!=9) throw new RuntimeException("Expected 9 green join points but got "+green); + } +} diff --git a/tests/java5/annotations/binding/WithinCodeBinding1.aj b/tests/java5/annotations/binding/WithinCodeBinding1.aj new file mode 100644 index 000000000..2754c15ea --- /dev/null +++ b/tests/java5/annotations/binding/WithinCodeBinding1.aj @@ -0,0 +1,44 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +@interface Colored { String color();} + +public class WithinCodeBinding1 { + + @Colored(color="red") void mRed() {System.out.println("red"); } + + @Colored(color="blue") void mBlue() {System.out.println("blue");} + + @Colored(color="green") void mGreen() {System.out.println("green");} + + @Colored(color="yellow") WithinCodeBinding1() { + System.out.println("yellow"); + } + + public static void main(String[]argv) { + WithinCodeBinding1 instance = new WithinCodeBinding1(); + instance.mRed(); + instance.mBlue(); + instance.mGreen(); + X.verifyRun(); + } +} + +aspect X { + + // Expected color order + static String exp[] = new String[]{"yellow","red","blue","green"}; + + static int i = 0; // Count of advice executions + + before(Colored c): @withincode(c) && call(* println(..)) { + System.err.println(thisJoinPoint+" color="+c.color()); + if (!c.color().equals(exp[i])) throw new RuntimeException("not "+exp[i]+"? "+c.color()); + i++; + } + + public static void verifyRun() { + if (X.i != exp.length) + throw new RuntimeException("Expected "+exp.length+" advice runs but did "+X.i); + } +} diff --git a/tests/src/org/aspectj/systemtest/ajc150/AnnotationBinding.java b/tests/src/org/aspectj/systemtest/ajc150/AnnotationBinding.java index 8c906f63b..84ea3435c 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/AnnotationBinding.java +++ b/tests/src/org/aspectj/systemtest/ajc150/AnnotationBinding.java @@ -221,6 +221,26 @@ public class AnnotationBinding extends XMLBasedAjcTestCase { runTest("handler and @annotation"); } + ///////////////////////////////////// @WITHIN + + // '@within()' + public void testWithinBinding1() { + runTest("@within"); + } + + //'@within()' but multiple types around (some annotated) + public void testWithinBinding2() { + runTest("@within - multiple types"); + System.err.println(getLastRunResult().getStdErr()); + } + + ///////////////////////////////////// @WITHINCODE + + // '@withincode() && call(* println(..))' + public void testWithinCodeBinding1() { + runTest("@withincode() and call(* println(..))"); + } + ///////////////////////////////////// @ANNOTATION complex tests diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index 8e100ce36..22be0285e 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -253,6 +253,21 @@ <compile files="HandlerBinding.aj" options="-1.5"/> <run class="HandlerBinding"/> </ajc-test> + + <ajc-test dir="java5/annotations/binding" vm="1.5" title="@withincode() and call(* println(..))"> + <compile files="WithinCodeBinding1.aj" options="-1.5"/> + <run class="WithinCodeBinding1"/> + </ajc-test> + + <ajc-test dir="java5/annotations/binding" vm="1.5" title="@within"> + <compile files="WithinBinding1.aj" options="-1.5"/> + <run class="WithinBinding1"/> + </ajc-test> + + <ajc-test dir="java5/annotations/binding" vm="1.5" title="@within - multiple types"> + <compile files="WithinBinding2.aj" options="-1.5"/> + <run class="WithinBinding2"/> + </ajc-test> <ajc-test dir="java5/annotations/binding/complexExample" vm="1.5" title="packages and no binding"> <compile files="A.java,B.java,Color.java,X.java" options="-1.5"/> @@ -897,5 +912,7 @@ <message kind="weave" text="Type 'SimpleVarargs' (SimpleVarargs.java:27) advised by before advice from 'VarargsAspect06' (VarargsAspect06.aj:3)"/> </compile> </ajc-test> + + </suite> |