]> source.dussan.org Git - aspectj.git/commitdiff
PerTypeWithin: Test data
authoraclement <aclement>
Tue, 18 Jan 2005 11:01:45 +0000 (11:01 +0000)
committeraclement <aclement>
Tue, 18 Jan 2005 11:01:45 +0000 (11:01 +0000)
13 files changed:
tests/java5/pertypewithin/A.java [new file with mode: 0644]
tests/java5/pertypewithin/B.java [new file with mode: 0644]
tests/java5/pertypewithin/C.java [new file with mode: 0644]
tests/java5/pertypewithin/D.java [new file with mode: 0644]
tests/java5/pertypewithin/G.java [new file with mode: 0644]
tests/java5/pertypewithin/H.java [new file with mode: 0644]
tests/java5/pertypewithin/Main.java [new file with mode: 0644]
tests/java5/pertypewithin/P.java [new file with mode: 0644]
tests/java5/pertypewithin/Q.java [new file with mode: 0644]
tests/java5/pertypewithin/R.java [new file with mode: 0644]
tests/java5/pertypewithin/U.java [new file with mode: 0644]
tests/java5/pertypewithin/V.java [new file with mode: 0644]
tests/java5/pertypewithin/X.java [new file with mode: 0644]

diff --git a/tests/java5/pertypewithin/A.java b/tests/java5/pertypewithin/A.java
new file mode 100644 (file)
index 0000000..ca56105
--- /dev/null
@@ -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 (file)
index 0000000..6233a7d
--- /dev/null
@@ -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 (file)
index 0000000..ffa7ea1
--- /dev/null
@@ -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 (file)
index 0000000..1bc337b
--- /dev/null
@@ -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 (file)
index 0000000..722482f
--- /dev/null
@@ -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 (file)
index 0000000..fd23c3e
--- /dev/null
@@ -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 (file)
index 0000000..b7b96ae
--- /dev/null
@@ -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 (file)
index 0000000..f11afd0
--- /dev/null
@@ -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 (file)
index 0000000..7c5d059
--- /dev/null
@@ -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 (file)
index 0000000..84df3fa
--- /dev/null
@@ -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 (file)
index 0000000..a1316fb
--- /dev/null
@@ -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 (file)
index 0000000..c649610
--- /dev/null
@@ -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 (file)
index 0000000..96474f9
--- /dev/null
@@ -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");
+ }
+}