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.

SanityTests19.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*******************************************************************************
  2. * Copyright (c) 2006 IBM
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v 2.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  7. *
  8. * Contributors:
  9. * Andy Clement - initial API and implementation
  10. *******************************************************************************/
  11. package org.aspectj.systemtest.ajc190;
  12. import org.aspectj.apache.bcel.Constants;
  13. import org.aspectj.testing.XMLBasedAjcTestCase;
  14. import junit.framework.Test;
  15. /*
  16. * Some very trivial tests that help verify things are OK.
  17. * These are a copy of the earlier Sanity Tests created for 1.6 but these supply the -1.9 option
  18. * to check code generation and modification with that version specified.
  19. */
  20. public class SanityTests19 extends XMLBasedAjcTestCase {
  21. public static final int bytecode_version_for_JDK_level = Constants.ClassFileVersion.of(9).MAJOR;
  22. // Incredibly trivial test programs that check the compiler works at all (these are easy-ish to debug)
  23. public void testSimpleJava_A() {
  24. runTest("simple - a");
  25. }
  26. public void testSimpleJava_B() {
  27. runTest("simple - b");
  28. }
  29. public void testSimpleCode_C() {
  30. runTest("simple - c");
  31. }
  32. public void testSimpleCode_D() {
  33. runTest("simple - d");
  34. }
  35. public void testSimpleCode_E() {
  36. runTest("simple - e");
  37. }
  38. public void testSimpleCode_F() {
  39. runTest("simple - f");
  40. }
  41. public void testSimpleCode_G() {
  42. runTest("simple - g");
  43. }
  44. public void testSimpleCode_H() {
  45. runTest("simple - h", true);
  46. }
  47. public void testSimpleCode_I() {
  48. runTest("simple - i");
  49. }
  50. // Check the version number in the classfiles is correct when Java6 options specified
  51. public void testVersionCorrect1() throws ClassNotFoundException {
  52. runTest("simple - j");
  53. checkVersion("A", bytecode_version_for_JDK_level, 0);
  54. }
  55. public void testVersionCorrect2() throws ClassNotFoundException {
  56. runTest("simple - k");
  57. checkVersion("A", bytecode_version_for_JDK_level, 0);
  58. }
  59. public void testVersionCorrect4() throws ClassNotFoundException { // check it is 49.0 when -1.5 is specified
  60. runTest("simple - m");
  61. checkVersion("A", Constants.ClassFileVersion.of(5).MAJOR, 0);
  62. }
  63. // Check the stackmap stuff appears for methods in a Java6 file
  64. // public void testStackMapAttributesAppear() throws ClassNotFoundException {
  65. // runTest("simple - n");
  66. // checkStackMapExistence("A","<init>_<clinit>");
  67. // checkStackMapExistence("X","<init>_<clinit>_ajc$pointcut$$complicatedPointcut$1fe");
  68. // }
  69. /* For the specified class, check that each method has a stackmap attribute */
  70. // private void checkStackMapExistence(String classname, String toIgnore) throws ClassNotFoundException {
  71. // toIgnore = "_" + (toIgnore == null ? "" : toIgnore) + "_";
  72. // JavaClass jc = getClassFrom(ajc.getSandboxDirectory(), classname);
  73. // Method[] methods = jc.getMethods();
  74. // for (int i = 0; i < methods.length; i++) {
  75. // Method method = methods[i];
  76. // if (toIgnore.contains("_" + method.getName() + "_")) {
  77. // continue;
  78. // }
  79. // boolean hasStackMapAttribute = findAttribute(method.getAttributes(), "StackMapTable");
  80. // if (!hasStackMapAttribute) {
  81. // fail("Could not find StackMap attribute for method " + method.getName());
  82. // }
  83. // }
  84. // }
  85. // private boolean findAttribute(Attribute[] attrs, String attributeName) {
  86. // if (attrs == null) {
  87. // return false;
  88. // }
  89. // for (int i = 0; i < attrs.length; i++) {
  90. // Attribute attribute = attrs[i];
  91. // if (attribute.getName().equals(attributeName)) {
  92. // return true;
  93. // }
  94. // // System.out.println(attribute.getName());
  95. // if (attribute.getName().equals("Code")) {
  96. // Code c = (Code) attribute;
  97. // Attribute[] codeAttributes = c.getAttributes();
  98. // for (int j = 0; j < codeAttributes.length; j++) {
  99. // Attribute codeAttribute = codeAttributes[j];
  100. // if (codeAttribute.getName().equals(attributeName)) {
  101. // return true;
  102. // // System.out.println(codeAttribute.getName());
  103. // }
  104. // }
  105. // }
  106. // }
  107. // return false;
  108. // }
  109. // Check the stackmap stuff is removed when a method gets woven (for now...)
  110. // public void testStackMapAttributesDeletedInWovenCode() {
  111. // fail("Not implemented");
  112. // }
  113. // ///////////////////////////////////////
  114. public static Test suite() {
  115. return XMLBasedAjcTestCase.loadSuite(SanityTests19.class);
  116. }
  117. protected java.net.URL getSpecFile() {
  118. return getClassResource("sanity-tests-19.xml");
  119. }
  120. }