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 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. /**
  24. * These are tests that will run on Java 1.4 and use the old harness format for test specification.
  25. */
  26. public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
  27. public static Test suite() {
  28. return XMLBasedAjcTestCase.loadSuite(Ajc150Tests.class);
  29. }
  30. protected File getSpecFile() {
  31. return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
  32. }
  33. public void test_typeProcessingOrderWhenDeclareParents() {
  34. runTest("Order of types passed to compiler determines weaving behavior");
  35. }
  36. public void test_aroundMethod() {
  37. runTest("method called around in class");
  38. }
  39. public void test_aroundMethodAspect() {
  40. runTest("method called around in aspect");
  41. }
  42. public void test_ambiguousBindingsDetection() {
  43. runTest("Various kinds of ambiguous bindings");
  44. }
  45. public void test_ambiguousArgsDetection() {
  46. runTest("ambiguous args");
  47. }
  48. public void testIncorrectExceptionTableWhenBreakInMethod_pr78021() {
  49. runTest("Injecting exception into while loop with break statement causes catch block to be ignored");
  50. }
  51. public void testIncorrectExceptionTableWhenReturnInMethod_pr79554() {
  52. runTest("Return in try-block disables catch-block if final-block is present");
  53. }
  54. public void testMissingDebugInfoForGeneratedMethods_pr82570() throws ClassNotFoundException {
  55. runTest("Weaved code does not include debug lines");
  56. boolean f = false;
  57. JavaClass jc = getClassFrom(ajc.getSandboxDirectory(),"PR82570_1");
  58. Method[] meths = jc.getMethods();
  59. for (int i = 0; i < meths.length; i++) {
  60. Method method = meths[i];
  61. if (f) System.err.println("Line number table for "+method.getName()+method.getSignature()+" = "+method.getLineNumberTable());
  62. assertTrue("Didn't find a line number table for method "+method.getName()+method.getSignature(),
  63. method.getLineNumberTable()!=null);
  64. }
  65. // This test would determine the info isn't there if you pass -g:none ...
  66. // cR = ajc(baseDir,new String[]{"PR82570_1.java","-g:none"});
  67. // assertTrue("Expected no compile problem:"+cR,!cR.hasErrorMessages());
  68. // System.err.println(cR.getStandardError());
  69. // jc = getClassFrom(ajc.getSandboxDirectory(),"PR82570_1");
  70. // meths = jc.getMethods();
  71. // for (int i = 0; i < meths.length; i++) {
  72. // Method method = meths[i];
  73. // assertTrue("Found a line number table for method "+method.getName(),
  74. // method.getLineNumberTable()==null);
  75. // }
  76. }
  77. public void testCanOverrideProtectedMethodsViaITDandDecp_pr83303() {
  78. runTest("compiler error when mixing inheritance, overriding and polymorphism");
  79. }
  80. public void testPerTypeWithinMissesNamedInnerTypes() {
  81. runTest("pertypewithin() handing of inner classes (1)");
  82. }
  83. public void testPerTypeWithinMissesAnonymousInnerTypes() {
  84. runTest("pertypewithin() handing of inner classes (2)");
  85. }
  86. public void testPerTypeWithinIncorrectlyMatchingInterfaces() {
  87. runTest("pertypewithin({interface}) illegal field modifier");
  88. }
  89. public void test051_arrayCloningInJava5() {
  90. runTest("AJC possible bug with static nested classes");
  91. }
  92. public void testBadASMforEnums() throws IOException {
  93. runTest("bad asm for enums");
  94. if (System.getProperty("java.vm.version").startsWith("1.5")) {
  95. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  96. PrintWriter pw = new PrintWriter(baos);
  97. AsmManager.dumptree(pw,AsmManager.getDefault().getHierarchy().getRoot(),0);
  98. pw.flush();
  99. String tree = baos.toString();
  100. assertTrue("Expected 'Red [enumvalue]' somewhere in here:"+tree,tree.indexOf("Red [enumvalue]")!=-1);
  101. }
  102. }
  103. // helper methods.....
  104. public SyntheticRepository createRepos(File cpentry) {
  105. ClassPath cp = new ClassPath(cpentry+File.pathSeparator+System.getProperty("java.class.path"));
  106. return SyntheticRepository.getInstance(cp);
  107. }
  108. protected JavaClass getClassFrom(File where,String clazzname) throws ClassNotFoundException {
  109. SyntheticRepository repos = createRepos(where);
  110. return repos.loadClass(clazzname);
  111. }
  112. }