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 3.9KB

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