From 24b9d46b15138ebffb164fad1abcf634a3eacf23 Mon Sep 17 00:00:00 2001 From: wisberg Date: Sat, 29 Jan 2005 10:08:56 +0000 Subject: Initial library module --- org.aspectj.lib/testsrc/LibModuleTests.java | 28 ++++++++ .../org/aspectj/lib/pointcuts/PointcutsTest.java | 60 ++++++++++++++++ .../org/aspectj/lib/pointcuts/PointcutsTests.java | 31 ++++++++ .../aspectj/lib/tracing/TraceJoinPointsTest.java | 83 ++++++++++++++++++++++ .../org/aspectj/lib/tracing/TracingTests.java | 29 ++++++++ 5 files changed, 231 insertions(+) create mode 100644 org.aspectj.lib/testsrc/LibModuleTests.java create mode 100644 org.aspectj.lib/testsrc/org/aspectj/lib/pointcuts/PointcutsTest.java create mode 100644 org.aspectj.lib/testsrc/org/aspectj/lib/pointcuts/PointcutsTests.java create mode 100644 org.aspectj.lib/testsrc/org/aspectj/lib/tracing/TraceJoinPointsTest.java create mode 100644 org.aspectj.lib/testsrc/org/aspectj/lib/tracing/TracingTests.java (limited to 'org.aspectj.lib/testsrc') 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; + } + +} -- cgit v1.2.3