KickJava   Java API By Example, From Geeks To Geeks.

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


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.api.debugger.jpda;
21
22 import java.util.List JavaDoc;
23 import org.netbeans.api.debugger.ActionsManager;
24 import org.netbeans.api.debugger.DebuggerManager;
25 import org.netbeans.junit.NbTestCase;
26 import org.netbeans.spi.debugger.jpda.EditorContext.Operation;
27
28
29 /**
30  * Tests JPDA expression stepping action.
31  *
32  * @author Martin Entlicher, Jan Jancura
33  */

34 public class ExpressionStepTest extends NbTestCase {
35
36     private DebuggerManager dm = DebuggerManager.getDebuggerManager ();
37     private String JavaDoc sourceRoot = System.getProperty ("test.dir.src");
38     private JPDASupport support;
39
40     public ExpressionStepTest (String JavaDoc s) {
41         super (s);
42     }
43
44     public void testExpressionStep() throws Exception JavaDoc {
45         try {
46             JPDASupport.removeAllBreakpoints ();
47             LineBreakpoint lb = LineBreakpoint.create (
48                 Utils.getURL(sourceRoot +
49                     "org/netbeans/api/debugger/jpda/testapps/ExpressionStepApp.java"),
50                 30
51             );
52             dm.addBreakpoint (lb);
53             support = JPDASupport.attach
54                 ("org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp");
55             support.waitState (JPDADebugger.STATE_STOPPED);
56             dm.removeBreakpoint (lb);
57             assertEquals (
58                 "Execution stopped in wrong class",
59                 support.getDebugger ().getCurrentCallStackFrame ().
60                     getClassName (),
61                 "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp"
62             );
63             assertEquals (
64                 "Execution stopped at wrong line",
65                 30,
66                 support.getDebugger ().getCurrentCallStackFrame ().
67                     getLineNumber (null)
68             );
69             stepCheck (
70                 ActionsManager.ACTION_STEP_OPERATION,
71                 "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp",
72                 30, 14,
73                 "factorial"
74             );
75             stepCheck (
76                 ActionsManager.ACTION_STEP_OPERATION,
77                 "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp",
78                 31, 14,
79                 "factorial",
80                 new Object JavaDoc[] {"3628800"}
81             );
82             stepCheck (
83                 ActionsManager.ACTION_STEP_OPERATION,
84                 "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp",
85                 31, 30,
86                 "factorial",
87                 new Object JavaDoc[] {"2432902008176640000"}
88             );
89             stepCheck (
90                 ActionsManager.ACTION_STEP_OPERATION,
91                 "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp",
92                 32, 14,
93                 "factorial",
94                 new Object JavaDoc[] {"2432902008176640000", "-8764578968847253504"}
95             );
96             stepCheck (
97                 ActionsManager.ACTION_STEP_OPERATION,
98                 "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp",
99                 32, 34,
100                 "factorial",
101                 new Object JavaDoc[] {"-70609262346240000"}
102             );
103             stepCheck (
104                 ActionsManager.ACTION_STEP_OPERATION,
105                 "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp",
106                 33, 37,
107                 "<init>", // "ExpressionStepApp",
108
new Object JavaDoc[] {"-70609262346240000", "-3258495067890909184"}
109             );
110             stepCheck (
111                 ActionsManager.ACTION_STEP_OPERATION,
112                 "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp",
113                 34, 20,
114                 "m2"
115             );
116             stepCheck (
117                 ActionsManager.ACTION_STEP_OPERATION,
118                 "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp",
119                 34, 13,
120                 "m1",
121                 new Object JavaDoc[] {"-899453552"}
122             );
123             
124             stepCheck (
125                 ActionsManager.ACTION_STEP_OPERATION,
126                 "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp",
127                 35, 27,
128                 "m2",
129                 new Object JavaDoc[] {"-899453552", "-404600928"}
130             );
131             stepCheck (
132                 ActionsManager.ACTION_STEP_OPERATION,
133                 "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp",
134                 35, 20,
135                 "m1",
136                 new Object JavaDoc[] {"497916032"}
137             );
138             stepCheck (
139                 ActionsManager.ACTION_STEP_OPERATION,
140                 "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp",
141                 35, 27,
142                 "m1",
143                 new Object JavaDoc[] {"497916032", "684193024"}
144             );
145             stepCheck (
146                 ActionsManager.ACTION_STEP_OPERATION,
147                 "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp",
148                 35, 13,
149                 "m3",
150                 new Object JavaDoc[] {"497916032", "684193024", "248958016"}
151             );
152             stepCheck (
153                 ActionsManager.ACTION_STEP_OPERATION,
154                 "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp",
155                 35, 13,
156                 "intValue",
157                 new Object JavaDoc[] {"497916032", "684193024", "248958016", "933151070"}
158             );
159             
160             support.doContinue ();
161             support.waitState (JPDADebugger.STATE_DISCONNECTED);
162         } finally {
163             support.doFinish ();
164         }
165     }
166
167     private void stepCheck (
168         Object JavaDoc stepType,
169         String JavaDoc clsExpected,
170         int lineExpected,
171         int column,
172         String JavaDoc methodName
173     ) {
174         try {
175             // We need to wait for all listeners to be notified and appropriate
176
// actions to be enabled/disabled
177
Thread.currentThread().sleep(10);
178         } catch (InterruptedException JavaDoc ex) {
179             ex.printStackTrace();
180         }
181         support.step (stepType);
182         assertEquals(
183             "Execution stopped in wrong class",
184             clsExpected,
185             support.getDebugger ().getCurrentCallStackFrame ().getClassName ()
186         );
187         assertEquals (
188             "Execution stopped at wrong line",
189             lineExpected,
190             support.getDebugger ().getCurrentCallStackFrame ().
191                 getLineNumber (null)
192         );
193         if (column > 0) {
194             Operation op = support.getDebugger ().getCurrentCallStackFrame ().getCurrentOperation(null);
195             assertNotNull(op);
196             assertEquals("Execution stopped at a wrong column", column, op.getMethodStartPosition().getColumn());
197         }
198         if (methodName != null) {
199             Operation op = support.getDebugger ().getCurrentCallStackFrame ().getCurrentOperation(null);
200             assertNotNull(op);
201             assertEquals("Execution stopped at a wrong method call", methodName, op.getMethodName());
202         }
203     }
204     
205     private void stepCheck (
206         Object JavaDoc stepType,
207         String JavaDoc clsExpected,
208         int lineExpected,
209         int column,
210         String JavaDoc methodName,
211         Object JavaDoc[] returnValues
212     ) {
213         stepCheck(stepType, clsExpected, lineExpected, column, methodName);
214         List JavaDoc<Operation> ops = support.getDebugger ().getCurrentThread().getLastOperations();
215         assertEquals("Different count of last operations and expected return values.", returnValues.length, ops.size());
216         for (int i = 0; i < returnValues.length; i++) {
217             Variable rv = ops.get(i).getReturnValue();
218             if (rv != null) {
219                 assertEquals("Bad return value", returnValues[i], rv.getValue());
220             }
221         }
222     }
223     
224 }
225
Popular Tags