From 0e14ef28ab34628b3399cccb0118362fc22114a7 Mon Sep 17 00:00:00 2001 From: aclement Date: Tue, 18 Jan 2005 11:01:45 +0000 Subject: [PATCH] PerTypeWithin: Test data --- tests/java5/pertypewithin/A.java | 20 +++++++++ tests/java5/pertypewithin/B.java | 30 +++++++++++++ tests/java5/pertypewithin/C.java | 70 +++++++++++++++++++++++++++++ tests/java5/pertypewithin/D.java | 14 ++++++ tests/java5/pertypewithin/G.java | 9 ++++ tests/java5/pertypewithin/H.java | 7 +++ tests/java5/pertypewithin/Main.java | 12 +++++ tests/java5/pertypewithin/P.java | 18 ++++++++ tests/java5/pertypewithin/Q.java | 13 ++++++ tests/java5/pertypewithin/R.java | 13 ++++++ tests/java5/pertypewithin/U.java | 24 ++++++++++ tests/java5/pertypewithin/V.java | 24 ++++++++++ tests/java5/pertypewithin/X.java | 23 ++++++++++ 13 files changed, 277 insertions(+) create mode 100644 tests/java5/pertypewithin/A.java create mode 100644 tests/java5/pertypewithin/B.java create mode 100644 tests/java5/pertypewithin/C.java create mode 100644 tests/java5/pertypewithin/D.java create mode 100644 tests/java5/pertypewithin/G.java create mode 100644 tests/java5/pertypewithin/H.java create mode 100644 tests/java5/pertypewithin/Main.java create mode 100644 tests/java5/pertypewithin/P.java create mode 100644 tests/java5/pertypewithin/Q.java create mode 100644 tests/java5/pertypewithin/R.java create mode 100644 tests/java5/pertypewithin/U.java create mode 100644 tests/java5/pertypewithin/V.java create mode 100644 tests/java5/pertypewithin/X.java diff --git a/tests/java5/pertypewithin/A.java b/tests/java5/pertypewithin/A.java new file mode 100644 index 000000000..ca56105c6 --- /dev/null +++ b/tests/java5/pertypewithin/A.java @@ -0,0 +1,20 @@ +package p; + +// This class does *nothing* clever, but does match the advice in X + +public class A { + + public A() { + } + + public static void main(String[] argv) { + A anA = new A(); + anA.sayhi(); + anA.sayhi(); + + System.err.println("Tests in A have passed"); + } + + public void sayhi() { System.err.println("hi from A"); } + +} diff --git a/tests/java5/pertypewithin/B.java b/tests/java5/pertypewithin/B.java new file mode 100644 index 000000000..6233a7d15 --- /dev/null +++ b/tests/java5/pertypewithin/B.java @@ -0,0 +1,30 @@ +package p; + +public class B { + + public B() { + } + + public static void main(String[] argv) { + B b = new B(); + b.sayhi(); + b.sayhi(); + b.sayhi(); + + if (!a.X.hasAspect(A.class)) { + throw new RuntimeException("hasAspect(A.class) should return true"); + } + + if (!a.X.hasAspect(B.class)) { + throw new RuntimeException("hasAspect(B.class) should return true"); + } + + if (a.X.hasAspect(q.D.class)) { + throw new RuntimeException("hasAspect(D.class) should return false"); + } + + } + + public void sayhi() { System.err.println("hi from B"); } + +} diff --git a/tests/java5/pertypewithin/C.java b/tests/java5/pertypewithin/C.java new file mode 100644 index 000000000..ffa7ea165 --- /dev/null +++ b/tests/java5/pertypewithin/C.java @@ -0,0 +1,70 @@ +package p; +import a.X; + +public class C { + + public C() { + } + + public static void main(String[] argv) { + + C c = new C(); + c.sayhi(); + c.sayhi(); + c.sayhi(); + c.sayhi(); + + if (a.X.aspectOf(A.class)==null) { + throw new RuntimeException("aspectOf(A.class) should not be null"); + } + + if (a.X.aspectOf(B.class)==null) { + throw new RuntimeException("aspecfOf(B.class) should not be null"); + } + + try { + Object o = a.X.aspectOf(q.D.class); + throw new RuntimeException("aspectOf(D.class) should be null"); + } catch (org.aspectj.lang.NoAspectBoundException nabe) { + } + + a.X instanceForA = a.X.aspectOf(A.class); + + a.X instanceForB = a.X.aspectOf(B.class); + + if (instanceForA.equals(instanceForB)) { + throw new RuntimeException("Instances for A("+instanceForA+") and for B("+instanceForB+") should not be the same!"); + } + + // Now lets check the counts don't interfere + + A aa = new A(); + B b = new B(); + c = new C(); + X.aspectOf(A.class).setI(0); + X.aspectOf(B.class).setI(0); + X.aspectOf(C.class).setI(0); + + aa.sayhi(); + b.sayhi(); + aa.sayhi(); + c.sayhi(); + b.sayhi(); + aa.sayhi(); + aa.sayhi(); + + if (a.X.aspectOf(A.class).getI()!=4) { + throw new RuntimeException("For A, i should be 4 but it is "+a.X.aspectOf(A.class).getI()); + } + if (a.X.aspectOf(B.class).getI()!=2) { + throw new RuntimeException("For B, i should be 2 but it is "+a.X.aspectOf(B.class).getI()); + } + if (a.X.aspectOf(C.class).getI()!=1) { + throw new RuntimeException("For C, i should be 1 but it is "+a.X.aspectOf(C.class).getI()); + } + + } + + public void sayhi() { System.err.println("hi C"); } + +} diff --git a/tests/java5/pertypewithin/D.java b/tests/java5/pertypewithin/D.java new file mode 100644 index 000000000..1bc337b06 --- /dev/null +++ b/tests/java5/pertypewithin/D.java @@ -0,0 +1,14 @@ +package q; + +public class D { + + public D() { + } + + public static void main(String[] argv) { + new D().sayhi(); + } + + public void sayhi() { System.err.println("hi D"); } + +} diff --git a/tests/java5/pertypewithin/G.java b/tests/java5/pertypewithin/G.java new file mode 100644 index 000000000..722482f84 --- /dev/null +++ b/tests/java5/pertypewithin/G.java @@ -0,0 +1,9 @@ +public class G { + + public static void main(String[]argv) { + m(); + } + + public static void m() { + } +} diff --git a/tests/java5/pertypewithin/H.java b/tests/java5/pertypewithin/H.java new file mode 100644 index 000000000..fd23c3e57 --- /dev/null +++ b/tests/java5/pertypewithin/H.java @@ -0,0 +1,7 @@ +public aspect H pertypewithin(G) { + + + after(): call(* *(..)) { + System.err.println("advice running"); + } +} diff --git a/tests/java5/pertypewithin/Main.java b/tests/java5/pertypewithin/Main.java new file mode 100644 index 000000000..b7b96ae66 --- /dev/null +++ b/tests/java5/pertypewithin/Main.java @@ -0,0 +1,12 @@ +import p.*; +import q.*; + +public class Main { + + public static void main(String[]argv) { + new A().sayhi(); + new B().sayhi(); + new C().sayhi(); + new D().sayhi(); + } +} diff --git a/tests/java5/pertypewithin/P.java b/tests/java5/pertypewithin/P.java new file mode 100644 index 000000000..f11afd09c --- /dev/null +++ b/tests/java5/pertypewithin/P.java @@ -0,0 +1,18 @@ +public class P { + + public static void main(String []argv) { + P p = new P(); + p.runA(); + p.runB(); + p.runA(); + p.runB(); + p.runB(); + } + + public void runA() { + } + + public void runB() { + } + +} diff --git a/tests/java5/pertypewithin/Q.java b/tests/java5/pertypewithin/Q.java new file mode 100644 index 000000000..7c5d05985 --- /dev/null +++ b/tests/java5/pertypewithin/Q.java @@ -0,0 +1,13 @@ +aspect Q pertypewithin(P) { + + int ctr = 0; + + after(): execution(* runA(..)) { + ctr=ctr+1; + } + + after(): execution(* main(..)) { + System.err.println("Q reporting "+ctr); + } + +} diff --git a/tests/java5/pertypewithin/R.java b/tests/java5/pertypewithin/R.java new file mode 100644 index 000000000..84df3fa01 --- /dev/null +++ b/tests/java5/pertypewithin/R.java @@ -0,0 +1,13 @@ +aspect R pertypewithin(P) { + + int ctr = 0; + + after(): execution(* runB(..)) { + ctr=ctr+1; + } + + after(): execution(* main(..)) { + System.err.println("R reporting "+ctr); + } + +} diff --git a/tests/java5/pertypewithin/U.java b/tests/java5/pertypewithin/U.java new file mode 100644 index 000000000..a1316fb7d --- /dev/null +++ b/tests/java5/pertypewithin/U.java @@ -0,0 +1,24 @@ +public class U { + + public static int staticVar; + public int instanceVar; + + public static void main(String[] argv) { + new U().m(); + } + + public void m() { + staticVar = 4; + instanceVar = 5; + } + + static { + System.err.println("In static initializer"); + } + +} + +aspect Uaspect { + + before(): within(U) { } +} diff --git a/tests/java5/pertypewithin/V.java b/tests/java5/pertypewithin/V.java new file mode 100644 index 000000000..c649610d1 --- /dev/null +++ b/tests/java5/pertypewithin/V.java @@ -0,0 +1,24 @@ +public class V { + + public static int staticVar; + public int instanceVar; + + public static void main(String[] argv) { + new V().m(); + } + + public void m() { + staticVar = 4; + instanceVar = 5; + } + + static { + System.err.println("In static initializer"); + } + +} + +aspect Vaspect pertypewithin(V) { + + before(): within(*) { } +} diff --git a/tests/java5/pertypewithin/X.java b/tests/java5/pertypewithin/X.java new file mode 100644 index 000000000..96474f98f --- /dev/null +++ b/tests/java5/pertypewithin/X.java @@ -0,0 +1,23 @@ +package a; + +public aspect X pertypewithin(p..*) { + + int i = 0; + + public int getI() { return i; } + + public void setI(int i) { this.i = i;} + + after() returning: execution(* sayhi(..)) { + System.err.println("after() returning from a method call to sayhi()"); + i++; + } + + after() returning: execution(* main(..)) { + System.err.println("callcount = "+i); + } + + public static void main(String []argv) { + System.err.println("X.main() running"); + } +} -- 2.39.5