001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.api.debugger.jpda;
043:
044: import java.util.*;
045: import org.netbeans.api.debugger.DebuggerManager;
046: import org.netbeans.junit.NbTestCase;
047:
048: /**
049: * Tests information about local variables.
050: *
051: * @author Maros Sandor, Jan Jancura
052: */
053: public class LocalVariablesTest extends NbTestCase {
054:
055: private JPDASupport support;
056: private DebuggerManager dm = DebuggerManager.getDebuggerManager();
057:
058: private static final String CLASS_NAME = "org.netbeans.api.debugger.jpda.testapps.LocalVariablesApp";
059:
060: public LocalVariablesTest(String s) {
061: super (s);
062: }
063:
064: public void testWatches() throws Exception {
065: try {
066: Utils.BreakPositions bp = Utils
067: .getBreakPositions(System
068: .getProperty("test.dir.src")
069: + "org/netbeans/api/debugger/jpda/testapps/LocalVariablesApp.java");
070: LineBreakpoint lb = bp.getLineBreakpoints().get(0);
071: dm.addBreakpoint(lb);
072:
073: support = JPDASupport.attach(CLASS_NAME);
074:
075: support.waitState(JPDADebugger.STATE_STOPPED); // breakpoint hit
076:
077: CallStackFrame sf = support.getDebugger()
078: .getCurrentCallStackFrame();
079: assertEquals("Debugger stopped at wrong line", lb
080: .getLineNumber(), sf.getLineNumber(null));
081:
082: LocalVariable[] vars = sf.getLocalVariables();
083: assertEquals("Wrong number of local variables", 4,
084: vars.length);
085: Arrays.sort(vars, new Comparator() {
086: public int compare(Object o1, Object o2) {
087: return ((LocalVariable) o1).getName().compareTo(
088: ((LocalVariable) o2).getName());
089: }
090: });
091: assertEquals("Wrong info about local variables", "g",
092: vars[0].getName());
093: assertEquals("Wrong info about local variables", "20",
094: vars[0].getValue());
095: assertEquals("Wrong info about local variables", "int",
096: vars[0].getDeclaredType());
097: assertEquals("Wrong info about local variables", "int",
098: vars[0].getType());
099: assertEquals("Wrong info about local variables",
100: CLASS_NAME, vars[0].getClassName());
101:
102: assertEquals("Wrong info about local variables", "s",
103: vars[1].getName());
104: assertEquals("Wrong info about local variables",
105: "\"asdfghjkl\"", vars[1].getValue());
106: assertEquals("Wrong info about local variables",
107: "java.lang.Object", vars[1].getDeclaredType());
108: assertEquals("Wrong info about local variables",
109: "java.lang.String", vars[1].getType());
110: assertEquals("Wrong info about local variables",
111: CLASS_NAME, vars[1].getClassName());
112:
113: assertEquals("Wrong info about local variables", "x",
114: vars[2].getName());
115: assertEquals("Wrong info about local variables", "40",
116: vars[2].getValue());
117: assertEquals("Wrong info about local variables", "int",
118: vars[2].getDeclaredType());
119: assertEquals("Wrong info about local variables", "int",
120: vars[2].getType());
121: assertEquals("Wrong info about local variables",
122: CLASS_NAME, vars[2].getClassName());
123:
124: assertEquals("Wrong info about local variables", "y",
125: vars[3].getName());
126: assertEquals("Wrong info about local variables", "50.5",
127: vars[3].getValue());
128: assertEquals("Wrong info about local variables", "float",
129: vars[3].getDeclaredType());
130: assertEquals("Wrong info about local variables", "float",
131: vars[3].getType());
132: assertEquals("Wrong info about local variables",
133: CLASS_NAME, vars[3].getClassName());
134:
135: support.stepOver();
136: support.stepOver();
137:
138: sf = support.getDebugger().getCurrentCallStackFrame();
139: vars = sf.getLocalVariables();
140: assertEquals("Wrong number of local variables", 4,
141: vars.length);
142: Arrays.sort(vars, new Comparator() {
143: public int compare(Object o1, Object o2) {
144: return ((LocalVariable) o1).getName().compareTo(
145: ((LocalVariable) o2).getName());
146: }
147: });
148: assertEquals("Wrong info about local variables", "g",
149: vars[0].getName());
150: assertEquals("Wrong info about local variables", "\"ad\"",
151: vars[0].getValue());
152: assertEquals("Wrong info about local variables",
153: "java.lang.CharSequence", vars[0].getDeclaredType());
154: assertEquals("Wrong info about local variables",
155: "java.lang.String", vars[0].getType());
156: assertEquals("Wrong info about local variables",
157: CLASS_NAME, vars[0].getClassName());
158:
159: } finally {
160: support.doFinish();
161: }
162: }
163: }
|