/core/test/unit/src/com/bluemarsh/jswat/core/stepping/StepperTest.java
Java | 105 lines | 68 code | 6 blank | 31 comment | 1 complexity | 20f20739f0347a5144edfb812c862048 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
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 JSwat. The Initial Developer of the Original 16 * Software is Nathan L. Fiedler. Portions created by Nathan L. Fiedler 17 * are Copyright (C) 2005-2010. All Rights Reserved. 18 * 19 * Contributor(s): Nathan L. Fiedler. 20 * 21 * $Id: StepperTest.java 261 2010-04-20 06:31:40Z nathanfiedler $ 22 */ 23package com.bluemarsh.jswat.core.stepping; 24 25import com.bluemarsh.jswat.core.CoreSettings; 26import com.bluemarsh.jswat.core.session.Session; 27import com.bluemarsh.jswat.core.SessionHelper; 28import com.bluemarsh.jswat.core.breakpoint.BreakpointHelper; 29import com.sun.jdi.Location; 30import java.util.ArrayList; 31import java.util.List; 32import org.junit.BeforeClass; 33import org.junit.Test; 34import static org.junit.Assert.*; 35 36/** 37 * Unit tests for the Stepper class. 38 * 39 * @author Nathan Fiedler 40 */ 41public class StepperTest { 42 43 @BeforeClass 44 public static void setupClass() { 45 // Set the excludes to avoid going places we don't want to go. 46 CoreSettings cs = CoreSettings.getDefault(); 47 List<String> excludes = new ArrayList<String>(); 48 excludes.add("com.sun.*"); 49 excludes.add("sun.*"); 50 excludes.add("java.*"); 51 excludes.add("javax.*"); 52 cs.setSteppingExcludes(excludes); 53 } 54 55 @Test 56 public void singleStepping() throws SteppingException { 57 Session session = SessionHelper.getSession(); 58 SessionHelper.launchDebuggee("SteppingTestCode", 59 "SteppingTestCode:main(java.lang.String[])"); 60 String[] methods = new String[]{ 61 "main", 62 "<init>", 63 "main", 64 "main", 65 "method_I", 66 "method_I", 67 "main", 68 "method_STS", 69 "method_STS", 70 "main", 71 "<init>", 72 "<init>", 73 "main", 74 "main", 75 "stepMethod", 76 "stepMethod", 77 "main",}; 78 for (int ii = 0; ii < methods.length; ii++) { 79 String method = methods[ii]; 80 // We are supposedly at a breakpoint, verify that this is so. 81 Location loc = BreakpointHelper.getLocation(session); 82 assertNotNull("no location for entry " + ii, loc); 83 assertEquals("entry " + ii, method, loc.method().name()); 84 SessionHelper.stepIntoAndWait(session); 85 } 86 87 // The debuggee will have exited now and the session is inactive. 88 } 89 90 @Test 91 public void steppingOut() throws SteppingException { 92 SessionHelper.launchDebuggee("SteppingTestCode", 93 "SteppingTestCode$Inner:method_I()"); 94 Session session = SessionHelper.getSession(); 95 Location loc = BreakpointHelper.getLocation(session); 96 assertNotNull(loc); 97 assertEquals("method_I", loc.method().name()); 98 SessionHelper.stepOutAndWait(session); 99 loc = BreakpointHelper.getLocation(session); 100 assertNotNull(loc); 101 assertEquals("main", loc.method().name()); 102 SessionHelper.resumeAndWait(); 103 // The debuggee will have exited now and the session is inactive. 104 } 105}