aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java
blob: 7a64444b9128bdb416a835f4246ee2b6c342eba6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*******************************************************************************
 * Copyright (c) 2006 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.ajc151;

import java.io.File;
import java.util.List;

import junit.framework.Test;

import org.aspectj.asm.AsmManager;
import org.aspectj.asm.IHierarchy;
import org.aspectj.asm.IProgramElement;
import org.aspectj.asm.internal.Relationship;
import org.aspectj.systemtest.ajc150.GenericsTests;
import org.aspectj.testing.XMLBasedAjcTestCase;

public class Ajc151Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
	  
  public void testMemberTypesInGenericTypes_pr122458()    { runTest("member types in generic types");}
  public void testMemberTypesInGenericTypes_pr122458_2()  { runTest("member types in generic types - 2");}
  public void testNPEOnDeclareAnnotation_pr123695() { runTest("Internal nullptr exception with complex declare annotation");}
  public void testHasMemberPackageProblem_pr124105() { runTest("hasMember problems with packages");}
  public void testDifferentNumbersofTVars_pr124803() { runTest("generics and different numbers of type variables");}
  public void testDifferentNumbersofTVars_pr124803_2() { runTest("generics and different numbers of type variables - classes");}
  public void testParameterizedCollectionFieldMatching_pr124808() { runTest("parameterized collection fields matched via pointcut");}
  public void testGenericAspectsAndAnnotations_pr124654() { runTest("generic aspects and annotations");}
  public void testCallInheritedGenericMethod_pr124999() { runTest("calling inherited generic method from around advice");}
  public void testIncorrectlyReferencingPointcuts_pr122452()    { runTest("incorrectly referencing pointcuts");}
  public void testIncorrectlyReferencingPointcuts_pr122452_2()    { runTest("incorrectly referencing pointcuts - 2");}
  public void testInlinevisitorNPE_pr123901() { runTest("inlinevisitor NPE");}
  //public void testExposingWithintype_enh123423() { runTest("exposing withintype");}
  //public void testMissingImport_pr127299() { runTest("missing import gives funny message");}
  public void testUnusedInterfaceMessage_pr120527() { runTest("incorrect unused interface message");}
  public void testAtAspectInheritsAdviceWithTJPAndThis_pr125699 () { runTest("inherit advice with this() and thisJoinPoint");  }
  public void testAtAspectInheritsAdviceWithTJPAndThis_pr125699_2 () {runTest("inherit advice with this() and thisJoinPoint - 2");  }
  
  public void testMixingNumbersOfTypeParameters_pr125080()   { 
	  runTest("mixing numbers of type parameters");    
	  GenericsTests.verifyClassSignature(ajc,"AspectInterface","<T:Ljava/lang/Object;S:Ljava/lang/Object;>Ljava/lang/Object;");
	  GenericsTests.verifyClassSignature(ajc,"AbstractAspect","<T:Ljava/lang/Object;>Ljava/lang/Object;LAspectInterface<TT;Ljava/lang/Integer;>;");
	  GenericsTests.verifyClassSignature(ajc,"ConcreteAspect","LAbstractAspect<Ljava/lang/String;>;");
  }
  
  public void testMixingNumbersOfTypeParameters_pr125080_2() { 
	  runTest("mixing numbers of type parameters - 2"); 
	  GenericsTests.verifyClassSignature(ajc,"AspectInterface","<T:Ljava/lang/Object;S:Ljava/lang/Number;>Ljava/lang/Object;");
	  GenericsTests.verifyClassSignature(ajc,"AbstractAspect","<T:Ljava/lang/Object;>Ljava/lang/Object;LAspectInterface<TT;Ljava/lang/Integer;>;");
	  GenericsTests.verifyClassSignature(ajc,"ConcreteAspect","LAbstractAspect<LStudent;>;");
  }
  
  public void testIProgramElementMethods_pr125295() {
	  runTest("new IProgramElement methods");  
  	  IHierarchy top = AsmManager.getDefault().getHierarchy();

  	  IProgramElement pe = top.findElementForType("pkg","foo");
  	  assertNotNull("Couldn't find 'foo' element in the tree",pe);
  	  // check that the defaults return the fully qualified arg
  	  assertEquals("foo(int, java.lang.Object)",pe.toLabelString());
  	  assertEquals("C.foo(int, java.lang.Object)",pe.toLinkLabelString());
  	  assertEquals("foo(int, java.lang.Object)",pe.toSignatureString());
  	  // check that can get hold of the non qualified args
  	  assertEquals("foo(int, Object)",pe.toLabelString(false));
  	  assertEquals("C.foo(int, Object)",pe.toLinkLabelString(false));
  	  assertEquals("foo(int, Object)",pe.toSignatureString(false));

  	  IProgramElement pe2 = top.findElementForType("pkg","printParameters");
  	  assertNotNull("Couldn't find 'printParameters' element in the tree",pe2);
  	  // the argument is org.aspectj.lang.JoinPoint, check that this is added
  	  assertFalse("printParameters method should have arguments",pe2.getParameterTypes().isEmpty());	  
  }

  public void testParameterizedEnum_pr126316() {
	  runTest("E extends Enum(E) again");
  }
  
  public void testSwallowedException() {
	  runTest("swallowed exceptions");
  }
  
  public void testSwallowedExceptionIgnored() {
	  runTest("swallowed exceptions with xlint");
  }
  /*
   * @AspectJ bugs and enhancements
   */
