diff options
author | wisberg <wisberg> | 2002-12-16 18:51:06 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2002-12-16 18:51:06 +0000 |
commit | 144143c2970a1e874d74cdbd0f8c622d4282a3c3 (patch) | |
tree | b12383d3d9e76c7e1f25f7fbec83051ef17f81fb /tests/design/around | |
parent | fafae443719b26159ab2d7dac1c9b46b5e00b671 (diff) | |
download | aspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.tar.gz aspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.zip |
initial version
Diffstat (limited to 'tests/design/around')
-rw-r--r-- | tests/design/around/FakeStackChecker.java | 6 | ||||
-rw-r--r-- | tests/design/around/ReturnCastProceed.java | 83 | ||||
-rw-r--r-- | tests/design/around/StackChecker.java | 16 |
3 files changed, 105 insertions, 0 deletions
diff --git a/tests/design/around/FakeStackChecker.java b/tests/design/around/FakeStackChecker.java new file mode 100644 index 000000000..f66cab919 --- /dev/null +++ b/tests/design/around/FakeStackChecker.java @@ -0,0 +1,6 @@ +import org.aspectj.testing.Tester; + +public class FakeStackChecker { + public static void setBaseDepth() { } + public static void checkDepth(int expectedDepth, String message) { } +} diff --git a/tests/design/around/ReturnCastProceed.java b/tests/design/around/ReturnCastProceed.java new file mode 100644 index 000000000..4141a8e98 --- /dev/null +++ b/tests/design/around/ReturnCastProceed.java @@ -0,0 +1,83 @@ +import org.aspectj.testing.Tester; + + +public class ReturnCastProceed extends Helper { + + public static void main(String[] args) { + StackChecker.setBaseDepth(); + + Tester.checkEqual(mInt(), 3, "mInt is 3"); + Tester.checkAndClearEvents( new String[] { "advice" } ); + + mVoid(); + Tester.checkAndClearEvents(new String[] {"advice", "void body" }); + + Tester.checkEqual(mString(), "I'm a string", "mString is right"); + Tester.checkAndClearEvents(new String[] { "advice" }); + + Tester.checkEqual(mInteger().intValue(), 5555, "mInteger is boxed 5555"); + Tester.checkAndClearEvents(new String[] { "advice" }); + + Tester.check(mRunnable() instanceof Runnable, "mRunnable returns a Runnable"); + Tester.checkAndClearEvents(new String[] { "advice" }); + + Tester.check(mObject() == f, "mObject returns f"); + Tester.checkAndClearEvents(new String[] { "advice" }); + + } +} + +class Helper { + static Float f = new Float(37.8); + + static int mInt() { + //StackChecker.checkDepth(2, "mInt"); + return 3; + } + + static void mVoid() { + StackChecker.checkDepth(2, "mVoid"); + Tester.event("void body"); + } + + static String mString() { + StackChecker.checkDepth(2, "mString"); + return "I'm a string"; + } + static Integer mInteger() { + StackChecker.checkDepth(2, "mInteger"); + return new Integer(5555); + } + + static Runnable mRunnable() { + //StackChecker.checkDepth(2, "mRunnable"); + return new Runnable() { + public void run() { + Tester.event("i'm running"); // not used yet. + } + }; + } + + static Object mObject() { + StackChecker.checkDepth(2, "mObject"); + return f; + } +} + +aspect A { + Object around(): execution(static * Helper.*(..)) { + Tester.event("advice"); + return (Object) proceed(); + } + +// Object around(): execution(static * ReturnCastProceed.*(..)) { +// Object ret = proceed(); +// System.err.println("doing stuff"); +// return ret; +// } + +// Object around(): execution(static * ReturnCastProceed.*(..)) { +// return proceed(); +// } + +} diff --git a/tests/design/around/StackChecker.java b/tests/design/around/StackChecker.java new file mode 100644 index 000000000..e55c64055 --- /dev/null +++ b/tests/design/around/StackChecker.java @@ -0,0 +1,16 @@ +import org.aspectj.testing.Tester; + +public class StackChecker { + static int baseStackDepth = 0; + + public static void setBaseDepth() { + int depth = new Throwable().getStackTrace().length - 2; // XXX 1.4 only + baseStackDepth = depth; + } + + + public static void checkDepth(int expectedDepth, String message) { + int depth = new Throwable().getStackTrace().length - 1 - baseStackDepth; + Tester.checkEqual(depth, expectedDepth, message); + } +} |