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.

NewFeatures.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*******************************************************************************
  2. * Copyright (c) 2010 Lucierna
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * Abraham Nevado - initial API and implementation
  10. *******************************************************************************/
  11. package org.aspectj.systemtest.ajc1610;
  12. import org.aspectj.apache.bcel.classfile.JavaClass;
  13. import org.aspectj.apache.bcel.classfile.Method;
  14. import org.aspectj.testing.XMLBasedAjcTestCase;
  15. import junit.framework.Test;
  16. public class NewFeatures extends org.aspectj.testing.XMLBasedAjcTestCase {
  17. public void testMakeSJPOptimizationLDCNo() {
  18. this.runTest("makeSJP optimization - LDC - No");
  19. try {
  20. JavaClass myClass = getMyClass("B");
  21. Method preClinitMethod = getPreClinitMethod(myClass);
  22. NewFeatures.assertTrue("For 1.4 it must use classForName", preClinitMethod.getCode().toString().contains("forName"));
  23. } catch (Exception e) {
  24. NewFeatures.fail(e.toString());
  25. }
  26. }
  27. @SuppressWarnings("unused")
  28. public void testMakeSJPOptimizationCollapsedSJPYes14() {
  29. this.runTest("makeSJP optimization - Collapsed SJP - Yes 1.4");
  30. try {
  31. JavaClass myClass = getMyClass("B");
  32. } catch (Exception e) {
  33. NewFeatures.fail(e.toString());
  34. }
  35. }
  36. public void testMakeSJPOptimizationLDCYes() {
  37. this.runTest("makeSJP optimization - LDC - Yes");
  38. try {
  39. JavaClass myClass = getMyClass("B");
  40. Method preClinitMethod = getPreClinitMethod(myClass);
  41. NewFeatures.assertTrue("For 1.5 it must not use classForName", !preClinitMethod.getCode().toString()
  42. .contains("forName"));
  43. } catch (Exception e) {
  44. NewFeatures.fail(e.toString());
  45. }
  46. }
  47. public void testMakeSJPOptimizationCollapsedSJPYes() {
  48. this.runTest("makeSJP optimization - Collapsed SJP - Yes");
  49. try {
  50. JavaClass myClass = getMyClass("B");
  51. Method preClinitMethod = getPreClinitMethod(myClass);
  52. NewFeatures.assertTrue("MakedMethodSig MUST not be present",
  53. !preClinitMethod.getCode().toString().contains("makeMethodSig"));
  54. } catch (Exception e) {
  55. NewFeatures.fail(e.toString());
  56. }
  57. }
  58. public void testMakeSJPOptimizationCollapsedSJPNo() {
  59. this.runTest("makeSJP optimization - Collapsed SJP - No");
  60. try {
  61. JavaClass myClass = getMyClass("B");
  62. Method preClinitMethod = getPreClinitMethod(myClass);
  63. NewFeatures.assertTrue("MakedMethodSig required", preClinitMethod.getCode().toString().contains("makeMethodSig"));
  64. } catch (Exception e) {
  65. NewFeatures.fail(e.toString());
  66. }
  67. }
  68. public void testMakeSJPOptimizationNoExceptionNo() {
  69. this.runTest("makeSJP optimization - No Exception - No");
  70. try {
  71. JavaClass myClass = getMyClass("B");
  72. Method preClinitMethod = getPreClinitMethod(myClass);
  73. NewFeatures
  74. .assertTrue(
  75. "MakedMethodSig required",
  76. preClinitMethod
  77. .getCode()
  78. .toString()
  79. .contains(
  80. "invokevirtual org.aspectj.runtime.reflect.Factory.makeMethodSig (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lorg/aspectj/lang/reflect/MethodSignature;"));
  81. } catch (Exception e) {
  82. NewFeatures.fail(e.toString());
  83. }
  84. }
  85. public void testMakeSJPOptimizationNoExceptionYes() {
  86. this.runTest("makeSJP optimization - No Exception - Yes");
  87. try {
  88. JavaClass myClass = getMyClass("B");
  89. Method preClinitMethod = getPreClinitMethod(myClass);
  90. NewFeatures
  91. .assertTrue(
  92. "MakedMethodSig required",
  93. preClinitMethod
  94. .getCode()
  95. .toString()
  96. .contains(
  97. "org.aspectj.runtime.reflect.Factory.makeSJP (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)Lorg/aspectj/lang/JoinPoint$StaticPart;"));
  98. } catch (Exception e) {
  99. NewFeatures.fail(e.toString());
  100. }
  101. }
  102. public void testMakeSJPOptimizationRemoveExtraColon() {
  103. this.runTest("makeSJP optimization - Remove Colon");
  104. try {
  105. JavaClass myClass = getMyClass("B");
  106. Method preClinitMethod = getPreClinitMethod(myClass);
  107. System.out.println(preClinitMethod.getCode().toString());
  108. NewFeatures.assertTrue("MakedMethodSig required",
  109. preClinitMethod.getCode().toString().contains("50: ldc \"java.lang.String\" (108)"));
  110. } catch (Exception e) {
  111. NewFeatures.fail(e.toString());
  112. }
  113. }
  114. // ///////////////////////////////////////
  115. private Method getPreClinitMethod(JavaClass myClass) {
  116. Method lm[] = myClass.getMethods();
  117. for (int i = 0; i < lm.length; i++) {
  118. if (lm[i].getName().equals("ajc$preClinit")) {
  119. return lm[i];
  120. }
  121. }
  122. return null;
  123. }
  124. public static Test suite() {
  125. return XMLBasedAjcTestCase.loadSuite(NewFeatures.class);
  126. }
  127. private JavaClass getMyClass(String className) throws ClassNotFoundException {
  128. return getClassFrom(ajc.getSandboxDirectory(), className);
  129. }
  130. protected java.net.URL getSpecFile() {
  131. return getClassResource("newfeatures-tests.xml");
  132. }
  133. }