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.

Ajc193Tests.java 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*******************************************************************************
  2. * Copyright (c) 2018-2019 Contributors
  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. package org.aspectj.systemtest.ajc193;
  9. import junit.framework.Test;
  10. import org.aspectj.apache.bcel.classfile.JavaClass;
  11. import org.aspectj.testing.JavaVersionSpecificXMLBasedAjcTestCase;
  12. import org.aspectj.testing.XMLBasedAjcTestCase;
  13. import org.aspectj.weaver.WeaverStateInfo;
  14. import java.io.File;
  15. /**
  16. * @author Andy Clement
  17. */
  18. public class Ajc193Tests extends JavaVersionSpecificXMLBasedAjcTestCase {
  19. public Ajc193Tests() {
  20. super(10);
  21. }
  22. public void testNestedAroundProceed() {
  23. runTest("nested around proceed");
  24. }
  25. public void testDeclareMixinOverweavingControl() {
  26. runTest("overweaving decm - control");
  27. }
  28. public void testDeclareMixinOverweavingReweaving() {
  29. runTest("overweaving decm - reweaving");
  30. }
  31. public void testDeclareMixinOverweaving() {
  32. runTest("overweaving decm - 1");
  33. }
  34. public void xtestDeclareMixinOverweaving2() {
  35. runTest("overweaving decm - 2");
  36. }
  37. public void xtestOverweavingDeclareMixinTargetingAspect() {
  38. runTest("mood indicator 4");
  39. }
  40. public void testOverweavingAtDecPControl() {
  41. runTest("overweaving atdecp - control");
  42. }
  43. public void testOverweavingAtDecP() {
  44. runTest("overweaving atdecp");
  45. }
  46. public void testComplexOverweaving1() {
  47. // This is the same code as the other test but overweaving OFF
  48. runTest("overweaving");
  49. }
  50. public void testComplexOverweaving2() throws Exception {
  51. // This is the same code as the other test but overweaving ON
  52. runTest("overweaving 2");
  53. // Asserting the weaver state info in the tests that will drive overweaving behaviour:
  54. // After step 1 of the test, MyAspect will have been applied.
  55. JavaClass jc = getClassFrom(new File(ajc.getSandboxDirectory(),"ow1.jar"), "Application");
  56. WeaverStateInfo wsi = getWeaverStateInfo(jc);
  57. assertEquals("[LMyAspect;]", wsi.getAspectsAffectingType().toString());
  58. assertTrue(wsi.getUnwovenClassFileData().length>0);
  59. // After overweaving, MyAspect2 should also be getting applied but the unwovenclassfile
  60. // data has been blanked out - because we can no longer use it, only overweaving is possible
  61. // once one overweaving step is done
  62. jc = getClassFrom(ajc.getSandboxDirectory(), "Application");
  63. wsi = getWeaverStateInfo(jc);
  64. assertEquals("[LMyAspect2;, LMyAspect;]", wsi.getAspectsAffectingType().toString());
  65. assertEquals(0,wsi.getUnwovenClassFileData().length);
  66. }
  67. // Two steps of overweaving
  68. public void testComplexOverweaving3() throws Exception {
  69. // This is the same code as the other test but overweaving ON
  70. runTest("overweaving 3");
  71. // Asserting the weaver state info in the tests that will drive overweaving behaviour:
  72. // After step 1 of the test, MyAspect will have been applied.
  73. JavaClass jc = getClassFrom(new File(ajc.getSandboxDirectory(),"ow1.jar"), "Application");
  74. WeaverStateInfo wsi = getWeaverStateInfo(jc);
  75. assertEquals("[LMyAspect;]", wsi.getAspectsAffectingType().toString());
  76. assertTrue(wsi.getUnwovenClassFileData().length>0);
  77. // After overweaving, MyAspect2 should also be getting applied but the unwovenclassfile
  78. // data has been blanked out - because we can no longer use it, only overweaving is possible
  79. // once one overweaving step is done
  80. jc = getClassFrom(new File(ajc.getSandboxDirectory(),"ow3.jar"), "Application");
  81. wsi = getWeaverStateInfo(jc);
  82. assertEquals("[LMyAspect2;, LMyAspect;]", wsi.getAspectsAffectingType().toString());
  83. assertEquals(0,wsi.getUnwovenClassFileData().length);
  84. jc = getClassFrom(ajc.getSandboxDirectory(), "Application");
  85. wsi = getWeaverStateInfo(jc);
  86. assertEquals("[LMyAspect3;, LMyAspect2;, LMyAspect;]", wsi.getAspectsAffectingType().toString());
  87. assertEquals(0,wsi.getUnwovenClassFileData().length);
  88. }
  89. // overweaving then attempt non overweaving - should fail
  90. public void testComplexOverweaving4() throws Exception {
  91. // This is the same code as the other test but overweaving ON
  92. runTest("overweaving 4");
  93. // Asserting the weaver state info in the tests that will drive overweaving behaviour:
  94. // After step 1 of the test, MyAspect will have been applied.
  95. JavaClass jc = getClassFrom(new File(ajc.getSandboxDirectory(),"ow1.jar"), "Application");
  96. WeaverStateInfo wsi = getWeaverStateInfo(jc);
  97. assertEquals("[LMyAspect;]", wsi.getAspectsAffectingType().toString());
  98. assertTrue(wsi.getUnwovenClassFileData().length>0);
  99. }
  100. // Altered version of this test from org.aspectj.systemtest.ajc150.Enums for 542682
  101. public void testDecpOnEnumNotAllowed_xlints() {
  102. runTest("wildcard enum match in itd");
  103. }
  104. public void testEnumDecmixinMessage() {
  105. runTest("declare mixin a");
  106. }
  107. public void testIsAbstractType() {
  108. runTest("is abstract");
  109. }
  110. public void testIsAbstractType2() {
  111. runTest("is abstract - 2");
  112. }
  113. // ---
  114. public static Test suite() {
  115. return XMLBasedAjcTestCase.loadSuite(Ajc193Tests.class);
  116. }
  117. @Override
  118. protected java.net.URL getSpecFile() {
  119. return getClassResource("ajc193.xml");
  120. }
  121. }