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.

CflowTest.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*******************************************************************************
  2. * Copyright (c) Jonas Bonér, Alexandre Vasseur
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Common Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/cpl-v10.html
  7. *******************************************************************************/
  8. package ataspectj;
  9. import org.aspectj.lang.annotation.Aspect;
  10. import org.aspectj.lang.annotation.Before;
  11. import org.aspectj.lang.annotation.Before;
  12. import org.aspectj.lang.JoinPoint;
  13. import org.aspectj.lang.ProceedingJoinPoint;
  14. import org.aspectj.runtime.internal.CFlowCounter;
  15. import junit.framework.TestCase;
  16. /**
  17. * Test cflow (LTW of the aspect to add cflow fields to it)
  18. *
  19. * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
  20. */
  21. public class CflowTest extends TestCase {
  22. static StringBuffer s_log = new StringBuffer();
  23. static void log(String s) {
  24. s_log.append(s).append(" ");
  25. }
  26. public static void main(String[] args) {
  27. TestHelper.runAndThrowOnFailure(suite());
  28. }
  29. public static junit.framework.Test suite() {
  30. return new junit.framework.TestSuite(CflowTest.class);
  31. }
  32. public void hello() {
  33. log("hello");
  34. }
  35. public void startCflow() {
  36. hello();
  37. }
  38. public void testCflow() {
  39. CflowTest me = new CflowTest();
  40. s_log = new StringBuffer();
  41. me.hello();
  42. assertEquals("hello ", s_log.toString());
  43. s_log = new StringBuffer();
  44. me.startCflow();
  45. assertEquals("before hello ", s_log.toString());
  46. }
  47. @Aspect
  48. public static class TestAspect {
  49. //LTW will add:
  50. //public static final CFlowCounter ajc$cflowCounter$0 = new CFlowCounter();
  51. @Before("execution(* ataspectj.CflowTest.hello(..)) && this(t) && cflow(execution(* ataspectj.CflowTest.startCflow(..)))")
  52. public void before(Object t, JoinPoint jp) {
  53. assertEquals(CflowTest.class.getName(), t.getClass().getName());
  54. try {
  55. //jp.proceed();
  56. } catch (Throwable throwable) {
  57. fail("proceed called in before Advice must be a NO-OP:" + throwable.toString());
  58. }
  59. log("before");
  60. }
  61. }
  62. }