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.8KB

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