aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java
blob: 36b3a0b91e5812f89e5372769151fa0b0a9e50d5 (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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*******************************************************************************
 * 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 junit.framework.Test;

import org.aspectj.apache.bcel.classfile.JavaClass;
import org.aspectj.apache.bcel.classfile.Method;
import org.aspectj.apache.bcel.util.ClassPath;
import org.aspectj.apache.bcel.util.SyntheticRepository;
import org.aspectj.asm.AsmManager;
import org.aspectj.testing.XMLBasedAjcTestCase;
import org.aspectj.util.LangUtil;

/**
 * These are tests that will run on Java 1.4 and use the old harness format for test specification.
 */
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 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 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 testIllegalStateExceptionOnNestedParameterizedType_pr106634() { 
	  runTest("IllegalStateException unpacking signature of nested parameterized type");
  }
  
  public void testMissingNamePattern_pr106461() { runTest("missing name pattern"); }
  
  // 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);
  }

}