KickJava   Java API By Example, From Geeks To Geeks.

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


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.net.URL JavaDoc;
23 import java.util.*;
24 import org.netbeans.api.debugger.DebuggerManager;
25 import org.netbeans.junit.NbTestCase;
26
27 /**
28  * Tests information about local variables.
29  *
30  * @author Maros Sandor, Jan Jancura
31  */

32 public class LocalVariablesTest extends NbTestCase {
33
34     private JPDASupport support;
35     private DebuggerManager dm = DebuggerManager.getDebuggerManager ();
36
37     private static final String JavaDoc CLASS_NAME =
38         "org.netbeans.api.debugger.jpda.testapps.LocalVariablesApp";
39
40
41     public LocalVariablesTest(String JavaDoc s) {
42         super(s);
43     }
44
45     public void testWatches () throws Exception JavaDoc {
46         try {
47             LineBreakpoint lb = LineBreakpoint.create (
48                     Utils.getURL(System.getProperty ("test.dir.src") +
49                                  "org/netbeans/api/debugger/jpda/testapps/LocalVariablesApp.java"),
50                     40);
51             lb.setPreferredClassName(CLASS_NAME);
52             dm.addBreakpoint (lb);
53
54             support = JPDASupport.attach (CLASS_NAME);
55
56             support.waitState (JPDADebugger.STATE_STOPPED); // breakpoint hit
57

58             CallStackFrame sf = support.getDebugger ().getCurrentCallStackFrame ();
59             assertEquals (
60                 "Debugger stopped at wrong line",
61                 lb.getLineNumber (),
62                 sf.getLineNumber (null)
63             );
64
65             LocalVariable [] vars = sf.getLocalVariables ();
66             assertEquals (
67                 "Wrong number of local variables",
68                 4,
69                 vars.length
70             );
71             Arrays.sort (vars, new Comparator () {
72                 public int compare (Object JavaDoc o1, Object JavaDoc o2) {
73                     return ((LocalVariable) o1).getName ().compareTo (
74                         ((LocalVariable) o2).getName ()
75                     );
76                 }
77             });
78             assertEquals (
79                 "Wrong info about local variables",
80                 "g",
81                 vars [0].getName ()
82             );
83             assertEquals (
84                 "Wrong info about local variables",
85                 "20",
86                 vars [0].getValue ()
87             );
88             assertEquals (
89                 "Wrong info about local variables",
90                 "int",
91                 vars [0].getDeclaredType ()
92             );
93             assertEquals (
94                 "Wrong info about local variables",
95                 "int",
96                 vars [0].getType ()
97             );
98             assertEquals (
99                 "Wrong info about local variables",
100                 CLASS_NAME,
101                 vars [0].getClassName ()
102             );
103
104             assertEquals (
105                 "Wrong info about local variables",
106                 "s",
107                 vars [1].getName ()
108             );
109             assertEquals (
110                 "Wrong info about local variables",
111                 "\"asdfghjkl\"",
112                 vars [1].getValue ()
113             );
114             assertEquals (
115                 "Wrong info about local variables",
116                 "java.lang.Object",
117                 vars [1].getDeclaredType ()
118             );
119             assertEquals (
120                 "Wrong info about local variables",
121                 "java.lang.String",
122                 vars [1].getType ()
123             );
124             assertEquals (
125                 "Wrong info about local variables",
126                 CLASS_NAME,
127                 vars [1].getClassName ()
128             );
129
130             assertEquals (
131                 "Wrong info about local variables",
132                 "x",
133                 vars [2].getName ()
134             );
135             assertEquals (
136                 "Wrong info about local variables",
137                 "40",
138                 vars [2].getValue ()
139             );
140             assertEquals (
141                 "Wrong info about local variables",
142                 "int",
143                 vars [2].getDeclaredType ()
144             );
145             assertEquals (
146                 "Wrong info about local variables",
147                 "int",
148                 vars [2].getType ()
149             );
150             assertEquals (
151                 "Wrong info about local variables",
152                 CLASS_NAME,
153                 vars [2].getClassName ()
154             );
155
156             assertEquals (
157                 "Wrong info about local variables",
158                 "y",
159                 vars [3].getName ()
160             );
161             assertEquals (
162                 "Wrong info about local variables",
163                 "50.5",
164                 vars [3].getValue ()
165             );
166             assertEquals (
167                 "Wrong info about local variables",
168                 "float",
169                 vars [3].getDeclaredType ()
170              );
171             assertEquals (
172                 "Wrong info about local variables",
173                 "float",
174                 vars [3].getType ()
175             );
176             assertEquals (
177                 "Wrong info about local variables",
178                 CLASS_NAME,
179                 vars [3].getClassName ()
180             );
181
182             support.stepOver ();
183             support.stepOver ();
184
185             sf = support.getDebugger ().getCurrentCallStackFrame ();
186             vars = sf.getLocalVariables ();
187             assertEquals ("Wrong number of local variables", 4, vars.length);
188             Arrays.sort (vars, new Comparator () {
189                 public int compare (Object JavaDoc o1, Object JavaDoc o2) {
190                     return ((LocalVariable) o1).getName ().compareTo (
191                         ((LocalVariable) o2).getName ()
192                     );
193                 }
194             });
195             assertEquals (
196                 "Wrong info about local variables",
197                 "g",
198                 vars [0].getName ()
199             );
200             assertEquals (
201                 "Wrong info about local variables",
202                 "\"ad\"",
203                 vars [0].getValue ()
204             );
205             assertEquals (
206                 "Wrong info about local variables",
207                 "java.lang.CharSequence",
208                 vars [0].getDeclaredType ()
209             );
210             assertEquals (
211                 "Wrong info about local variables",
212                 "java.lang.String",
213                 vars [0].getType ()
214              );
215             assertEquals (
216                 "Wrong info about local variables",
217                 CLASS_NAME,
218                 vars [0].getClassName ()
219             );
220
221         } finally {
222             support.doFinish ();
223         }
224     }
225 }
226
Popular Tags