diff --git a/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/AbstractDebugTest.java b/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/AbstractDebugTest.java new file mode 100644 index 00000000000..f977106440c --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/AbstractDebugTest.java @@ -0,0 +1,191 @@ +package org.eclipse.cdt.debug.core.tests; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.debug.core.cdi.CDIException; +import org.eclipse.cdt.debug.core.cdi.ICDISession; +import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; +import org.eclipse.cdt.debug.mi.core.MIException; +import org.eclipse.cdt.debug.testplugin.CDebugHelper; +import org.eclipse.cdt.debug.testplugin.CProjectHelper; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; + +import junit.extensions.TestSetup; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public abstract class AbstractDebugTest extends TestCase { + IWorkspace workspace; + IWorkspaceRoot root; + NullProgressMonitor monitor; + static ICProject testProject = null; + static ICDISession session = null; + static ICDITarget targets[] = null; + ICDITarget currentTarget; + static boolean oneTimeSetupDone = false; + + @Override + protected void setUp() throws Exception { + super.setUp(); + if (oneTimeSetupDone == false) { + oneTimeSetUp(); // this can happened when run junit failed test from UI, without invoking suite() + oneTimeSetupDone = false; // re-set it back so tarDownOnes will run + } + /*********************************************************************** + * The tests assume that they have a working workspace and workspace + * root object to use to create projects/files in, so we need to get + * them setup first. + */ + workspace = ResourcesPlugin.getWorkspace(); + root = workspace.getRoot(); + monitor = new NullProgressMonitor(); + if (workspace == null) + fail("Workspace was not setup"); //$NON-NLS-1$ + if (root == null) + fail("Workspace root was not setup"); //$NON-NLS-1$ + } + + void createDebugSession() throws IOException, MIException, CModelException { + session = CDebugHelper.createSession(getProjectBinary(), testProject); + assertNotNull(session); + targets = session.getTargets(); + assertNotNull(targets); + assertTrue(targets.length > 0); + currentTarget = targets[0]; + } + + /** + * Sets up the test fixture. + * + * Called before every test case method. + * + * Example code test the packages in the project + * "com.qnx.tools.ide.cdt.core" + */ + protected void oneTimeSetUp() throws CoreException, InvocationTargetException, IOException { + ResourcesPlugin.getWorkspace().getDescription().setAutoBuilding(false); + /*********************************************************************** + * Create a new project and import the test source. + */ + Path imputFile = new Path(getProjectZip()); //$NON-NLS-1$ + testProject = CProjectHelper.createCProjectWithImport(getProjectName(), imputFile); //$NON-NLS-1$ + if (testProject == null) + fail("Unable to create project"); //$NON-NLS-1$ + /* Build the test project.. */ + + testProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null); + oneTimeSetupDone = true; + } + + protected String getProjectName() { + return "filetest"; + } + + protected String getProjectZip() { + return "resources/debugTest.zip"; + } + + protected String getProjectBinary() { + return "main"; + } + + /** + * Tears down the test fixture. + * + * Called after every test case method. + */ + protected void oneTimeTearDown() throws CoreException { + if (targets != null) { + try { + targets[0].terminate(); + } catch (CDIException e) { + } + } + if (session != null) { + try { + session.terminate(); + } catch (CDIException e) { + } + } + CProjectHelper.delete(testProject); + if (oneTimeSetupDone == false) { + oneTimeTearDown(); // this can happened when run junit failed test from UI, without invoking suite() + } + + } + + static class DebugTestWrapper extends TestSetup { + private AbstractDebugTest newInstance; + + public DebugTestWrapper(Class clazz) { + super(new TestSuite(clazz)); + /*********************************************************************** + * Create a wrapper suite around the test suite we created above to + * allow us to only do the general setup once for all the tests. This is + * needed because the creation of the source and target projects takes a + * long time and we really only need to do it once. We could do the + * setup in the constructor, but we need to be able to remove everything + * when we are done. + */ + try { + newInstance = (AbstractDebugTest) clazz.newInstance(); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + } + + protected void setUp() throws FileNotFoundException, IOException, InterruptedException, + InvocationTargetException, CoreException { + newInstance.oneTimeSetUp(); + } + + protected void tearDown() throws FileNotFoundException, IOException, CoreException { + newInstance.oneTimeTearDown(); + } + } + + void pause() { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + } + } + + void waitSuspend(ICDITarget currentTarget) { + int loop; + loop = 0; + while ((currentTarget.isSuspended() == false) && (currentTarget.isTerminated() == false) && (loop < 20)) { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // Ignore + } + loop++; + } + assertFalse("Target should be suspended, but it is terminated " + currentTarget.isTerminated(), currentTarget + .isTerminated()); + assertTrue("Target should be suspended but it is not", currentTarget.isSuspended()); + + } + + @Override + protected void tearDown() throws Exception { + /* clean up the session */ + if (session == null) { + session.terminate(); + session = null; + } + super.tearDown(); + } +} diff --git a/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/AllDebugTests.java b/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/AllDebugTests.java index 9ef84d4952b..7dcf17cbdc0 100644 --- a/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/AllDebugTests.java +++ b/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/AllDebugTests.java @@ -38,6 +38,7 @@ public class AllDebugTests { suite.addTest(DebugTests.suite()); suite.addTest(BreakpointTests.suite()); suite.addTest(LocationTests.suite()); + suite.addTest(CatchpointTests.suite()); return suite; diff --git a/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/BreakpointTests.java b/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/BreakpointTests.java index 8e249542df1..c2cae35c696 100644 --- a/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/BreakpointTests.java +++ b/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/BreakpointTests.java @@ -46,143 +46,44 @@ import org.eclipse.core.runtime.Path; * It will currenly use the mi implementation. * */ -public class BreakpointTests extends TestCase { +public class BreakpointTests extends AbstractDebugTest { - IWorkspace workspace; - IWorkspaceRoot root; - static ICProject testProject = null; - NullProgressMonitor monitor; - static ICDISession session = null; - static ICDITarget targets[] = null; - - /** - * Constructor for BreakpointTests - * - * @param name - */ - public BreakpointTests(String name) { - super(name); - /*********************************************************************** - * The tests assume that they have a working workspace and workspace - * root object to use to create projects/files in, so we need to get - * them setup first. - */ - workspace = ResourcesPlugin.getWorkspace(); - root = workspace.getRoot(); - monitor = new NullProgressMonitor(); - if (workspace == null) - fail("Workspace was not setup"); //$NON-NLS-1$ - if (root == null) - fail("Workspace root was not setup"); //$NON-NLS-1$ - - } - - /** - * Sets up the test fixture. - * - * Called before every test case method. - * - * Example code test the packages in the project - * "com.qnx.tools.ide.cdt.core" - */ - protected static void oneTimeSetUp() throws CoreException, InvocationTargetException, IOException { - ResourcesPlugin.getWorkspace().getDescription().setAutoBuilding(false); - /*********************************************************************** - * Create a new project and import the test source. - */ - Path imputFile = new Path("resources/debugTest.zip"); //$NON-NLS-1$ - testProject = CProjectHelper.createCProjectWithImport("filetest", imputFile); //$NON-NLS-1$ - if (testProject == null) - fail("Unable to create project"); //$NON-NLS-1$ - /* Build the test project.. */ - - testProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null); - } - - /** - * Tears down the test fixture. - * - * Called after every test case method. - */ - protected void tearDown() throws CoreException { - if (targets != null) { - try { - targets[0].terminate(); - targets = null; - } catch (CDIException e) { - } - } - if (session != null) { - try { - session.terminate(); - session = null; - } catch (CDIException e) { - } - } - } - - /** - * Tears down the test fixture. - * - * Called after every test case method. - */ - protected static void oneTimeTearDown() throws CoreException { - if (targets != null) { - try { - targets[0].terminate(); - } catch (CDIException e) { - } - } - if (session != null) { - try { - session.terminate(); - } catch (CDIException e) { - } - } - CProjectHelper.delete(testProject); - - } public static Test suite() { - TestSuite suite = new TestSuite(BreakpointTests.class); - /*********************************************************************** - * Create a wrapper suite around the test suite we created above to - * allow us to only do the general setup once for all the tests. This is - * needed because the creation of the source and target projects takes a - * long time and we really only need to do it once. We could do the - * setup in the constructor, but we need to be able to remove everything - * when we are done. - */ - TestSetup wrapper = new TestSetup(suite) { - - protected void setUp() throws FileNotFoundException, IOException, InterruptedException, InvocationTargetException, - CoreException { - oneTimeSetUp(); - } - - protected void tearDown() throws FileNotFoundException, IOException, CoreException { - oneTimeTearDown(); - } - }; - return (wrapper); + return new DebugTestWrapper(BreakpointTests.class) {}; } + @Override + protected void setUp() throws Exception { + super.setUp(); + createDebugSession(); + assertNotNull(currentTarget); + currentTarget.deleteAllBreakpoints(); + pause(); + } + @Override + protected void tearDown() throws Exception { + /* clean up the session */ + targets[0].terminate(); + int x = 0; + while ((!targets[0].isTerminated()) && (x < 30)) { + Thread.sleep(100); + } + if (!targets[0].isTerminated()) + targets[0].terminate(); + super.tearDown(); + } + /*************************************************************************** * A couple tests to make sure setting breakpoints on functions works as * expected. */ public void testFunctionBreak() throws CoreException, MIException, IOException, CDIException, InterruptedException { - ICDISession session; - ICDITarget cdiTarget; + + ICDITarget cdiTarget = currentTarget; ICDIFunctionLocation location; boolean caught = false; - session = CDebugHelper.createSession("main", testProject); //$NON-NLS-1$ - assertNotNull(session); - ICDITarget[] targets = session.getTargets(); - assertNotNull(targets); - assertTrue(targets.length > 0); - cdiTarget = targets[0]; - assertNotNull(cdiTarget); + /*********************************************************************** * Create a break point on a generic function @@ -250,19 +151,10 @@ public class BreakpointTests extends TestCase { ICDILocator locator = targets[0].getCurrentThread().getStackFrames()[0].getLocator(); assertTrue(locator.getLineNumber() == 6); assertTrue(locator.getFunction().equals("func1")); //$NON-NLS-1$ - assertTrue(locator.getFile().equals("main.c")); //$NON-NLS-1$ + assertTrue(locator.getFile().endsWith("main.c")); //$NON-NLS-1$ + + - /* clean up the session */ - targets[0].terminate(); - int x = 0; - while ((!targets[0].isTerminated()) && (x < 30)) { - Thread.sleep(100); - } - if (!targets[0].isTerminated()) - targets[0].terminate(); - session.terminate(); - session = null; - targets = null; } @@ -271,16 +163,10 @@ public class BreakpointTests extends TestCase { * expected. */ public void testLineBreak() throws CoreException, MIException, IOException, CDIException, InterruptedException { - ICDITarget cdiTarget; + ICDITarget cdiTarget = currentTarget; ICDILineLocation location; boolean caught = false; - session = CDebugHelper.createSession("main", testProject); - assertNotNull(session); - ICDITarget[] targets = session.getTargets(); - assertNotNull(targets); - assertTrue(targets.length > 0); - cdiTarget = targets[0]; - assertNotNull(cdiTarget); + /*********************************************************************** * Create a break point in a generic function @@ -376,12 +262,7 @@ public class BreakpointTests extends TestCase { ICDILocator locator = targets[0].getCurrentThread().getStackFrames()[0].getLocator(); assertTrue(locator.getLineNumber() == 7); assertTrue(locator.getFunction().equals("func1")); - assertTrue(locator.getFile().equals("main.c")); - - /* clean up the session */ - session.terminate(); - session = null; - targets = null; + assertTrue(locator.getFile().endsWith("main.c")); } @@ -389,17 +270,11 @@ public class BreakpointTests extends TestCase { * A couple tests to make sure getting breakpoints works as expected */ public void testGetBreak() throws CoreException, MIException, IOException, CDIException { - ICDITarget cdiTarget; + ICDITarget cdiTarget = currentTarget; ICDIFunctionLocation location; ICDIBreakpoint[] breakpoints; ICDILocationBreakpoint curbreak; - session = CDebugHelper.createSession("main", testProject); - assertNotNull(session); - ICDITarget[] targets = session.getTargets(); - assertNotNull(targets); - assertTrue(targets.length > 0); - cdiTarget = targets[0]; - assertNotNull(cdiTarget); + /*********************************************************************** * Make sure initially we don't have any breakpoints @@ -466,9 +341,6 @@ public class BreakpointTests extends TestCase { cdiTarget.deleteAllBreakpoints(); - /* clean up the session */ - session.terminate(); - session = null; } @@ -476,20 +348,12 @@ public class BreakpointTests extends TestCase { * A couple tests to make sure deleting breakpoints works as expected */ public void testDelBreak() throws CoreException, MIException, IOException, CDIException { - ICDITarget cdiTarget; + ICDITarget cdiTarget = currentTarget; ICDIFunctionLocation location; ICDILocator savedLocation; ICDIBreakpoint[] breakpoints, savedbreakpoints; ICDILocationBreakpoint curbreak; - session = CDebugHelper.createSession("main", testProject); - assertNotNull(session); - ICDITarget[] targets = session.getTargets(); - assertNotNull(targets); - assertTrue(targets.length > 0); - cdiTarget = targets[0]; - assertNotNull(cdiTarget); - /* Make sure initially we don't have any breakpoints */ breakpoints = cdiTarget.getBreakpoints(); assertNotNull(breakpoints); @@ -626,10 +490,6 @@ public class BreakpointTests extends TestCase { breakpoints = cdiTarget.getBreakpoints(); assertTrue(breakpoints.length == 0); - /* clean up the session */ - session.terminate(); - session = null; - } /*************************************************************************** @@ -638,13 +498,7 @@ public class BreakpointTests extends TestCase { */ public void testCondBreak() throws CoreException, MIException, IOException, CDIException, InterruptedException { boolean caught = false; - session = CDebugHelper.createSession("main", testProject); - assertNotNull(session); - ICDITarget[] targets = session.getTargets(); - assertNotNull(targets); - assertTrue(targets.length > 0); - ICDITarget cdiTarget = targets[0]; - assertNotNull(cdiTarget); + ICDITarget cdiTarget = currentTarget; /*********************************************************************** * Create a break point on a generic function with an empty condition @@ -714,22 +568,11 @@ public class BreakpointTests extends TestCase { ICDILocator locator = frame.getLocator(); assertTrue(locator.getLineNumber() == 23); assertTrue(locator.getFunction().equals("main")); - assertTrue(locator.getFile().equals("main.c")); + assertTrue(locator.getFile().endsWith("main.c")); /* Get the value of a and and make sure it is 11 */ assertTrue(targets[0].evaluateExpressionToString(frame, "a"), targets[0].evaluateExpressionToString(frame, "a").equals("11")); - /* clean up the session */ - session.terminate(); - session = null; - targets = null; - } - void pause() { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - } - } } \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/LocationTests.java b/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/LocationTests.java index 868fd9a7c66..015f692fd4b 100644 --- a/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/LocationTests.java +++ b/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/LocationTests.java @@ -11,28 +11,17 @@ package org.eclipse.cdt.debug.core.tests; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.eclipse.cdt.core.model.ICProject; + +import junit.framework.Test; + import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.ICDIFunctionLocation; import org.eclipse.cdt.debug.core.cdi.ICDILineLocation; -import org.eclipse.cdt.debug.core.cdi.ICDISession; import org.eclipse.cdt.debug.core.cdi.model.ICDIBreakpoint; import org.eclipse.cdt.debug.core.cdi.model.ICDILocationBreakpoint; import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; import org.eclipse.cdt.debug.mi.core.MIException; -import org.eclipse.cdt.debug.testplugin.CDebugHelper; -import org.eclipse.cdt.debug.testplugin.CProjectHelper; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.IncrementalProjectBuilder; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; /** * @author Peter Graves @@ -41,96 +30,34 @@ import org.eclipse.core.runtime.Path; * It will currenly use the mi implementation. * */ -public class LocationTests extends TestCase { - IWorkspace workspace; - IWorkspaceRoot root; - ICProject testProject; - NullProgressMonitor monitor; - ICDISession session; +public class LocationTests extends AbstractDebugTest { + public static Test suite() { + return new DebugTestWrapper(LocationTests.class){}; + } + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } - /** - * Constructor for LocationTests - * @param name - */ - public LocationTests(String name) { - super(name); - /*** - * The assume that they have a working workspace - * and workspace root object to use to create projects/files in, - * so we need to get them setup first. - */ - workspace= ResourcesPlugin.getWorkspace(); - root= workspace.getRoot(); - monitor = new NullProgressMonitor(); - if (workspace==null) - fail("Workspace was not setup"); - if (root==null) - fail("Workspace root was not setup"); - - } - - /** - * Sets up the test fixture. - * - * Called before every test case method. - * - * Example code test the packages in the project - * "com.qnx.tools.ide.cdt.core" - */ - protected void setUp() throws CoreException, InvocationTargetException, IOException { - ResourcesPlugin.getWorkspace().getDescription().setAutoBuilding(false); - /*** - * Create a new project and import the test source. - */ - IPath importFile = new Path("resources/debugTest.zip"); - testProject=CProjectHelper.createCProjectWithImport("filetest", importFile); - if (testProject==null) - fail("Unable to create project"); - /* Build the test project.. */ - - testProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null); - - } - - /** - * Tears down the test fixture. - * - * Called after every test case method. - */ - protected void tearDown() throws CoreException, CDIException { - if (session!=null) { - session.terminate(); - session=null; - } - CProjectHelper.delete(testProject); - } - - public static TestSuite suite() { - return new TestSuite(LocationTests.class); - } - - public static void main (String[] args){ - junit.textui.TestRunner.run(suite()); - } - + @Override + protected void setUp() throws Exception { + super.setUp(); + createDebugSession(); + assertNotNull(currentTarget); + currentTarget.deleteAllBreakpoints(); + pause(); + } /*** * A couple tests to make sure comparing Locations works as expected. */ public void testIsEquals() throws CoreException, MIException, IOException, CDIException { - ICDITarget cdiTarget; + ICDITarget cdiTarget = currentTarget; ICDILineLocation lineLocation, lineLocation2; ICDIFunctionLocation functionLocation, functionLocation2; ICDIBreakpoint[] breakpoints; ICDILocationBreakpoint curbreak; - session=CDebugHelper.createSession("main",testProject); - assertNotNull(session); - ICDITarget[] targets = session.getTargets(); - assertNotNull(targets); - assertTrue(targets.length > 0); - cdiTarget = targets[0]; - assertNotNull(cdiTarget); + /********************************************************************** * Simple test.. this should work. @@ -166,6 +93,7 @@ public class LocationTests extends TestCase { assertTrue(curbreak.getLocator().equals(functionLocation2)); cdiTarget.deleteAllBreakpoints(); + pause(); /* Create a break point on a generic function with a file name that * gdb will change to the relitive path of the source file. This * should work, but at the time of writing (Sept 25, 2002) does not. @@ -184,12 +112,7 @@ public class LocationTests extends TestCase { assertNotNull(curbreak); assertTrue("PR:23879",curbreak.getLocator().equals(functionLocation)); - - - /* clean up the session */ - session.terminate(); - session=null; - + }