You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Ajc150Tests.java 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*******************************************************************************
  2. * Copyright (c) 2004 IBM
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Common Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/cpl-v10.html
  7. *
  8. * Contributors:
  9. * Andy Clement - initial API and implementation
  10. *******************************************************************************/
  11. package org.aspectj.systemtest.ajc150;
  12. import java.io.ByteArrayOutputStream;
  13. import java.io.File;
  14. import java.io.IOException;
  15. import java.io.PrintWriter;
  16. import junit.framework.Test;
  17. import org.aspectj.apache.bcel.classfile.JavaClass;
  18. import org.aspectj.apache.bcel.classfile.Method;
  19. import org.aspectj.apache.bcel.util.ClassPath;
  20. import org.aspectj.apache.bcel.util.SyntheticRepository;
  21. import org.aspectj.asm.AsmManager;
  22. import org.aspectj.testing.XMLBasedAjcTestCase;
  23. import org.aspectj.util.LangUtil;
  24. /**
  25. * These are tests that will run on Java 1.4 and use the old harness format for test specification.
  26. */
  27. public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
  28. public static Test suite() {
  29. return XMLBasedAjcTestCase.loadSuite(Ajc150Tests.class);
  30. }
  31. protected File getSpecFile() {
  32. return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
  33. }
  34. public void test_typeProcessingOrderWhenDeclareParents() {
  35. runTest("Order of types passed to compiler determines weaving behavior");
  36. }
  37. public void test_aroundMethod() {
  38. runTest("method called around in class");
  39. }
  40. public void test_aroundMethodAspect() {
  41. runTest("method called around in aspect");
  42. }
  43. public void test_ambiguousBindingsDetection() {
  44. runTest("Various kinds of ambiguous bindings");
  45. }
  46. public void test_ambiguousArgsDetection() {
  47. runTest("ambiguous args");
  48. }
  49. public void testIncorrectExceptionTableWhenBreakInMethod_pr78021() {
  50. runTest("Injecting exception into while loop with break statement causes catch block to be ignored");
  51. }
  52. public void testIncorrectExceptionTableWhenReturnInMethod_pr79554() {
  53. runTest("Return in try-block disables catch-block if final-block is present");
  54. }
  55. public void testMissingDebugInfoForGeneratedMethods_pr82570() throws ClassNotFoundException {
  56. runTest("Weaved code does not include debug lines");
  57. boolean f = false;
  58. JavaClass jc = getClassFrom(ajc.getSandboxDirectory(),"PR82570_1");
  59. Method[] meths = jc.getMethods();
  60. for (int i = 0; i < meths.length; i++) {
  61. Method method = meths[i];
  62. if (f) System.err.println("Line number table for "+method.getName()+method.getSignature()+" = "+method.getLineNumberTable());
  63. assertTrue("Didn't find a line number table for method "+method.getName()+method.getSignature(),
  64. method.getLineNumberTable()!=null);
  65. }
  66. // This test would determine the info isn't there if you pass -g:none ...
  67. // cR = ajc(baseDir,new String[]{"PR82570_1.java","-g:none"});
  68. // assertTrue("Expected no compile problem:"+cR,!cR.hasErrorMessages());
  69. // System.err.println(cR.getStandardError());
  70. // jc = getClassFrom(ajc.getSandboxDirectory(),"PR82570_1");
  71. // meths = jc.getMethods();
  72. // for (int i = 0; i < meths.length; i++) {
  73. // Method method = meths[i];
  74. // assertTrue("Found a line number table for method "+method.getName(),
  75. // method.getLineNumberTable()==null);
  76. // }
  77. }
  78. public void testCanOverrideProtectedMethodsViaITDandDecp_pr83303() {
  79. runTest("compiler error when mixing inheritance, overriding and polymorphism");
  80. }
  81. public void testPerTypeWithinMissesNamedInnerTypes() {
  82. runTest("pertypewithin() handing of inner classes (1)");
  83. }
  84. public void testPerTypeWithinMissesAnonymousInnerTypes() {
  85. runTest("pertypewithin() handing of inner classes (2)");
  86. }
  87. public void testPerTypeWithinIncorrectlyMatchingInterfaces() {
  88. runTest("pertypewithin({interface}) illegal field modifier");
  89. }
  90. public void test051_arrayCloningInJava5() {
  91. runTest("AJC possible bug with static nested classes");
  92. }
  93. public void testBadASMforEnums() throws IOException {
  94. runTest("bad asm for enums");
  95. if (LangUtil.is15VMOrGreater()) {
  96. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  97. PrintWriter pw = new PrintWriter(baos);
  98. AsmManager.dumptree(pw,AsmManager.getDefault().getHierarchy().getRoot(),0);
  99. pw.flush();
  100. String tree = baos.toString();
  101. assertTrue("Expected 'Red [enumvalue]' somewhere in here:"+tree,tree.indexOf("Red [enumvalue]")!=-1);
  102. }
  103. }
  104. public void npeOnTypeNotFound() {
  105. runTest("structure model npe on type not found");
  106. }
  107. public void testNoRuntimeExceptionSoftening() {
  108. runTest("declare soft of runtime exception");
  109. }
  110. public void testRuntimeNoSoftenWithHandler() {
  111. runTest("declare soft w. catch block");
  112. }
  113. public void testSyntaxError() {
  114. runTest("invalid cons syntax");
  115. }
  116. public void testVarargsInConsBug() {
  117. runTest("varargs in constructor sig");
  118. }
  119. public void testAspectpathdirs() {
  120. runTest("dirs on aspectpath");
  121. }
  122. public void testIntroSample() {
  123. runTest("introduction sample");
  124. }
  125. public void testPTWInterface() {
  126. runTest("pertypewithin({interface}) illegal field modifier");
  127. }
  128. public void testEnumCalledEnumEtc() {
  129. runTest("enum called Enum, annotation called Annotation, etc");
  130. }
  131. public void testInternalCompilerError_pr86832() {
  132. runTest("Internal compiler error");
  133. }
  134. /**
  135. * IfPointcut.findResidueInternal() was modified to make this test complete in a short amount
  136. * of time - if you see it hanging, someone has messed with the optimization.
  137. */
  138. public void testIfEvaluationExplosion_pr94086() {
  139. runTest("Exploding compile time with if() statements in pointcut");
  140. }
  141. public void testReflectNPE_pr94167() {
  142. runTest("NPE in reflect implementation");
  143. }
  144. // helper methods.....
  145. public SyntheticRepository createRepos(File cpentry) {
  146. ClassPath cp = new ClassPath(cpentry+File.pathSeparator+System.getProperty("java.class.path"));
  147. return SyntheticRepository.getInstance(cp);
  148. }
  149. protected JavaClass getClassFrom(File where,String clazzname) throws ClassNotFoundException {
  150. SyntheticRepository repos = createRepos(where);
  151. return repos.loadClass(clazzname);
  152. }
  153. }