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.

PatternWeaveTestCase.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.bcel;
  13. import java.io.*;
  14. import java.util.*;
  15. import org.aspectj.weaver.*;
  16. import org.aspectj.weaver.patterns.*;
  17. public class PatternWeaveTestCase extends WeaveTestCase {
  18. {
  19. regenerate = false;
  20. }
  21. public PatternWeaveTestCase(String name) {
  22. super(name);
  23. }
  24. String[] none = new String[0];
  25. //XXX this test is incompatible with optimizations made to weaver
  26. public void testPublic() throws IOException {
  27. String[] publicHello = new String[] {
  28. "method-execution(void HelloWorld.main(java.lang.String[]))",
  29. };
  30. String[] publicFancyHello = new String[] {
  31. "method-execution(void FancyHelloWorld.main(java.lang.String[]))",
  32. "method-execution(java.lang.String FancyHelloWorld.getName())",
  33. };
  34. checkPointcut("execution(public * *(..))", publicHello, publicFancyHello);
  35. }
  36. //
  37. // public void testPrintln() throws IOException {
  38. // String[] callPrintlnHello = new String[] {
  39. // "method-call(void java.io.PrintStream.println(java.lang.String))",
  40. // };
  41. // String[] callPrintlnFancyHello = new String[] {
  42. // "method-call(void java.io.PrintStream.println(java.lang.String))",
  43. // "method-call(void java.io.PrintStream.println(java.lang.String))",
  44. // "method-call(void java.io.PrintStream.println(java.lang.Object))",
  45. // };
  46. // checkPointcut("call(* println(*))", callPrintlnHello, callPrintlnFancyHello);
  47. // }
  48. //
  49. // public void testMumble() throws IOException {
  50. // checkPointcut("call(* mumble(*))", none, none);
  51. // }
  52. //
  53. // public void testFooBar() throws IOException {
  54. // checkPointcut("call(FooBar *(..))", none, none);
  55. // }
  56. //
  57. // public void testGetOut() throws IOException {
  58. // String[] getOutHello = new String[] {
  59. // "field-get(java.io.PrintStream java.lang.System.out)",
  60. // };
  61. //
  62. // checkPointcut("get(* java.lang.System.out)", getOutHello, getOutHello);
  63. // }
  64. //
  65. //// private Pointcut makePointcut(String s) {
  66. //// return new PatternParser(s).parsePointcut();
  67. //// }
  68. //
  69. private void checkPointcut(String pointcutSource, String[] expectedHelloShadows,
  70. String[] expectedFancyShadows) throws IOException
  71. {
  72. Pointcut sp = Pointcut.fromString(pointcutSource);
  73. Pointcut rp = sp.resolve(new SimpleScope(world, FormalBinding.NONE));
  74. Pointcut cp = rp.concretize(ResolvedTypeX.MISSING, 0);
  75. final List l = new ArrayList();
  76. BcelAdvice p = new BcelAdvice(null, cp, null, 0, -1, -1, null, null) {
  77. public void implementOn(Shadow shadow) {
  78. l.add(shadow);
  79. }
  80. };
  81. weaveTest(new String[] {"HelloWorld"}, "PatternWeave", p);
  82. checkShadowSet(l, expectedHelloShadows);
  83. l.clear();
  84. weaveTest(new String[] {"FancyHelloWorld"}, "PatternWeave", p);
  85. checkShadowSet(l, expectedFancyShadows);
  86. checkSerialize(rp);
  87. }
  88. public void checkSerialize(Pointcut p) throws IOException {
  89. ByteArrayOutputStream bo = new ByteArrayOutputStream();
  90. DataOutputStream out = new DataOutputStream(bo);
  91. p.write(out);
  92. out.close();
  93. ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray());
  94. VersionedDataInputStream in = new VersionedDataInputStream(bi);
  95. Pointcut newP = Pointcut.read(in, null);
  96. assertEquals("write/read", p, newP);
  97. }
  98. }