1   /***************************************************************************************
2    * Copyright (c) Jonas Bonér, Alexandre Vasseur. All rights reserved.                 *
3    * http://aspectwerkz.codehaus.org                                                    *
4    * ---------------------------------------------------------------------------------- *
5    * The software in this package is published under the terms of the LGPL license      *
6    * a copy of which has been included with this distribution in the license.txt file.  *
7    **************************************************************************************/
8   package test;
9   
10  import junit.framework.TestCase;
11  
12  /***
13   * test "pc AND (cf OR cf2)"
14   * 
15   * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér</a>
16   * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
17   */
18  public class CFlowTest extends TestCase implements Loggable {
19      private String m_logString = "";
20  
21      public CFlowTest(String name) {
22          super(name);
23      }
24  
25      public void testCallWithinCFlow() {
26          m_logString = "";
27          step1(); //will have cflow and will call step2()
28          assertEquals("step1 advice-before step2 advice-after ", m_logString);
29      }
30  
31      public void testCallWithinCFlowAnonymous() {
32          m_logString = "";
33          step1Anonymous(); //will have cflow and will call step2()
34          assertEquals(
35              "step1Anonymous advice-beforeAnonymous step2Anonymous advice-afterAnonymous ",
36              m_logString);
37      }
38  
39      public void testCallWithinCFlowWithinCflow() {
40          m_logString = "";
41          step1_A(); //will have cflow and will call step1_B that will call step2_B()
42          assertEquals("step1_A step1_B advice-before2 step2_B advice-after2 ", m_logString);
43      }
44  
45      public void testCallOutsideCFlow() {
46          m_logString = "";
47          step2();
48          assertEquals("step2 ", m_logString);
49      }
50  
51      public void testCallWithinCFlow_B() {
52          m_logString = "";
53          step1_B(); //will have cflow and will call step2_B() but is NOT in step1_A cflow
54          assertEquals("step1_B step2_B ", m_logString);
55      }
56  
57      public void testCallOutsideCFlowAnonymous() {
58          m_logString = "";
59          step2Anonymous();
60          assertEquals("step2Anonymous ", m_logString);
61      }
62  
63  //    //FIXME: see the aspect, pc is deactivated - see AW-251
64  //    public void testCallWithinNotCFlow_C() {
65  //        m_logString = "";
66  //        step1_C(); //will have "NOT cflow" and will call step2_C
67  //        assertEquals("step1_C step2_C ", m_logString);
68  //        m_logString = "";
69  //        step2_C(); //should be advised since not in step1_C cflow
70  //        assertEquals("advice-beforeC step2_C advice-afterC ", m_logString);
71  //    }
72  
73      public static void main(String[] args) {
74          junit.textui.TestRunner.run(suite());
75      }
76  
77      public static junit.framework.Test suite() {
78          return new junit.framework.TestSuite(CFlowTest.class);
79      }
80  
81      // ==== methods to test ====
82      public void log(final String wasHere) {
83          m_logString += wasHere;
84      }
85  
86      public void step1() {
87          log("step1 ");
88          step2();
89      }
90  
91      public void step1Anonymous() {
92          log("step1Anonymous ");
93          step2Anonymous();
94      }
95  
96      public void step1_B() {
97          log("step1_B ");
98          step2_B();
99      }
100 
101     public void step1_A() {
102         log("step1_A ");
103         step1_B();
104     }
105 
106     public void step2() {
107         log("step2 ");
108     }
109 
110     public void step2Anonymous() {
111         log("step2Anonymous ");
112     }
113 
114     public void step2_B() {
115         log("step2_B ");
116     }
117 
118     public void step1_C() {
119         log("step1_C ");
120         step2_C();
121     }
122 
123     public void step2_C() {
124         log("step2_C ");
125     }
126 }