Index: debuggerjpda/test/unit/src/org/netbeans/api/debugger/jpda/ExpressionStepTest.java diff -u /dev/null debuggerjpda/test/unit/src/org/netbeans/api/debugger/jpda/ExpressionStepTest.java:1.1.2.1 --- /dev/null Thu Feb 1 11:02:02 2007 +++ debuggerjpda/test/unit/src/org/netbeans/api/debugger/jpda/ExpressionStepTest.java Thu Feb 1 09:33:20 2007 @@ -0,0 +1,224 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.api.debugger.jpda; + +import java.util.List; +import org.netbeans.api.debugger.ActionsManager; +import org.netbeans.api.debugger.DebuggerManager; +import org.netbeans.junit.NbTestCase; +import org.netbeans.spi.debugger.jpda.EditorContext.Operation; + + +/** + * Tests JPDA expression stepping action. + * + * @author Martin Entlicher, Jan Jancura + */ +public class ExpressionStepTest extends NbTestCase { + + private DebuggerManager dm = DebuggerManager.getDebuggerManager (); + private String sourceRoot = System.getProperty ("test.dir.src"); + private JPDASupport support; + + public ExpressionStepTest (String s) { + super (s); + } + + public void testExpressionStep() throws Exception { + try { + JPDASupport.removeAllBreakpoints (); + LineBreakpoint lb = LineBreakpoint.create ( + Utils.getURL(sourceRoot + + "org/netbeans/api/debugger/jpda/testapps/ExpressionStepApp.java"), + 30 + ); + dm.addBreakpoint (lb); + support = JPDASupport.attach + ("org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp"); + support.waitState (JPDADebugger.STATE_STOPPED); + dm.removeBreakpoint (lb); + assertEquals ( + "Execution stopped in wrong class", + support.getDebugger ().getCurrentCallStackFrame (). + getClassName (), + "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp" + ); + assertEquals ( + "Execution stopped at wrong line", + 30, + support.getDebugger ().getCurrentCallStackFrame (). + getLineNumber (null) + ); + stepCheck ( + ActionsManager.ACTION_STEP_OPERATION, + "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", + 30, 14, + "factorial" + ); + stepCheck ( + ActionsManager.ACTION_STEP_OPERATION, + "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", + 31, 14, + "factorial", + new Object[] {"3628800"} + ); + stepCheck ( + ActionsManager.ACTION_STEP_OPERATION, + "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", + 31, 30, + "factorial", + new Object[] {"2432902008176640000"} + ); + stepCheck ( + ActionsManager.ACTION_STEP_OPERATION, + "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", + 32, 14, + "factorial", + new Object[] {"2432902008176640000", "-8764578968847253504"} + ); + stepCheck ( + ActionsManager.ACTION_STEP_OPERATION, + "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", + 32, 34, + "factorial", + new Object[] {"-70609262346240000"} + ); + stepCheck ( + ActionsManager.ACTION_STEP_OPERATION, + "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", + 33, 37, + "", // "ExpressionStepApp", + new Object[] {"-70609262346240000", "-3258495067890909184"} + ); + stepCheck ( + ActionsManager.ACTION_STEP_OPERATION, + "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", + 34, 20, + "m2" + ); + stepCheck ( + ActionsManager.ACTION_STEP_OPERATION, + "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", + 34, 13, + "m1", + new Object[] {"-899453552"} + ); + + stepCheck ( + ActionsManager.ACTION_STEP_OPERATION, + "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", + 35, 27, + "m2", + new Object[] {"-899453552", "-404600928"} + ); + stepCheck ( + ActionsManager.ACTION_STEP_OPERATION, + "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", + 35, 20, + "m1", + new Object[] {"497916032"} + ); + stepCheck ( + ActionsManager.ACTION_STEP_OPERATION, + "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", + 35, 27, + "m1", + new Object[] {"497916032", "684193024"} + ); + stepCheck ( + ActionsManager.ACTION_STEP_OPERATION, + "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", + 35, 13, + "m3", + new Object[] {"497916032", "684193024", "248958016"} + ); + stepCheck ( + ActionsManager.ACTION_STEP_OPERATION, + "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", + 35, 13, + "intValue", + new Object[] {"497916032", "684193024", "248958016", "933151070"} + ); + + support.doContinue (); + support.waitState (JPDADebugger.STATE_DISCONNECTED); + } finally { + support.doFinish (); + } + } + + private void stepCheck ( + Object stepType, + String clsExpected, + int lineExpected, + int column, + String methodName + ) { + try { + // We need to wait for all listeners to be notified and appropriate + // actions to be enabled/disabled + Thread.currentThread().sleep(10); + } catch (InterruptedException ex) { + ex.printStackTrace(); + } + support.step (stepType); + assertEquals( + "Execution stopped in wrong class", + clsExpected, + support.getDebugger ().getCurrentCallStackFrame ().getClassName () + ); + assertEquals ( + "Execution stopped at wrong line", + lineExpected, + support.getDebugger ().getCurrentCallStackFrame (). + getLineNumber (null) + ); + if (column > 0) { + Operation op = support.getDebugger ().getCurrentCallStackFrame ().getCurrentOperation(null); + assertNotNull(op); + assertEquals("Execution stopped at a wrong column", column, op.getMethodStartPosition().getColumn()); + } + if (methodName != null) { + Operation op = support.getDebugger ().getCurrentCallStackFrame ().getCurrentOperation(null); + assertNotNull(op); + assertEquals("Execution stopped at a wrong method call", methodName, op.getMethodName()); + } + } + + private void stepCheck ( + Object stepType, + String clsExpected, + int lineExpected, + int column, + String methodName, + Object[] returnValues + ) { + stepCheck(stepType, clsExpected, lineExpected, column, methodName); + List ops = support.getDebugger ().getCurrentThread().getLastOperations(); + assertEquals("Different count of last operations and expected return values.", returnValues.length, ops.size()); + for (int i = 0; i < returnValues.length; i++) { + Variable rv = ops.get(i).getReturnValue(); + if (rv != null) { + assertEquals("Bad return value", returnValues[i], rv.getValue()); + } + } + } + +} Index: debuggerjpda/test/unit/src/org/netbeans/api/debugger/jpda/test/TestContextProvider.java diff -u debuggerjpda/test/unit/src/org/netbeans/api/debugger/jpda/test/TestContextProvider.java:1.12 debuggerjpda/test/unit/src/org/netbeans/api/debugger/jpda/test/TestContextProvider.java:1.9.70.2 --- debuggerjpda/test/unit/src/org/netbeans/api/debugger/jpda/test/TestContextProvider.java:1.12 Thu Sep 21 01:35:46 2006 +++ debuggerjpda/test/unit/src/org/netbeans/api/debugger/jpda/test/TestContextProvider.java Thu Feb 1 09:33:21 2007 @@ -123,6 +123,140 @@ return url; } + public Operation[] getOperations(String url, final int lineNumber, + final BytecodeProvider bytecodeProvider) { + //EditorContextImpl impl = new EditorContextImpl(); + //return impl.getOperations(url, lineNumber, bytecodeProvider); + // Hard-coded operations, because of problematic access to jpda/projects module + if (url.endsWith("ExpressionStepApp.java")) { + Operation[] ops = createExpressionSteppAppOperations(lineNumber); + if (ops == null) { + throw new IllegalStateException(url+":"+lineNumber); + } + return ops; + } + throw new IllegalStateException(url); + } + + private Operation[] createExpressionSteppAppOperations(int lineNumber) { + if (lineNumber == 30) { + return new Operation[] { + createMethodOperation(createPosition(1124, 30, 14), + createPosition(1137, 30, 27), + createPosition(1124, 30, 14), + createPosition(1133, 30, 23), + "factorial", + "debuggertest1.ExpressionStepApp", + 5) + }; + } + if (lineNumber == 31) { + return new Operation[] { + createMethodOperation(createPosition(1152, 31, 14), + createPosition(1165, 31, 27), + createPosition(1152, 31, 14), + createPosition(1161, 31, 23), + "factorial", + "debuggertest1.ExpressionStepApp", + 17), + createMethodOperation(createPosition(1168, 31, 30), + createPosition(1181, 31, 43), + createPosition(1168, 31, 30), + createPosition(1177, 31, 39), + "factorial", + "debuggertest1.ExpressionStepApp", + 22) + }; + } + if (lineNumber == 32) { + return new Operation[] { + createMethodOperation(createPosition(1196, 32, 14), + createPosition(1209, 32, 27), + createPosition(1196, 32, 14), + createPosition(1205, 32, 23), + "factorial", + "debuggertest1.ExpressionStepApp", + 35), + createMethodOperation(createPosition(1216, 32, 34), + createPosition(1229, 32, 47), + createPosition(1216, 32, 34), + createPosition(1225, 32, 43), + "factorial", + "debuggertest1.ExpressionStepApp", + 47) + }; + } + if (lineNumber == 33) { + return new Operation[] { + createMethodOperation(createPosition(1263, 33, 33), + createPosition(1286, 33, 56), + createPosition(1267, 33, 37), + createPosition(1284, 33, 54), + "", + "debuggertest1.ExpressionStepApp", + 58) + }; + } + if (lineNumber == 34) { + return new Operation[] { + createMethodOperation(createPosition(1307, 34, 20), + createPosition(1322, 34, 35), + createPosition(1307, 34, 20), + createPosition(1313, 34, 26), + "m2", + "debuggertest1.ExpressionStepApp", + 68), + createMethodOperation(createPosition(1300, 34, 13), + createPosition(1323, 34, 36), + createPosition(1300, 34, 13), + createPosition(1306, 34, 19), + "m1", + "debuggertest1.ExpressionStepApp", + 71) + }; + } + if (lineNumber == 35) { + return new Operation[] { + createMethodOperation(createPosition(1351, 35, 27), + createPosition(1366, 35, 42), + createPosition(1351, 35, 27), + createPosition(1357, 35, 33), + "m2", + "debuggertest1.ExpressionStepApp", + 85), + createMethodOperation(createPosition(1344, 35, 20), + createPosition(1367, 35, 43), + createPosition(1344, 35, 20), + createPosition(1350, 35, 26), + "m1", + "debuggertest1.ExpressionStepApp", + 88), + createMethodOperation(createPosition(1395, 36, 27), + createPosition(1410, 36, 42), + createPosition(1395, 36, 27), + createPosition(1401, 36, 33), + "m1", + "debuggertest1.ExpressionStepApp", + 96), + createMethodOperation(createPosition(1337, 35, 13), + createPosition(1411, 35, 43), + createPosition(1337, 35, 13), + createPosition(1343, 35, 19), + "m3", + "debuggertest1.ExpressionStepApp", + 99), + createMethodOperation(createPosition(1337, 35, 13), + createPosition(1422, 36, 54), + createPosition(1337, 35, 13), + createPosition(1420, 36, 52), + "intValue", + "debuggertest1.ExpressionStepApp", + 102) + }; + } + return null; + } + public String[] getImports(String url) { return new String[0]; } Index: debuggerjpda/test/unit/src/org/netbeans/api/debugger/jpda/testapps/ExpressionStepApp.java diff -u /dev/null debuggerjpda/test/unit/src/org/netbeans/api/debugger/jpda/testapps/ExpressionStepApp.java:1.1.2.1 --- /dev/null Thu Feb 1 11:02:02 2007 +++ debuggerjpda/test/unit/src/org/netbeans/api/debugger/jpda/testapps/ExpressionStepApp.java Thu Feb 1 09:46:09 2007 @@ -0,0 +1,66 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.api.debugger.jpda.testapps; + +/** + * Sample step application. DO NOT MODIFY - line numbers must not change in this source file. + * + * @author Martin Entlicher + */ +public class ExpressionStepApp { + + public static void main(String[] args) { + x += factorial(10); + x += factorial(20) + factorial(30); + x += factorial(40); x += factorial(50); + ExpressionStepApp exs = new ExpressionStepApp(); + x = exs.m1(exs.m2((int) x)); + x = exs.m3(exs.m1(exs.m2((int) x)), exs.m1((int) x)).intValue(); + System.out.println(x); + } + + public ExpressionStepApp() { + } + + public static long factorial(int n) { + long f = 1; + for (int i = 2; i <= n; i++) { + f *= i; + } + return f; + } + + private int m1(int x) { + int im1 = 10; + return im1*x; + } + + private int m2(int x) { + int im2 = 20; + return im2*x; + } + + private Integer m3(int x, int y) { + int im3 = 30; + return new Integer(im3 + x + y); + } + + static long x = 20L; +}