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.

IdWeaveTestCase.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.bcel;
  13. import java.io.IOException;
  14. import java.util.ArrayList;
  15. import java.util.List;
  16. import org.aspectj.weaver.Shadow;
  17. import org.aspectj.weaver.World;
  18. import org.aspectj.weaver.patterns.Pointcut;
  19. public class IdWeaveTestCase extends WeaveTestCase {
  20. {
  21. regenerate = false;
  22. }
  23. public IdWeaveTestCase(String name) {
  24. super(name);
  25. }
  26. public void testFancyId() throws IOException {
  27. final List l = new ArrayList();
  28. Pointcut pointcut2 = makePointcutAll();
  29. BcelAdvice p = new BcelAdvice(null, pointcut2, null, 0, -1, -1, null, null) {
  30. public boolean match(Shadow shadow, World world) {
  31. if (super.match(shadow, world)) {
  32. l.add(shadow);
  33. }
  34. return false;
  35. }
  36. };
  37. weaveTest(new String[] { "FancyHelloWorld" }, "Id2", p);
  38. checkShadowSet(l, new String[] { "method-call(void java.io.PrintStream.println(java.lang.Object))",
  39. "method-call(void java.io.PrintStream.println(java.lang.String))",
  40. "method-call(java.lang.StringBuffer java.lang.StringBuffer.append(int))",
  41. "method-call(java.lang.String java.lang.StringBuffer.toString())",
  42. "method-execution(java.lang.String FancyHelloWorld.getName())",
  43. "field-get(java.io.PrintStream java.lang.System.out)",
  44. "method-call(void java.io.PrintStream.println(java.lang.String))",
  45. "method-execution(void FancyHelloWorld.main(java.lang.String[]))", "method-call(int java.lang.String.hashCode())",
  46. "constructor-execution(void FancyHelloWorld.<init>())",
  47. "constructor-call(void java.lang.StringBuffer.<init>(java.lang.String))" });
  48. }
  49. public void testId() throws IOException {
  50. final List l = new ArrayList();
  51. BcelAdvice p = new BcelAdvice(null, makePointcutAll(), null, 0, -1, -1, null, null) {
  52. public boolean implementOn(Shadow shadow) {
  53. l.add(shadow);
  54. return true;
  55. }
  56. };
  57. weaveTest(new String[] { "HelloWorld" }, "Id2", p);
  58. checkShadowSet(l, new String[] { "method-execution(void HelloWorld.main(java.lang.String[]))",
  59. "method-call(void java.io.PrintStream.println(java.lang.String))",
  60. "field-get(java.io.PrintStream java.lang.System.out)", "constructor-execution(void HelloWorld.<init>())", });
  61. }
  62. // this test requires that Trace has been unzipped and placed in the correct place
  63. // public void testTraceId() throws IOException {
  64. // String saveClassDir = classDir;
  65. // try {
  66. // classDir = "testdata/dummyAspect.jar";
  67. //
  68. //
  69. //
  70. // final List l = new ArrayList();
  71. // BcelAdvice p = new BcelAdvice(null, makePointcutAll(), null, 0, -1, -1, null, null) {
  72. // public void implementOn(Shadow shadow) {
  73. // l.add(shadow);
  74. // }
  75. // };
  76. // boolean tempRunTests = runTests;
  77. // runTests = false;
  78. // weaveTest(new String[] {"DummyAspect"}, "Id", p);
  79. // runTests = tempRunTests;
  80. //
  81. // checkShadowSet(l, new String[] {
  82. // "constructor-execution(void DummyAspect.<init>())",
  83. // // XXX waiting on parser stuff
  84. // //"advice-execution(void DummyAspect.ajc_before_1(java.lang.Object))",
  85. // });
  86. // } finally {
  87. // classDir = saveClassDir;
  88. // }
  89. // }
  90. }