/******************************************************************************* * Copyright (c) 2004 IBM * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * Andy Clement - initial API and implementation *******************************************************************************/ package org.aspectj.systemtest.ajc150; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.Iterator; import java.util.List; import junit.framework.Test; import org.aspectj.apache.bcel.classfile.JavaClass; import org.aspectj.apache.bcel.classfile.Method; import org.aspectj.apache.bcel.classfile.Signature; import org.aspectj.apache.bcel.util.ClassPath; import org.aspectj.apache.bcel.util.SyntheticRepository; import org.aspectj.asm.AsmManager; import org.aspectj.asm.IHierarchy; import org.aspectj.asm.IProgramElement; import org.aspectj.asm.IRelationship; import org.aspectj.asm.internal.Relationship; import org.aspectj.testing.XMLBasedAjcTestCase; import org.aspectj.util.LangUtil; public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase { public static Test suite() { return XMLBasedAjcTestCase.loadSuite(Ajc150Tests.class); } protected File getSpecFile() { return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); } public void testCantCallSuperMethods_pr90143() { runTest("cant call super methods");} /* public void testBrokenDispatchByITD_pr72834() { runTest("broken dispatch");} public void testMissingAccessor_pr73856() { runTest("missing accessor");} public void testCunningDeclareParents_pr92311() { runTest("cunning declare parents");} public void testGenericITDsAndAbstractMethodError_pr102357() { runTest("generic itds and abstract method error");} public void testITDCtor_pr112783() { runTest("Problem with constructor ITDs");} */ public void testPossibleStaticImports_pr113066() { runTest("possible static imports bug");} public void testBrokenDecp_pr112476() { runTest("binary weaving decp broken");} public void testUnboundFormal_pr112027() { runTest("unexpected error unboundFormalInPC");} public void testNPEScopeSetup_pr115038() { runTest("NPE in ensureScopeSetup");} public void testCCEGenerics_pr113445() { runTest("Generics ClassCastException");} public void testMatthewsAspect_pr113947_1() { runTest("maws generic aspect - 1");} public void testMatthewsAspect_pr113947_2() { runTest("maws generic aspect - 2");} public void testFieldGet_pr114343() { runTest("field-get, generics and around advice");} public void testFieldGet_pr114343_2() { runTest("field-get, generics and around advice - 2");} public void testFieldGet_pr114343_3() { runTest("field-get, generics and around advice - 3");} public void testCaptureBinding_pr114744() { runTest("capturebinding wildcard problem");} public void testBadDecp_pr110788_1() { runTest("bad generic decp - 1");} public void testBadDecp_pr110788_2() { runTest("bad generic decp - 2");} public void testBadDecp_pr110788_3() { runTest("bad generic decp - 3");} public void testBadDecp_pr110788_4() { runTest("bad generic decp - 4");} public void testVarargsITD_pr110906() { runTest("ITD varargs problem");} public void testBadRenderer_pr86903() { runTest("bcelrenderer bad");} public void testIncompatibleClassChangeError_pr113630_1() {runTest("IncompatibleClassChangeError - errorscenario");} public void testIncompatibleClassChangeError_pr113630_2() {runTest("IncompatibleClassChangeError - workingscenario");} public void testFieldGetProblemWithGenericField_pr113861() {runTest("field-get problems with generic field");} public void testDeclareAnnotationOnNonExistentType_pr99191_1() { runTest("declare annotation on non existent type - 1");} public void testDeclareAnnotationOnNonExistentType_pr99191_2() { runTest("declare annotation on non existent type - 2");} public void testDeclareAnnotationOnNonExistentType_pr99191_3() { runTest("declare annotation on non existent type - 3");} public void testDeclareAnnotationOnNonExistentType_pr99191_4() { runTest("declare annotation on non existent type - 4");} public void testDeclareAnnotationOnNonExistentType_pr99191_5() { runTest("declare annotation on non existent type - 5");} public void testBadGenericSigAttribute_pr110927() { runTest("cant create signature attribute"); Signature sig = GenericsTests.getClassSignature(ajc,"I"); if (sig==null) fail("Couldn't find signature attribute for type I"); String sigString = sig.getSignature(); if (!(sigString.equals("Ljava/lang/Object;LIE2;LIE1;") || sigString.equals("Ljava/lang/Object;LIE1;LIE2;"))) { fail("Signature was "+sigString+" when should have been something like Ljava/lang/Object;LIE1;LIE2;"); } } public void test_typeProcessingOrderWhenDeclareParents() { runTest("Order of types passed to compiler determines weaving behavior"); } public void test_aroundMethod() { runTest("method called around in class"); } public void test_aroundMethodAspect() { runTest("method called around in aspect"); } public void test_ambiguousBindingsDetection() { runTest("Various kinds of ambiguous bindings"); } public void test_ambiguousArgsDetection() { runTest("ambiguous args"); } public void testIncorrectExceptionTableWhenBreakInMethod_pr78021() { runTest("Injecting exception into while loop with break statement causes catch block to be ignored"); } public void testIncorrectExceptionTableWhenReturnInMethod_pr79554() { runTest("Return in try-block disables catch-block if final-block is present"); } public void testMissingDebugInfoForGeneratedMethods_pr82570() throws ClassNotFoundException { runTest("Weaved code does not include debug lines"); boolean f = false; JavaClass jc = getClassFrom(ajc.getSandboxDirectory(),"PR82570_1"); Method[] meths = jc.getMethods(); for (int i = 0; i < meths.length; i++) { Method method = meths[i]; if (f) System.err.println("Line number table for "+method.getName()+method.getSignature()+" = "+method.getLineNumberTable()); assertTrue("Didn't find a line number table for method "+method.getName()+method.getSignature(), method.getLineNumberTable()!=null); } // This test would determine the info isn't there if you pass -g:none ... // cR = ajc(baseDir,new String[]{"PR82570_1.java","-g:none"}); // assertTrue("Expected no compile problem:"+cR,!cR.hasErrorMessages()); // System.err.println(cR.getStandardError()); // jc = getClassFrom(ajc.getSandboxDirectory(),"PR82570_1"); // meths = jc.getMethods(); // for (int i = 0; i < meths.length; i++) { // Method method = meths[i]; // assertTrue("Found a line number table for method "+method.getName(), // method.getLineNumberTable()==null); // } } public void testCanOverrideProtectedMethodsViaITDandDecp_pr83303() { runTest("compiler error when mixing inheritance, overriding and polymorphism"); } public void testPerTypeWithin_pr106554() {runTest("Problem in staticinitialization with pertypewithin aspect");} public void testPerTypeWithinMissesNamedInnerTypes() { runTest("pertypewithin() handing of inner classes (1)"); } public void testPerTypeWithinMissesAnonymousInnerTypes() { runTest("pertypewithin() handing of inner classes (2)"); } public void testPerTypeWithinIncorrectlyMatchingInterfaces() { runTest("pertypewithin({interface}) illegal field modifier"); } public void test051_arrayCloningInJava5() { runTest("AJC possible bug with static nested classes"); } public void testBadASMforEnums() throws IOException { runTest("bad asm for enums"); if (LangUtil.is15VMOrGreater()) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintWriter pw = new PrintWriter(baos); AsmManager.dumptree(pw,AsmManager.getDefault().getHierarchy().getRoot(),0); pw.flush(); String tree = baos.toString(); assertTrue("Expected 'Red [enumvalue]' somewhere in here:"+tree,tree.indexOf("Red [enumvalue]")!=-1); } } public void npeOnTypeNotFound() { runTest("structure model npe on type not found"); } public void testNoRuntimeExceptionSoftening() { runTest("declare soft of runtime exception"); } public void testRuntimeNoSoftenWithHandler() { runTest("declare soft w. catch block"); } public void testSyntaxError() { runTest("invalid cons syntax"); } public void testVarargsInConsBug() { runTest("varargs in constructor sig"); } public void testAspectpathdirs() { runTest("dirs on aspectpath"); } public void testIntroSample() { runTest("introduction sample"); } public void testPTWInterface() { runTest("pertypewithin({interface}) illegal field modifier"); } public void testEnumCalledEnumEtc() { runTest("enum called Enum, annotation called Annotation, etc"); } public void testInternalCompilerError_pr86832() { runTest("Internal compiler error"); } public void testCloneMethod_pr83311() { runTest("overriding/polymorphism error on interface method introduction"); } // IfPointcut.findResidueInternal() was modified to make this test complete in a short amount // of time - if you see it hanging, someone has messed with the optimization. public void testIfEvaluationExplosion_pr94086() { runTest("Exploding compile time with if() statements in pointcut"); } public void testReflectNPE_pr94167() {runTest("NPE in reflect implementation");} public void testStaticImports_pr84260() {runTest("static import failures");} public void testGenerics_pr99089() {runTest("ArrayIndexOutOfBoundsException - Generics in privileged aspects");} public void testGenerics_pr95993() {runTest("NPE at ClassScope.java:660 when compiling generic class");} public void testItdGenerics_pr99228() {runTest("ITD of a field into a generic class");} public void testItdGenerics_pr98320() {runTest("intertype with nested generic type");} public void testItdGenerics_pr100227() {runTest("inner class with generic enclosing class");} public void testItdGenerics_pr100260() {runTest("methods inherited from a generic parent");} public void testSyntaxErrorNPE_pr103266() {runTest("NPE on syntax error");} public void testFinalAbstractClass_pr109486() { runTest("Internal compiler error (ClassParser.java:242)");} public void testComplexBinding_pr102210() { runTest("NullPointerException trying to compile");} public void testIllegalStateExceptionOnNestedParameterizedType_pr106634() { runTest("IllegalStateException unpacking signature of nested parameterized type"); } public void testParseErrorOnAnnotationStarPlusPattern() { runTest("(@Foo *)+ type pattern parse error"); } public void test_pr106130_tooManyLocals() { runTest("test weaving with > 256 locals"); } public void testMissingNamePattern_pr106461() { runTest("missing name pattern"); } public void testMissingNamePattern_pr107059() { runTest("parser crashes on call(void (@a *)(..)"); } public void testIntermediateAnnotationMatching() { runTest("intermediate annotation matching"); } public void testBadRuntimeTestGeneration() { runTest("target(@Foo *)"); } public void testErrorMessageOnITDWithTypePatterns() { runTest("clear error message on itd with type pattern"); } public void testAjKeywordsAsIdentifiers() { runTest("before and after are valid identifiers in classes"); } public void testAjKeywordsAsIdentifiers2() { runTest("before and after are valid identifiers in classes, part 2"); } public void testNoBeforeReturningAdvice() { runTest("before returning advice not allowed!"); } public void testDetectVoidFieldType() { runTest("void field type in pointcut expression"); } public void testPointcutOverriding() { runTest("overriding final pointcut from super-aspect"); } public void testAtSuppressWarnings() { runTest("@SuppressWarnings should suppress"); } public void testDEOWWithBindingPointcut() { runTest("declare warning : foo(str) : ...;"); } public void testAroundAdviceAndInterfaceInitializer() { runTest("around advice on interface initializer"); } public void testGoodErrorMessageOnUnmatchedMemberSyntax() { runTest("good error message for unmatched member syntax"); } public void testITDWithNoExceptionAndIntermediary() { runTest("itd override with no exception clause"); } public void testAnonymousInnerClasses() { runTest("anonymous inner classes"); } public void testMultipleAnonymousInnerClasses() { runTest("multiple anonymous inner classes"); } public void testPrivilegedMethodAccessorsGetRightExceptions_pr82989() { runTest("Compiler error due to a wrong exception check in try blocks"); } public void testAnonymousInnerClassWithMethodReturningTypeParameter_pr107898() { runTest("anonymous inner class with method returning type parameter"); } public void testMatchingOfObjectArray() { runTest("matching against Object[]"); } public void testMultipleAnonymousInnerClasses_pr108104() { runTest("multiple anonymous inner classes 2"); } public void testSignatureMatchingInMultipleOverrideScenario() { runTest("signature matching in override scenario"); } public void testWildcardAnnotationMatching_pr108245() { runTest("wildcard annotation matching - pr108245"); } public void testInnerTypesAndTypeVariables() { runTest("inner types and type variables"); } public void testAtAfterThrowingWithNoFormal() { runTest("@AfterThrowing with no formal specified"); } public void testParameterizedVarArgsMatch() { runTest("varargs with type variable"); } public void testFieldAccessInsideITDM() { runTest("itd field access inside itd method"); } public void testTypeVarWithTypeVarBound() { runTest("type variable with type variable bound"); } public void testEnumSwitchInITD() { runTest("switch on enum inside ITD method"); } public void testInnerTypeOfGeneric() { runTest("inner type of generic interface reference from parameterized type"); } public void testDeclareParentsIntroducingCovariantReturnType() { runTest("declare parents introducing override with covariance"); } public void testInnerClassPassedToVarargs() { runTest("inner class passed as argument to varargs method"); } public void testInlinedFieldAccessInProceedCall() { runTest("inlined field access in proceed call"); } public void testVisibiltyInSignatureMatchingWithOverridesPart1() { runTest("visibility in signature matching with overrides - 1"); } public void testVisibiltyInSignatureMatchingWithOverridesPart2() { runTest("visibility in signature matching with overrides - 2"); } public void testVisibiltyInSignatureMatchingWithOverridesPart3() { runTest("visibility in signature matching with overrides - 3"); } public void testArgsGeneratedCorrectlyForAdviceExecution() { runTest("args generated correctly for advice execution join point"); } public void testNoUnusedWarningsOnAspectTypes() { runTest("no unused warnings on aspect types"); } public void testSyntheticArgumentsOnITDConstructorsNotUsedInMatching() { runTest("synthetic arguments on itd cons are not used in matching"); } public void testParsingOfGenericTypeSignature() { runTest("parse generic type signature with parameterized type in interface"); } public void testOverrideAndCovarianceWithDecPRuntime() { runTest("override and covariance with decp - runtime"); } public void testOverrideAndCovarianceWithDecPRuntimeMultiFiles() { runTest("override and covariance with decp - runtime separate files"); } public void testOverrideAndCovarianceWithDecPRuntimeMultiFilesBinaryWeaving() { runTest("override and covariance with decp - binary weaving"); } public void testAbstractSynchronizedITDMethods() { runTest("abstract synchronized itdms not detected"); } public void testSynchronizedITDInterfaceMethods() { runTest("synchronized itd interface methods"); } public void testNoWarningOnUnusedPointcut() { runTest("unused private pointcuts"); } public void testITDOnInterfaceWithExistingMember() { runTest("itd interface method already existing on interface"); } public void testFinalITDMOnInterface() { runTest("final itd methods on interfaces"); } public void testPrivatePointcutOverriding() { runTest("can't override private pointcut in abstract aspect"); } public void testAdviceOnCflow() { runTest("advising cflow advice execution"); } public void testNoTypeMismatchOnSameGenericTypes() { runTest("no type mismatch on generic types in itds"); } public void testSuperCallInITD() { runTest("super call in ITD"); } public void testSuperCallInITDPart2() { runTest("super call in ITD - part 2"); } public void testAtAnnotationBadTest_pr103740() { runTest("Compiler failure on at_annotation"); } public void testNoUnusedParameterWarningsForSyntheticAdviceArgs() { runTest("no unused parameter warnings for synthetic advice args"); } public void testNoVerifyErrorWithSetOnInnerType() { runTest("no verify error with set on inner type"); } public void testCantFindTypeErrorWithGenericReturnTypeOrParameter() { runTest("cant find type error with generic return type or parameter"); } public void testNoVerifyErrorOnGenericCollectionMemberAccess() { runTest("no verify error on generic collection member access"); } public void testRawAndGenericTypeConversionITDCons() { runTest("raw and generic type conversion with itd cons"); } public void testAtAnnotationBindingWithAround() { runTest("@annotation binding with around advice"); } public void testUnableToBuildShadows_pr109728() { runTest("Unable to build shadows");} public void testMessageOnMissingTypeInDecP() { runTest("declare parents on a missing type"); } public void testParameterizedGenericMethods() { runTest("parameterized generic methods"); } public void testIllegalChangeToPointcutDeclaration_pr111915() { runTest("test illegal change to pointcut declaration"); } public void testCantProvideDefaultImplViaITD_pr110307_1() {runTest("Cant provide default implementation via ITD - 1");} public void testCantProvideDefaultImplViaITD_pr110307_2() {runTest("Cant provide default implementation via ITD - 2");} public void testCantProvideDefaultImplViaITD_pr110307_3() {runTest("Cant provide default implementation via ITD - 3");} public void testCantProvideDefaultImplViaITD_pr110307_4() {runTest("Cant provide default implementation via ITD - 4");} public void testCantProvideDefaultImplViaITD_pr110307_5() {runTest("Cant provide default implementation via ITD - 5");} // Needs a change in the compiler so that getType() can be overridden in the intertype scope - thats // where we can police whether a type variable has been used without being specified appropriately. //public void testCantProvideDefaultImplViaITD_pr110307_6() {runTest("Cant provide default implementation via ITD - 6");} public void testCantProvideDefaultImplViaITD_pr110307_7() {runTest("Cant provide default implementation via ITD - 7");} public void testCallJoinPointsInAnonymousInnerClasses() { runTest("call join points in anonymous inner classes"); } public void testNoRequirementForUnwovenTypesToBeExposedToWeaver() { runTest("default impl of Runnable"); } public void testArrayCloneCallJoinPoints() { runTest("array clone call join points in 1.4 vs 1.3"); } public void testDebugInfoForAroundAdvice() { runTest("debug info in around advice inlining"); } public void testCCEWithGenericWildcard_pr112602() { runTest("ClassCastException with generic wildcard"); } public void testAdviceInStructureModelWithAnonymousInnerClass_pr77269() { //AsmManager.setReporting("c:/debug.txt",true,true,true,true); runTest("advice in structure model with anonymous inner class"); IHierarchy top = AsmManager.getDefault().getHierarchy(); // checking that the run() method inside anonymous inner class is in // the structure model IProgramElement anonRunMethodIPE = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.METHOD,"run()"); assertNotNull("Couldn't find 'run()' element in the tree",anonRunMethodIPE); List l = AsmManager.getDefault().getRelationshipMap().get(anonRunMethodIPE); assertNotNull("Should have some relationships but does not",l); assertTrue("Should have one relationship but has " + l.size(),l.size()==1); Relationship rel = (Relationship)l.get(0); List targets = rel.getTargets(); assertTrue("Should have one target but has" + targets.size(), targets.size()==1); IProgramElement target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)targets.get(0)); assertEquals("target of relationship should be 'before(): p..' but is " + target.toLabelString(),"before(): p..",target.toLabelString()); IProgramElement adviceIPE = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.ADVICE,"before(): p.."); assertNotNull("Couldn't find 'before(): p..' element in the tree",adviceIPE); l = AsmManager.getDefault().getRelationshipMap().get(adviceIPE); assertNotNull("Should have some relationships but does not",l); assertTrue("Should have a relationship but does not ",l.size()>0); for (Iterator iter = l.iterator(); iter.hasNext();) { IRelationship element = (IRelationship) iter.next(); if (element.getName().equals("advises")) { rel = (Relationship) element; break; } } targets = rel.getTargets(); assertTrue("Should have one target but has" + targets.size(), targets.size()==1); target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)targets.get(0)); assertEquals("target of relationship should be 'run()' but is " + target.toLabelString(),"run()",target.toLabelString()); } public void testAdviceInStructureModelWithNamedInnerClass_pr77269() { //AsmManager.setReporting("c:/debug.txt",true,true,true,true); runTest("advice in structure model with named inner class"); IHierarchy top = AsmManager.getDefault().getHierarchy(); // checking that the m() method inside named inner class is in // the structure model IProgramElement namedMethodIPE = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.METHOD,"m()"); assertNotNull("Couldn't find 'm()' element in the tree",namedMethodIPE); List l = AsmManager.getDefault().getRelationshipMap().get(namedMethodIPE); assertNotNull("Should have some relationships but does not",l); assertTrue("Should have one relationship but has " + l.size(),l.size()==1); Relationship rel = (Relationship)l.get(0); List targets = rel.getTargets(); assertTrue("Should have one target but has" + targets.size(), targets.size()==1); IProgramElement target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)targets.get(0)); assertEquals("target of relationship should be 'before(): p..' but is " + target.toLabelString(),"before(): p..",target.toLabelString()); IProgramElement adviceIPE = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.ADVICE,"before(): p.."); assertNotNull("Couldn't find 'before(): p..' element in the tree",adviceIPE); l = AsmManager.getDefault().getRelationshipMap().get(adviceIPE); assertNotNull("Should have some relationships but does not",l); assertTrue("Should have a relationship but does not ",l.size()>0); for (Iterator iter = l.iterator(); iter.hasNext();) { IRelationship element = (IRelationship) iter.next(); if (element.getName().equals("advises")) { rel = (Relationship) element; break; } } targets = rel.getTargets(); assertTrue("Should have one target but has" + targets.size(), targets.size()==1); target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)targets.get(0)); assertEquals("target of relationship should be 'm()' but is " + target.toLabelString(),"m()",target.toLabelString()); } public void testDWInStructureModelWithAnonymousInnerClass_pr77269() { // AsmManager.setReporting("c:/debug.txt",true,true,true,true); runTest("declare warning in structure model with anonymous inner class"); IHierarchy top = AsmManager.getDefault().getHierarchy(); IProgramElement pe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.CODE,"method-call(void pack.Test.someMethod())"); assertNotNull("Couldn't find 'method-call(void pack.Test.someMethod())' element in the tree",pe); } public void testVarArgsIITDInConstructor() { runTest("ITD varargs in constructor"); } public void testWeaveInfoMessageForDeclareAtMethodOnITDdMethod() { runTest("weaveinfo message for declare at method on an ITDd method"); } public void testNoVerifyErrorWithTwoThisPCDs_pr113447() { runTest("no verify error with two this pcds"); } public void testITDCWithNoExplicitConsCall() { runTest("ITDC with no explicit cons call"); } public void testJava5SpecificFeaturesUsedAtJava14OrLower() { runTest("java 5 pointcuts and declares at pre-java 5 compliance levels"); } public void testAnonymousTypes() { runTest("Anonymous types and nome matching"); } // helper methods..... public SyntheticRepository createRepos(File cpentry) { ClassPath cp = new ClassPath(cpentry+File.pathSeparator+System.getProperty("java.class.path")); return SyntheticRepository.getInstance(cp); } protected JavaClass getClassFrom(File where,String clazzname) throws ClassNotFoundException { SyntheticRepository repos = createRepos(where); return repos.loadClass(clazzname); } }