//  public void testAtAspectInheritsAdviceWithTJPAndThis_pr125699 () {
//	  runTest("inherit adivce with this() and thisJoinPoint"); 
//  }
  
  public void testAtAspectInheritsAbstractPointcut_pr125810 () {
	  runTest("warning when inherited pointcut not made concrete"); 
  }
  
  public void testAtAspectDEOWInStructureModel_pr120356() {
	  //AsmManager.setReporting("c:/debug.txt",true,true,true,true);
	  runTest("@AJ deow appear correctly when structure model is generated");  
  	  IHierarchy top = AsmManager.getDefault().getHierarchy();
  	   
  	  // get the IProgramElements corresponding to the @DeclareWarning statement
  	  // and the method it matches.
  	  IProgramElement warningMethodIPE = top.findElementForLabel(top.getRoot(),
  			  IProgramElement.Kind.METHOD,"warningMethod()");  	   	 
  	  assertNotNull("Couldn't find 'warningMethod()' element in the tree",warningMethodIPE);
  	  IProgramElement atDeclareWarningIPE = top.findElementForLabel(top.getRoot(),
  			  IProgramElement.Kind.FIELD,"warning");
  	  assertNotNull("Couldn't find @DeclareWarning element in the tree",atDeclareWarningIPE);

  	  // check that the method has a matches declare relationship with @DeclareWarning
  	  List matches = AsmManager.getDefault().getRelationshipMap().get(warningMethodIPE);	
  	  assertNotNull("warningMethod should have some relationships but does not",matches);
  	  assertTrue("warningMethod should have one relationships but has " + matches.size(),matches.size()==1);
  	  List matchesTargets = ((Relationship)matches.get(0)).getTargets();
  	  assertTrue("warningMethod should have one targets but has" + matchesTargets.size(),matchesTargets.size()==1);
  	  IProgramElement target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)matchesTargets.get(0));
  	  assertEquals("target of relationship should be the @DeclareWarning 'warning' but is IPE with label "
  			  + target.toLabelString(),atDeclareWarningIPE,target);
  	  
  	  // check that the @DeclareWarning has a matches relationship with the warningMethod
  	  List matchedBy = AsmManager.getDefault().getRelationshipMap().get(atDeclareWarningIPE);
  	  assertNotNull("@DeclareWarning should have some relationships but does not",matchedBy);
  	  assertTrue("@DeclareWarning should have one relationship but has " + matchedBy.size(), matchedBy.size() == 1);
  	  List matchedByTargets = ((Relationship)matchedBy.get(0)).getTargets();
  	  assertTrue("@DeclareWarning 'matched by' relationship should have one target " +
  	  		"but has " + matchedByTargets.size(), matchedByTargets.size() == 1);
  	  IProgramElement matchedByTarget = AsmManager.getDefault().getHierarchy().findElementForHandle((String)matchedByTargets.get(0));
  	  assertEquals("target of relationship should be the warningMethod but is IPE with label "
  			  + matchedByTarget.toLabelString(),warningMethodIPE,matchedByTarget);
  	  
  	  // get the IProgramElements corresponding to the @DeclareError statement
  	  // and the method it matches.
  	  IProgramElement errorMethodIPE = top.findElementForLabel(top.getRoot(),
  			  IProgramElement.Kind.METHOD,"badMethod()");  	   	 
  	  assertNotNull("Couldn't find 'badMethod()' element in the tree",errorMethodIPE);
  	  IProgramElement atDeclarErrorIPE = top.findElementForLabel(top.getRoot(),
  			  IProgramElement.Kind.FIELD,"error");
  	  assertNotNull("Couldn't find @DeclareError element in the tree",atDeclarErrorIPE);

  	  // check that the @DeclareError has a matches relationship with the badMethod
  	  List matchedByE = AsmManager.getDefault().getRelationshipMap().get(atDeclarErrorIPE);
  	  assertNotNull("@DeclareError should have some relationships but does not",matchedByE);
  	  assertTrue("@DeclareError should have one relationship but has " + matchedByE.size(), matchedByE.size() == 1);
  	  List matchedByTargetsE = ((Relationship)matchedByE.get(0)).getTargets();
  	  assertTrue("@DeclareError 'matched by' relationship should have one target " +
  	  		"but has " + matchedByTargetsE.size(), matchedByTargetsE.size() == 1);
  	  IProgramElement matchedByTargetE = AsmManager.getDefault().getHierarchy().findElementForHandle((String)matchedByTargetsE.get(0));
  	  assertEquals("target of relationship should be the badMethod but is IPE with label "
  			  + matchedByTargetE.toLabelString(),errorMethodIPE,matchedByTargetE);

  }
  
  public void testAtAspectNoNPEWithDEOWWithoutStructureModel_pr120356() {
	  runTest("@AJ no NPE with deow when structure model isn't generated"); 
  }
  
  /*
   * Load-time weaving bugs and enhancements
   */
  public void testEmptyPointcutInAtAspectJ_pr125475 () {
	  runTest("define empty pointcut using an annotation"); 
  }

  public void testEmptyPointcutInAtAspectJ_pr125475_2() {
	  runTest("define empty pointcut using an annotation - 2"); 
  }
  
  public void testEmptyPointcutInAtAspectJWithLTW_pr125475 () {
	  runTest("define empty pointcut using aop.xml"); 
  }
  
  public void testLTWGeneratedAspectWithAbstractMethod_pr125480 () {
	  runTest("aop.xml aspect inherits abstract method that has concrete implementation in parent"); 
  }
  
  /////////////////////////////////////////
  public static Test suite() {
    return XMLBasedAjcTestCase.loadSuite(Ajc151Tests.class);
  }

  protected File getSpecFile() {
    return new File("../tests/src/org/aspectj/systemtest/ajc151/ajc151.xml");
  }
  
}