diff options
author | wisberg <wisberg> | 2005-01-29 10:08:56 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2005-01-29 10:08:56 +0000 |
commit | 24b9d46b15138ebffb164fad1abcf634a3eacf23 (patch) | |
tree | 37e54a2c622a3a07481d47a65de5cb62de80433d /org.aspectj.lib/testsrc | |
parent | 5108369ed7306ce85749b8fbf611e2e5c5e05b1e (diff) | |
download | aspectj-24b9d46b15138ebffb164fad1abcf634a3eacf23.tar.gz aspectj-24b9d46b15138ebffb164fad1abcf634a3eacf23.zip |
Initial library module
Diffstat (limited to 'org.aspectj.lib/testsrc')
5 files changed, 231 insertions, 0 deletions
diff --git a/org.aspectj.lib/testsrc/LibModuleTests.java b/org.aspectj.lib/testsrc/LibModuleTests.java new file mode 100644 index 000000000..6a521ca97 --- /dev/null +++ b/org.aspectj.lib/testsrc/LibModuleTests.java @@ -0,0 +1,28 @@ +/* ******************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wes Isberg initial implementation + * ******************************************************************/ + +// default package + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class LibModuleTests extends TestCase { + + public static Test suite() { + TestSuite suite = new TestSuite(LibModuleTests.class.getName()); + suite.addTest(org.aspectj.lib.pointcuts.PointcutsTests.suite()); + suite.addTest(org.aspectj.lib.tracing.TracingTests.suite()); + return suite; + } + +} diff --git a/org.aspectj.lib/testsrc/org/aspectj/lib/pointcuts/PointcutsTest.java b/org.aspectj.lib/testsrc/org/aspectj/lib/pointcuts/PointcutsTest.java new file mode 100644 index 000000000..7cc082a51 --- /dev/null +++ b/org.aspectj.lib/testsrc/org/aspectj/lib/pointcuts/PointcutsTest.java @@ -0,0 +1,60 @@ +/* ******************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wes Isberg initial implementation + * ******************************************************************/ + +package org.aspectj.lib.pointcuts; + +import junit.framework.TestCase; + +/** + * + */ +public class PointcutsTest extends TestCase { + + public void test_anyPublicMethodExecution() { + try { + Test_anyPublicMethodExecution.error(); + assertTrue("no exception thrown", false); + } catch (Error e) { + // ok, advice worked + } + } + + private static aspect Test_anyPublicMethodExecution { + public static void error() { + throw new RuntimeException("wrong exception"); + } + + static void nonpublic() {} + + before() : + execution(static void Test_anyPublicMethodExecution.error()) + && Pointcuts.anyPublicMethodExecution() { + throw new Error(""); + } + + declare error : + execution(static void Test_anyPublicMethodExecution.nonpublic()) + && Pointcuts.anyPublicMethodExecution() + : "anyPublicMethodExecution failed - not public"; + + } + private static aspect compileChecks { + /** balk if Pointcuts has code - s.b. only pointcuts */ + declare error : within(Pointcuts) && + (set(* *) || Pointcuts.anyMethodExecution() || + (Pointcuts.anyConstructorExecution() + && !execution(private Pointcuts.new()))) : + "only pointcuts permitted in Pointcuts"; + + + } +} diff --git a/org.aspectj.lib/testsrc/org/aspectj/lib/pointcuts/PointcutsTests.java b/org.aspectj.lib/testsrc/org/aspectj/lib/pointcuts/PointcutsTests.java new file mode 100644 index 000000000..3844804fb --- /dev/null +++ b/org.aspectj.lib/testsrc/org/aspectj/lib/pointcuts/PointcutsTests.java @@ -0,0 +1,31 @@ +/* ******************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wes Isberg initial implementation + * ******************************************************************/ + +package org.aspectj.lib.pointcuts; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class PointcutsTests extends TestCase { + + public static Test suite() { + TestSuite suite = new TestSuite(PointcutsTests.class.getName()); + //$JUnit-BEGIN$ + suite.addTestSuite(PointcutsTest.class); + //$JUnit-END$ + return suite; + } + + public PointcutsTests(String name) { super(name); } + +} diff --git a/org.aspectj.lib/testsrc/org/aspectj/lib/tracing/TraceJoinPointsTest.java b/org.aspectj.lib/testsrc/org/aspectj/lib/tracing/TraceJoinPointsTest.java new file mode 100644 index 000000000..75b27d472 --- /dev/null +++ b/org.aspectj.lib/testsrc/org/aspectj/lib/tracing/TraceJoinPointsTest.java @@ -0,0 +1,83 @@ +/* ******************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wes Isberg initial implementation + * ******************************************************************/ + + +package org.aspectj.lib.tracing; + +import junit.framework.TestCase; + +import org.aspectj.lang.JoinPoint.StaticPart; + +/** + * + */ +public class TraceJoinPointsTest extends TestCase { + + public void testTraceJoinPoints() { + checkTjp(); + TestTJP aspect = TestTJP.aspectOf(); + assertNotNull("aspect", aspect); + assertTrue("checked", aspect.checked); + } + + static final int NUMJP = 1; + + static void checkTjp() { + // NUMJP: only 1 join point + long l = System.currentTimeMillis(); + } + + /** poor design/test */ + static aspect TestTJP extends TraceJoinPoints { + + protected pointcut withinScope() : within(TraceJoinPointsTest) + && !within(TestTJP); + pointcut traceJoinPoints() : + execution(static void TraceJoinPointsTest.testTraceJoinPoints()); + + protected pointcut entry() : + execution(static void TraceJoinPointsTest.checkTjp()); + + boolean checked; + int logEnter = 10; + int logExit = 10; + int startLog = 10; + int completeLog = 10; + protected void logEnter(StaticPart jp) { + logEnter++; + } + + protected void logExit(StaticPart jp) { + logExit++; + } + + protected void startLog() { + startLog = 0; + completeLog = 0; + logEnter = 0; + logExit = 0; + startLog++; + } + + protected void completeLog() { + completeLog++; + } + after() returning : entry() { + assertEquals("startLog", 1, startLog); + assertEquals("completeLog", 1, startLog); + assertEquals("logExit", NUMJP, startLog); + assertEquals("logEntry", NUMJP, startLog); + assertTrue(!checked); + checked = true; + } + } +} diff --git a/org.aspectj.lib/testsrc/org/aspectj/lib/tracing/TracingTests.java b/org.aspectj.lib/testsrc/org/aspectj/lib/tracing/TracingTests.java new file mode 100644 index 000000000..9f4daafe0 --- /dev/null +++ b/org.aspectj.lib/testsrc/org/aspectj/lib/tracing/TracingTests.java @@ -0,0 +1,29 @@ +/* ******************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wes Isberg initial implementation + * ******************************************************************/ + +package org.aspectj.lib.tracing; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class TracingTests extends TestCase { + + public static Test suite() { + TestSuite suite = new TestSuite(TracingTests.class.getName()); + //$JUnit-BEGIN$ + suite.addTestSuite(TraceJoinPointsTest.class); + //$JUnit-END$ + return suite; + } + +} |