1 19 20 package org.netbeans.api.debugger.jpda; 21 22 import org.netbeans.api.debugger.ActionsManager; 23 import org.netbeans.api.debugger.DebuggerManager; 24 import org.netbeans.junit.NbTestCase; 25 26 27 32 public class StepTest extends NbTestCase { 33 34 private DebuggerManager dm = DebuggerManager.getDebuggerManager (); 35 private String sourceRoot = System.getProperty ("test.dir.src"); 36 private JPDASupport support; 37 38 public StepTest (String s) { 39 super (s); 40 } 41 42 public void testStepOver () throws Exception { 43 try { 44 JPDASupport.removeAllBreakpoints (); 45 LineBreakpoint lb = LineBreakpoint.create ( 46 Utils.getURL(sourceRoot + 47 "org/netbeans/api/debugger/jpda/testapps/StepApp.java"), 48 30 49 ); 50 dm.addBreakpoint (lb); 51 support = JPDASupport.attach 52 ("org.netbeans.api.debugger.jpda.testapps.StepApp"); 53 support.waitState (JPDADebugger.STATE_STOPPED); 54 dm.removeBreakpoint (lb); 55 assertEquals ( 56 "Execution stopped in wrong class", 57 support.getDebugger ().getCurrentCallStackFrame (). 58 getClassName (), 59 "org.netbeans.api.debugger.jpda.testapps.StepApp" 60 ); 61 assertEquals ( 62 "Execution stopped at wrong line", 63 30, 64 support.getDebugger ().getCurrentCallStackFrame (). 65 getLineNumber (null) 66 ); 67 stepCheck ( 68 ActionsManager.ACTION_STEP_OVER, 69 "org.netbeans.api.debugger.jpda.testapps.StepApp", 70 31 71 ); 72 stepCheck ( 73 ActionsManager.ACTION_STEP_OVER, 74 "org.netbeans.api.debugger.jpda.testapps.StepApp", 75 32 76 ); 77 stepCheck ( 78 ActionsManager.ACTION_STEP_OVER, 79 "org.netbeans.api.debugger.jpda.testapps.StepApp", 80 33 81 ); 82 stepCheck ( 83 ActionsManager.ACTION_STEP_OVER, 84 "org.netbeans.api.debugger.jpda.testapps.StepApp", 85 34 86 ); 87 stepCheck ( 88 ActionsManager.ACTION_STEP_OVER, 89 "org.netbeans.api.debugger.jpda.testapps.StepApp", 90 35 91 ); 92 support.doContinue (); 93 support.waitState (JPDADebugger.STATE_DISCONNECTED); 94 } finally { 95 support.doFinish (); 96 } 97 } 98 99 public void testStepInto () throws Exception { 100 try { 101 JPDASupport.removeAllBreakpoints (); 102 LineBreakpoint lb = LineBreakpoint.create ( 103 Utils.getURL(sourceRoot + 104 "org/netbeans/api/debugger/jpda/testapps/StepApp.java"), 105 30 106 ); 107 dm.addBreakpoint (lb); 108 support = JPDASupport.attach 109 ("org.netbeans.api.debugger.jpda.testapps.StepApp"); 110 support.waitState (JPDADebugger.STATE_STOPPED); 111 dm.removeBreakpoint (lb); 112 assertEquals ( 113 "Execution stopped in wrong class", 114 support.getDebugger ().getCurrentCallStackFrame (). 115 getClassName (), 116 "org.netbeans.api.debugger.jpda.testapps.StepApp" 117 ); 118 assertEquals ( 119 "Execution stopped at wrong line", 120 30, 121 support.getDebugger ().getCurrentCallStackFrame (). 122 getLineNumber (null) 123 ); 124 125 stepCheck ( 126 ActionsManager.ACTION_STEP_INTO, 127 "org.netbeans.api.debugger.jpda.testapps.StepApp", 128 38 129 ); 130 stepCheck ( 132 ActionsManager.ACTION_STEP_OVER, 133 "org.netbeans.api.debugger.jpda.testapps.StepApp", 134 39 135 ); 136 stepCheck ( 137 ActionsManager.ACTION_STEP_OVER, 138 "org.netbeans.api.debugger.jpda.testapps.StepApp", 139 30 140 ); 141 stepCheck ( 142 ActionsManager.ACTION_STEP_OVER, 143 "org.netbeans.api.debugger.jpda.testapps.StepApp", 144 31 145 ); 146 stepCheck ( 147 ActionsManager.ACTION_STEP_INTO, 148 "org.netbeans.api.debugger.jpda.testapps.StepApp", 149 42 150 ); 151 stepCheck ( 152 ActionsManager.ACTION_STEP_OVER, 153 "org.netbeans.api.debugger.jpda.testapps.StepApp", 154 43 155 ); 156 stepCheck ( 157 ActionsManager.ACTION_STEP_INTO, 158 "org.netbeans.api.debugger.jpda.testapps.StepApp", 159 48 160 ); 161 162 support.doContinue (); 163 support.waitState (JPDADebugger.STATE_DISCONNECTED); 164 } finally { 165 support.doFinish (); 166 } 167 } 168 169 public void testStepOut () throws Exception { 170 try { 171 JPDASupport.removeAllBreakpoints (); 172 LineBreakpoint lb = LineBreakpoint.create ( 173 Utils.getURL(sourceRoot + 174 "org/netbeans/api/debugger/jpda/testapps/StepApp.java"), 175 30 176 ); 177 dm.addBreakpoint (lb); 178 support = JPDASupport.attach 179 ("org.netbeans.api.debugger.jpda.testapps.StepApp"); 180 support.waitState (JPDADebugger.STATE_STOPPED); 181 dm.removeBreakpoint (lb); 182 assertEquals ( 183 "Execution stopped in wrong class", 184 support.getDebugger ().getCurrentCallStackFrame (). 185 getClassName (), 186 "org.netbeans.api.debugger.jpda.testapps.StepApp" 187 ); 188 assertEquals ( 189 "Execution stopped at wrong line", 190 30, 191 support.getDebugger ().getCurrentCallStackFrame (). 192 getLineNumber (null) 193 ); 194 stepCheck ( 195 ActionsManager.ACTION_STEP_OVER, 196 "org.netbeans.api.debugger.jpda.testapps.StepApp", 197 31 198 ); 199 stepCheck ( 200 ActionsManager.ACTION_STEP_INTO, 201 "org.netbeans.api.debugger.jpda.testapps.StepApp", 202 42 203 ); 204 stepCheck ( 205 ActionsManager.ACTION_STEP_OVER, 206 "org.netbeans.api.debugger.jpda.testapps.StepApp", 207 43 208 ); 209 stepCheck ( 210 ActionsManager.ACTION_STEP_INTO, 211 "org.netbeans.api.debugger.jpda.testapps.StepApp", 212 48 213 ); 214 stepCheck ( 215 ActionsManager.ACTION_STEP_OUT, 216 "org.netbeans.api.debugger.jpda.testapps.StepApp", 217 43 218 ); 219 stepCheck ( 220 ActionsManager.ACTION_STEP_OUT, 221 "org.netbeans.api.debugger.jpda.testapps.StepApp", 222 31 223 ); 224 225 support.doContinue (); 226 support.waitState (JPDADebugger.STATE_DISCONNECTED); 227 } finally { 228 support.doFinish (); 229 } 230 } 231 232 private void stepCheck ( 233 Object stepType, 234 String clsExpected, 235 int lineExpected 236 ) { 237 support.step (stepType); 238 assertEquals( 239 "Execution stopped in wrong class", 240 clsExpected, 241 support.getDebugger ().getCurrentCallStackFrame ().getClassName () 242 ); 243 assertEquals ( 244 "Execution stopped at wrong line", 245 lineExpected, 246 support.getDebugger ().getCurrentCallStackFrame (). 247 getLineNumber (null) 248 ); 249 } 250 } 251 | Popular Tags |