1 19 20 package org.netbeans.api.debugger.jpda; 21 22 import java.util.List ; 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 34 public class ExpressionStepTest extends NbTestCase { 35 36 private DebuggerManager dm = DebuggerManager.getDebuggerManager (); 37 private String sourceRoot = System.getProperty ("test.dir.src"); 38 private JPDASupport support; 39 40 public ExpressionStepTest (String s) { 41 super (s); 42 } 43 44 public void testExpressionStep() throws Exception { 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 [] {"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 [] {"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 [] {"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 [] {"-70609262346240000"} 102 ); 103 stepCheck ( 104 ActionsManager.ACTION_STEP_OPERATION, 105 "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", 106 33, 37, 107 "<init>", new Object [] {"-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 [] {"-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 [] {"-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 [] {"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 [] {"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 [] {"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 [] {"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 stepType, 169 String clsExpected, 170 int lineExpected, 171 int column, 172 String methodName 173 ) { 174 try { 175 Thread.currentThread().sleep(10); 178 } catch (InterruptedException 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 stepType, 207 String clsExpected, 208 int lineExpected, 209 int column, 210 String methodName, 211 Object [] returnValues 212 ) { 213 stepCheck(stepType, clsExpected, lineExpected, column, methodName); 214 List <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 |