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.

NewarrayJoinpointTests.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*******************************************************************************
  2. * Copyright (c) 2006 IBM Corporation and others.
  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. * Andy Clement - initial implementation
  10. *******************************************************************************/
  11. package org.aspectj.systemtest.ajc151;
  12. import java.util.List;
  13. import org.aspectj.asm.AsmManager;
  14. import org.aspectj.asm.IProgramElement;
  15. import org.aspectj.asm.IRelationship;
  16. import org.aspectj.testing.XMLBasedAjcTestCase;
  17. import junit.framework.Test;
  18. /*
  19. * The design:
  20. *
  21. * There are 3 instructions that create arrays:
  22. *
  23. * - NEWARRAY for primitive arrays
  24. * - ANEWARRAY for object arrays
  25. * - MULTIANEWARRAY for multidimensional arrays
  26. *
  27. * The changes to expose the new joinpoint are in:
  28. * BcelClassWeaver.match(LazyMethodGen mg,InstructionHandle ih,BcelShadow enclosingShadow,List shadowAccumulator)
  29. *
  30. * Determining the type of the array is easy. Determining the size of the array is not easy statically, it is on the stack.
  31. *
  32. *
  33. * What still needs testing:
  34. * - structure model
  35. *
  36. */
  37. public class NewarrayJoinpointTests extends XMLBasedAjcTestCase {
  38. // when its the creation of a new 'object' (not a primitive) single dimension array
  39. public void testTheBasics_1() {
  40. runTest("basics");
  41. }
  42. public void testTheBasics_2() {
  43. runTest("basics - 2");
  44. }
  45. public void testWhatShouldntMatch() {
  46. runTest("shouldnt match");
  47. }
  48. public void testThisJoinPoint() {
  49. runTest("thisjoinpoint");
  50. }
  51. public void testThisJoinPoint19() {
  52. try {
  53. System.setProperty("ASPECTJ_OPTS", "-Xajruntimetarget:1.9");
  54. runTest("thisjoinpoint");
  55. } finally {
  56. System.setProperty("ASPECTJ_OPTS", "");
  57. }
  58. }
  59. public void testDifferentAdviceKinds() {
  60. runTest("different advice kinds");
  61. }
  62. public void testArgs() {
  63. runTest("args");
  64. }
  65. // when it is the creation of a new array of primitives
  66. public void testBasicWithAPrimitiveArray() {
  67. runTest("basic primitive array creation");
  68. }
  69. // when it is the creation of a new multi-dimensional array
  70. public void testBasicWithAMultiDimensionalArray() {
  71. runTest("multi dimensional array creation");
  72. }
  73. public void testArgsWithAMultiDimensionalArray() {
  74. runTest("multi dimensional array args");
  75. }
  76. // various
  77. public void testOptionoff() {
  78. runTest("option deactivated - no match expected");
  79. }
  80. public void testUsingTargetAndAfterReturningAdvice() {
  81. runTest("using target and after returning");
  82. }
  83. public void testUsingItForReal() {
  84. runTest("using it for real");
  85. }
  86. public void testDifferentiatingArrayTypes() {
  87. runTest("differentiating array types");
  88. }
  89. public void testStructureModel() {
  90. // AsmManager.setReporting("c:/foo.txt",true,true,true,true);
  91. runTest("structure model");
  92. IProgramElement ipe = AsmManager.lastActiveStructureModel.getHierarchy().findElementForType("", "Five");
  93. assertTrue("Couldnt find 'Five' type in the model", ipe != null);
  94. List<IProgramElement> kids = ipe.getChildren();
  95. assertTrue("Couldn't find 'main' method in the 'Five' type", kids != null && kids.size() == 1);
  96. List<IProgramElement> codenodes = kids.get(0).getChildren();
  97. assertTrue("Couldn't find nodes below 'main' method", codenodes != null && codenodes.size() == 1);
  98. IProgramElement arrayCtorCallNode = codenodes.get(0);
  99. String exp = "constructor-call(void java.lang.Integer[].<init>(int))";
  100. assertTrue("Expected '" + exp + "' but found " + arrayCtorCallNode.toString(), arrayCtorCallNode.toString().equals(exp));
  101. List<IRelationship> rels = AsmManager.lastActiveStructureModel.getRelationshipMap().get(arrayCtorCallNode);
  102. assertTrue("Should have a relationship from the ctorcall node, but didn't find one?", rels != null && rels.size() == 1);
  103. }
  104. //
  105. public static Test suite() {
  106. return XMLBasedAjcTestCase.loadSuite(NewarrayJoinpointTests.class);
  107. }
  108. @Override
  109. protected java.net.URL getSpecFile() {
  110. return getClassResource("newarray_joinpoint.xml");
  111. }
  112. }