/core/test/unit/src/com/bluemarsh/jswat/core/stepping/StepperTest.java

http://jswat.googlecode.com/ · Java · 105 lines · 68 code · 6 blank · 31 comment · 1 complexity · 20f20739f0347a5144edfb812c862048 MD5 · raw file

  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. */
  23. package com.bluemarsh.jswat.core.stepping;
  24. import com.bluemarsh.jswat.core.CoreSettings;
  25. import com.bluemarsh.jswat.core.session.Session;
  26. import com.bluemarsh.jswat.core.SessionHelper;
  27. import com.bluemarsh.jswat.core.breakpoint.BreakpointHelper;
  28. import com.sun.jdi.Location;
  29. import java.util.ArrayList;
  30. import java.util.List;
  31. import org.junit.BeforeClass;
  32. import org.junit.Test;
  33. import static org.junit.Assert.*;
  34. /**
  35. * Unit tests for the Stepper class.
  36. *
  37. * @author Nathan Fiedler
  38. */
  39. public class StepperTest {
  40. @BeforeClass
  41. public static void setupClass() {
  42. // Set the excludes to avoid going places we don't want to go.
  43. CoreSettings cs = CoreSettings.getDefault();
  44. List<String> excludes = new ArrayList<String>();
  45. excludes.add("com.sun.*");
  46. excludes.add("sun.*");
  47. excludes.add("java.*");
  48. excludes.add("javax.*");
  49. cs.setSteppingExcludes(excludes);
  50. }
  51. @Test
  52. public void singleStepping() throws SteppingException {
  53. Session session = SessionHelper.getSession();
  54. SessionHelper.launchDebuggee("SteppingTestCode",
  55. "SteppingTestCode:main(java.lang.String[])");
  56. String[] methods = new String[]{
  57. "main",
  58. "<init>",
  59. "main",
  60. "main",
  61. "method_I",
  62. "method_I",
  63. "main",
  64. "method_STS",
  65. "method_STS",
  66. "main",
  67. "<init>",
  68. "<init>",
  69. "main",
  70. "main",
  71. "stepMethod",
  72. "stepMethod",
  73. "main",};
  74. for (int ii = 0; ii < methods.length; ii++) {
  75. String method = methods[ii];
  76. // We are supposedly at a breakpoint, verify that this is so.
  77. Location loc = BreakpointHelper.getLocation(session);
  78. assertNotNull("no location for entry " + ii, loc);
  79. assertEquals("entry " + ii, method, loc.method().name());
  80. SessionHelper.stepIntoAndWait(session);
  81. }
  82. // The debuggee will have exited now and the session is inactive.
  83. }
  84. @Test
  85. public void steppingOut() throws SteppingException {
  86. SessionHelper.launchDebuggee("SteppingTestCode",
  87. "SteppingTestCode$Inner:method_I()");
  88. Session session = SessionHelper.getSession();
  89. Location loc = BreakpointHelper.getLocation(session);
  90. assertNotNull(loc);
  91. assertEquals("method_I", loc.method().name());
  92. SessionHelper.stepOutAndWait(session);
  93. loc = BreakpointHelper.getLocation(session);
  94. assertNotNull(loc);
  95. assertEquals("main", loc.method().name());
  96. SessionHelper.resumeAndWait();
  97. // The debuggee will have exited now and the session is inactive.
  98. }
  99. }