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.

EfficientTJPTests.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*******************************************************************************
  2. * Copyright (c) 2018 Contributors
  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. package org.aspectj.systemtest.ajc190;
  9. import org.aspectj.apache.bcel.classfile.JavaClass;
  10. import org.aspectj.apache.bcel.classfile.Method;
  11. import org.aspectj.testing.XMLBasedAjcTestCase;
  12. import junit.framework.Assert;
  13. import junit.framework.Test;
  14. /**
  15. *
  16. * @author Andy Clement
  17. */
  18. public class EfficientTJPTests extends XMLBasedAjcTestCase {
  19. public void testThisJoinPointMethodExecution() {
  20. // Test setting it via sys props rather than passing the option directly
  21. try {
  22. System.setProperty("ASPECTJ_OPTS", "-Xajruntimetarget:1.9");
  23. runTest("tjp 1");
  24. checkPreClinitContains("One","Factory.makeMethodSJP");
  25. } finally {
  26. System.setProperty("ASPECTJ_OPTS", "");
  27. }
  28. }
  29. public void testThisEnclosingJoinPointMethodExecution() {
  30. runTest("tjp 2");
  31. checkPreClinitContains("Two","Factory.makeMethodESJP");
  32. }
  33. public void testThisJoinPointConstructorExecution() {
  34. runTest("tjp 3");
  35. checkPreClinitContains("Three","Factory.makeConstructorSJP");
  36. }
  37. public void testThisEnclosingJoinPointConstructorExecution() {
  38. runTest("tjp 3a");
  39. checkPreClinitContains("ThreeA","Factory.makeConstructorESJP");
  40. }
  41. public void testThisJoinPointHandler() {
  42. runTest("tjp 4");
  43. checkPreClinitContains("Four","Factory.makeCatchClauseSJP");
  44. }
  45. public void testThisEnclosingJoinPointHandler() {
  46. runTest("tjp 4a");
  47. checkPreClinitContains("FourA","Factory.makeMethodESJP");
  48. }
  49. public void testThisJoinPointFieldGet() {
  50. runTest("tjp get fields");
  51. checkPreClinitContains("Fields","Factory.makeFieldSJP");
  52. }
  53. public void testThisEnclosingJoinPointFieldGet() {
  54. runTest("tjp get fieldsE");
  55. checkPreClinitContains("FieldsE","Factory.makeMethodESJP");
  56. }
  57. public void testThisJoinPointFieldSet() {
  58. runTest("tjp set fields");
  59. checkPreClinitContains("Fields2","Factory.makeFieldSJP");
  60. }
  61. public void testThisJoinPointClinit() {
  62. runTest("tjp clinit");
  63. checkPreClinitContains("Clinit","Factory.makeInitializerSJP");
  64. }
  65. public void testThisEnclosingJoinPointClinit() {
  66. runTest("tejp clinit");
  67. checkPreClinitContains("ClinitE","Factory.makeInitializerESJP");
  68. }
  69. public void testThisJoinPointAdvice() {
  70. // covers enclosing joinpoint too
  71. runTest("tjp advice");
  72. checkPreClinitContains("X","Factory.makeAdviceESJP");
  73. }
  74. public void testThisJoinPointInitialization() {
  75. runTest("tjp init");
  76. checkPreClinitContains("A","Factory.makeConstructorESJP");
  77. checkPreClinitContains("B","Factory.makeConstructorESJP");
  78. }
  79. // ///////////////////////////////////////
  80. public static Test suite() {
  81. return XMLBasedAjcTestCase.loadSuite(EfficientTJPTests.class);
  82. }
  83. @Override
  84. protected java.net.URL getSpecFile() {
  85. return getClassResource("features190.xml");
  86. }
  87. public void checkPreClinitContains(String classname, String text) {
  88. try {
  89. JavaClass jc = getClassFrom(ajc.getSandboxDirectory(), classname);
  90. Method[] meths = jc.getMethods();
  91. for (int i = 0; i < meths.length; i++) {
  92. Method method = meths[i];
  93. if (method.getName().equals("ajc$preClinit")) {
  94. String code = method.getCode().getCodeString();
  95. assertTrue("Expected to contain '"+text+"':\n"+code,code.contains(text));
  96. return;
  97. }
  98. }
  99. Assert.fail("Unable to find ajc$preClinit in class "+classname);
  100. } catch (Exception e) {
  101. Assert.fail(e.toString());
  102. }
  103. }
  104. }