KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > debugger > jpda > AsynchStepTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.api.debugger.jpda;
21
22 import org.netbeans.api.debugger.ActionsManager;
23 import org.netbeans.api.debugger.ActionsManagerListener;
24 import org.netbeans.api.debugger.DebuggerManager;
25 import org.netbeans.junit.NbTestCase;
26
27
28 /**
29  * Tests JPDA stepping actions: step in, step out and step over.
30  *
31  * @author Maros Sandor, Jan Jancura
32  */

33 public class AsynchStepTest extends NbTestCase {
34
35     private DebuggerManager dm = DebuggerManager.getDebuggerManager ();
36     private String JavaDoc sourceRoot = System.getProperty ("test.dir.src");
37     private JPDASupport support;
38
39     public AsynchStepTest (String JavaDoc s) {
40         super (s);
41     }
42
43     public void testStepOver () throws Exception JavaDoc {
44         try {
45             JPDASupport.removeAllBreakpoints ();
46             LineBreakpoint lb = LineBreakpoint.create (
47                 Utils.getURL(sourceRoot +
48                     "org/netbeans/api/debugger/jpda/testapps/AsynchStepApp.java"),
49                 30
50             );
51             dm.addBreakpoint (lb);
52             support = JPDASupport.attach
53                 ("org.netbeans.api.debugger.jpda.testapps.AsynchStepApp");
54             support.waitState (JPDADebugger.STATE_STOPPED);
55             dm.removeBreakpoint (lb);
56             assertEquals (
57                 "Execution stopped in wrong class",
58                 support.getDebugger ().getCurrentCallStackFrame ().
59                     getClassName (),
60                 "org.netbeans.api.debugger.jpda.testapps.AsynchStepApp"
61             );
62             assertEquals (
63                 "Execution stopped at wrong line",
64                 30,
65                 support.getDebugger ().getCurrentCallStackFrame ().
66                     getLineNumber (null)
67             );
68             stepCheck (
69                 ActionsManager.ACTION_STEP_OVER,
70                 "org.netbeans.api.debugger.jpda.testapps.AsynchStepApp",
71                 31
72             );
73             stepCheck (
74                 ActionsManager.ACTION_STEP_OVER,
75                 "org.netbeans.api.debugger.jpda.testapps.AsynchStepApp",
76                 32
77             );
78             stepCheck (
79                 ActionsManager.ACTION_STEP_OVER,
80                 "org.netbeans.api.debugger.jpda.testapps.AsynchStepApp",
81                 33
82             );
83             stepCheck (
84                 ActionsManager.ACTION_STEP_OVER,
85                 "org.netbeans.api.debugger.jpda.testapps.AsynchStepApp",
86                 34
87             );
88             stepCheck (
89                 ActionsManager.ACTION_STEP_OVER,
90                 "org.netbeans.api.debugger.jpda.testapps.AsynchStepApp",
91                 35
92             );
93             support.doContinue ();
94             support.waitState (JPDADebugger.STATE_DISCONNECTED);
95         } finally {
96             if (support != null) {
97                 support.doFinish ();
98             }
99         }
100     }
101
102     public void testStepInto () throws Exception JavaDoc {
103         try {
104             JPDASupport.removeAllBreakpoints ();
105             LineBreakpoint lb = LineBreakpoint.create (
106                 Utils.getURL(sourceRoot +
107                     "org/netbeans/api/debugger/jpda/testapps/AsynchStepApp.java"),
108                 30
109             );
110             dm.addBreakpoint (lb);
111             support = JPDASupport.attach
112                 ("org.netbeans.api.debugger.jpda.testapps.AsynchStepApp");
113             support.waitState (JPDADebugger.STATE_STOPPED);
114             dm.removeBreakpoint (lb);
115             assertEquals (
116                 "Execution stopped in wrong class",
117                 support.getDebugger ().getCurrentCallStackFrame ().
118                     getClassName (),
119                 "org.netbeans.api.debugger.jpda.testapps.AsynchStepApp"
120             );
121             assertEquals (
122                 "Execution stopped at wrong line",
123                 30,
124                 support.getDebugger ().getCurrentCallStackFrame ().
125                     getLineNumber (null)
126             );
127
128             stepCheck (
129                 ActionsManager.ACTION_STEP_INTO,
130                 "org.netbeans.api.debugger.jpda.testapps.AsynchStepApp",
131                 38
132             );
133 // stepCheck (ActionsManager.ACTION_STEP_INTO, "java.lang.Object", -1);
134
stepCheck (
135                 ActionsManager.ACTION_STEP_OVER,
136                 "org.netbeans.api.debugger.jpda.testapps.AsynchStepApp",
137                 39
138             );
139             stepCheck (
140                 ActionsManager.ACTION_STEP_OVER,
141                 "org.netbeans.api.debugger.jpda.testapps.AsynchStepApp",
142                 30
143             );
144             stepCheck (
145                 ActionsManager.ACTION_STEP_OVER,
146                 "org.netbeans.api.debugger.jpda.testapps.AsynchStepApp",
147                 31
148             );
149             stepCheck (
150                 ActionsManager.ACTION_STEP_INTO,
151                 "org.netbeans.api.debugger.jpda.testapps.AsynchStepApp",
152                 42
153             );
154             stepCheck (
155                 ActionsManager.ACTION_STEP_OVER,
156                 "org.netbeans.api.debugger.jpda.testapps.AsynchStepApp",
157                 43
158             );
159             stepCheck (
160                 ActionsManager.ACTION_STEP_INTO,
161                 "org.netbeans.api.debugger.jpda.testapps.AsynchStepApp",
162                 48
163             );
164
165             support.doContinue ();
166             support.waitState (JPDADebugger.STATE_DISCONNECTED);
167         } finally {
168             if (support != null) {
169                 support.doFinish ();
170             }
171         }
172     }
173
174     public void testStepOut () throws Exception JavaDoc {
175         try {
176             JPDASupport.removeAllBreakpoints ();
177             LineBreakpoint lb = LineBreakpoint.create (
178                 Utils.getURL(sourceRoot +
179                     "org/netbeans/api/debugger/jpda/testapps/AsynchStepApp.java"),
180                 30
181             );
182             dm.addBreakpoint (lb);
183             support = JPDASupport.attach
184                 ("org.netbeans.api.debugger.jpda.testapps.AsynchStepApp");
185             support.waitState (JPDADebugger.STATE_STOPPED);
186             dm.removeBreakpoint (lb);
187             assertEquals (
188                 "Execution stopped in wrong class",
189                 support.getDebugger ().getCurrentCallStackFrame ().
190                     getClassName (),
191                 "org.netbeans.api.debugger.jpda.testapps.AsynchStepApp"
192             );
193             assertEquals (
194                 "Execution stopped at wrong line",
195                 30,
196                 support.getDebugger ().getCurrentCallStackFrame ().
197                     getLineNumber (null)
198             );
199             stepCheck (
200                 ActionsManager.ACTION_STEP_OVER,
201                 "org.netbeans.api.debugger.jpda.testapps.AsynchStepApp",
202                 31
203             );
204             stepCheck (
205                 ActionsManager.ACTION_STEP_INTO,
206                 "org.netbeans.api.debugger.jpda.testapps.AsynchStepApp",
207                 42
208             );
209             stepCheck (
210                 ActionsManager.ACTION_STEP_OVER,
211                 "org.netbeans.api.debugger.jpda.testapps.AsynchStepApp",
212                 43
213             );
214             stepCheck (
215                 ActionsManager.ACTION_STEP_INTO,
216                 "org.netbeans.api.debugger.jpda.testapps.AsynchStepApp",
217                 48
218             );
219             stepCheck (
220                 ActionsManager.ACTION_STEP_OUT,
221                 "org.netbeans.api.debugger.jpda.testapps.AsynchStepApp",
222                 43
223             );
224             stepCheck (
225                 ActionsManager.ACTION_STEP_OUT,
226                 "org.netbeans.api.debugger.jpda.testapps.AsynchStepApp",
227                 31
228             );
229
230             support.doContinue ();
231             support.waitState (JPDADebugger.STATE_DISCONNECTED);
232         } finally {
233             if (support != null) {
234                 support.doFinish ();
235             }
236         }
237     }
238
239     private void stepCheck (
240         final Object JavaDoc stepType,
241         String JavaDoc clsExpected,
242         int lineExpected
243     ) {
244         final boolean[] waitLock = new boolean[] { false };
245         support.stepAsynch (stepType, new ActionsManagerListener() {
246             public void actionPerformed(Object JavaDoc action) {
247                 if (stepType == action) {
248                     synchronized (waitLock) {
249                         waitLock[0] = true;
250                         waitLock.notify();
251                     }
252                 }
253             }
254             public void actionStateChanged(Object JavaDoc action, boolean enabled) {
255             }
256         });
257         synchronized (waitLock) {
258             try {
259                 waitLock.wait(10000);
260             } catch (InterruptedException JavaDoc iex) {
261             }
262             assertEquals("Asynchronous action did not notify...", true, waitLock[0]);
263         }
264         // The asynchronous action has finished, wait for the debugger to stop...
265
support.waitState (JPDADebugger.STATE_STOPPED);
266         assertEquals(
267             "Execution stopped in wrong class",
268             clsExpected,
269             support.getDebugger ().getCurrentCallStackFrame ().getClassName ()
270         );
271         assertEquals (
272             "Execution stopped at wrong line",
273             lineExpected,
274             support.getDebugger ().getCurrentCallStackFrame ().
275                 getLineNumber (null)
276         );
277     }
278 }
279
Popular Tags