KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.*;
23 import org.netbeans.api.debugger.DebuggerEngine;
24 import org.netbeans.api.debugger.DebuggerManager;
25 import org.netbeans.junit.NbTestCase;
26 import org.netbeans.modules.debugger.jpda.SourcePath;
27 import org.netbeans.spi.debugger.jpda.SourcePathProvider;
28
29
30 /**
31  * Tests information about stack call stacks.
32  *
33  * @author Maros Sandor
34  */

35 public class CallStackTest extends NbTestCase {
36
37
38     public CallStackTest (String JavaDoc s) {
39         super (s);
40     }
41
42     public void testInstanceCallStackInfo () throws Exception JavaDoc {
43         JPDASupport support = null;
44         try {
45             JPDASupport.removeAllBreakpoints ();
46             LineBreakpoint lb = LineBreakpoint.create (
47                 Utils.getURL(System.getProperty ("test.dir.src") +
48                              "org/netbeans/api/debugger/jpda/testapps/CallStackApp.java"),
49                 30
50             );
51             lb.setPreferredClassName("org.netbeans.api.debugger.jpda.testapps.CallStackApp");
52             DebuggerManager.getDebuggerManager ().addBreakpoint (lb);
53             support = JPDASupport.attach (
54                 "org.netbeans.api.debugger.jpda.testapps.CallStackApp"
55             );
56             support.waitState (JPDADebugger.STATE_STOPPED);
57             support.stepOver ();
58             support.stepInto ();
59             support.stepOver ();
60             support.stepInto ();
61             support.stepOver ();
62
63             CallStackFrame sf = support.getDebugger ().
64                 getCurrentCallStackFrame ();
65
66             List strata = sf.getAvailableStrata ();
67             assertEquals (
68                 "Available strata",
69                 1,
70                 strata.size ()
71             );
72             assertEquals (
73                 "Java stratum is not available",
74                 "Java",
75                 strata.get (0)
76             );
77             assertEquals (
78                 "Java stratum is not default",
79                 "Java",
80                 sf.getDefaultStratum ()
81             );
82             assertEquals (
83                 "Wrong class name",
84                 "org.netbeans.api.debugger.jpda.testapps.CallStackApp",
85                 sf.getClassName ()
86             );
87             assertEquals (
88                 "Wrong line number",
89                 49,
90                 sf.getLineNumber (null)
91             );
92             LocalVariable [] vars = sf.getLocalVariables ();
93             assertEquals (
94                 "Wrong number of local variables",
95                 1, vars.length
96             );
97             assertEquals (
98                 "Wrong info about local variables",
99                 "im2",
100                 vars [0].getName ()
101             );
102             assertEquals (
103                 "Wrong info about current method",
104                 "m2",
105                 sf.getMethodName ()
106             );
107             assertNotNull (
108                 "Wrong info about this object",
109                 sf.getThisVariable ()
110             );
111             assertFalse (
112                 "Wrong info about obsolete method",
113                 sf.isObsolete ()
114             );
115
116             JPDAThread thread = sf.getThread ();
117             assertEquals (
118                 "Callstack and Thread info mismatch",
119                 thread.getCallStack () [0],
120                 sf
121             );
122             assertEquals (
123                 "Callstack and Thread info mismatch",
124                 thread.getClassName (),
125                 sf.getClassName ()
126             );
127             assertEquals (
128                 "Callstack and Thread info mismatch",
129                 thread.getMethodName (),
130                 sf.getMethodName ()
131             );
132             assertEquals (
133                 "Callstack and Thread info mismatch",
134                 thread.getSourceName (null),
135                 sf.getSourceName (null)
136             );
137         } finally {
138             if (support != null)
139                 support.doFinish ();
140         }
141     }
142
143     public void testStaticCallStackInfo() throws Exception JavaDoc {
144         JPDASupport support = null;
145         try {
146             JPDASupport.removeAllBreakpoints ();
147             LineBreakpoint lb = LineBreakpoint.create (
148                 Utils.getURL(System.getProperty ("test.dir.src") +
149                              "org/netbeans/api/debugger/jpda/testapps/CallStackApp.java"),
150                 30
151             );
152             lb.setPreferredClassName("org.netbeans.api.debugger.jpda.testapps.CallStackApp");
153             DebuggerManager.getDebuggerManager ().addBreakpoint (lb);
154             support = JPDASupport.attach (
155                 "org.netbeans.api.debugger.jpda.testapps.CallStackApp"
156             );
157             support.waitState (JPDADebugger.STATE_STOPPED);
158             CallStackFrame sf = support.getDebugger ().
159                 getCurrentCallStackFrame ();
160
161             List strata = sf.getAvailableStrata ();
162             assertEquals (
163                 "Available strata", 1, strata.size ()
164             );
165             assertEquals (
166                 "Java stratum is not available", "Java", strata.get (0)
167             );
168             assertEquals (
169                 "Java stratum is not default", "Java", sf.getDefaultStratum ()
170             );
171             assertEquals (
172                 "Wrong class name",
173                 "org.netbeans.api.debugger.jpda.testapps.CallStackApp",
174                 sf.getClassName ()
175             );
176             assertEquals (
177                 "Wrong line number",
178                 30,
179                 sf.getLineNumber (null)
180             );
181
182             LocalVariable [] vars = sf.getLocalVariables ();
183             assertEquals (
184                 "Wrong number of local variables", 1, vars.length
185             );
186             assertEquals (
187                 "Wrong info about local variables",
188                 "args",
189                 vars[0].getName ()
190             );
191             assertEquals (
192                 "Wrong info about current method",
193                 "main",
194                 sf.getMethodName ()
195             );
196             assertNull (
197                 "Wrong info about this object", sf.getThisVariable ()
198             );
199             assertFalse (
200                 "Wrong info about obsolete method", sf.isObsolete ()
201             );
202
203             JPDAThread thread = sf.getThread();
204             assertEquals (
205                 "Callstack and Thread info mismatch",
206                 thread.getCallStack () [0],
207                 sf
208             );
209             assertEquals (
210                 "Callstack and Thread info mismatch",
211                 thread.getClassName (),
212                 sf.getClassName ()
213             );
214             assertEquals (
215                 "Callstack and Thread info mismatch",
216                 thread.getMethodName (),
217                 sf.getMethodName ()
218             );
219             assertEquals (
220                 "Callstack and Thread info mismatch",
221                 thread.getSourceName (null),
222                 sf.getSourceName (null)
223             );
224         } finally {
225             if (support != null)
226                 support.doFinish ();
227         }
228     }
229 }
230
Popular Tags