diff options
Diffstat (limited to 'tests/base')
96 files changed, 2397 insertions, 0 deletions
diff --git a/tests/base/OneArgCallsIsOkay.java b/tests/base/OneArgCallsIsOkay.java new file mode 100644 index 000000000..c0e7916a7 --- /dev/null +++ b/tests/base/OneArgCallsIsOkay.java @@ -0,0 +1,7 @@ +//allow one argument calls even when there's a comma in the arglist (PR#384) + +public class OneArgCallsIsOkay { + public static void main(String[] args) {} + static void foo(int x, int y) {} + pointcut cut(): call(void OneArgCallsIsOkay.foo(int, int)); +} diff --git a/tests/base/test100/Driver.java b/tests/base/test100/Driver.java new file mode 100644 index 000000000..cc2315377 --- /dev/null +++ b/tests/base/test100/Driver.java @@ -0,0 +1,73 @@ +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + + Pos p1 = new Pos(); + Pos p2 = new Pos(); + Pos p3 = new Pos(); + + Foo f1 = Foo.aspectOf(p1); + Foo f2 = Foo.aspectOf(p2); + Foo f3 = Foo.aspectOf(p3); + + p1.move(1, 2); + Tester.checkEqual(p1.getX(), 1, "p1.x"); + Tester.checkEqual(p1.getY(), 2, "p1.y"); + + p2.move(1, 2); + Tester.checkEqual(p2.getX(), 1, "p2.x"); + Tester.checkEqual(p2.getY(), 2, "p2.y"); + + p3.move(1, 2); + Tester.checkEqual(p3.getX(), 1, "p3.x"); + Tester.checkEqual(p3.getY(), 2, "p3.y"); + + Tester.checkEqual(f1.count, 3, "f1.count"); + Tester.checkEqual(f2.count, 3, "f2.count"); + Tester.checkEqual(f3.count, 3, "f3.count"); + Tester.checkEqual(Bar.countx, 9, "Bar.countx"); + } +} + +class Pos { + + int x = 0; + int y = 0; + + int getX() { + return(x); + } + + int getY() { + return(y); + } + + void move(int newX, int newY) { + x=newX; + y=newY; + } +} + +aspect Foo pertarget(target(Pos)) { + int count = 0; + + before (): ( call(* getX(..)) || + call(* getY(..)) || + call(* move(..)) ) { + count++; + } +} + +aspect Bar { + static int countx = 0; + + /*static*/ before (): target(Pos) && + ( call(* getX(..)) || + call(* getY(..)) || + call(* move(..)) ) { + countx++; + } +} diff --git a/tests/base/test100/Readme.txt b/tests/base/test100/Readme.txt new file mode 100644 index 000000000..4befd80f4 --- /dev/null +++ b/tests/base/test100/Readme.txt @@ -0,0 +1,6 @@ +Mode: vm run +Title: before methods, count++ + +A simple test of before methods weaving, in both the static and +non-static cases. In this test, all the classes and aspects are in +the same file. (Keep test101 in synch with this one.) diff --git a/tests/base/test101/Bar.java b/tests/base/test101/Bar.java new file mode 100644 index 000000000..99b516a40 --- /dev/null +++ b/tests/base/test101/Bar.java @@ -0,0 +1,11 @@ + +aspect Bar { + static int count = 0; + + before (): target(Pos) && + ( call(* getX(..)) || + call(* getY(..)) || + call(* move(..)) ) { + count++; + } +} diff --git a/tests/base/test101/Driver.java b/tests/base/test101/Driver.java new file mode 100644 index 000000000..9964538f3 --- /dev/null +++ b/tests/base/test101/Driver.java @@ -0,0 +1,33 @@ +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + + Pos p1 = new Pos(); + Pos p2 = new Pos(); + Pos p3 = new Pos(); + + Foo f1 = Foo.aspectOf(p1); + Foo f2 = Foo.aspectOf(p2); + Foo f3 = Foo.aspectOf(p3); + + p1.move(1, 2); + Tester.checkEqual(p1.getX(), 1, "p1.x"); + Tester.checkEqual(p1.getY(), 2, "p1.y"); + + p2.move(1, 2); + Tester.checkEqual(p2.getX(), 1, "p2.x"); + Tester.checkEqual(p2.getY(), 2, "p2.y"); + + p3.move(1, 2); + Tester.checkEqual(p3.getX(), 1, "p3.x"); + Tester.checkEqual(p3.getY(), 2, "p3.y"); + + Tester.checkEqual(f1.count, 3, "f1.count"); + Tester.checkEqual(f2.count, 3, "f2.count"); + Tester.checkEqual(f3.count, 3, "f3.count"); + Tester.checkEqual(Bar.count, 9, "Bar.count"); + } +} diff --git a/tests/base/test101/Foo.java b/tests/base/test101/Foo.java new file mode 100644 index 000000000..79097078a --- /dev/null +++ b/tests/base/test101/Foo.java @@ -0,0 +1,11 @@ + +aspect Foo pertarget(target(Pos)) { + int count = 0; + + before (): ( call(* getX(..)) || + call(* getY(..)) || + call(* move(..)) ) { + count++; + } +} + diff --git a/tests/base/test101/Pos.java b/tests/base/test101/Pos.java new file mode 100644 index 000000000..b6a70e6ba --- /dev/null +++ b/tests/base/test101/Pos.java @@ -0,0 +1,19 @@ + +class Pos { + + int x = 0; + int y = 0; + + int getX() { + return(x); + } + + int getY() { + return(y); + } + + void move(int newX, int newY) { + x=newX; + y=newY; + } +} diff --git a/tests/base/test101/README b/tests/base/test101/README new file mode 100644 index 000000000..445e688b1 --- /dev/null +++ b/tests/base/test101/README @@ -0,0 +1,4 @@ +Mode: vm run
+Title: before methods, count++, multiple files
+
+Exactly like test001, except this one uses multiple files.
diff --git a/tests/base/test102/Driver.java b/tests/base/test102/Driver.java new file mode 100644 index 000000000..6d5cf27cd --- /dev/null +++ b/tests/base/test102/Driver.java @@ -0,0 +1,34 @@ +import org.aspectj.testing.Tester; + +public class Driver { + static Object objectFromClass; + static Object objectFromAspect; + + static String stringFromClass; + static String stringFromAspect; + + public static void main(String[] args) { test(); } + + static public void test() { + Driver obj = new Driver(); + + obj.doit(); + + Tester.check(objectFromClass == objectFromAspect, + "this matches this"); + Tester.check(stringFromClass.equals(stringFromAspect), + "this.toString() matches this.toString()"); + } + + void doit() { + objectFromClass = this; + stringFromClass = this.toString(); + } +} + +aspect DriverAspect pertarget(target(Driver)) { + before (Driver d): target(d) && call(* doit(..)) { + d.objectFromAspect = d; + d.stringFromAspect = d.toString(); + } +} diff --git a/tests/base/test102/Readme.txt b/tests/base/test102/Readme.txt new file mode 100644 index 000000000..14bcca6a9 --- /dev/null +++ b/tests/base/test102/Readme.txt @@ -0,0 +1,4 @@ +Mode: vm run +Title: this redirection in non-static before methods + +A simple test of whether this redirection works in before methods. diff --git a/tests/base/test103/Driver.java b/tests/base/test103/Driver.java new file mode 100644 index 000000000..68961d801 --- /dev/null +++ b/tests/base/test103/Driver.java @@ -0,0 +1,56 @@ +// -*- Mode: java; -*- +import org.aspectj.testing.Tester; + +public class Driver { + + public static void main(String[] args) { test(); } + + public static void test() { + MagicKey key = new MagicKey(); + + Pos p1 = new Pos(key); + + Tester.checkEqual(p1.getOther(), 1, "introduced value"); + } +} +class Pos { + + int _x = 0; + int _y = 0; + + public int getX() { + return(_x); + } + + public int getY() { + return(_y); + } + + public void move(int x, int y) { + _x = x; + _y = y; + } +} + +aspect Foo { + // this has been declared illegal syntax as of 4/19/99, see below for fix + // introduce public int Pos.id = 1, Pos.other; + + //introduction Pos { + //XXX might want to test for this in the future + //public int Pos.id=1, Pos.other; + public int Pos.id=1; + public int Pos.other; + + int Pos.getOther() { + return other; + } + + Pos.new(MagicKey key) { + other = id; + id = getOther(); + } + //} +} + +class MagicKey {} diff --git a/tests/base/test103/Readme.txt b/tests/base/test103/Readme.txt new file mode 100644 index 000000000..15dbc7353 --- /dev/null +++ b/tests/base/test103/Readme.txt @@ -0,0 +1,7 @@ +Mode: vm run +Title: a simple test of new fields, methods and constructors + +A simple test of new fields, methods and constructors, +using introduce. This is deprecated as of 0.7, but we +still need to test the deprecated stuff until we kill +it completely. -eh diff --git a/tests/base/test104/Driver.java b/tests/base/test104/Driver.java new file mode 100644 index 000000000..5cc2f9079 --- /dev/null +++ b/tests/base/test104/Driver.java @@ -0,0 +1,88 @@ +import org.aspectj.testing.Tester; + +public aspect Driver { + + static boolean point, line, circle; + + public static void main(String[] args) { test(); } + + public static void test() { + Point p = new Point(); + Line l = new Line(); + Circle c = new Circle(); + + Tester.check(point, "point"); + Tester.check(line, "line"); + Tester.check(circle, "circle"); + } + + before (): target(Point) && execution(new(..)) { + point = true; + } + + before (): target(Line) && execution(new(..)) { + line = true; + } + + // the * thrown in just for fun + before (): target(*) && target(Circle) && execution(new()) { + circle = true; + } +} + +class Point { + int _x = 0; + int _y = 0; + + Point() {} + + void set (int x, int y) { + _x = x; _y = y; + } + + void setX (int x) { _x = x; } + void setY (int y) { _y = y; } + + int getX() { return _x; } + int getY() { return _y; } +} + +class Line { + int _x1, _y1, _x2, _y2; + + Line() {} + + void set (int x1, int y1, int x2, int y2) { + _x1 = x1; _y1 = y1; _x2 = x2; _y2 = y2; + } + + void setX1 (int x1) { _x1 = x1; } + void setY1 (int y1) { _y1 = y1; } + void setX2 (int x2) { _x2 = x2; } + void setY2 (int y2) { _y2 = y2; } + + int getX1() { return _x1; } + int getY1() { return _y1; } + int getX2() { return _x2; } + int getY2() { return _y2; } +} + +class Circle { + int _x = 0; + int _y = 0; + int _r = 0; + + Circle() {} + + void set (int x, int y, int r) { + _x = x; _y = y; _r = r; + } + + void setX (int x) { _x = x; } + void setY (int y) { _y = y; } + void setR (int r) { _r = r; } + + int getX() { return _x; } + int getY() { return _y; } + int getR() { return _r; } +} diff --git a/tests/base/test104/Readme.txt b/tests/base/test104/Readme.txt new file mode 100644 index 000000000..411a8a957 --- /dev/null +++ b/tests/base/test104/Readme.txt @@ -0,0 +1,5 @@ +Mode: vm run +Title: before constructors + +A simple test of before methods on constructors. In this test, all +the classes and aspects are in the same file. diff --git a/tests/base/test105/Driver.java b/tests/base/test105/Driver.java new file mode 100644 index 000000000..5578c84f8 --- /dev/null +++ b/tests/base/test105/Driver.java @@ -0,0 +1,46 @@ +import org.aspectj.testing.Tester; + +public aspect Driver { + + static boolean t1, t2, t3, t4; + + public static void main(String[] args) { test(); } + + public static void test() { + + Foo f1 = new Foo(); + + f1.m1("foo"); + f1.m2(1); + f1.m3("foo"); + f1.m3(1); + + Tester.check(t1, "finding m1(String)"); + Tester.check(t2, "finding m2(int)"); + Tester.check(t3, "finding m3(String)"); + Tester.check(t4, "finding m3(int)"); + } + + before(String x): target(Foo) && call(void m1(String)) && args(x) { + t1 = true; + } + + before(int x): target(Foo) && call(void m2(int)) && args(x) { + t2 = true; + } + + before(String x): target(Foo) && call(void m3(String)) && args(x) { + t3 = true; + } + + before(int x): target(Foo) && call(void m3(int)) && args(x) { + t4 = true; + } +} + +class Foo { + void m1(String x) { } + void m2(int x) { } + void m3(String x) { } + void m3(int x) { } +} diff --git a/tests/base/test105/Readme.txt b/tests/base/test105/Readme.txt new file mode 100644 index 000000000..54e21223e --- /dev/null +++ b/tests/base/test105/Readme.txt @@ -0,0 +1,5 @@ +Mode: vm run +Title: advise weaves find methods typed to builtins or non-woven classes + +A simple test to make sure advise weaves find methods typed to +built-ins or on classes that aren't being woven. diff --git a/tests/base/test106/Driver.java b/tests/base/test106/Driver.java new file mode 100644 index 000000000..a1c8a51d4 --- /dev/null +++ b/tests/base/test106/Driver.java @@ -0,0 +1,11 @@ +import pkg.*; +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + Obj obj = new Obj(); + Tester.checkEqual(obj.m(), 3, "obj.m()"); + } +} diff --git a/tests/base/test106/Readme.txt b/tests/base/test106/Readme.txt new file mode 100644 index 000000000..b9261b99e --- /dev/null +++ b/tests/base/test106/Readme.txt @@ -0,0 +1,4 @@ +Mode: vm run +Title: make sure new weaves work inside of packages + +A simple test to make sure new weaves work inside of packages. diff --git a/tests/base/test106/pkg/Obj.java b/tests/base/test106/pkg/Obj.java new file mode 100644 index 000000000..3886c2bd3 --- /dev/null +++ b/tests/base/test106/pkg/Obj.java @@ -0,0 +1,13 @@ +package pkg; + +public class Obj { + public int m() { + return 2; + } +} + +aspect Asp { + int around(): target(Obj) && execution(int m()) { + return 3; + } +} diff --git a/tests/base/test107/C1.java b/tests/base/test107/C1.java new file mode 100644 index 000000000..1393cb85c --- /dev/null +++ b/tests/base/test107/C1.java @@ -0,0 +1,8 @@ + +import pack1.Foo; + +public class C1 { + int m() { + return 999; + } +} diff --git a/tests/base/test107/C2.java b/tests/base/test107/C2.java new file mode 100644 index 000000000..aea80e6f5 --- /dev/null +++ b/tests/base/test107/C2.java @@ -0,0 +1,7 @@ +import pack2.Foo; + +public class C2 { + int m() { + return 998; + } +} diff --git a/tests/base/test107/Driver.java b/tests/base/test107/Driver.java new file mode 100644 index 000000000..2079b820d --- /dev/null +++ b/tests/base/test107/Driver.java @@ -0,0 +1,33 @@ + +import pack3.Foo; +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + C1 c1 = new C1(); + C2 c2 = new C2(); + C3 c3 = new C3(); + + Tester.checkEqual(c1.m(), 3, "c1.m()"); + Tester.checkEqual(c2.m(), 3, "c2.m()"); + Tester.checkEqual(c3.m(), 3, "c3.m()"); + } +} + +class C3 { + int m () { + Foo f = new Foo(); + return f.hello(); + } +} + +aspect Test { + int around(): ( target(C1) || + target(C2) ) && + call(int m()) { + Foo f = new Foo(); + return f.hello(); + } +} diff --git a/tests/base/test107/Readme.txt b/tests/base/test107/Readme.txt new file mode 100644 index 000000000..b9261b99e --- /dev/null +++ b/tests/base/test107/Readme.txt @@ -0,0 +1,4 @@ +Mode: vm run +Title: make sure new weaves work inside of packages + +A simple test to make sure new weaves work inside of packages. diff --git a/tests/base/test107/pack1/Foo.java b/tests/base/test107/pack1/Foo.java new file mode 100644 index 000000000..4694a8edc --- /dev/null +++ b/tests/base/test107/pack1/Foo.java @@ -0,0 +1,6 @@ + +package pack1; + +public class Foo { + public int hello() { return 1; } +} diff --git a/tests/base/test107/pack2/Foo.java b/tests/base/test107/pack2/Foo.java new file mode 100644 index 000000000..fb065349b --- /dev/null +++ b/tests/base/test107/pack2/Foo.java @@ -0,0 +1,6 @@ + +package pack2; + +public class Foo { + public int hello() { return 2; } +} diff --git a/tests/base/test107/pack3/Foo.java b/tests/base/test107/pack3/Foo.java new file mode 100644 index 000000000..e4065dee4 --- /dev/null +++ b/tests/base/test107/pack3/Foo.java @@ -0,0 +1,6 @@ + +package pack3; + +public class Foo { + public int hello() { return 3; } +} diff --git a/tests/base/test108/Driver.java b/tests/base/test108/Driver.java new file mode 100644 index 000000000..30af86fd7 --- /dev/null +++ b/tests/base/test108/Driver.java @@ -0,0 +1,40 @@ + +import org.aspectj.testing.Tester; +/** + * This does accessibility of class and class variables, both inherited + * and non-inherited, in the body of a weave. + */ + +public class Driver { + public static void main(String[] args) { test(); } + public static void test() { + Tester.checkEqual((new Bar()).m(), 10, "Bar.m"); + } +} + +class Foo { + int fooVar = 1; + public int getFooVar( ) { return fooVar; } +} + +class Bar extends Foo { + int barVar = 2; + int ans = 0; + public int getBarVar() { return barVar; } + public void setAns( int newAns ) { ans = newAns; } + int m() { + return ans; + } +} + +abstract aspect A { + static int aVar = 3; +} + +aspect B extends A { + static int bVar = 4; + + before(Bar b): target(b) && call(* m(..)) { + b.setAns(b.getFooVar() + b.getBarVar() + aVar + bVar); + } +} diff --git a/tests/base/test108/Readme.txt b/tests/base/test108/Readme.txt new file mode 100644 index 000000000..e0665b4bf --- /dev/null +++ b/tests/base/test108/Readme.txt @@ -0,0 +1,6 @@ +Mode: vm run +Title: Inheritance of class and aspect vars in weaves. + +This checks accessibility of class and aspect variables, both inherited +and non-inherited, in the body of a weave. + diff --git a/tests/base/test109/Aspect.java b/tests/base/test109/Aspect.java new file mode 100644 index 000000000..4e77df375 --- /dev/null +++ b/tests/base/test109/Aspect.java @@ -0,0 +1,28 @@ +aspect Aspect pertarget(target(Foo)) { + + public String toString() {return "The Aspect";} + + before (Foo f): target(f) && call(* foo(..)) { + // do some incrementing and reading of f's variables: + // f.PRIVATECONST; + // f.privateClassVar++; + // f.privateInstanceVar++; + f.protectedClassVar++; + f.protectedInstanceVar++; + f.publicClassVar++; + f.publicInstanceVar++; + f.ClassVar++; + f.InstanceVar++; + + // do some calling of f's methods + + //f.privateClassMethod(); + //f.privateInstanceMethod(); + f.protectedClassMethod(); + f.protectedInstanceMethod(); + f.publicClassMethod(); + f.publicInstanceMethod(); + f.ClassMethod(); + f.InstanceMethod(); + } +} diff --git a/tests/base/test109/Driver.java b/tests/base/test109/Driver.java new file mode 100644 index 000000000..c68725a19 --- /dev/null +++ b/tests/base/test109/Driver.java @@ -0,0 +1,9 @@ + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + Foo f = new Foo(); + f.foo(); + } +} diff --git a/tests/base/test109/Foo.java b/tests/base/test109/Foo.java new file mode 100644 index 000000000..8a2a3de38 --- /dev/null +++ b/tests/base/test109/Foo.java @@ -0,0 +1,56 @@ + +public class Foo { + private String _name; + private static final int PRIVATECONST = 1; + private static int privateClassVar = 2; + private int privateInstanceVar = 3; + + protected static int protectedClassVar = 4; + protected int protectedInstanceVar = 5; + + public static int publicClassVar = 6; + public int publicInstanceVar = 7; + + public static int ClassVar = 8; + public int InstanceVar = 9; + + public void foo() { + // System.out.println("running " + this + ".foo()"); + } + + private static void privateClassMethod() { + // System.out.println("in " + "Foo.privateClassMethod()"); + } + + private void privateInstanceMethod() { + // System.out.println("in " + this + ".privateInstanceMethod()"); + } + + protected static void protectedClassMethod() { + // System.out.println("in " + "Foo.protectedClassMethod()"); + } + + protected void protectedInstanceMethod() { + // System.out.println("in " + this + ".protectedInstanceMethod()"); + } + + public static void publicClassMethod() { + // System.out.println("in " + "Foo.publicClassMethod()"); + } + + public void publicInstanceMethod() { + // System.out.println("in " + this + ".publicInstanceMethod()"); + } + + static void ClassMethod() { + // System.out.println("in " + "Foo.ClassMethod()"); + } + + void InstanceMethod() { + // System.out.println("in " + this + ".InstanceMethod()"); + } + + +} + + diff --git a/tests/base/test109/Readme.txt b/tests/base/test109/Readme.txt new file mode 100644 index 000000000..a524b5485 --- /dev/null +++ b/tests/base/test109/Readme.txt @@ -0,0 +1,13 @@ +Mode: VM run +Title: Accessibility of class and aspect members from inside weaves + + Code inside a weave does the full cross-product of the + following things: + + read a var of the class private static + set a var X X protected X non-static + call a method public + default + + +Both the aspect and the class are in the default (unnamed) package. diff --git a/tests/base/test110/Driver.java b/tests/base/test110/Driver.java new file mode 100644 index 000000000..5a9a717f9 --- /dev/null +++ b/tests/base/test110/Driver.java @@ -0,0 +1,14 @@ + +import pClass.Class; +import pAspect.Aspect; +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + Class f = new Class(); + f.foo(); + Tester.check(Aspect.ranAdvice, "advice on class in different package"); + } +} diff --git a/tests/base/test110/Readme.txt b/tests/base/test110/Readme.txt new file mode 100644 index 000000000..fb53602f0 --- /dev/null +++ b/tests/base/test110/Readme.txt @@ -0,0 +1,9 @@ +Mode: VM run +Title: Packaged aspects referring to packaged classes + +This test case has an aspect and a class, each in a separate +package. The test is to check if the weaver generates the correct +names for the class and the aspect in the woven code. + + + diff --git a/tests/base/test110/pAspect/Aspect.java b/tests/base/test110/pAspect/Aspect.java new file mode 100644 index 000000000..e7733f5a6 --- /dev/null +++ b/tests/base/test110/pAspect/Aspect.java @@ -0,0 +1,9 @@ +package pAspect; + +public aspect Aspect { + public static boolean ranAdvice = false; + + before (): target(pClass.Class) && call(* foo(..)) { + ranAdvice = true; + } +} diff --git a/tests/base/test110/pClass/Class.java b/tests/base/test110/pClass/Class.java new file mode 100644 index 000000000..98653c7fb --- /dev/null +++ b/tests/base/test110/pClass/Class.java @@ -0,0 +1,9 @@ +package pClass; + +public class Class { + public void foo() { + // nothing to do here. + } +} + + diff --git a/tests/base/test111/Driver.java b/tests/base/test111/Driver.java new file mode 100644 index 000000000..00ec6c33c --- /dev/null +++ b/tests/base/test111/Driver.java @@ -0,0 +1,11 @@ +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + SubClass sub = new SubClass(3); + //System.out.println("Invoking SubClass's getX method"); + Tester.checkEqual(sub.getX(), 3+42, "x value"); + } +} diff --git a/tests/base/test111/Readme.txt b/tests/base/test111/Readme.txt new file mode 100644 index 000000000..3995ae7bf --- /dev/null +++ b/tests/base/test111/Readme.txt @@ -0,0 +1,6 @@ +Mode: VM Run +Title: Inheritance of methods advised by aspects + +A subclass SubClass inherits a super-class SuperClass's method getX +which is affected by the aspect SuperAspect. + diff --git a/tests/base/test111/SubClass.java b/tests/base/test111/SubClass.java new file mode 100644 index 000000000..2aadb8d3f --- /dev/null +++ b/tests/base/test111/SubClass.java @@ -0,0 +1,5 @@ +public class SubClass extends SuperClass { + public SubClass(int _x) { + super(_x); + } +} diff --git a/tests/base/test111/SuperAspect.java b/tests/base/test111/SuperAspect.java new file mode 100644 index 000000000..df97973b8 --- /dev/null +++ b/tests/base/test111/SuperAspect.java @@ -0,0 +1,12 @@ +import org.aspectj.testing.Tester; + +public aspect SuperAspect { + before(SuperClass s): target(s) && call(* getX(..)) { + Tester.checkEqual(thisJoinPoint.getSignature().getName(), "getX", "method name"); + //!!! It's unclear what they value of this really should be + //Tester.checkEqual(thisJoinPoint.className, "SubClass", "class name"); + // make a change to prove this is run + //x = x+42; + s.setX( s.checkX()+42 ); + } +} diff --git a/tests/base/test111/SuperClass.java b/tests/base/test111/SuperClass.java new file mode 100644 index 000000000..3e57e0473 --- /dev/null +++ b/tests/base/test111/SuperClass.java @@ -0,0 +1,8 @@ +public class SuperClass { + int x; + + public SuperClass(int _x) { x = _x; } + public int getX() { return x; } + public int checkX() { return x; } + public void setX( int newX ) { x = newX; } +} diff --git a/tests/base/test112/Driver.java b/tests/base/test112/Driver.java new file mode 100644 index 000000000..6e8a757c9 --- /dev/null +++ b/tests/base/test112/Driver.java @@ -0,0 +1,28 @@ +import org.aspectj.testing.Tester; + +public class Driver { + public static int constructorCount = 0; + + public static void main(String[] args) { test(); } + + public static void test() { + SubClass sub1 = new SubClass(); + // only one constructor has been called + Tester.checkEqual(constructorCount, 1, "constructor called"); + } +} + + +class SuperClass { + public SuperClass() {} +} + +class SubClass extends SuperClass { + public SubClass() {} +} + +aspect SuperAspect { + after () returning(): call(SuperClass+.new(..)) { + Driver.constructorCount += 1; + } +} diff --git a/tests/base/test112/Readme.txt b/tests/base/test112/Readme.txt new file mode 100644 index 000000000..ad7c9c1a2 --- /dev/null +++ b/tests/base/test112/Readme.txt @@ -0,0 +1,8 @@ +Mode: VM Run +Title: Inherited weaves on constructor + +SubClass picks up the weave specified by SuperAspect on SuperClass's +constructor. The weave runs only once, but only after +returning advice can have this property. + + diff --git a/tests/base/test113/Driver.java b/tests/base/test113/Driver.java new file mode 100644 index 000000000..3431da405 --- /dev/null +++ b/tests/base/test113/Driver.java @@ -0,0 +1,38 @@ +import org.aspectj.testing.Tester; + +public class Driver { + public static boolean classStaticInitRan, classInitRan; + + public static boolean aspectStaticInitRan, aspectInitRan; + + public static void main(String[] args) { test(); } + + public static void test() { + Class c = new Class(); + Tester.check(classStaticInitRan, "ran class's static initializer"); + Tester.check(classInitRan, "ran class's initializer"); + Tester.check(aspectStaticInitRan, "ran aspect's static initializer"); + Tester.check(aspectInitRan, "ran aspect's initializer"); + + } +} + +class Class { + static { + Driver.classStaticInitRan = true; + } + + { + Driver.classInitRan = true; + } +} + +aspect Aspect pertarget(target(Class)) { + static { + Driver.aspectStaticInitRan = true; + } + // non-static initializer + { + Driver.aspectInitRan = true; + } +} diff --git a/tests/base/test113/Readme.txt b/tests/base/test113/Readme.txt new file mode 100644 index 000000000..dc76983f4 --- /dev/null +++ b/tests/base/test113/Readme.txt @@ -0,0 +1,5 @@ +Mode: VM Run +Title: Initializers in Aspect and Class Bodies + +This test ensures that initializers (static or non-static) work inside +bodies of aspects and classes. diff --git a/tests/base/test114/Driver.java b/tests/base/test114/Driver.java new file mode 100644 index 000000000..456f8d899 --- /dev/null +++ b/tests/base/test114/Driver.java @@ -0,0 +1,31 @@ +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + Class c = new Class(); + + c.foo(5); + } +} + +class Class { + void foo(int x) { + //System.out.println(x); + } + int baz(int y) { + return 2; + } +} + +aspect Aspect pertarget(target(Class)) { + int bar(int x) { return 5;} + + after (Class c, int z): target(c) && call(* foo(int)) && args(z) { + // calls a class method whose argument is an class method call + Tester.check(c.baz(bar(6)) == 2, "didn't run class method"); + // calls an class method whose argument is a class method call + Tester.check(bar(c.baz(4)) == 5, "Didn't run aspect method"); + } +} diff --git a/tests/base/test114/Readme.txt b/tests/base/test114/Readme.txt new file mode 100644 index 000000000..791f1256b --- /dev/null +++ b/tests/base/test114/Readme.txt @@ -0,0 +1,6 @@ +Mode: VM Run +Title: Weaver Resolution of method names in method calls passed as args. + +This test ensures that method names are properly resolved when they +are used in method calls that are passed as arguments in other method calls. + diff --git a/tests/base/test115/Driver.java b/tests/base/test115/Driver.java new file mode 100644 index 000000000..a15967fc0 --- /dev/null +++ b/tests/base/test115/Driver.java @@ -0,0 +1,25 @@ +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + static public void test() { + SubClass s = new SubClass(0); + Tester.checkEqual(Aspect.count, 2, "introduced constructors"); + } +} + +class Class {} + +class SubClass extends Class {} + +// this should introduce a unary constructor for +// Class and SubClass + +aspect Aspect { + static int count = 0; + //introduction subtypes(Class) { + Class.new(int i) {count++;} + SubClass.new(int i) {super(2); count++;} + //} +} diff --git a/tests/base/test115/Readme.txt b/tests/base/test115/Readme.txt new file mode 100644 index 000000000..b8451bd8c --- /dev/null +++ b/tests/base/test115/Readme.txt @@ -0,0 +1,11 @@ +Mode: VM Run +Title: Introduce constructor with class inheritance + +This test ensures that when a constructor is introduced in a type (class) +then that constructor is introduced with the same formal parameter +structure and body in all classes and subclasses implementing the +type. + +Deprecated -eh + + diff --git a/tests/base/test116/Driver.java b/tests/base/test116/Driver.java new file mode 100644 index 000000000..b1dc67d7d --- /dev/null +++ b/tests/base/test116/Driver.java @@ -0,0 +1,60 @@ +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + Class c = new Class(); + + c.l(); + c.l(2); + c.m(3); + + Tester.checkEqual(Aspect.c1, 3, "Aspect.c1"); + Tester.checkEqual(Aspect.c2, 2, "Aspect.c2"); + Tester.checkEqual(Aspect.c3, 1, "Aspect.c3"); + Tester.checkEqual(Aspect.c4, 2, "Aspect.c4"); + } +} + +class Class { + + public void l() throws Error { + //System.out.println("public void l() throws Error"); + //throw(new Error ()); + } + + void l(int x) { + //System.out.println(" void l(int)"); + } + + public void m(int x) throws Error { + //System.out.println("public void m(int) throws Error"); + // throw(new Error ()); + } + +} + +aspect Aspect { + static int c1, c2, c3, c4 = 0; + + before(): target(Class) && call(void *(..)) { + //System.out.println("before Class.*(..)"); + c1++; + } + + before(int x): target(Class) && call(void *(int))&& args(x) { + //System.out.println("before Class.*(int)"); + c2++; + } + + before(int x): target(Class) && call(public void *(int)) && args(x){ + //System.out.println("before public Class.*(int)"); + c3++; + } + + before(): target(Class) && call(void *(..) throws Error) { + //System.out.println("before Class.*(..) throws Error"); + c4++; + } +} diff --git a/tests/base/test116/Readme.txt b/tests/base/test116/Readme.txt new file mode 100644 index 000000000..03ae9bc44 --- /dev/null +++ b/tests/base/test116/Readme.txt @@ -0,0 +1,21 @@ +Mode: VM Run +Title: empty and singular patterns on modifiers and throws + +This test identifies sets of methods based on the patterns on +modifiers and throws. + +If the modifier pattern is empty, then the constraint on +methods means "quantify over methods that may or may not have any +modifier". + +If the modifier pattern is a single value, +then the constraint means "quantify over methods that have that +modifier value". + +The same rule applies for pattern in the throws clause. + + + + + + diff --git a/tests/base/test117/Driver.java b/tests/base/test117/Driver.java new file mode 100644 index 000000000..9abfb1789 --- /dev/null +++ b/tests/base/test117/Driver.java @@ -0,0 +1,126 @@ +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + C1 c1 = new C1(); + C11 c11 = new C11(); + C111 c111 = new C111(); + C12 c12 = new C12(); + Cleaf1 cleaf1 = new Cleaf1(); + Cleaf11 cleaf11 = new Cleaf11(); + Cleaf111 cleaf111 = new Cleaf111(); + Cleaf12 cleaf12 = new Cleaf12(); + + Tester.checkEqual(c1.a, 0, "c1.a"); + Tester.checkEqual(c11.a, 0, "c11.a"); + Tester.checkEqual(c111.a, 0, "c111.a"); + Tester.checkEqual(c12.a, 0, "c12.a"); + + Tester.checkEqual(cleaf1.a, 0, "cleaf1.a"); + Tester.checkEqual(cleaf11.a, 0, "cleaf11.a"); + Tester.checkEqual(cleaf111.a, 0, "cleaf111.a"); + Tester.checkEqual(cleaf12.a, 0, "cleaf12.a"); + + Tester.checkEqual(c1.b, 0, "c1.b"); + Tester.checkEqual(cleaf1.b, 0, "cleaf1.b"); + + Tester.checkEqual(I1.c, 5, "I1.c"); + + Tester.checkEqual(c1.d, 1, "c1.d"); + Tester.checkEqual(c11.d, 1, "c11.d"); + Tester.checkEqual(c111.d, 1, "c111.d"); + Tester.checkEqual(c12.d, 1, "c12.d"); + + Tester.checkEqual(c1.e, 2, "c1.e"); + Tester.checkEqual(cleaf1.e, 2, "cleaf1.e"); + + Tester.checkEqual(C1.f, 4, "C1.f"); + Tester.checkEqual(cleaf1.f, 4, "cleaf1.f"); + Tester.checkEqual(c1.f, 4, "c1.f"); + + Tester.checkEqual(c1.getF(), 4, "c1.getF()"); + } +} + +interface I1 { } +interface I11 extends I1 { } +interface I111 extends I11 { } +interface I12 extends I1 { } + +class C1 implements I1 { } +class C11 implements I11 { } +class C111 implements I111 { } +class C12 implements I12 { } + +class Cleaf1 extends C1 { } +class Cleaf11 extends C11 { } +class Cleaf111 extends C111 { } +class Cleaf12 extends C12 { } + +// For this class structure: here is the "directly implements" relation +// C1 directly implements I1 +// C11 directly implements I11 +// C11 directly implements I1 +// C111 directly implements I111 +// C111 directly implements I11 +// C111 directly implements I1 +// C12 directly implements I12 +// C12 directly implements I1 + + + +// introducing a bunch of variables (almost all non-static). +aspect A1 { + + // Variable Introductions: + // without initializer X designator is interface + // with initializer X designator is class + + // with initializer, interface also has the two cases of presence or + // absence of the modifiers. + + // introduce on initializer without initializer + // should introduce into: + // C1, C11, C111, C12 + int I1.a; + + // introduce on interface with initializer but no Mods + // should introduce into: + // C1, C11, C111, C12 + int I1.d = 1; + + // introduce on interface with initializer and Mods + // should introduce into: + // I1 + public static final int I1.c = 5; + + // introduce on class + // should introduce into + // C1 + int C1.b; + int C1.e = 2; + + // introduce on class with static modifier + // should introduce into + // C1 + static int C1.f = 2; + + int C1.getF() { return 2; } +} + +aspect A2 { + declare dominates: A2, A1; + + int around() : set(int C1.f) && within(A1) { + return C1.f = 3; + } + + after (): staticinitialization(C1) { + C1.f = 4; + } + + // this should override the introduction from A1 + int C1.getF() { return 4; } +} diff --git a/tests/base/test117/Readme.txt b/tests/base/test117/Readme.txt new file mode 100644 index 000000000..51d75a7c3 --- /dev/null +++ b/tests/base/test117/Readme.txt @@ -0,0 +1,12 @@ +Mode: vm run +Title: introduce of variables + +This tests if variable introductions happen at all the places that +they are supposed to happen in the presence of interfaces, +subinterfaces, classes and inheritance. It tests rule 2 partly, (the +non-error causing cases only). + +It DOES NOT test if variable introductions do not happen at all the +places they should not happen. (That will be a separate test.) + + diff --git a/tests/base/test118/Driver.java b/tests/base/test118/Driver.java new file mode 100644 index 000000000..5d0db8c15 --- /dev/null +++ b/tests/base/test118/Driver.java @@ -0,0 +1,75 @@ +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + C1 c1 = new C1(); + C11 c11 = new C11(); + C111 c111 = new C111(); + C12 c12 = new C12(); + Cleaf1 cleaf1 = new Cleaf1(); + Cleaf11 cleaf11 = new Cleaf11(); + Cleaf111 cleaf111 = new Cleaf111(); + Cleaf12 cleaf12 = new Cleaf12(); + } +} + + +interface I1 { } +interface I11 extends I1 { } +interface I111 extends I11 { } +interface I12 extends I1 { } + +class C1 implements I1 { C1(String s) {} } +class C11 implements I11 { } +class C111 implements I111 { } +class C12 implements I12 { } + +class Cleaf1 extends C1 { } +class Cleaf11 extends C11 { } +class Cleaf111 extends C111 { } +class Cleaf12 extends C12 { } + +// For this class structure: here is the "directly implements" relation +// C1 directly implements I1 +// C11 directly implements I11 +// C11 directly implements I1 +// C111 directly implements I111 +// C111 directly implements I11 +// C111 directly implements I1 +// C12 directly implements I12 +// C12 directly implements I1 + + + +aspect A1 { + static int i1Count, c1Count, c1IntCount = 0; + // interface + before(): initialization(I1.new(..)) { + i1Count++; + } + + + C1.new() { + c1Count++; + } + C1.new(int x) { + c1IntCount++; + } + } + +aspect Verify { + + // In the current model, introduces on constructors !don't! work their way + // down the inheritance. With the given hierarchy, the number of + // invocations of the introduced constructors should match the + // numbers below. + + after(): within(Driver) && execution(static void test(..)) { + Tester.checkEqual(A1.i1Count, 8, "A1.i1Count"); + Tester.checkEqual(A1.c1Count, 2, "A1.c1Count"); + Tester.checkEqual(A1.c1IntCount, 0, "A1.c1IntCount"); + } +} + diff --git a/tests/base/test118/Readme.txt b/tests/base/test118/Readme.txt new file mode 100644 index 000000000..3df50ec2b --- /dev/null +++ b/tests/base/test118/Readme.txt @@ -0,0 +1,12 @@ +Mode: VM run +Title: Introduce of constructors + +This tests if constructor introductions happen at all the places that +they are supposed to happen in the presence of interfaces, +subinterfaces, classes and inheritance. + +It DOES NOT test if constructor introductions do not happen at all the +places they should not happen. (That will be a separate test.) Nor +does it test for the special cases when the constructors with the +signatures used in the introductions already exist. (That should be a +separate test.) diff --git a/tests/base/test119/Driver.java b/tests/base/test119/Driver.java new file mode 100644 index 000000000..b2e971845 --- /dev/null +++ b/tests/base/test119/Driver.java @@ -0,0 +1,34 @@ +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + Foo foo = new Foo(); + foo.m(); + } +} + +aspect A { + //static advice(): Foo && (void m(..) || new(..)) { + //!!!no around advice allowed on constructors right now + void around(): target(Foo) && call(void m(..)) { + class Internal { + int val() { return 1; } + } + int i = 1; + Internal j = new Internal(); + proceed(); + Tester.checkEqual(i, 1, "i"); + Tester.checkEqual(j.val(), 1, "j.val()"); + } +} + +class Foo { + Foo() { + // System.out.println("constructor Foo()"); + } + void m() { + // System.out.println("method m()"); + } +} diff --git a/tests/base/test119/Readme.txt b/tests/base/test119/Readme.txt new file mode 100644 index 000000000..77f93fa4c --- /dev/null +++ b/tests/base/test119/Readme.txt @@ -0,0 +1,12 @@ +Mode: VM run +Title: Local declarations in advise bodies + +This tests local declarations in the body of advises. Local +declarations help the weaves inside advises to share variables between +them. These variables should be resolved in the context of the +methods being advised. + +The syntax supports local variable as well as class declrations. But +the weaver can't handle inner classes yet, so only the local variable +declaration case is tested. + diff --git a/tests/base/test120/Driver.java b/tests/base/test120/Driver.java new file mode 100644 index 000000000..14bf33201 --- /dev/null +++ b/tests/base/test120/Driver.java @@ -0,0 +1,53 @@ +public \u0063l\u0061ss Driver { + + public static void main(String[] args) { test(); } + + public static void test() { + + // integer literals + int dec = 5; + long longDec = 5; + long longDecL = 5L; + + int hex = 0xAbcdE; + long longHex = 0xAbcdE; + long longHexL = 0xAbcdEL; + + int oct = 0762; + long longOct = 0762; + long longOctL = 0762L; + + // boolean literals + boolean btrue = true; + boolean bfalse = false; + + // float literals + float f1 = 1e1f, f2 = 2.f, f3 = .3f, f4 = 3.14f, f5 = 6.023e+23f; + + // character literals + char + // c1 = '\u2352', + c2 = '\u0063'; // 'c' + // c3 = '\u0007'; + + // string literals + String \u0063 = "c"; // String c = "c"; + String s1 = ""; + String s2 = "\u0063"; // the string "c"; + // String s3 = "\u3333"; // uncommenting this will break weaver + + // string literals with escapes + String bs = "\b"; + String ht = "\t"; + String lf = "\n"; + String cr = "\r"; + String dq = "\""; + String sq = "\'"; + String backslash = "\\"; + String oes = "\u0000"; // octal escape smallest + String oeb = "\u00ff"; // octal escape biggest + String ctrlg = ""; // this turns into "\u0007" by the time it is parsed. + String random = "\u3333"; + } +} + diff --git a/tests/base/test120/Readme.txt b/tests/base/test120/Readme.txt new file mode 100644 index 000000000..351d8d6e5 --- /dev/null +++ b/tests/base/test120/Readme.txt @@ -0,0 +1,9 @@ +Mode: VM run +Title: unicodes and literals + +This test checks if the weaver correctly handles all forms of Java +literal expressions and unicodes. See bugs b076 and b077. + + + + diff --git a/tests/base/test121/Driver.java b/tests/base/test121/Driver.java new file mode 100644 index 000000000..ff9fffb28 --- /dev/null +++ b/tests/base/test121/Driver.java @@ -0,0 +1,95 @@ +import org.aspectj.testing.Tester; +public class Driver { + + public static void main(String[] args) { test(); } + + public static void test() { + Foo.staticMethod(); + Foo.introducedStaticMethod(); + + Foo foo = new Foo(10); + + foo.nonStaticMethod(); + foo.introducedNonStaticMethod(); + + Tester.checkEqual(A.fooStaticCounter, 1, "A.fooStaticCounter"); + Tester.checkEqual(A.fooCounter, 1, "A.fooCounter"); + Tester.checkEqual(A.aStaticCounter, 1, "A.aStaticCounter"); + Tester.checkEqual(A.aCounter, 1, "A.aCounter"); + // these is only one constructor call, for Foo + Tester.checkEqual(A.constructorCounter, 1, "constructor calls"); + // one for Foo, one for A + Tester.checkEqual(A.initializationCounter, 2, "initializations"); + Tester.check(A.ranIntroducedConstructor, + "no overriding of the real thing"); + } +} + +class Foo { + + static void staticMethod() { } + void nonStaticMethod() { } +} + +aspect A0_8beta1 { + after() returning(): /*target(*) &&*/ call(new(int)) { + A.constructorCounter++; + } + after() returning(): /*target(*) &&*/ initialization(new(..)) && !within(A0_8beta1) { + System.out.println("init at " + thisJoinPoint); + A.initializationCounter++; + } + + before(): within(Foo) && execution(static * Foo.*(..)) { + A.fooStaticCounter++; + } + + before(): within(A) && execution(static * Foo.*(..)) { + A.aStaticCounter++; + } + + before(): within(A) && execution(!static * Foo.*(..)) { + A.aCounter++; + System.out.println("external before advise on " + thisJoinPoint); + } +} + +aspect A pertarget(target(Foo)){ + + static int constructorCounter = 0; + static int initializationCounter = 0; + static int aStaticCounter = 0; + static int aCounter = 0; + static int fooStaticCounter = 0; + static int fooCounter = 0; + + static boolean ranIntroducedConstructor = false; + + //introduction Foo { + static void Foo.introducedStaticMethod() { + // System.out.println(thisJoinPoint.className +"."+ + // thisJoinPoint.methodName); + } + void Foo.introducedNonStaticMethod() { + // System.out.println(thisJoinPoint.className +"."+ + // thisJoinPoint.methodName); + } + Foo.new(int n) { ranIntroducedConstructor = true; } + + // make sure advice doesn't go on the toString() method + // this would result in an infinite recursion + before(): within(Foo) && execution(!static * Foo.*(..)) { + fooCounter++; + //System.out.println("before advise on " + + //thisJoinPoint.className +"."+ thisJoinPoint.methodName); + } + + public A() { System.err.println("creating: " + this); } + + //XXX moved to other aspect, need to think about this... + //before(): within(A) && executions(!static * Foo.*(..)) { + //aCounter++; + //System.out.println("before advise on " + thisJoinPoint); + //} +} + diff --git a/tests/base/test121/Readme.txt b/tests/base/test121/Readme.txt new file mode 100644 index 000000000..957fe1c44 --- /dev/null +++ b/tests/base/test121/Readme.txt @@ -0,0 +1,8 @@ +Mode: VM run +Title: advises on introduced methods + +This test checks three things: + + - ! pattern in modifiers + - advice can apply to introduced methods + diff --git a/tests/base/test122/Driver.java b/tests/base/test122/Driver.java new file mode 100644 index 000000000..87c31350c --- /dev/null +++ b/tests/base/test122/Driver.java @@ -0,0 +1,24 @@ +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + I i = new C4(); + Tester.checkEqual(i.m(), 42, "i.m()"); + } +} + + +interface I {} +abstract class C1 implements I{} +class C2 extends C1 implements I {} +class C3 extends C1 {} +class C4 extends C2 {} + + +aspect Aspect { + //introduction I { + public int I.m() {return 42;} + //} +} diff --git a/tests/base/test122/Readme.txt b/tests/base/test122/Readme.txt new file mode 100644 index 000000000..307a93744 --- /dev/null +++ b/tests/base/test122/Readme.txt @@ -0,0 +1,5 @@ +Mode: VM Run +Title: Method introduction into interface implemented by abstract class + +This tests the implementation of method introductions into interfaces +which are implemented by abstract class. diff --git a/tests/base/test123/Driver.java b/tests/base/test123/Driver.java new file mode 100644 index 000000000..41d099c07 --- /dev/null +++ b/tests/base/test123/Driver.java @@ -0,0 +1,48 @@ +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + C1 c1 = new C1(333); + Tester.checkEqual(c1.afterAdvises, 0, "C1(int)"); + c1 = new C1("asdfasdf"); + Tester.checkEqual(c1.afterAdvises, 1, "C1(String)"); + C2 c2 = new C2(333); + Tester.checkEqual(c2.afterAdvises, 0, "C2(int) -> C1(String)"); + c2 = new C2("foo"); + Tester.checkEqual(c2.afterAdvises, 1, "C2(String) -> C1(int)"); + c2 = new C2("foo", 42); + Tester.checkEqual(c2.afterAdvises, 1, "C2(String,int) -> C1(String)"); + } +} + +class C1 { + public int afterAdvises = 0; + + C1() { } + C1(int i) { } + C1(String s) { } +} + +class C2 extends C1 { + + C2(int i) { + super("asdf"); + } + + C2(String s) { + super(42); + } + + C2(String s, int i) { + super(s); + } +} + +aspect A { + after(/*C1 c1*/) returning(C1 c1): /*target(c1) && */ + call(new(String, ..)) { + c1.afterAdvises += 1; + } +} diff --git a/tests/base/test123/Readme.txt b/tests/base/test123/Readme.txt new file mode 100644 index 000000000..0de4cc836 --- /dev/null +++ b/tests/base/test123/Readme.txt @@ -0,0 +1,5 @@ +Mode: VM Run +Title: Crossing super calls in constructors. + +This tests how crossing super calls work with reception +advice in constructors. diff --git a/tests/base/test124/Driver.java b/tests/base/test124/Driver.java new file mode 100644 index 000000000..3c9e058b3 --- /dev/null +++ b/tests/base/test124/Driver.java @@ -0,0 +1,29 @@ +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + Driver.m(4); + Tester.checkEqual(Trace.enterCount, 2, "befores"); + // The after for this method hasn't been run yet + Tester.checkEqual(Trace.exitCount, 1, "afters"); + } + + static int m(int x) { + return 0; + } +} + +aspect Trace { + public static int enterCount, exitCount; + // notice the absence of any modifiers in the advise + before(): within(Driver) && (execution(void test()) || + execution(* m(..))) { + enterCount++; + } + after(): within(Driver) && (execution(void test()) || + execution(* m(..))) { + exitCount++; + } +} diff --git a/tests/base/test124/Readme.txt b/tests/base/test124/Readme.txt new file mode 100644 index 000000000..bca6d2360 --- /dev/null +++ b/tests/base/test124/Readme.txt @@ -0,0 +1,6 @@ +Mode: VM run +Title: empty modifier pattern + +An advise specifies an empty modifier pattern which functions like a +wildcard on modifiers. + diff --git a/tests/base/test125/Driver.java b/tests/base/test125/Driver.java new file mode 100644 index 000000000..171c2370b --- /dev/null +++ b/tests/base/test125/Driver.java @@ -0,0 +1,45 @@ +import java.io.*; +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + Point p = new Point(); + p.setX(3); + } +} + +class Point { + int _x = 0; + int _y = 0; + + Point() {} + + void set (int x, int y) { + _x = x; _y = y; + } + + void setX (int x) { _x = x; } + void setY (int y) { _y = y; } + + int getX() { return _x; } + int getY() { return _y; } +} + +aspect Trace { + static int oldvalue; + + before(Point p, int newvalue): target(p) && args(newvalue) && + (call(void setX(int)) || + call(void setY(int))) { + oldvalue = p.getX(); + } + after(Point p, int newvalue): target(p) && args(newvalue) && + (call(void setX(int)) || + call(void setY(int))) { + + Tester.checkEqual(oldvalue,0, "oldvalue"); + Tester.checkEqual(newvalue,3, "newvalue"); + } +} diff --git a/tests/base/test125/Readme.txt b/tests/base/test125/Readme.txt new file mode 100644 index 000000000..49428a896 --- /dev/null +++ b/tests/base/test125/Readme.txt @@ -0,0 +1,6 @@ +Mode: VM run +Title: Alpha conversion of argument names in designators + + +This tests if parameter names in designators are alpha-converted to +the parameter names used in the definition of the method. diff --git a/tests/base/test126/Driver.java b/tests/base/test126/Driver.java new file mode 100644 index 000000000..e855c5781 --- /dev/null +++ b/tests/base/test126/Driver.java @@ -0,0 +1,18 @@ +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + + // local variable declaration in the init part of a for + for (int i = 0, j = 0; j < 10 ; i++, j++) { + j++; + } + int m, n, j = 0; + + // init part without local var declaration + for (m = 0, n = 0; j < 10 ; m++, n++) { + j++; + m++; + } + } +} diff --git a/tests/base/test126/Readme.txt b/tests/base/test126/Readme.txt new file mode 100644 index 000000000..b4b666098 --- /dev/null +++ b/tests/base/test126/Readme.txt @@ -0,0 +1,7 @@ +Mode: VM run +Title: For Statement + +This tests the weaving of For statements. More variants of the for +statement can be added to the test. The current test only checks for +variation in the init part of the for loop. + diff --git a/tests/base/test127/Driver.java b/tests/base/test127/Driver.java new file mode 100644 index 000000000..c72e10327 --- /dev/null +++ b/tests/base/test127/Driver.java @@ -0,0 +1,21 @@ +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + new C().foo("hello"); + } +} + +class C { + void foo(String s) { + Tester.checkEqual(s, "hello", "in method body"); + } +} + +aspect A { + before(String str): target(C) && call(void foo(String)) && args(str) { + Tester.checkEqual(str, "hello", "in advice body"); + } +} diff --git a/tests/base/test127/Readme.txt b/tests/base/test127/Readme.txt new file mode 100644 index 000000000..4f2d0e349 --- /dev/null +++ b/tests/base/test127/Readme.txt @@ -0,0 +1,6 @@ +Mode: vm compile +Title: advice uses its own formals to get actuals + +A simple test to be sure that when an advice uses a different formal +than the actual member does that proper re-naming happens. + diff --git a/tests/base/test128/Driver.java b/tests/base/test128/Driver.java new file mode 100644 index 000000000..12d966638 --- /dev/null +++ b/tests/base/test128/Driver.java @@ -0,0 +1,19 @@ +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + C c = new C(); + Tester.check(c == c.foo(), "this wasn't this"); + } +} + +class C { } + +aspect A { + //introduction C { + C C.foo() { return this; } + //} +} + diff --git a/tests/base/test128/Readme.txt b/tests/base/test128/Readme.txt new file mode 100644 index 000000000..744b68df7 --- /dev/null +++ b/tests/base/test128/Readme.txt @@ -0,0 +1,6 @@ +Mode: vm compile +Title: introduce weaves can use this + +A simple test to be sure that introduce weaves are allowed to use +this. + diff --git a/tests/base/test129/Driver.java b/tests/base/test129/Driver.java new file mode 100644 index 000000000..6a2f7c04b --- /dev/null +++ b/tests/base/test129/Driver.java @@ -0,0 +1,34 @@ +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + AbstractC aC = new C(); + Tester.checkEqual(aC.foo(), 42, "introduced abstract"); + Tester.checkEqual(((I)aC).bar(), 12, "introduced on interface"); + } +} + +interface I { +} + +abstract class AbstractC implements I { +} + +class C extends AbstractC { +} + +aspect A { + //introduction AbstractC { + abstract int AbstractC.foo(); + //} + + //introduction C { + int C.foo() { return 42; } + //} + + //introduction I { + public int I.bar() { return 12; } + //} +} diff --git a/tests/base/test130/Driver.java b/tests/base/test130/Driver.java new file mode 100644 index 000000000..06b0184ab --- /dev/null +++ b/tests/base/test130/Driver.java @@ -0,0 +1,31 @@ +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + public static void test() { + C c = new C(); + + Tester.checkEqual(c.basic(), 4, "basic()"); + Tester.checkEqual(c.exceptional(), 3, "exceptional()"); + } +} + +class C { + public int basic() { + return 1; + } + + public int exceptional() { + return 1; + } +} + +aspect B { + int around(): target(C) && call(int basic()) { + return 4; + } + int around(): target(C) && call(int exceptional()) { + return 3; + } +} + diff --git a/tests/base/test131/Driver.java b/tests/base/test131/Driver.java new file mode 100644 index 000000000..752224626 --- /dev/null +++ b/tests/base/test131/Driver.java @@ -0,0 +1,44 @@ +// various forms of package name pattern matching work + +import org.aspectj.testing.Tester; + +import p1.C1; +import p1.p2.C2; + +public class Driver { + public static void test() { + Top t = new Top(); + p1.C1 c1 = new p1.C1(); + p1.p2.C2 c2 = new p1.p2.C2(); + + Tester.checkEqual(t.bar(), 11, "top.bar()"); + + Tester.checkEqual(c1.bar(), 1111, "c1.bar()"); + + Tester.checkEqual(c2.bar(), 1011, "c2.bar()"); + } + public static void main(String[] args) { test(); } +} + +class Top { + public int bar() { + return 1; + } +} + +aspect TopAdvice { + int around(): target(*) && call(int *()) { + int result = proceed(); + return result+10; + } + + int around(): target(p1.*) && call(int *()) { + int result = proceed(); + return result+100; + } + + int around(): target(p1..*) && call(int *()) { + int result = proceed(); + return result+1000; + } +} diff --git a/tests/base/test131/p1/C1.java b/tests/base/test131/p1/C1.java new file mode 100644 index 000000000..b7557b5c0 --- /dev/null +++ b/tests/base/test131/p1/C1.java @@ -0,0 +1,5 @@ +package p1; + +public class C1 { + public int bar() { return 1; } +} diff --git a/tests/base/test131/p1/p2/C2.java b/tests/base/test131/p1/p2/C2.java new file mode 100644 index 000000000..e2d6b2fe5 --- /dev/null +++ b/tests/base/test131/p1/p2/C2.java @@ -0,0 +1,5 @@ +package p1.p2; + +public class C2 { + public int bar() { return 1; } +} diff --git a/tests/base/test132/Driver.java b/tests/base/test132/Driver.java new file mode 100644 index 000000000..5ed0292ca --- /dev/null +++ b/tests/base/test132/Driver.java @@ -0,0 +1,26 @@ +// proper matching of overloaded constructors + +import org.aspectj.testing.Tester; + +public aspect Driver { + public static void main(String[] args) { test(); } + after(/*Foo f,*/ String aspectName) returning(Foo f): + /*target(f) &&*/ call(new(String)) && args(aspectName) { + f.name = aspectName+"-ADVISED"; + } + + public static void test() { + Foo foo = new Foo("NAME"); + Tester.checkEqual(foo.name, "NAME-ADVISED", "new Foo(name)"); + foo = new Foo(); + Tester.checkEqual(foo.name, "NONE", "new Foo()"); + } +} + +class Foo { + public String name = "NONE"; + public Foo() { } + public Foo(String name) { + this.name = name; + } +} diff --git a/tests/base/test133/Driver.java b/tests/base/test133/Driver.java new file mode 100644 index 000000000..1f1b1f7ab --- /dev/null +++ b/tests/base/test133/Driver.java @@ -0,0 +1,24 @@ +// PUREJAVA: Corrrect supercall lookup for method().name() +import org.aspectj.testing.Tester; + +public class Driver { + private Foo foo = new Foo(); + + public static void main(String[] args) { test(); } + + public Foo getFoo() { return foo; } + + public String bar() { + return getFoo().bar(); + } + + public static void test() { + Tester.checkEqual(new Driver().bar(), "Foo", "getFoo().bar()"); + } +} + +class Foo { + public String bar() { + return "Foo"; + } +} diff --git a/tests/base/test134/Driver.java b/tests/base/test134/Driver.java new file mode 100644 index 000000000..ac5d54e5e --- /dev/null +++ b/tests/base/test134/Driver.java @@ -0,0 +1,26 @@ +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + public int divide(int x, int y) { + return x/y; + } + + public static void test() { + Tester.checkEqual(new Driver().divide(6, 3), 2, "divide(6, 3)"); + Tester.checkEqual(new Driver().divide(6, 0), -1, "divide(6, 0)"); + } +} + +aspect CatchArithmetic { + int around(): target(*) && call(int *(..)) { + int x; + try { + x = proceed(); + } + catch (ArithmeticException e) { + return -1; + } + return x; + } +} diff --git a/tests/base/test135/Driver.java b/tests/base/test135/Driver.java new file mode 100644 index 000000000..7c2b0b5e2 --- /dev/null +++ b/tests/base/test135/Driver.java @@ -0,0 +1,50 @@ +// proper values for thisJoinPoint attributes +// Currently there is a bug (?) in that the parameters value +// of the joinpoint seems to always be null. +package test135; + +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + + TopFoo foo = new TopFoo(); + JoinPointFields jpf = JoinPointFields.aspectOf(); + + foo.bar(1, "one"); + + Tester.checkEqual(jpf.className, "test135.TopFoo", "className"); + Tester.checkEqual(jpf.methodName, "bar", "methodName"); + Tester.checkEqual(jpf.parameterNames, + new String[] {"intParam", "stringParam"}, + "parameterNames"); + Tester.checkEqual(jpf.parameterTypes, + new Class[] {Integer.TYPE, String.class}, + "parameterTypes"); + //System.out.println(jpf.parameters); + Tester.checkEqual(jpf.parameters, + new Object[] {new Integer(1), "one"}, + "parameters"); //!!! + + test135.pack.PackFoo foo1 = new test135.pack.PackFoo(); + test135.pack.PackJoinPointFields jpf1 = + test135.pack.PackJoinPointFields.aspectOf(); + + foo1.bar(2, "two"); + Tester.checkEqual(jpf1.className, "test135.pack.PackFoo", "className"); + Tester.checkEqual(jpf1.methodName, "bar", "methodName"); + Tester.checkEqual(jpf1.parameterNames, + new String[] {"packIntParam", "packStringParam"}, + "parameterNames"); + Tester.checkEqual(jpf1.parameterTypes, + new Class[] {Integer.TYPE, String.class}, + "parameterTypes"); + Tester.checkEqual(jpf1.parameters, + new Object[] {new Integer(2), "two"}, + "parameters"); + } +} + + diff --git a/tests/base/test135/JoinPointFields.java b/tests/base/test135/JoinPointFields.java new file mode 100644 index 000000000..dd83e7969 --- /dev/null +++ b/tests/base/test135/JoinPointFields.java @@ -0,0 +1,7 @@ +package test135; + +public aspect JoinPointFields extends test135.pack.JoinPointFields issingleton() { //of eachJVM() { + protected pointcut onTypes(): target(*); + + private int x = protectedField; +} diff --git a/tests/base/test135/TopFoo.java b/tests/base/test135/TopFoo.java new file mode 100644 index 000000000..f2d98f40e --- /dev/null +++ b/tests/base/test135/TopFoo.java @@ -0,0 +1,6 @@ +package test135; + +class TopFoo { + public void bar(int intParam, String stringParam) { + } +} diff --git a/tests/base/test135/pack/JoinPointFields.java b/tests/base/test135/pack/JoinPointFields.java new file mode 100644 index 000000000..c541ba2a4 --- /dev/null +++ b/tests/base/test135/pack/JoinPointFields.java @@ -0,0 +1,35 @@ +package test135.pack; + +import org.aspectj.lang.*; +import org.aspectj.lang.reflect.*; + +// a first try at a library class in the test suite +public abstract aspect JoinPointFields { + public String className; + public String methodName; + public String[] parameterNames; + public Class[] parameterTypes; + public Object[] parameters; + + protected int protectedField = 42; + + abstract protected pointcut onTypes(); + + before(): call(!static * *(..)) && onTypes() && !within(JoinPointFields+) { + System.out.println(thisJoinPoint); + + Signature sig = thisJoinPoint.getSignature(); + CodeSignature codeSig = (CodeSignature) sig; + //ReceptionJoinPoint rjp = (ReceptionJoinPoint) thisJoinPoint; + + className = sig.getDeclaringType().getName(); + System.out.println(className); + + methodName = sig.getName(); + parameterNames = codeSig.getParameterNames(); + parameterTypes = codeSig.getParameterTypes(); + //parameters = rjp.getParameters(); + parameters = thisJoinPoint.getArgs(); + System.out.println("DONE: " + thisJoinPoint); + } +} diff --git a/tests/base/test135/pack/PackFoo.java b/tests/base/test135/pack/PackFoo.java new file mode 100644 index 000000000..f00eee490 --- /dev/null +++ b/tests/base/test135/pack/PackFoo.java @@ -0,0 +1,6 @@ +package test135.pack; + +public class PackFoo { + public void bar(int packIntParam, String packStringParam) { + } +} diff --git a/tests/base/test135/pack/PackJoinPointFields.java b/tests/base/test135/pack/PackJoinPointFields.java new file mode 100644 index 000000000..bd6bf46e3 --- /dev/null +++ b/tests/base/test135/pack/PackJoinPointFields.java @@ -0,0 +1,6 @@ +package test135.pack; + +public aspect PackJoinPointFields + extends JoinPointFields issingleton() { /*of eachJVM() {*/ + protected pointcut onTypes(): target(test135.pack.PackFoo); +} diff --git a/tests/base/test136/Driver.java b/tests/base/test136/Driver.java new file mode 100644 index 000000000..aca8e2dcc --- /dev/null +++ b/tests/base/test136/Driver.java @@ -0,0 +1,119 @@ +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + C0 c = new C2(); + c.m1(2, 2); + Tester.checkEqual(A.C0_m1_calls, 1, "C2.m1 -- C0 calls"); + Tester.checkEqual(A.C2_m1_calls, 1, "C2.m1 -- C2 calls"); + Tester.checkEqual(A.m1_afters, 1, "C2.m1 -- after advice"); + A.clearCounts(); + + c.m2(c); + Tester.checkEqual(A.C0_m1_calls, 1, "C2.m2 -- C0.m1 calls"); + Tester.checkEqual(A.C2_m1_calls, 0, "C2.m2 -- C2.m1 calls"); + Tester.checkEqual(A.m1_afters, 0, "C2.m2 -- after m1 advice"); + Tester.checkEqual(A.C0_m2_calls, 1, "C2.m2 -- C0.m2 calls"); + Tester.checkEqual(A.C2_m2_calls, 1, "C2.m2 -- C2.m2 calls"); + Tester.checkEqual(A.m2_afters, 1, "C2.m2 -- after m2 advice"); + + c.m3("hi"); + Tester.checkEqual(A.C0_m3_calls, 1, "C2.m3 -- C0 calls"); + Tester.checkEqual(A.C1_m3_calls, 1, "C2.m3 -- C1 calls"); + Tester.checkEqual(A.C2_m3_calls, 1, "C2.m3 -- C2 calls"); + } +} + +class C0 { + public C0() { + } + + void m1(int x, double y) { + A.C0_m1_calls += 1; + } + + void m2(C0 c0) { + A.C0_m2_calls += 1; + } + void m3(String s) { + A.C0_m3_calls += 1; + } + +} + +class C1 extends C0 { + void m3(String s) { + super.m3(s); + A.C1_m3_calls += 1; + } +} + +class C2 extends C1 { + public boolean C2_after_called = false; + + public void setC2_after_called( boolean newVal ) { + C2_after_called = newVal; + } + + public C2() { + super(); + } + + void m1(int x, double y) { + A.C2_m1_calls += 1; + super.m1(x*2, x+y); + } + + void m2(C0 c0) { + A.C2_m2_calls += 1; + super.m1(2, 2); + super.m2(this); + } + void m3(String s) { + super.m3(s); + A.C2_m3_calls += 1; + } +} + +aspect A { + public static int C0_m1_calls = 0; + public static int C2_m1_calls = 0; + public static int C0_m2_calls = 0; + public static int C2_m2_calls = 0; + public static int C0_m3_calls = 0; + public static int C1_m3_calls = 0; + public static int C2_m3_calls = 0; + public static int m1_afters = 0; + public static int m2_afters = 0; + + public static void clearCounts() { + C0_m1_calls = 0; + C2_m1_calls = 0; + C0_m2_calls = 0; + C2_m2_calls = 0; + C0_m3_calls = 0; + C1_m3_calls = 0; + C2_m3_calls = 0; + m1_afters = 0; + m2_afters = 0; + } + + after(): target(C0+) && call(void m1(int, double)) { + m1_afters += 1; + } + after(): target(C0+) && call(* m2(..)) { + m2_afters += 1; + } + + after(): target(C0+) && call(* m3(..)) { + int x = 22; + } + + after(C2 c2) returning(): + target(c2) && call(new()) { + c2.setC2_after_called( true ); + } +} + diff --git a/tests/base/test137/Driver.java b/tests/base/test137/Driver.java new file mode 100644 index 000000000..1358e2ac6 --- /dev/null +++ b/tests/base/test137/Driver.java @@ -0,0 +1,87 @@ +// operations on private && protected aspect members (++, -- in partciular) + +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + Foo foo = new Foo(); + + foo.foo(); + + Tester.checkEqual(Aspect.getPrivateAspectVar(), 23); + Tester.checkEqual(Aspect.aspectOf().getPrivateAspectInstanceVar(), 23); + } +} + +class Foo { + public void foo() { + } +} + +//XXX need to put some of eachobject back into this some day + +aspect Aspect { + private static final int PRIVATEASPECTCONST = 10; + private static int privateAspectVar = 20; + + protected static int protectedAspectVar = 40; + + public static int getPrivateAspectVar() { + return privateAspectVar; + } + + private int privateAspectInstanceVar = 30; + protected int protectedAspectInstanceVar = 50; + + public int getPrivateAspectInstanceVar() { + return privateAspectInstanceVar; + } + + + + pointcut onFoo(): target(Foo) && call(void foo()); + + before(): onFoo() { + privateAspectVar = 21; + privateAspectVar = 1 + privateAspectVar; + Tester.checkEqual(privateAspectVar, 22); + Tester.checkEqual(privateAspectVar += 1, 23); + Tester.checkEqual(privateAspectVar++, 23); + Tester.checkEqual(privateAspectVar, 24); + Tester.checkEqual(privateAspectVar--, 24); + Tester.checkEqual(privateAspectVar, 23); + Tester.checkEqual(++privateAspectVar, 24); + Tester.checkEqual(privateAspectVar, 24); + Tester.checkEqual(--privateAspectVar, 23); + } + + before(): onFoo() { + privateAspectVar = 21; + privateAspectVar = 1 + privateAspectVar; + Tester.checkEqual(privateAspectVar, 22); + Tester.checkEqual(privateAspectVar += 1, 23); + Tester.checkEqual(privateAspectVar++, 23); + Tester.checkEqual(privateAspectVar, 24); + Tester.checkEqual(privateAspectVar--, 24); + Tester.checkEqual(privateAspectVar, 23); + Tester.checkEqual(++privateAspectVar, 24); + Tester.checkEqual(privateAspectVar, 24); + Tester.checkEqual(--privateAspectVar, 23); + Tester.checkEqual(privateAspectVar, 23); + + privateAspectInstanceVar = 21; + privateAspectInstanceVar = 1 + privateAspectInstanceVar; + Tester.checkEqual(privateAspectInstanceVar, 22); + Tester.checkEqual(privateAspectInstanceVar += 1, 23); + Tester.checkEqual(privateAspectInstanceVar++, 23); + Tester.checkEqual(privateAspectInstanceVar, 24); + Tester.checkEqual(privateAspectInstanceVar--, 24); + Tester.checkEqual(privateAspectInstanceVar, 23); + Tester.checkEqual(++privateAspectInstanceVar, 24); + Tester.checkEqual(privateAspectInstanceVar, 24); + Tester.checkEqual(--privateAspectInstanceVar, 23); + Tester.checkEqual(privateAspectInstanceVar, 23); + } +} diff --git a/tests/base/test138/Driver.java b/tests/base/test138/Driver.java new file mode 100644 index 000000000..f61d360af --- /dev/null +++ b/tests/base/test138/Driver.java @@ -0,0 +1,34 @@ +//only register things once. + +import org.aspectj.testing.Tester; + +public class Driver { + public static void test() { + A a = new A(); + B b = new B(); + + // instances of A, B are created (the instanceof Aspect isn't counted for timing reasons) + Tester.checkEqual(Aspect.count, 2, "instance count"); + } + + public static void main(String[] args) { test(); } +} + + +class A { + public A() {} + public void foo() {} +} + +class B extends A { + public B() {} + public void bar() {} +} + +aspect Aspect { + public static int count = 0; + + after() returning(): /*target(*) &&*/ call(new()) { + count++; + } +} diff --git a/tests/base/test139/Driver.java b/tests/base/test139/Driver.java new file mode 100644 index 000000000..10553e90a --- /dev/null +++ b/tests/base/test139/Driver.java @@ -0,0 +1,36 @@ +// inner aspects and around + +import org.aspectj.testing.Tester; + +public class Driver { + public static void test() { + C2 c2 = new C2(); + + Tester.checkEqual(c2.foo(), 142, "modified c2.foo()"); + } + + public static void main(String[] args) { test(); } +} + + +class C1 { + private int myInteger = 100; + + static aspect A { + int around(C2 c2): + target(c2) && call(int foo()) { + int result = proceed(c2); + return result + c2.getC1().myInteger; + } + } +} + +class C2 { + public C1 getC1() { + return new C1(); + } + int foo() { + return 42; + } +} + diff --git a/tests/base/test140/Driver.java b/tests/base/test140/Driver.java new file mode 100644 index 000000000..db03998ae --- /dev/null +++ b/tests/base/test140/Driver.java @@ -0,0 +1,68 @@ +import org.aspectj.testing.Tester; + +// aspect inheritance and advice, introduction + +public class Driver { + public static void test() { + C1 c1 = new C1(); + + Tester.checkEqual(c1.foo(), "from A2", "sub-aspects"); + Tester.checkEqual(c1.bar(), + "from A0 #2", + "sub-aspects and position"); + + // the around advice lexically in A1 runs twice, once for each concrete + // sub-aspects. putting advice on a concrete pointcut in an abstract + // aspect will always have this odd behavior, and possibly should be illegal + Tester.checkEqual(c1.getString(), + ":A2:A1:A1:C1", + "multiple arounds"); + } + + public static void main(String[] args) { test(); } +} + +class C1 { + String getString() { + return ":C1"; + } +} + +abstract aspect A1 { + String C1.foo() { + return "from A1"; + } + + String C1.bar() { + return "from A1"; + } + + String around(): + call(String C1.getString()) { + return ":A1" + proceed(); + } +} + +aspect A2 extends A1 { + String C1.foo() { + return "from A2"; + } + + String around(): + call(String C1.getString()) { + return ":A2" + proceed(); + } + +} + +aspect A0 extends A1 { + // multiple conflicting declarations in the same aspect are now an error + //String C1.bar() { + // return "from A0 #1"; + //} + + String C1.bar() { + return "from A0 #2"; + } +} + diff --git a/tests/base/test141/Driver.java b/tests/base/test141/Driver.java new file mode 100644 index 000000000..0bf61f906 --- /dev/null +++ b/tests/base/test141/Driver.java @@ -0,0 +1,60 @@ +// thisResultObject for primitives +// I think this is a bad test. Is there a way to do this? -eh + +import org.aspectj.testing.Tester; + +public class Driver { + public static void test() { + C1 c1 = new C1(); + + c1.getInteger(); + c1.getDouble(); + c1.getVoid(); + c1.getString(); + c1.getBoolean(); + } + + public static void main(String[] args) { test(); } +} + +class C1 { + int getInteger() { + return 1; + } + + double getDouble() { + return 3.14; + } + + void getVoid() { + } + + String getString() { + return "Hello World"; + } + + boolean getBoolean() { + return true; + } +} + +aspect A1 { + // don't advise the finalize reception, or weird interactions with GC can happen + after() returning (Object result): + target(C1) && call(* *()) && !call(void finalize()) { + if (result == null) { + Tester.checkEqual(thisJoinPoint.getSignature().getName(), + "getVoid", + "void method"); + } + else { + String resultClassName = result.getClass().getName(); + + Tester.checkEqual("java.lang." + + thisJoinPoint.getSignature().getName().substring(3), + resultClassName, + "result object type"); + } + } +} + diff --git a/tests/base/test142/Driver.java b/tests/base/test142/Driver.java new file mode 100644 index 000000000..5e95eb8ee --- /dev/null +++ b/tests/base/test142/Driver.java @@ -0,0 +1,32 @@ +// introductions calling super. + +import org.aspectj.testing.Tester; + +public class Driver { + public static void test() { + C2 c2 = new C2("FooBar"); + + Tester.checkEqual(c2.name, "FooBar", "C2's name"); + } + + public static void main(String[] args) { test(); } +} + +class C1 { + public String name = null; + + public C1(String name) { + this.name = name; + } +} + +class C2 extends C1 { + C2() { super("dummy"); } +} + +aspect A { + C2.new(String name) { + super(name); + } +} + |