diff options
author | mwebster <mwebster> | 2006-08-07 16:41:05 +0000 |
---|---|---|
committer | mwebster <mwebster> | 2006-08-07 16:41:05 +0000 |
commit | 6dca4cc41d0af83c9baeb1aa1734b48cec11b1b0 (patch) | |
tree | 10d9e0127bcee36905c427d91d50e0de6af28a97 /weaver | |
parent | 51ace9a1a3bbcb24fd2a0f08ff6fdbec27f47738 (diff) | |
download | aspectj-6dca4cc41d0af83c9baeb1aa1734b48cec11b1b0.tar.gz aspectj-6dca4cc41d0af83c9baeb1aa1734b48cec11b1b0.zip |
Bug 152982 "org.aspectj Restructure - Phase 2: Move tests" (move Java 5 dependedent tests to weaver5, reduce use of reflection and conditional execution, remove duplication)
Diffstat (limited to 'weaver')
4 files changed, 13 insertions, 189 deletions
diff --git a/weaver/testsrc/org/aspectj/weaver/BcweaverModuleTests15.java b/weaver/testsrc/org/aspectj/weaver/BcweaverModuleTests15.java deleted file mode 100644 index 7220ea50a..000000000 --- a/weaver/testsrc/org/aspectj/weaver/BcweaverModuleTests15.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.aspectj.weaver; -/* ******************************************************************* - * 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: - * Adrian Colyer Initial implementation - * ******************************************************************/ -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.aspectj.testing.util.TestUtil; -import org.aspectj.util.LangUtil; -import org.aspectj.weaver.bcel.BcelGenericSignatureToTypeXTestCase; -import org.aspectj.weaver.patterns.WildTypePatternResolutionTestCase; - -public class BcweaverModuleTests15 extends TestCase { - public static Test suite() { - TestSuite suite = new TestSuite(BcweaverModuleTests15.class.getName()); - suite.addTestSuite(TypeVariableTestCase.class); - suite.addTestSuite(ReferenceTypeTestCase.class); - suite.addTestSuite(BoundedReferenceTypeTestCase.class); - suite.addTestSuite(TypeVariableReferenceTypeTestCase.class); - suite.addTestSuite(MemberTestCase15.class); - suite.addTestSuite(BcelGenericSignatureToTypeXTestCase.class); - suite.addTestSuite(WildTypePatternResolutionTestCase.class); - if (LangUtil.is15VMOrGreater()) { - TestUtil.loadTestsReflectively(suite, "org.aspectj.weaver.tools.Java15PointcutExpressionTest", false); - TestUtil.loadTestsReflectively(suite, "org.aspectj.weaver.TestJava5ReflectionBasedReferenceTypeDelegate", false); - } - return suite; - } - - public BcweaverModuleTests15(String name) { super(name); } -} diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/AsmDelegateTests.java b/weaver/testsrc/org/aspectj/weaver/bcel/AsmDelegateTests.java index 146a5ba2b..58918b778 100644 --- a/weaver/testsrc/org/aspectj/weaver/bcel/AsmDelegateTests.java +++ b/weaver/testsrc/org/aspectj/weaver/bcel/AsmDelegateTests.java @@ -31,7 +31,6 @@ import org.aspectj.weaver.ResolvedMemberImpl; import org.aspectj.weaver.ResolvedType; import org.aspectj.weaver.ShadowMunger; import org.aspectj.weaver.TypeVariable; -import org.aspectj.weaver.UnresolvedType; import org.aspectj.weaver.World; import org.aspectj.weaver.AjAttribute.EffectiveSignatureAttribute; import org.aspectj.weaver.asm.AsmDelegate; @@ -153,105 +152,6 @@ public class AsmDelegateTests extends AbstractWorldTestCase { checkEquivalent("",(AbstractReferenceTypeDelegate)aComplex.getDelegate(),(AbstractReferenceTypeDelegate)bComplex.getDelegate()); } - /** - * Methods are transformed according to generic signatures - this checks - * that some of the generic methods in java.lang.Class appear the same - * whether viewed through an ASM or a BCEL delegate. - */ - public void testCompareGenericMethods() { - BcelWorld slowWorld = new BcelWorld(); - slowWorld.setFastDelegateSupport(false); - slowWorld.setBehaveInJava5Way(true); - - BcelWorld fastWorld = new BcelWorld(); - fastWorld.setBehaveInJava5Way(true); - - ResolvedType bcelJavaLangClass = slowWorld.resolve(UnresolvedType.forName("java.lang.Class")); - ResolvedType asmJavaLangClass = fastWorld.resolve(UnresolvedType.forName("java.lang.Class")); - - bcelJavaLangClass = bcelJavaLangClass.getGenericType(); - asmJavaLangClass = asmJavaLangClass.getGenericType(); - - //if (bcelJavaLangClass == null) return; // for < 1.5 - - ResolvedMember[] bcelMethods = bcelJavaLangClass.getDeclaredMethods(); - ResolvedMember[] asmMethods = asmJavaLangClass.getDeclaredMethods(); - - for (int i = 0; i < bcelMethods.length; i++) { - bcelMethods[i].setParameterNames(null); // forget them, asm delegates dont currently know them - String one = bcelMethods[i].toDebugString(); - String two = asmMethods[i].toDebugString(); - if (!one.equals(two)) { - fail("These methods look different when viewed through ASM or BCEL\nBCEL='"+bcelMethods[i].toDebugString()+ - "'\n ASM='"+asmMethods[i].toDebugString()+"'"); - } - // If one is parameterized, check the other is... - if (bcelMethods[i].canBeParameterized()) { - assertTrue("ASM method '"+asmMethods[i].toDebugString()+"' can't be parameterized whereas its' BCEL variant could", - asmMethods[i].canBeParameterized()); - } - - } - - // Let's take a special look at: - // public <U> Class<? extends U> asSubclass(Class<U> clazz) - ResolvedMember bcelSubclassMethod = null; - for (int i = 0; i < bcelMethods.length; i++) { - if (bcelMethods[i].getName().equals("asSubclass")) { bcelSubclassMethod = bcelMethods[i]; break; } - } - ResolvedMember asmSubclassMethod = null; - for (int i = 0; i < asmMethods.length; i++) { - if (asmMethods[i].getName().equals("asSubclass")) { asmSubclassMethod = asmMethods[i];break; } - } - - TypeVariable[] tvs = bcelSubclassMethod.getTypeVariables(); - assertTrue("should have one type variable on the bcel version but found: "+format(tvs),tvs!=null && tvs.length==1); - tvs = asmSubclassMethod.getTypeVariables(); - assertTrue("should have one type variable on the asm version but found: "+format(tvs),tvs!=null && tvs.length==1); - - } - - private String format(TypeVariable[] tvs) { - if (tvs==null) return "null"; - StringBuffer s = new StringBuffer(); - s.append("["); - for (int i = 0; i < tvs.length; i++) { - s.append(tvs[i]); - if ((i+1)<tvs.length) s.append(","); - } - s.append("]"); - return s.toString(); - } - - public void testCompareGenericFields() { - BcelWorld slowWorld = new BcelWorld(); - slowWorld.setFastDelegateSupport(false); - slowWorld.setBehaveInJava5Way(true); - - BcelWorld fastWorld = new BcelWorld(); - fastWorld.setBehaveInJava5Way(true); - - ResolvedType bcelJavaLangClass = slowWorld.resolve(UnresolvedType.forName("java.lang.Class")); - ResolvedType asmJavaLangClass = fastWorld.resolve(UnresolvedType.forName("java.lang.Class")); - - bcelJavaLangClass = bcelJavaLangClass.getGenericType(); - asmJavaLangClass = asmJavaLangClass.getGenericType(); - - if (bcelJavaLangClass == null) return; // for < 1.5 - - ResolvedMember[] bcelFields = bcelJavaLangClass.getDeclaredFields(); - ResolvedMember[] asmFields = asmJavaLangClass.getDeclaredFields(); - - for (int i = 0; i < bcelFields.length; i++) { - UnresolvedType bcelFieldType = bcelFields[i].getGenericReturnType(); - UnresolvedType asmFieldType = asmFields[i].getGenericReturnType(); - if (!bcelFields[i].getGenericReturnType().toDebugString().equals(asmFields[i].getGenericReturnType().toDebugString())) { - fail("These fields look different when viewed through ASM or BCEL\nBCEL='"+bcelFieldType.toDebugString()+ - "'\n ASM='"+asmFieldType.toDebugString()+"'"); - } - } - } - public void testCompareDelegatesMonster() { BcelWorld slowWorld = new BcelWorld("../lib/aspectj/lib/aspectjtools.jar");slowWorld.setFastDelegateSupport(false); BcelWorld fastWorld = new BcelWorld("../lib/aspectj/lib/aspectjtools.jar"); diff --git a/weaver/testsrc/org/aspectj/weaver/tools/PointcutExpressionTest.java b/weaver/testsrc/org/aspectj/weaver/tools/PointcutExpressionTest.java index 205423c35..acd510f50 100644 --- a/weaver/testsrc/org/aspectj/weaver/tools/PointcutExpressionTest.java +++ b/weaver/testsrc/org/aspectj/weaver/tools/PointcutExpressionTest.java @@ -14,13 +14,12 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; -import junit.framework.TestCase; - import org.aspectj.util.LangUtil; +import junit.framework.TestCase; + public class PointcutExpressionTest extends TestCase { - boolean needToSkip = false; PointcutParser p; Constructor asCons; Constructor bsCons; @@ -38,8 +37,6 @@ public class PointcutExpressionTest extends TestCase { Method bar; public void testMatchesMethodCall() { - if (needToSkip) return; - PointcutExpression ex = p.parsePointcutExpression("call(* *..A.a*(..))"); assertTrue("Should match call to A.a()",ex.matchesMethodCall(a,a).alwaysMatches()); assertTrue("Should match call to A.aaa()",ex.matchesMethodCall(aaa,a).alwaysMatches()); @@ -89,8 +86,6 @@ public class PointcutExpressionTest extends TestCase { } public void testMatchesMethodExecution() { - if (needToSkip) return; - PointcutExpression ex = p.parsePointcutExpression("execution(* *..A.aa(..))"); assertTrue("Should match execution of A.aa",ex.matchesMethodExecution(aa).alwaysMatches()); assertTrue("Should match execution of B.aa",ex.matchesMethodExecution(bsaa).alwaysMatches()); @@ -129,8 +124,6 @@ public class PointcutExpressionTest extends TestCase { } public void testMatchesConstructorCall() { - if (needToSkip) return; - PointcutExpression ex = p.parsePointcutExpression("call(new(String))"); assertTrue("Should match A(String)", ex.matchesConstructorCall(asCons,b).alwaysMatches()); assertTrue("Should match B(String)", ex.matchesConstructorCall(bsStringCons,b).alwaysMatches()); @@ -166,8 +159,6 @@ public class PointcutExpressionTest extends TestCase { } public void testMatchesConstructorExecution() { - if (needToSkip) return; - PointcutExpression ex = p.parsePointcutExpression("execution(new(String))"); assertTrue("Should match A(String)", ex.matchesConstructorExecution(asCons).alwaysMatches()); assertTrue("Should match B(String)", ex.matchesConstructorExecution(bsStringCons).alwaysMatches()); @@ -211,8 +202,6 @@ public class PointcutExpressionTest extends TestCase { } public void testMatchesAdviceExecution() { - if (needToSkip) return; - PointcutExpression ex = p.parsePointcutExpression("adviceexecution()"); assertTrue("Should match (advice) A.a",ex.matchesAdviceExecution(a).alwaysMatches()); // test this @@ -248,8 +237,6 @@ public class PointcutExpressionTest extends TestCase { } public void testMatchesHandler() { - if (needToSkip) return; - PointcutExpression ex = p.parsePointcutExpression("handler(Exception)"); assertTrue("Should match catch(Exception)",ex.matchesHandler(Exception.class,Client.class).alwaysMatches()); assertTrue("Should not match catch(Throwable)",ex.matchesHandler(Throwable.class,Client.class).neverMatches()); @@ -281,8 +268,6 @@ public class PointcutExpressionTest extends TestCase { } public void testMatchesInitialization() { - if (needToSkip) return; - PointcutExpression ex = p.parsePointcutExpression("initialization(new(String))"); assertTrue("Should match A(String)",ex.matchesInitialization(asCons).alwaysMatches()); assertTrue("Should match B(String)", ex.matchesInitialization(bsStringCons).alwaysMatches()); @@ -318,8 +303,6 @@ public class PointcutExpressionTest extends TestCase { } public void testMatchesPreInitialization() { - if (needToSkip) return; - PointcutExpression ex = p.parsePointcutExpression("preinitialization(new(String))"); assertTrue("Should match A(String)",ex.matchesPreInitialization(asCons).alwaysMatches()); assertTrue("Should match B(String)", ex.matchesPreInitialization(bsStringCons).alwaysMatches()); @@ -350,8 +333,6 @@ public class PointcutExpressionTest extends TestCase { } public void testMatchesStaticInitialization() { - if (needToSkip) return; - // staticinit PointcutExpression ex = p.parsePointcutExpression("staticinitialization(*..A+)"); assertTrue("Matches A",ex.matchesStaticInitialization(A.class).alwaysMatches()); @@ -381,8 +362,6 @@ public class PointcutExpressionTest extends TestCase { } public void testMatchesFieldSet() { - if (needToSkip) return; - PointcutExpression ex = p.parsePointcutExpression("set(* *..A+.*)"); assertTrue("matches x",ex.matchesFieldSet(x,a).alwaysMatches()); assertTrue("matches y",ex.matchesFieldSet(y,foo).alwaysMatches()); @@ -415,8 +394,6 @@ public class PointcutExpressionTest extends TestCase { } public void testMatchesFieldGet() { - if (needToSkip) return; - PointcutExpression ex = p.parsePointcutExpression("get(* *..A+.*)"); assertTrue("matches x",ex.matchesFieldGet(x,a).alwaysMatches()); assertTrue("matches y",ex.matchesFieldGet(y,foo).alwaysMatches()); @@ -447,8 +424,6 @@ public class PointcutExpressionTest extends TestCase { } public void testArgsMatching() { - if (needToSkip) return; - // too few args PointcutExpression ex = p.parsePointcutExpression("args(*,*,*,*)"); assertTrue("Too few args",ex.matchesMethodExecution(foo).neverMatches()); @@ -526,15 +501,11 @@ public class PointcutExpressionTest extends TestCase { //} public void testGetPointcutExpression() { - if (needToSkip) return; - PointcutExpression ex = p.parsePointcutExpression("staticinitialization(*..A+)"); assertEquals("staticinitialization(*..A+)",ex.getPointcutExpression()); } public void testCouldMatchJoinPointsInType() { - if (needToSkip) return; - PointcutExpression ex = p.parsePointcutExpression("execution(* org.aspectj.weaver.tools.PointcutExpressionTest.B.*(..))"); assertTrue("Could maybe match String (as best we know at this point)",ex.couldMatchJoinPointsInType(String.class)); assertTrue("Will always match B",ex.couldMatchJoinPointsInType(B.class)); @@ -543,9 +514,7 @@ public class PointcutExpressionTest extends TestCase { assertTrue("Will always match B",ex.couldMatchJoinPointsInType(B.class)); } - public void testMayNeedDynamicTest() { - if (needToSkip) return; - + public void testMayNeedDynamicTest() { PointcutExpression ex = p.parsePointcutExpression("execution(* org.aspectj.weaver.tools.PointcutExpressionTest.B.*(..))"); assertFalse("No dynamic test needed",ex.mayNeedDynamicTest()); ex = p.parsePointcutExpression("execution(* org.aspectj.weaver.tools.PointcutExpressionTest.B.*(..)) && args(org.aspectj.weaver.tools.PointcutExpressionTest.X)"); @@ -554,8 +523,6 @@ public class PointcutExpressionTest extends TestCase { protected void setUp() throws Exception { super.setUp(); - needToSkip = needToSkipPointcutParserTests(); - if (needToSkip) return; p = PointcutParser.getPointcutParserSupportingAllPrimitivesAndUsingSpecifiedClassloaderForResolution(this.getClass().getClassLoader()); asCons = A.class.getConstructor(new Class[]{String.class}); bsCons = B.class.getConstructor(new Class[0]); @@ -573,17 +540,6 @@ public class PointcutExpressionTest extends TestCase { bar = Client.class.getDeclaredMethod("bar",new Class[]{String.class,int.class,Integer.class,Number.class}); } - /** this condition can occur on the build machine only, and is way too complex to fix right now... */ - private boolean needToSkipPointcutParserTests() { - if (!LangUtil.is15VMOrGreater()) return false; - try { - Class.forName("org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate",false,this.getClass().getClassLoader());//ReflectionBasedReferenceTypeDelegate.class.getClassLoader()); - } catch (ClassNotFoundException cnfEx) { - return true; - } - return false; - } - static class A { public A(String s) {} public void a() {} @@ -608,4 +564,5 @@ public class PointcutExpressionTest extends TestCase { } static class X {} + } diff --git a/weaver/testsrc/org/aspectj/weaver/tools/ToolsTests.java b/weaver/testsrc/org/aspectj/weaver/tools/ToolsTests.java index 557ec0ad7..636fd7a1f 100644 --- a/weaver/testsrc/org/aspectj/weaver/tools/ToolsTests.java +++ b/weaver/testsrc/org/aspectj/weaver/tools/ToolsTests.java @@ -9,16 +9,23 @@ * ******************************************************************/ package org.aspectj.weaver.tools; +import org.aspectj.testing.util.TestUtil; + import junit.framework.Test; import junit.framework.TestSuite; public class ToolsTests { public static Test suite() { - TestSuite suite = new TestSuite("Test for org.aspectj.weaver.tools"); + TestSuite suite = new TestSuite(ToolsTests.class.getName()); //$JUnit-BEGIN$ + /* FIXME maw The CLASSPATH is wrong so run them in weaver5 instead */ + if (!TestUtil.is15VMOrGreater()) { + suite.addTestSuite(PointcutExpressionTest.class); + } else { + suite.addTest(TestUtil.testNamed("run from weaver5 under 1.5")); + } suite.addTestSuite(PointcutParserTest.class); - suite.addTestSuite(PointcutExpressionTest.class); suite.addTestSuite(TypePatternMatcherTest.class); suite.addTestSuite(PointcutDesignatorHandlerTests.class); //$JUnit-END$ |