From 32b09f9ef933e32bbe02db970b6756d249d561c4 Mon Sep 17 00:00:00 2001 From: Peter Graves <pgraves@qnx.com> Date: Thu, 10 Oct 2002 13:06:39 +0000 Subject: [PATCH] Initial commit of new debug tests. --- .../org.eclipse.cdt.debug.ui.tests/.classpath | 19 + .../org.eclipse.cdt.debug.ui.tests/.cvsignore | 1 + debug/org.eclipse.cdt.debug.ui.tests/.project | 27 + .../org.eclipse.cdt.debug.ui.tests/about.html | 44 ++ .../build.properties | 1 + .../eclipse/cdt/debug/core/tests/.cvsignore | 3 + .../cdt/debug/core/tests/AllDebugTests.java | 43 ++ .../cdt/debug/core/tests/BreakpointTests.java | 615 ++++++++++++++++++ .../cdt/debug/core/tests/DebugTests.java | 120 ++++ .../cdt/debug/core/tests/resources/main.c | 26 + .../debug/core/tests/resources/win/Makefile | 2 + .../debug/core/tests/resources/win/main.exe | Bin 0 -> 25658 bytes .../org.eclipse.cdt.debug.ui.tests/plugin.xml | 24 + .../cdt/debug/testplugin/CDebugHelper.java | 48 ++ .../debug/testplugin/CElementDecorator.java | 30 + .../cdt/debug/testplugin/CProjectHelper.java | 293 +++++++++ .../cdt/debug/testplugin/CTestPlugin.java | 58 ++ .../cdt/debug/testplugin/CTestSetup.java | 31 + .../eclipse/cdt/debug/testplugin/Main.java | 528 +++++++++++++++ .../eclipse/cdt/debug/testplugin/NewMain.java | 73 +++ .../debug/testplugin/TestPluginLauncher.java | 57 ++ .../cdt/debug/testplugin/TestWorkbench.java | 79 +++ .../cdt/debug/testplugin/test/HelloWorld.java | 49 ++ .../util/AccessibilityTestPass.java | 66 ++ .../debug/testplugin/util/DialogCheck.java | 225 +++++++ .../testplugin/util/ExpectedStrings.java | 96 +++ .../testplugin/util/ExpectedStringsTests.java | 114 ++++ .../debug/testplugin/util/FailureDialog.java | 107 +++ .../debug/testplugin/util/FocusTestPass.java | 68 ++ .../testplugin/util/IDialogTestPass.java | 48 ++ .../debug/testplugin/util/SizingTestPass.java | 76 +++ .../debug/testplugin/util/VerifyDialog.java | 305 +++++++++ debug/org.eclipse.cdt.debug.ui.tests/test.xml | 51 ++ 33 files changed, 3327 insertions(+) create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/.classpath create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/.cvsignore create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/about.html create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/build.properties create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/.cvsignore create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/AllDebugTests.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/BreakpointTests.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/DebugTests.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/resources/main.c create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/resources/win/Makefile create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/resources/win/main.exe create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/plugin.xml create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CDebugHelper.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CElementDecorator.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CProjectHelper.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CTestPlugin.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CTestSetup.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/Main.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/NewMain.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/TestPluginLauncher.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/TestWorkbench.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/test/HelloWorld.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/AccessibilityTestPass.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/DialogCheck.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/ExpectedStrings.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/ExpectedStringsTests.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/FailureDialog.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/FocusTestPass.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/IDialogTestPass.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/SizingTestPass.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/VerifyDialog.java create mode 100644 debug/org.eclipse.cdt.debug.ui.tests/test.xml diff --git a/debug/org.eclipse.cdt.debug.ui.tests/.classpath b/debug/org.eclipse.cdt.debug.ui.tests/.classpath new file mode 100644 index 00000000000..87442503767 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/.classpath @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src/"/> + <classpathentry kind="src" path="ui/"/> + <classpathentry kind="src" path="core/"/> + <classpathentry kind="src" path="model/"/> + <classpathentry kind="src" path="/org.apache.xerces"/> + <classpathentry kind="src" path="/org.eclipse.core.boot"/> + <classpathentry kind="src" path="/org.eclipse.core.resources"/> + <classpathentry kind="src" path="/org.eclipse.core.runtime"/> + <classpathentry kind="src" path="/org.eclipse.swt"/> + <classpathentry kind="src" path="/org.junit"/> + <classpathentry kind="src" path="/org.eclipse.cdt.debug.core"/> + <classpathentry kind="src" path="/org.eclipse.cdt.debug.mi.core"/> + <classpathentry kind="src" path="/org.eclipse.cdt.core"/> + <classpathentry kind="src" path="/org.eclipse.ui"/> + <classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" sourcepath="JRE_SRC"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/debug/org.eclipse.cdt.debug.ui.tests/.cvsignore b/debug/org.eclipse.cdt.debug.ui.tests/.cvsignore new file mode 100644 index 00000000000..ba077a4031a --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/debug/org.eclipse.cdt.debug.ui.tests/.project b/debug/org.eclipse.cdt.debug.ui.tests/.project index 33cf21f7f9f..3e216ded820 100644 --- a/debug/org.eclipse.cdt.debug.ui.tests/.project +++ b/debug/org.eclipse.cdt.debug.ui.tests/.project @@ -3,9 +3,36 @@ <name>org.eclipse.cdt.debug.ui.tests</name> <comment></comment> <projects> + <project>org.apache.xerces</project> + <project>org.eclipse.cdt.core</project> + <project>org.eclipse.cdt.debug.core</project> + <project>org.eclipse.cdt.debug.mi.core</project> + <project>org.eclipse.core.boot</project> + <project>org.eclipse.core.resources</project> + <project>org.eclipse.core.runtime</project> + <project>org.eclipse.swt</project> + <project>org.eclipse.ui</project> + <project>org.junit</project> </projects> <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> </buildSpec> <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>org.eclipse.pde.PluginNature</nature> </natures> </projectDescription> diff --git a/debug/org.eclipse.cdt.debug.ui.tests/about.html b/debug/org.eclipse.cdt.debug.ui.tests/about.html new file mode 100644 index 00000000000..fad1e4a429b --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/about.html @@ -0,0 +1,44 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> +<html> +<head> +<title>About</title> +<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1"> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>20th June, 2002</p> +<h3>License</h3> +<p>Eclipse.org makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Common Public License Version 1.0 ("CPL"). A copy of the CPL is available at <a href="http://www.eclipse.org/legal/cpl-v10.html">http://www.eclipse.org/legal/cpl-v10.html</a>. +For purposes of the CPL, "Program" will mean the Content.</p> + +<h3>Third Party Content</h3> + +<p>The Content includes items that may be have been sourced from third parties as follows:</p> + +<p><b>JUnit 3.7</b></p> +<p>The plug-in is based on software developed by JUnit.org. Your use of JUnit 3.7 in both source and binary code +form contained in the plug-in is subject to the terms and conditions of the IBM Public License 1.0 which is available at +<a href="http://oss.software.ibm.com/developerworks/opensource/license10.html">http://oss.software.ibm.com/developerworks/opensource/license10.html</a>. +The source code is located in testresources/junit37-noUI-src.zip.</p> + +<p>i) IBM effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;</p> +<p>ii) IBM effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;</p> +<p>iii) IBM states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party.</p> + +<h3>Contributions</h3> + +<p>If this Content is licensed to you under the terms and conditions of the CPL, any Contributions, as defined in the CPL, uploaded, submitted, or otherwise +made available to Eclipse.org, members of Eclipse.org and/or the host of Eclipse.org web site, by you that relate to such +Content are provided under the terms and conditions of the CPL and can be made available to others under the terms of the CPL.</p> + +<p>If this Content is licensed to you under license terms and conditions other than the CPL ("Other License"), any modifications, enhancements and/or +other code and/or documentation ("Modifications") uploaded, submitted, or otherwise made available to Eclipse.org, members of Eclipse.org and/or the +host of Eclipse.org, by you that relate to such Content are provided under terms and conditions of the Other License and can be made available +to others under the terms of the Other License. In addition, with regard to Modifications for which you are the copyright holder, you are also +providing the Modifications under the terms and conditions of the CPL and such Modifications can be made available to others under the terms of +the CPL.</p> + +</body> +</html> \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.ui.tests/build.properties b/debug/org.eclipse.cdt.debug.ui.tests/build.properties new file mode 100644 index 00000000000..36df47cc74a --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/build.properties @@ -0,0 +1 @@ +source.cdttests.jar = src/, ui/, core/, model/ diff --git a/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/.cvsignore b/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/.cvsignore new file mode 100644 index 00000000000..7d268d723cd --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/.cvsignore @@ -0,0 +1,3 @@ +WatchpointTests.java +LocationTests.java +TargetTests.java 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 new file mode 100644 index 00000000000..29895cf4142 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/AllDebugTests.java @@ -0,0 +1,43 @@ +package org.eclipse.cdt.debug.core.tests; +/* + * (c) Copyright QNX Software Systems Ltd. 2002. + * All Rights Reserved. + */ + + + +import junit.framework.Test; +import junit.framework.TestSuite; + + +/** + * + * AllDedbugTests.java + * This is the main entry point for running this suite of JUnit tests + * for all tests within the package "org.eclipse.cdt.debug.core" + * + * @author Judy N. Green + * @since Jul 19, 2002 + */ +public class AllDebugTests { + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } + + public static Test suite() { + TestSuite suite = new TestSuite(); + + // Just add more test cases here as you create them for + // each class being tested + + suite.addTest(DebugTests.suite()); + suite.addTest(BreakpointTests.suite()); + suite.addTest(LocationTests.suite()); + suite.addTest(TargetTests.suite()); + return suite; + + + } +} // End of AllDebugTests.java + 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 new file mode 100644 index 00000000000..11925668a1b --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/BreakpointTests.java @@ -0,0 +1,615 @@ +package org.eclipse.cdt.debug.core.tests; + +/* + * (c) Copyright QNX Software Systems Ltd. 2002. + * All Rights Reserved. + */ + + +import java.io.FileNotFoundException; +import java.io.IOException; + +import junit.framework.TestCase; +import junit.framework.TestSuite; +import org.eclipse.cdt.debug.testplugin.*; +import org.eclipse.cdt.core.model.*; +import org.eclipse.core.resources.*; +import org.eclipse.core.runtime.*; +import org.eclipse.cdt.debug.mi.core.*; +import org.eclipse.cdt.debug.core.cdi.*; +import org.eclipse.cdt.debug.core.cdi.model.*; + +/** + * @author Peter Graves + * + * This file contains a set of generic tests for the CDI break point interfaces. + * It will currenly use the mi implementation. + * + */ +public class BreakpointTests extends TestCase { + IWorkspace workspace; + IWorkspaceRoot root; + ICProject testProject; + NullProgressMonitor monitor; + + + /** + * 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"); + 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,FileNotFoundException { + + /*** + * Setup the various files, paths and projects that are needed by the + * tests + */ + testProject=CProjectHelper.createCProject("filetest", "none"); + if (testProject==null) + fail("Unable to create project"); + } + + /** + * Tears down the test fixture. + * + * Called after every test case method. + */ + protected void tearDown() throws CoreException { + CProjectHelper.delete(testProject); + } + + public static TestSuite suite() { + return new TestSuite(BreakpointTests.class); + } + + public static void main (String[] args){ + junit.textui.TestRunner.run(suite()); + } + + + /*** + * A couple tests to make sure setting breakpoints on functions works as + * expected. + */ + public void testFunctionBreak() throws CoreException, MIException, IOException, CDIException, InterruptedException { + ICDISession session; + ICDIBreakpointManager breaks; + ICDILocation location; + ICDITarget targets[]; + boolean caught=false; + session=CDebugHelper.createSession("main"); + assertNotNull(session); + breaks=session.getBreakpointManager(); + assertNotNull(breaks); + + /********************************************************************** + * Create a break point on a generic function + **********************************************************************/ + + location=breaks.createLocation(null, "func1", 0); + assertNotNull(location); + breaks.setLocationBreakpoint(0, location, null, null); + + /********************************************************************** + * Create a break point on main + **********************************************************************/ + + location=breaks.createLocation(null, "main", 0); + assertNotNull(location); + breaks.setLocationBreakpoint(0, location, null, null); + + + /********************************************************************** + * Try to create a break point on a function name that does not exist + * We expect that this will cause the setLocationBreakpoint to throw + * a CDIException + **********************************************************************/ + + location=breaks.createLocation(null, "badname", 0); + assertNotNull(location); + try { + breaks.setLocationBreakpoint(0, location, null, null); + } catch (CDIException e) { + caught=true; + } + assertTrue(caught); + + breaks.deleteAllBreakpoints(); + + /********************************************************************** + * Create a break point on a generic function and see if it will + * get hit and stop program execution. + **********************************************************************/ + + location=breaks.createLocation(null, "func1", 0); + assertNotNull(location); + breaks.setLocationBreakpoint(0, location, null, null); + targets=session.getTargets(); + /* We better only have one target connected to this session or something + * is not right... + */ + assertTrue(targets.length==1); + /* Resume the target, this should cause it to run till it hits the + * breakpoint + */ + targets[0].resume(); + /** + * Give the process up to 10 seconds to become either terminated or + * suspended. It sould hit the breakponint almost immediatly so we + * should only sleep for max 100 ms + */ + for (int x=0;x<100;x++) { + if (targets[0].isTerminated() || targets[0].isSuspended()) + break; + Thread.sleep(100); + } + assertTrue(targets[0].isSuspended()); + location=targets[0].getCurrentThread().getStackFrames()[0].getLocation(); + assertTrue(location.getLineNumber()==6); + assertTrue(location.getFunction().equals("func1")); + assertTrue(location.getFile().equals("../main.c")); + + /* clean up the session */ + session.terminate(); + + + } + + /*** + * A couple tests to make sure setting breakpoints on line numbers works as + * expected. + */ + public void testLineBreak() throws CoreException, MIException, IOException, CDIException, InterruptedException { + ICDISession session; + ICDIBreakpointManager breaks; + ICDILocation location; + ICDITarget targets[]; + boolean caught=false; + session=CDebugHelper.createSession("main"); + assertNotNull(session); + breaks=session.getBreakpointManager(); + assertNotNull(breaks); + + /********************************************************************** + * Create a break point in a generic function + **********************************************************************/ + location=breaks.createLocation("main.c", null, 7); + assertNotNull(location); + breaks.setLocationBreakpoint(0, location, null, null); + + + /********************************************************************** + * Create a break point in main + **********************************************************************/ + location=breaks.createLocation("main.c", null, 18); + assertNotNull(location); + breaks.setLocationBreakpoint(0, location, null, null); + + + /********************************************************************** + * Try to create a break point on a line that does not exist + * We expect that this will cause the setLocationBreakpoint to throw + * a CDIException + **********************************************************************/ + + location=breaks.createLocation("main.c", null, 30); + assertNotNull(location); + try { + breaks.setLocationBreakpoint(0, location, null, null); + } catch (CDIException e) { + caught=true; + } + assertTrue(caught); + + caught=false; + /********************************************************************** + * Try to create a break point on a line that does not have code on it + **********************************************************************/ + + location=breaks.createLocation("main.c", null, 11); + assertNotNull(location); + breaks.setLocationBreakpoint(0, location, null, null); + + /********************************************************************** + * Create a break point in a generic function without passing the source + * file name. At the time of writing this would just silently fail, so + * to make sure it works, we will do it once with a valid line number + * and once with an invalid line number, and the first should always + * succeed and the second should always throw an exception. + **********************************************************************/ + location=breaks.createLocation(null, null, 7); + assertNotNull(location); + breaks.setLocationBreakpoint(0, location, null, null); + caught=false; + location=breaks.createLocation(null, null, 30); + assertNotNull(location); + try { + breaks.setLocationBreakpoint(0, location, null, null); + } catch (CDIException e) { + caught=true; + } + assertTrue("Ignoring line numbers with no file specified?", caught); + + breaks.deleteAllBreakpoints(); + + /********************************************************************** + * Create a break point on a line number and see if it will + * get hit and stop program execution. + **********************************************************************/ + + location=breaks.createLocation(null, null, 7); + assertNotNull(location); + breaks.setLocationBreakpoint(0, location, null, null); + targets=session.getTargets(); + /* We better only have one target connected to this session or something + * is not right... + */ + assertTrue(targets.length==1); + /* Resume the target, this should cause it to run till it hits the + * breakpoint + */ + targets[0].resume(); + /** + * Give the process up to 10 seconds to become either terminated or + * suspended. It sould hit the breakponint almost immediatly so we + * should only sleep for max 100 ms + */ + for (int x=0;x<100;x++) { + if (targets[0].isSuspended() || targets[0].isTerminated()) + break; + Thread.sleep(100); + } + assertTrue("Suspended: " + targets[0].isSuspended() + " Termiunated: " + targets[0].isTerminated(), targets[0].isSuspended()); + location=targets[0].getCurrentThread().getStackFrames()[0].getLocation(); + assertTrue(location.getLineNumber()==7); + assertTrue(location.getFunction().equals("func1")); + assertTrue(location.getFile().equals("../main.c")); + + + /* clean up the session */ + session.terminate(); + + } + /*** + * A couple tests to make sure getting breakpoints works as expected + */ + public void testGetBreak() throws CoreException, MIException, IOException, CDIException { + ICDISession session; + ICDIBreakpointManager breaks; + ICDILocation location; + ICDIBreakpoint[] breakpoints; + ICDILocationBreakpoint curbreak; + session=CDebugHelper.createSession("main"); + assertNotNull(session); + breaks=session.getBreakpointManager(); + assertNotNull(breaks); + + /********************************************************************** + * Make sure initially we don't have any breakpoints + **********************************************************************/ + breakpoints=breaks.getBreakpoints(); + assertNotNull(breakpoints); + assertTrue(breakpoints.length==0); + + /********************************************************************** + * Make sure if we create a simple breakpoint, that we can get it back + * from the system + *********************************************************************/ + /* Create a break point on a generic function */ + location=breaks.createLocation("../main.c", "func1", 0); + assertNotNull(location); + breaks.setLocationBreakpoint(0, location, null, null); + + breakpoints=breaks.getBreakpoints(); + assertNotNull(breakpoints); + assertTrue(breakpoints.length==1); + if (breakpoints[0] instanceof ICDILocationBreakpoint) { + curbreak=(ICDILocationBreakpoint) breakpoints[0]; + } else + curbreak=null; + assertNotNull(curbreak); + + assertTrue(curbreak.getLocation().equals(location)); + + /********************************************************************** + * Make sure if we create multiple break points that we can still + * get them all back from the system, + **********************************************************************/ + /* Create another break point on main */ + location=breaks.createLocation("../main.c", "main", 0); + assertNotNull(location); + breaks.setLocationBreakpoint(0, location, null, null); + + breakpoints=breaks.getBreakpoints(); + assertNotNull(breakpoints); + assertTrue(breakpoints.length==2); + if (breakpoints[1] instanceof ICDILocationBreakpoint) { + curbreak=(ICDILocationBreakpoint) breakpoints[1]; + } else + curbreak=null; + assertNotNull(curbreak); + /* Make sure the location still looks like we expect it to.. + . */ + assertTrue(curbreak.getLocation().equals(location)); + + breaks.deleteAllBreakpoints(); + + + /* clean up the session */ + session.terminate(); + + + } + + /*** + * A couple tests to make sure deleting breakpoints works as expected + */ + public void testDelBreak() throws CoreException, MIException, IOException, CDIException { + ICDISession session; + ICDIBreakpointManager breaks; + ICDILocation location, savedLocation; + ICDIBreakpoint[] breakpoints, savedbreakpoints; + ICDILocationBreakpoint curbreak; + + session=CDebugHelper.createSession("main"); + assertNotNull(session); + breaks=session.getBreakpointManager(); + assertNotNull(breaks); + + /* Make sure initially we don't have any breakpoints */ + breakpoints=breaks.getBreakpoints(); + assertNotNull(breakpoints); + assertTrue(breakpoints.length==0); + + /********************************************************************** + * + * Test to make sure if we create a new breakpoint, we can delete + * it by passing a refrence to it to deleteBreakpoint() + * + **********************************************************************/ + + /* Create a break point on a generic function */ + location=breaks.createLocation("../main.c", "func1", 0); + assertNotNull(location); + curbreak=breaks.setLocationBreakpoint(0, location, null, null); + breaks.deleteBreakpoint(curbreak); + /** + * we should not have any breakpoints left. + */ + breakpoints=breaks.getBreakpoints(); + assertTrue(breakpoints.length==0); + + /********************************************************************** + * + * Test to make sure if we create multiple new breakpoint, we can delete + * one of them by passing a refrence to it to deleteBreakpoint() + * + **********************************************************************/ + + /* Create a break point on a generic function */ + location=breaks.createLocation("../main.c", "func1", 0); + assertNotNull(location); + curbreak=breaks.setLocationBreakpoint(0, location, null, null); + savedLocation=curbreak.getLocation(); + + location=breaks.createLocation("../main.c", "main", 0); + assertNotNull(location); + curbreak=breaks.setLocationBreakpoint(0, location, null, null); + breaks.deleteBreakpoint(curbreak); + + breakpoints=breaks.getBreakpoints(); + /*** + * Make sure there is only 1 breakpoint left, and it's the one we expect + */ + assertTrue(breakpoints.length==1); + curbreak=(ICDILocationBreakpoint) breakpoints[0]; + assertNotNull(curbreak); + assertTrue(curbreak.getLocation().equals(savedLocation)); + /*** + * Then delete the other breakpoint. + */ + breaks.deleteBreakpoint(curbreak); + + breakpoints=breaks.getBreakpoints(); + assertTrue(breakpoints.length==0); + + /********************************************************************** + * Make sure deleteBreakpoints works when given 1 breakpoint to delete + **********************************************************************/ + savedbreakpoints= new ICDIBreakpoint[1]; + for (int x=0;x<10;x++) { + location=breaks.createLocation("../main.c", null, x+1); + savedbreakpoints[0]=breaks.setLocationBreakpoint(0, location, null, null); + assertNotNull(savedbreakpoints[0]); + } + breaks.deleteBreakpoints(savedbreakpoints); + + /* We should now have 9 breakpoints left. */ + breakpoints=breaks.getBreakpoints(); + assertTrue(breakpoints.length==9); + /* Make sure we have the correct 9 breakpoints left */ + for (int x=0;x<breakpoints.length;x++) { + curbreak=(ICDILocationBreakpoint)breakpoints[x]; + assertTrue(curbreak.getLocation().getLineNumber()==x+1); + } + breaks.deleteAllBreakpoints(); + assertTrue(breaks.getBreakpoints().length==0); + + /********************************************************************** + * Make sure deleteBreakpoints works when given more then 1 but less + * then all breakpoints to delete + **********************************************************************/ + savedbreakpoints= new ICDIBreakpoint[4]; + for (int x=0;x<10;x++) { + location=breaks.createLocation("../main.c", null, x+1); + savedbreakpoints[x%4]=breaks.setLocationBreakpoint(0, location, null, null); + assertNotNull(savedbreakpoints[x%4]); + } + breaks.deleteBreakpoints(savedbreakpoints); + + /* We should now have 6 breakpoints left. */ + breakpoints=breaks.getBreakpoints(); + assertTrue(breakpoints.length==6); + /* Make sure we have the correct 6 breakpoints left */ + for (int x=0;x<breakpoints.length;x++) { + curbreak=(ICDILocationBreakpoint)breakpoints[x]; + assertTrue(curbreak.getLocation().getLineNumber()==x+1); + } + breaks.deleteAllBreakpoints(); + assertTrue(breaks.getBreakpoints().length==0); + + /********************************************************************** + * Make sure deleteBreakpoints works when given all the breakpoints + **********************************************************************/ + savedbreakpoints= new ICDIBreakpoint[10]; + for (int x=0;x<10;x++) { + location=breaks.createLocation("../main.c", null, x+1); + savedbreakpoints[x]=breaks.setLocationBreakpoint(0, location, null, null); + assertNotNull(savedbreakpoints[x]); + } + breaks.deleteBreakpoints(savedbreakpoints); + + /* We should now have 0 breakpoints left. */ + breakpoints=breaks.getBreakpoints(); + assertTrue(breakpoints.length==0); + + /********************************************************************** + * Make sure deleteAllBreakpoints works + **********************************************************************/ + + for (int x=0;x<10;x++) { + location=breaks.createLocation("../main.c", null, x+1); + curbreak=breaks.setLocationBreakpoint(0, location, null, null); + assertNotNull(curbreak); + } + breaks.deleteAllBreakpoints(); + + /* We should now have 0 breakpoints left. */ + breakpoints=breaks.getBreakpoints(); + assertTrue(breakpoints.length==0); + + + + /* clean up the session */ + session.terminate(); + + + } + /*** + * A couple tests to make sure setting breakpoints with conditions seems to + * work as expected. + */ + public void testCondBreak() throws CoreException, MIException, IOException, CDIException, InterruptedException { + ICDISession session; + ICDIBreakpointManager breaks; + ICDILocation location; + ICDICondition cond; + ICDITarget targets[]; + boolean caught=false; + session=CDebugHelper.createSession("main"); + assertNotNull(session); + breaks=session.getBreakpointManager(); + assertNotNull(breaks); + + /********************************************************************** + * Create a break point on a generic function with an empty condition + **********************************************************************/ + cond=breaks.createCondition(0, ""); + location=breaks.createLocation(null, "func1", 0); + assertNotNull(location); + breaks.setLocationBreakpoint(0, location, cond, null); + + /********************************************************************** + * Create a break point on a generic function with an valid condition + **********************************************************************/ + cond=breaks.createCondition(0, "x<10"); + location=breaks.createLocation(null, "func1", 0); + assertNotNull(location); + breaks.setLocationBreakpoint(0, location, cond, null); + + /********************************************************************** + * Create a break point on a generic function with an invalid condition + * We expect to get a CDIException when we try to set the breakpoint. + **********************************************************************/ + cond=breaks.createCondition(0, "nonexist<10"); + location=breaks.createLocation(null, "func1", 0); + assertNotNull(location); + try { + breaks.setLocationBreakpoint(0, location, cond, null); + } catch (CDIException e) { + caught=true; + } + assertTrue(caught); + + /********************************************************************** + * Create a break point on a line number with a condition and make sure + * it does not suspend execution of the application until the condition + * is true + **********************************************************************/ + breaks.deleteAllBreakpoints(); + location=breaks.createLocation(null, null, 23); + assertNotNull(location); + cond=breaks.createCondition(0, "a>10"); + + breaks.setLocationBreakpoint(0, location, cond, null); + targets=session.getTargets(); + /* We better only have one target connected to this session or something + * is not right... + */ + assertTrue(targets.length==1); + /* Resume the target, this should cause it to run till it hits the + * breakpoint + */ + targets[0].resume(); + /** + * Give the process up to 10 seconds to become either terminated or + * suspended. It sould hit the breakponint almost immediatly so we + * should only sleep for max 100 ms + */ + for (int x=0;x<100;x++) { + if (targets[0].isSuspended() || targets[0].isTerminated()) + break; + Thread.sleep(100); + } + assertTrue("Suspended: " + targets[0].isSuspended() + " Termiunated: " + targets[0].isTerminated(), targets[0].isSuspended()); + location=targets[0].getCurrentThread().getStackFrames()[0].getLocation(); + assertTrue(location.getLineNumber()==23); + assertTrue(location.getFunction().equals("main")); + assertTrue(location.getFile().equals("../main.c")); + /* Get the value of a and and make sure it is 11 */ + assertTrue(targets[0].evaluateExpressionToString("a"), + targets[0].evaluateExpressionToString("a").equals("11")); + + + /* clean up the session */ + session.terminate(); + + + } + + +} diff --git a/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/DebugTests.java b/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/DebugTests.java new file mode 100644 index 00000000000..5a7c2c22f23 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/DebugTests.java @@ -0,0 +1,120 @@ +package org.eclipse.cdt.debug.core.tests; + +/* + * (c) Copyright QNX Software Systems Ltd. 2002. + * All Rights Reserved. + */ + + +import java.io.FileNotFoundException; +import java.io.IOException; + +import junit.framework.TestCase; +import junit.framework.TestSuite; +import org.eclipse.cdt.debug.testplugin.*; +import org.eclipse.cdt.core.model.*; +import org.eclipse.core.resources.*; +import org.eclipse.core.runtime.*; +import org.eclipse.cdt.debug.mi.core.*; +import org.eclipse.cdt.debug.core.cdi.*; + +/** + * @author Peter Graves + * + * This file contains a set of generic tests for the debug stuff. It currenly + * uses the mi debugger. + * + */ +public class DebugTests extends TestCase { + IWorkspace workspace; + IWorkspaceRoot root; + ICProject testProject; + NullProgressMonitor monitor; + + + /** + * Constructor for DebugTests + * @param name + */ + public DebugTests(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,FileNotFoundException { + + /*** + * Setup the various files, paths and projects that are needed by the + * tests + */ + testProject=CProjectHelper.createCProject("filetest", "none"); + if (testProject==null) + fail("Unable to create project"); + } + + /** + * Tears down the test fixture. + * + * Called after every test case method. + */ + protected void tearDown() throws CoreException { + CProjectHelper.delete(testProject); + } + + public static TestSuite suite() { + return new TestSuite(DebugTests.class); + } + + public static void main (String[] args){ + junit.textui.TestRunner.run(suite()); + } + + + /*** + * Can we setup a debug? + * This is sort of a catch all sanity tests to make sure we can create a debug + * session with a break point and start it without having any exceptions thrown. + * It's not ment to be a real proper test. + */ + public void testDebug() throws CoreException, MIException, IOException, CDIException { + ICDISession session; + ICDISourceManager source; + ICDIBreakpointManager breaks; + ICDILocation location; + + session=CDebugHelper.createSession("main"); + assertNotNull(session); + source=session.getSourceManager(); + assertNotNull(source); + breaks=session.getBreakpointManager(); + assertNotNull(breaks); + location=breaks.createLocation(null, "func1", 0); + assertNotNull(location); + breaks.setLocationBreakpoint(0, location, null, null); + session.getCurrentTarget().resume(); + + + } + + +} diff --git a/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/resources/main.c b/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/resources/main.c new file mode 100644 index 00000000000..80405cedf32 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/resources/main.c @@ -0,0 +1,26 @@ +#include <stdio.h> + +void func1() +{ + int x,y,z; + x=1; + y=2; + z=3; + printf("Hello world\n"); + printf("Hello world\n"); + printf("Hello world\n"); +} + +int main() +{ + int a,b,c; + a=b=c=10; + a=12; + b=124; + c=1; + func1(); + for (a=0;a<100;a++) { + c++; + } + return(1); +} diff --git a/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/resources/win/Makefile b/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/resources/win/Makefile new file mode 100644 index 00000000000..cedfb06fb2c --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/resources/win/Makefile @@ -0,0 +1,2 @@ +win: + gcc -g -o main ../main.c diff --git a/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/resources/win/main.exe b/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/resources/win/main.exe new file mode 100644 index 0000000000000000000000000000000000000000..ab54e4871e999b2b87e752a2c6caebbdedba0762 GIT binary patch literal 25658 zcmeHP4RBo7Rlc&7)OFIvX__=GDOHLMQCLg+ua%U7l$D&gk!{72TenU7vf6!;w%#9Q ze`Kc(L8+a#!tIQQrlrG_A%p;(0g5}rPw1552|pr30)dtmS{O1zDbB<U8O8%GWFo%r z+<V`<Z&!Ad;4qz`Z?t;fJNMjk&pr3tbN}A%zW1I|Ta{A1_^huh^%(BF#^nFS|E(bT z^>6#q>(y_+_Nf~m>zR7$#@WSkvu~+UUuYDneZ@kpR&Vvq`F)Lct*>0`n>aAjSFM-) zf!Dom`%WWzdQz#Wp3BuY+Yh}%O)K?n(4SGSQCIYA$%#@_Yzsa+%%=}`YR6~LncRa9 z?{Yni|9JT9x0TdOsXooi49tVe-1NhkQWXmLKfVT9{;?Lyyqm_SLaabg31D1(NFFE^ zS_O@TAhy`X)bJWp>de4gvq_57Egq)1XoY-bEl}z_hE&>iJ3h`eM!sgNFbCSVufo4+ zd?@%ze4J~`Hg&7;HCv5OCXsMAK52Yzz{k1B=RE!Zeji!j(CR-QKez3dRNt6-@Jy@c z$-n!l7q9xg$rpE>d47F;esxkFUiXu5Qa=1$^~JT`oe%FAQ)mAebyz+3{y)0iuT<)N zN9&DBX}kL5vJ!dMuT8$dKD9RaUAouW<av7e@jpJlIL5r+m4_X{^VyE)ztztae@e?c z`#T^(3>_6h_3Z_7qgR4>pJrjXXP4L4*P#O-bvpi2FBI?J^4zxd$@A-zFFg1BW8`_R z=M)Rj@>kn0oNRAfegAh8-&#%YT$|V_J@KpuK3M0$GwmB6ICq-D?%KHxsnY+zxO&&l z-m@c`Y4wJk>({P~jj2<SYkgNsXke0Seb*-<&nQ1}X6E?0-jnaY^1*Lib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-Jr-kP_;AH+k^UHpG{= zq_8ufg!(k`^zlfp2SA~W(DI)F<y64qp;1ewy=W#R;`$ZbY*g2jKg8`(q-cGx{*szL z18P|MlX$Z8L!IlJxP|^q$!8^Dhoesq40Aq^OrF<+LTiOO-+)Iu@70oT2Ib3<Tw|cv zIi%*f1C;wBJaeF|L@38WVV!U@bw34oBEs`IP-q)tdB^QSi~TkQ1Uy840t)9Y+G3=9 z6%<CvkaD&wS1%KBnX;DjPn_ztRiDxD2JqO3y+tMQB<tb)!P%Ksq0wqDDZc58mr$!q zSdy0p&?))7{D9yUm8W0UlAl{evhzeP9Q%*u0-h!8oa0^PR3{<XNl0`O;w;&fJ-5UF zfp4$!i*}6`{0<Dxev*>tvGH%f;>4IgS5Tj4UVM{@dg41o6cJ6pHzWMUvM(vs!Uyq^ zYqLFvt?-s#^_KDVB<!;>t@Br6$I_65vBgo%%3bseOKy3!DypS>0Kx*kgw*ixwQNVW z$Df?Qmm=}qZmpn?Z%LxqLIvLttnzEAP{0@luh{6H!1eHzJsmzTWB{?8?ys8JxJP93 z&eX!Px%+yy%!HV^EE77<L+wgN8A*VEa&-v}qjy;l!{9|x)ir|&0_3BWyG#HXCQ4b6 z8`_+;4$9&~m?`2KK{HEpxUI}gfihuZ(>0_fL0ge=W3$UpYuP(~o7j*q{PV=ZfN$h* zXVsQz1ZvZ0cW@m9KZk-dVo$z$FD@dA2JI<rf_c^vxQ1WBOP~eF)t(mC&y}asHYmrH Kfmb*<hyNeIlQ=#A literal 0 HcmV?d00001 diff --git a/debug/org.eclipse.cdt.debug.ui.tests/plugin.xml b/debug/org.eclipse.cdt.debug.ui.tests/plugin.xml new file mode 100644 index 00000000000..3ca1e3de2f5 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/plugin.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<plugin + id="org.eclipse.cdt.debug.ui.tests" + name="org.eclipse.cdt.debug.ui.tests" + version="1.0.0"> + + <runtime> + <library name="cdtdebugtests.jar"/> + </runtime> + <requires> + <import plugin="org.apache.xerces"/> + <import plugin="org.eclipse.core.boot"/> + <import plugin="org.eclipse.core.resources"/> + <import plugin="org.eclipse.core.runtime"/> + <import plugin="org.eclipse.swt"/> + <import plugin="org.junit"/> + <import plugin="org.eclipse.cdt.debug.core"/> + <import plugin="org.eclipse.cdt.debug.mi.core"/> + <import plugin="org.eclipse.cdt.core"/> + <import plugin="org.eclipse.ui"/> + </requires> + + +</plugin> diff --git a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CDebugHelper.java b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CDebugHelper.java new file mode 100644 index 00000000000..9e3f4ab17f6 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CDebugHelper.java @@ -0,0 +1,48 @@ +package org.eclipse.cdt.debug.testplugin; + +import java.io.IOException; + +import org.eclipse.cdt.debug.core.cdi.*; +import org.eclipse.cdt.debug.mi.core.*; +import org.eclipse.core.runtime.Path; + + +/** + * Helper methods to set up a Debug session. + */ +public class CDebugHelper { + + + + /** + * Creates a ICDISession. + */ + public static ICDISession createSession(String exe) throws IOException, MIException { + MIPlugin mi; + ICDISession session; + String os = System.getProperty("os.name"); + String exename; + mi=MIPlugin.getDefault(); + + exename=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.debug.ui.tests").find(new Path("/")).getFile(); + exename+="core/org/eclipse/cdt/debug/core/tests/resources/"; + os=os.toLowerCase(); + /* We need to get the correct executable to execute + */ + if (os.indexOf("windows")!=-1) + exename+="win/"+ exe +".exe"; + else if (os.indexOf("qnx")!=-1) + exename+="qnx/" + exe; + else if (os.indexOf("linux")!=-1) + exename+="linux/"+exe; + else if (os.indexOf("sol")!=-1) + exename+="sol/" + exe; + else + return(null); + session=mi.createCSession(null, exename); + return(session); + } + + +} + diff --git a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CElementDecorator.java b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CElementDecorator.java new file mode 100644 index 00000000000..5020091fa06 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CElementDecorator.java @@ -0,0 +1,30 @@ +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ +package org.eclipse.cdt.debug.testplugin; + +import org.eclipse.swt.graphics.Image; + +import org.eclipse.jface.viewers.ILabelDecorator; +import org.eclipse.jface.viewers.LabelProvider; + +/** + * Allows to test decorators for Java elements + */ +public class CElementDecorator extends LabelProvider implements ILabelDecorator { + + /* + * @see ILabelDecorator#decorateImage(Image, Object) + */ + public Image decorateImage(Image image, Object element) { + return null; + } + + /* + * @see ILabelDecorator#decorateText(String, Object) + */ + public String decorateText(String text, Object element) { + return text + "*"; + } +} diff --git a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CProjectHelper.java b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CProjectHelper.java new file mode 100644 index 00000000000..b976f0f2316 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CProjectHelper.java @@ -0,0 +1,293 @@ +package org.eclipse.cdt.debug.testplugin; + +import java.io.File; +import java.lang.reflect.InvocationTargetException; +import java.util.zip.ZipFile; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.CProjectNature; +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.IArchiveContainer; +import org.eclipse.cdt.core.model.IBinaryContainer; +import org.eclipse.cdt.core.model.ICFolder; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.IArchive; +import org.eclipse.cdt.core.model.IBinary; +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.ui.dialogs.IOverwriteQuery; +import org.eclipse.ui.wizards.datatransfer.ImportOperation; +import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider; + +/** + * Helper methods to set up a ICProject. + */ +public class CProjectHelper { + + public static final IPath RT_STUBS= new Path("testresources/rtstubs.jar"); + public static final IPath JUNIT_SRC= new Path("testresources/junit37-noUI-src.zip"); + + public static final IPath MYLIB= new Path("testresources/mylib.jar"); + + + /** + * Creates a ICProject. + */ + public static ICProject createCProject(String projectName, String binFolderName) throws CoreException { + IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); + IProject project= root.getProject(projectName); + if (!project.exists()) { + project.create(null); + } else { + project.refreshLocal(IResource.DEPTH_INFINITE, null); + } + + if (!project.isOpen()) { + project.open(null); + } + + + if (!project.hasNature(CProjectNature.C_NATURE_ID)) { + addNatureToProject(project, CProjectNature.C_NATURE_ID, null); + } + + ICProject cproject = CCorePlugin.getDefault().getCoreModel().create(project); + + return cproject; + } + + /** + * Removes a ICProject. + */ + public static void delete(ICProject cproject) throws CoreException { + performDummySearch(); + cproject.getProject().delete(true, true, null); + } + + public static void performDummySearch() throws CModelException { + /* SearchEngine().searchAllTypeNames( + ResourcesPlugin.getWorkspace(), + null, + null, + IJavaSearchConstants.EXACT_MATCH, + IJavaSearchConstants.CASE_SENSITIVE, + IJavaSearchConstants.CLASS, + SearchEngine.createJavaSearchScope(new IJavaElement[0]), + new Requestor(), + IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, + null); */ + } + + + /** + * Adds a source container to a ICProject. + */ + public static ICFolder addSourceContainer(ICProject cproject, String containerName) throws CoreException { + IProject project= cproject.getProject(); + IContainer container= null; + if (containerName == null || containerName.length() == 0) { + container= project; + } else { + IFolder folder= project.getFolder(containerName); + if (!folder.exists()) { + folder.create(false, true, null); + } + container= folder; + } + + return (ICFolder)container; + } + + /** + * Adds a source container to a ICProject and imports all files contained + * in the given Zip file. + */ + public static ICFolder addSourceContainerWithImport(ICProject cproject, String containerName, ZipFile zipFile) throws InvocationTargetException, CoreException { + ICFolder root= addSourceContainer(cproject, containerName); + importFilesFromZip(zipFile, root.getPath(), null); + return root; + } + + /** + * Removes a source folder from a IJavaProject. + */ + public static void removeSourceContainer(ICProject cproject, String containerName) throws CoreException { + IFolder folder= cproject.getProject().getFolder(containerName); + folder.delete(true, null); + } + + + /** + * Adds a required project entry. + */ + public static void addRequiredProject(ICProject cproject, ICProject required) throws CModelException { + //IClasspathEntry cpe= JavaCore.newProjectEntry(required.getProject().getFullPath()); + //addToClasspath(cproject, cpe); + } + + /** + * Attempts to find an archive with the given name in the workspace + */ + public static IArchive findArchive(ICProject testProject,String name) { + int x; + IArchive[] myArchives; + IArchiveContainer archCont; + archCont=testProject.getArchiveContainer(); + myArchives=archCont.getArchives(); + if (myArchives.length<1) + return(null); + for (x=0;x<myArchives.length;x++) { + if (myArchives[x].getElementName().equals(name)) + return(myArchives[x]); + } + return(null); + } + /** + * Attempts to find a binary with the given name in the workspace + */ + public static IBinary findBinary(ICProject testProject,String name) { + IBinaryContainer binCont; + int x; + IBinary[] myBinaries; + binCont=testProject.getBinaryContainer(); + myBinaries=binCont.getBinaries(); + if (myBinaries.length<1) + return(null); + for (x=0;x<myBinaries.length;x++) { + if (myBinaries[x].getElementName().equals(name)) + return(myBinaries[x]); + + } + return(null); + } + + /** + * Attempts to find an object with the given name in the workspace + */ + public static IBinary findObject(ICProject testProject,String name) { + int x; + ICElement[] myElements; + myElements=testProject.getChildren(); + if (myElements.length<1) + return(null); + for (x=0;x<myElements.length;x++) { + if (myElements[x].getElementName().equals(name)) + if (myElements[x] instanceof ICElement) { + if (myElements[x] instanceof IBinary) { + return((IBinary) myElements[x]); + } + } + } + return(null); + } + /** + * Attempts to find a TranslationUnit with the given name in the workspace + */ + public static ITranslationUnit findTranslationUnit(ICProject testProject,String name) { + int x; + ICElement[] myElements; + myElements=testProject.getChildren(); + if (myElements.length<1) + return(null); + for (x=0;x<myElements.length;x++) { + if (myElements[x].getElementName().equals(name)) + if (myElements[x] instanceof ICElement) { + if (myElements[x] instanceof ITranslationUnit) { + return((ITranslationUnit) myElements[x]); + } + } + } + return(null); + } + + + + /** + * Attempts to find an element with the given name in the workspace + */ + public static ICElement findElement(ICProject testProject,String name) { + int x; + ICElement[] myElements; + myElements=testProject.getChildren(); + if (myElements.length<1) + return(null); + for (x=0;x<myElements.length;x++) { + if (myElements[x].getElementName().equals(name)) + if (myElements[x] instanceof ICElement) { + return((ICElement) myElements[x]); + } + + + } + return(null); + } + + + /** + * Try to find rt.jar + */ + public static IPath[] findRtJar() { + File rtStubs= CTestPlugin.getDefault().getFileInPlugin(RT_STUBS); + if (rtStubs != null && rtStubs.exists()) { + return new IPath[] { + new Path(rtStubs.getPath()), + null, + null + }; + } + + /* + IVMInstall vmInstall= JavaRuntime.getDefaultVMInstall(); + if (vmInstall != null) { + LibraryLocation loc= vmInstall.getVMInstallType().getDefaultLibraryLocation(vmInstall.getInstallLocation()); + if (loc != null) { + return new IPath[] { + new Path(loc.getSystemLibrary().getPath()), + new Path(loc.getSystemLibrarySource().getPath()), + loc.getPackageRootPath() + }; + } + }*/ + return null; + } + + private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException { + IProjectDescription description = proj.getDescription(); + String[] prevNatures= description.getNatureIds(); + String[] newNatures= new String[prevNatures.length + 1]; + System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length); + newNatures[prevNatures.length]= natureId; + description.setNatureIds(newNatures); + proj.setDescription(description, monitor); + } + + private static void importFilesFromZip(ZipFile srcZipFile, IPath destPath, IProgressMonitor monitor) throws InvocationTargetException { + ZipFileStructureProvider structureProvider= new ZipFileStructureProvider(srcZipFile); + try { + ImportOperation op= new ImportOperation(destPath, structureProvider.getRoot(), structureProvider, new ImportOverwriteQuery()); + op.run(monitor); + } catch (InterruptedException e) { + // should not happen + } + } + + private static class ImportOverwriteQuery implements IOverwriteQuery { + public String queryOverwrite(String file) { + return ALL; + } + } + + +} + diff --git a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CTestPlugin.java b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CTestPlugin.java new file mode 100644 index 00000000000..3eceaecf6ea --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CTestPlugin.java @@ -0,0 +1,58 @@ +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ +package org.eclipse.cdt.debug.testplugin; + +import java.io.File; +import java.io.IOException; +import java.net.URL; + +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceDescription; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IPluginDescriptor; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Plugin; + + +public class CTestPlugin extends Plugin { + + private static CTestPlugin fgDefault; + + public CTestPlugin(IPluginDescriptor descriptor) { + super(descriptor); + fgDefault= this; + } + + public static CTestPlugin getDefault() { + return fgDefault; + } + + public static IWorkspace getWorkspace() { + return ResourcesPlugin.getWorkspace(); + } + + public static void enableAutobuild(boolean enable) throws CoreException { + // disable auto build + IWorkspace workspace= fgDefault.getWorkspace(); + IWorkspaceDescription desc= workspace.getDescription(); + desc.setAutoBuilding(enable); + workspace.setDescription(desc); + } + + public File getFileInPlugin(IPath path) { + try { + URL installURL= new URL(getDescriptor().getInstallURL(), path.toString()); + URL localURL= Platform.asLocalURL(installURL); + return new File(localURL.getFile()); + } catch (IOException e) { + return null; + } + } + + + +} \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CTestSetup.java b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CTestSetup.java new file mode 100644 index 00000000000..c9a8395525f --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CTestSetup.java @@ -0,0 +1,31 @@ +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ +package org.eclipse.cdt.debug.testplugin; + +import junit.extensions.TestSetup; +import junit.framework.Test; + + + +public class CTestSetup extends TestSetup { + + /** + * @deprecated + * Not needed anymore. No added value + */ + public CTestSetup(Test test) { + super(test); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + + + +} \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/Main.java b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/Main.java new file mode 100644 index 00000000000..dffaf3d3af4 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/Main.java @@ -0,0 +1,528 @@ +package org.eclipse.cdt.debug.testplugin; + +// copied from startup.jar. planned to be removed soon + + +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ + +import java.net.*; +import java.lang.reflect.*; +import java.io.*; +import java.util.*; +/** + * Startup class for Eclipse. Creates a class loader using + * supplied URL of platform installation, loads and calls + * the Eclipse Boot Loader. The startup arguments are as follows: + * <dl> + * <dd> + * -application <id>: the identifier of the application to run + * </dd> + * <dd> + * -boot <location>: the location, expressed as a URL, of the platform's boot.jar + * </dd> + * <dd> + * -consolelog : enables log to the console. Handy when combined with -debug + * </dd> + * <dd> + * -data <location>: sets the workspace location and the default location for projects + * </dd> + * <dd> + * -debug [options file]: turns on debug mode for the platform and optionally specifies a location + * for the .options file. This file indicates what debug points are available for a + * plug-in and whether or not they are enabled. If a location is not specified, the platform searches + * for the .options file under the install directory + * </dd> + * <dd> + * -dev [entries]: turns on dev mode and optionally specifies comma-separated class path entries + * which are added to the class path of each plug-in + * </dd> + * <dd> + * -keyring <location>: the location of the authorization database on disk. This argument + * has to be used together with the -password argument + * </dd> + * <dd> + * -password <passwd>: the password for the authorization database + * </dd> + * <dd> + * -plugins <location>: The arg is a URL pointing to a file which specs the plugin + * path for the platform. The file is in property file format where the keys are user-defined + * names and the values are comma separated lists of either explicit paths to plugin.xml + * files or directories containing plugins. (e.g., .../eclipse/plugins). + * </dd> + * <dd> + * -ws <window system>: sets the window system value + * </dd> + * </dl> + */ +public class Main { + /** + * Indicates whether this instance is running in debug mode. + */ + protected boolean debug = false; + + /** + * The location of the launcher to run. + */ + protected String bootLocation = null; + + /** + * The identifier of the application to run. + */ + protected String application; + + /** + * The path for finding find plugins. + */ + protected URL pluginPathLocation; + + /** + * The boot path location. + */ + protected String location; + + /** + * Indicates whether items for UNinstallation should be looked for. + */ + protected boolean uninstall = false; + + /** + * The item to be uninstalled. + */ + protected String uninstallCookie; + + /** + * The class path entries. + */ + protected String devClassPath = null; + + /** + * Indicates whether this instance is running in development mode. + */ + protected boolean inDevelopmentMode = false; + + // static token describing how to take down the splash screen + private static String endSplash = null; + + // constants + private static final String APPLICATION = "-application"; + private static final String BOOT = "-boot"; + private static final String DEBUG = "-debug"; + private static final String DEV = "-dev"; + private static final String ENDSPLASH = "-endsplash"; + private static final String UNINSTALL = "-uninstall"; + private static final String PI_BOOT = "org.eclipse.core.boot"; + private static final String BOOTLOADER = "org.eclipse.core.boot.BootLoader"; + private static final String UPDATELOADER = "org.eclipse.core.internal.boot.LaunchInfo"; + + // The project containing the boot loader code. This is used to construct + // the correct class path for running in VAJ and VAME. + private static final String PROJECT_NAME = "Eclipse Core Boot"; + + private static boolean inVAJ; + static { + try { + Class.forName("com.ibm.uvm.lang.ProjectClassLoader"); + inVAJ = true; + } catch (Exception e) { + inVAJ = false; + } + } + private static boolean inVAME; + static { + try { + Class.forName("com.ibm.eclipse.core.VAME"); + inVAME = true; + } catch (Exception e) { + inVAME = false; + } + } + +/** + * Executes the launch. + * + * @return the result of performing the launch + * @param args command-line arguments + * @exception Exception thrown if a problem occurs during the launch + */ +protected Object basicRun(String[] args) throws Exception { + Class clazz = getBootLoader(bootLocation); + Method method = clazz.getDeclaredMethod("run", new Class[] { String.class, URL.class, String.class, String[].class }); + try { + return method.invoke(clazz, new Object[] { application, pluginPathLocation, location, args }); + } catch (InvocationTargetException e) { + if (e.getTargetException() instanceof Error) + throw (Error) e.getTargetException(); + else + throw e; + } +} + +/** + * Returns the result of converting a list of comma-separated tokens into an array + * + * @return the array of string tokens + * @param prop the initial comma-separated string + */ +private String[] getArrayFromList(String prop) { + if (prop == null || prop.trim().equals("")) + return new String[0]; + Vector list = new Vector(); + StringTokenizer tokens = new StringTokenizer(prop, ","); + while (tokens.hasMoreTokens()) { + String token = tokens.nextToken().trim(); + if (!token.equals("")) + list.addElement(token); + } + return list.isEmpty() ? new String[0] : (String[]) list.toArray(new String[0]); +} +/** + * Creates and returns a platform <code>BootLoader</code> which can be used to start + * up and run the platform. The given base, if not <code>null</code>, + * is the location of the boot loader code. If the value is <code>null</code> + * then the boot loader is located relative to this class. + * + * @return the new boot loader + * @param base the location of the boot loader + */ +public Class getBootLoader(String base) throws Exception { + URLClassLoader loader = new URLClassLoader(getBootPath(base), null); + return loader.loadClass(BOOTLOADER); +} +/** + * Returns the <code>URL</code>-based class path describing where the boot classes + * are located when running in development mode. + * + * @return the url-based class path + * @param base the base location + * @exception MalformedURLException if a problem occurs computing the class path + */ +protected URL[] getDevPath(URL base) throws MalformedURLException { + URL url; + String devBase = base.toExternalForm(); + if (!inDevelopmentMode) { + url = new URL(devBase + "boot.jar"); + return new URL[] {url}; + } + String[] locations = getArrayFromList(devClassPath); + ArrayList result = new ArrayList(locations.length); + for (int i = 0; i < locations.length; i++) { + String spec = devBase + locations[i]; + char lastChar = spec.charAt(spec.length() - 1); + if ((spec.endsWith(".jar") || (lastChar == '/' || lastChar == '\\'))) + url = new URL (spec); + else + url = new URL(spec + "/"); + //make sure URL exists before adding to path + if (new java.io.File(url.getFile()).exists()) + result.add(url); + } + url = new URL(devBase + "boot.jar"); + if (new java.io.File(url.getFile()).exists()) + result.add(url); + return (URL[])result.toArray(new URL[result.size()]); +} + +/** + * Returns the <code>URL</code>-based class path describing where the boot classes are located. + * + * @return the url-based class path + * @param base the base location + * @exception MalformedURLException if a problem occurs computing the class path + */ +protected URL[] getBootPath(String base) throws MalformedURLException { + URL url = null; + // if the given location is not null, assume it is correct and use it. + if (base != null) { + url = new URL(base); + if (debug) + System.out.println("Boot URL: " + url.toExternalForm()); + return new URL[] {url}; + } + // Create a URL based on the location of this class' code. + // strip off jar file and/or last directory to get + // to the directory containing projects. + URL[] result = null; + url = getClass().getProtectionDomain().getCodeSource().getLocation(); + String path = url.getFile(); + if (path.endsWith(".jar")) + path = path.substring(0, path.lastIndexOf("/")); + else + if (path.endsWith("/")) + path = path.substring(0, path.length() - 1); + if (inVAJ || inVAME) { + int ix = path.lastIndexOf("/"); + path = path.substring(0, ix + 1); + path = path + PROJECT_NAME + "/"; + url = new URL(url.getProtocol(), url.getHost(), url.getPort(), path); + result = new URL[] {url}; + } else { + path = searchForPlugins(path); + path = searchForBoot(path); + // add on any dev path elements + url = new URL(url.getProtocol(), url.getHost(), url.getPort(), path); + result = getDevPath(url); + } + if (debug) { + System.out.println("Boot URL:"); + for (int i = 0; i < result.length; i++) + System.out.println(" " + result[i].toExternalForm()); + } + return result; +} + +/** + * Searches for a plugins root starting at a given location. If one is + * found then this location is returned; otherwise an empty string is + * returned. + * + * @return the location where plugins were found, or an empty string + * @param start the location to begin searching at + */ +protected String searchForPlugins(String start) { + File path = new File(start); + while (path != null) { + File test = new File(path, "plugins"); + if (test.exists()) + return test.toString(); + path = path.getParentFile(); + path = (path == null || path.length() == 1) ? null : path; + } + return ""; +} +/** + * Searches for a boot directory starting at a given location. If one + * is found then this location is returned; otherwise an empty string + * is returned. + * + * @return the location where plugins were found, or an empty string + * @param start the location to begin searching at + */ +protected String searchForBoot(String start) { + FileFilter filter = new FileFilter() { + public boolean accept(File candidate) { + return candidate.getName().startsWith(PI_BOOT); + } + }; + File[] boots = new File(start).listFiles(filter); + String result = null; + String maxVersion = null; + for (int i = 0; i < boots.length; i++) { + String name = boots[i].getName(); + int index = name.lastIndexOf('_'); + if (index == -1) { + result = boots[i].getAbsolutePath(); + i = boots.length; + } else { + if (index > 0) { + String version = name.substring(index + 1); + if (maxVersion == null) { + result = boots[i].getAbsolutePath(); + maxVersion = version; + } else + if (maxVersion.compareTo(version) == -1) { + result = boots[i].getAbsolutePath(); + maxVersion = version; + } + } + } + } + if (result == null) + throw new RuntimeException("Could not find bootstrap code. Check location of boot plug-in or specify -boot."); + return result.replace(File.separatorChar, '/') + "/"; +} +/** + * Returns the update loader for the given boot path. + * + * @return the update loader + * @param base the boot path base + * @exception Exception thrown is a problem occurs determining this loader + */ +public Class getUpdateLoader(String base) throws Exception { + URLClassLoader loader = new URLClassLoader(getBootPath(base), null); + return loader.loadClass(UPDATELOADER); +} +/** + * Runs the platform with the given arguments. The arguments must identify + * an application to run (e.g., <code>-application com.example.application</code>). + * After running the application <code>System.exit(N)</code> is executed. + * The value of N is derived from the value returned from running the application. + * If the application's return value is an <code>Integer</code>, N is this value. + * In all other cases, N = 0. + * <p> + * Clients wishing to run the platform without a following <code>System.exit</code> + * call should use <code>run()</code>. + * + * @see #run + * + * @param args the command line arguments + */ +public static void main(String[] args) { + Object result = null; + try { + result = new Main().run(args); + } catch (Throwable e) { + // try and take down the splash screen. + endSplash(); + System.out.println("Exception launching the Eclipse Platform:"); + e.printStackTrace(); + } + int exitCode = result instanceof Integer ? ((Integer) result).intValue() : 0; + System.exit(exitCode); +} +/** + * Tears down the currently-displayed splash screen. + */ +public static void endSplash() { + if (endSplash == null) + return; + try { + Runtime.getRuntime().exec(endSplash); + } catch (Exception e) { + } +} + +/** + * Runs this launcher with the arguments specified in the given string. + * + * @param argString the arguments string + * @exception Exception thrown if a problem occurs during launching + */ +public static void main(String argString) throws Exception { + Vector list = new Vector(5); + for (StringTokenizer tokens = new StringTokenizer(argString, " "); tokens.hasMoreElements();) + list.addElement((String) tokens.nextElement()); + main((String[]) list.toArray(new String[list.size()])); +} + +/** + * Processes the command line arguments + * + * @return the arguments to pass through to the launched application + * @param args the command line arguments + */ +protected String[] processCommandLine(String[] args) throws Exception { + int[] configArgs = new int[100]; + configArgs[0] = -1; // need to initialize the first element to something that could not be an index. + int configArgIndex = 0; + for (int i = 0; i < args.length; i++) { + boolean found = false; + // check for args without parameters (i.e., a flag arg) + // check if debug should be enabled for the entire platform + if (args[i].equalsIgnoreCase(DEBUG)) { + debug = true; + // passed thru this arg (i.e., do not set found = true + continue; + } + + // check if development mode should be enabled for the entire platform + // If this is the last arg or there is a following arg (i.e., arg+1 has a leading -), + // simply enable development mode. Otherwise, assume that that the following arg is + // actually some additional development time class path entries. This will be processed below. + if (args[i].equalsIgnoreCase(DEV) && ((i + 1 == args.length) || ((i + 1 < args.length) && (args[i + 1].startsWith("-"))))) { + inDevelopmentMode = true; + // do not mark the arg as found so it will be passed through + continue; + } + + // done checking for args. Remember where an arg was found + if (found) { + configArgs[configArgIndex++] = i; + continue; + } + // check for args with parameters. If we are at the last argument or if the next one + // has a '-' as the first character, then we can't have an arg with a parm so continue. + if (i == args.length - 1 || args[i + 1].startsWith("-")) + continue; + String arg = args[++i]; + + // look for the laucher to run + if (args[i - 1].equalsIgnoreCase(BOOT)) { + bootLocation = arg; + found = true; + } + + // look for the development mode and class path entries. + if (args[i - 1].equalsIgnoreCase(DEV)) { + inDevelopmentMode = true; + devClassPath = arg; + continue; + } + + // look for the application to run + if (args[i - 1].equalsIgnoreCase(APPLICATION)) { + application = arg; + found = true; + } + + // look for token to use to end the splash screen + if (args[i - 1].equalsIgnoreCase(ENDSPLASH)) { + endSplash = arg; + continue; + } + + // look for items to uninstall + if (args[i - 1].equalsIgnoreCase(UNINSTALL)) { + uninstall = true; + uninstallCookie = arg; + found = true; + } + + // done checking for args. Remember where an arg was found + if (found) { + configArgs[configArgIndex++] = i - 1; + configArgs[configArgIndex++] = i; + } + } + // remove all the arguments consumed by this argument parsing + if (configArgIndex == 0) + return args; + String[] passThruArgs = new String[args.length - configArgIndex]; + configArgIndex = 0; + int j = 0; + for (int i = 0; i < args.length; i++) { + if (i == configArgs[configArgIndex]) + configArgIndex++; + else + passThruArgs[j++] = args[i]; + } + return passThruArgs; +} +/** + * Runs the application to be launched. + * + * @return the return value from the launched application + * @param args the arguments to pass to the application + * @exception thrown if a problem occurs during launching + */ +public Object run(String[] args) throws Exception { + String[] passThruArgs = processCommandLine(args); + if (uninstall) + return updateRun(UNINSTALL, uninstallCookie, passThruArgs); + else + return basicRun(passThruArgs); +} +/** + * Performs an update run. + * + * @return the return value from the update loader + * @param flag flag to give to the update loader + * @param value value to give to the update loader + * @param args arguments to give to the update loader. + * @exception Exception thrown if a problem occurs during execution + */ +protected Object updateRun(String flag, String value, String[] args) throws Exception { + Class clazz = getUpdateLoader(bootLocation); + Method method = clazz.getDeclaredMethod("run", new Class[] { String.class, String.class, String.class, String[].class }); + try { + return method.invoke(clazz, new Object[] { flag, value, location, args }); + } catch (InvocationTargetException e) { + if (e.getTargetException() instanceof Error) + throw (Error) e.getTargetException(); + else + throw e; + } +} +} diff --git a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/NewMain.java b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/NewMain.java new file mode 100644 index 00000000000..db442c80e60 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/NewMain.java @@ -0,0 +1,73 @@ +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ +package org.eclipse.cdt.debug.testplugin; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URL; +import java.util.Properties; +import java.util.StringTokenizer; +import java.util.Vector; + +/** + * Application is responsible for calling core launch api + */ + +public class NewMain extends Main { + private static final String DEFAULT_APPLICATION= "org.eclipse.ui.workbench"; + + + public NewMain(String application, String location, URL pluginPathLocation, String bootLocation, boolean debug) throws IOException { + this.application= application; + this.location= location; + this.pluginPathLocation= pluginPathLocation; + this.bootLocation= bootLocation; + } + + public static void main(String[] args) { + try { + String location= getLocationFromProperties("platform"); + new NewMain(DEFAULT_APPLICATION, location, null, null, true).run(args); + } catch (Throwable e) { + System.out.println("Exception launching the Eclipse Platform UI:"); + e.printStackTrace(); + } + System.exit(0); + } + + + /** + * Run this launcher with the arguments specified in the given string. + * This is a short cut method for people running the launcher from + * a scrapbook (i.e., swip-and-doit facility). + */ + public static void main(String argString) throws Exception { + Vector list= new Vector(5); + for (StringTokenizer tokens= new StringTokenizer(argString, " "); tokens.hasMoreElements();) + list.addElement((String) tokens.nextElement()); + main((String[]) list.toArray(new String[list.size()])); + } + + public static String getLocationFromProperties(String key) { + Properties properties= new Properties(); + try { + FileInputStream fis= new FileInputStream(getSettingsFile()); + properties.load(fis); + return properties.getProperty(key); + } catch (IOException e) { + } + return null; + } + + private static File getSettingsFile() { + String home= System.getProperty("user.home"); + if (home == null) { + System.out.println("Home dir not defined"); + return null; + } + return new File(home, "eclipse-workspaces.properties"); + } +} \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/TestPluginLauncher.java b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/TestPluginLauncher.java new file mode 100644 index 00000000000..ce3e74013d1 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/TestPluginLauncher.java @@ -0,0 +1,57 @@ +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ +package org.eclipse.cdt.debug.testplugin; + +import java.net.URL; + +/** + * Helper class to launch a test + */ +public class TestPluginLauncher { + + public static final String APP_NAME= "org.eclipse.jdt.ui.tests.app"; + + public static void run(String location, Class testCase, String[] args) { + run(APP_NAME, location, testCase, args); + } + + public static void run(String application, String location, Class testCase, String[] args) { + try { + String bootLocation= getBootLocation(); + int nArgs= args.length; + String[] newArgs= new String[4 + nArgs]; + newArgs[0]= testCase.getName(); + for (int i= 0; i < nArgs; i++) { + newArgs[1 + i]= args[i]; + } + newArgs[1 + nArgs]= "-dev"; + newArgs[1 + nArgs + 1]= "bin"; + newArgs[1 + nArgs + 2]= "-debug"; + NewMain newMain= new NewMain(application, location, null, bootLocation, false); + newMain.run(newArgs); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static String getLocationFromProperties(String key) { + return NewMain.getLocationFromProperties(key); + } + + public static String getLocationFromProperties() { + return NewMain.getLocationFromProperties("tests"); + } + + public static String getBootLocation() { + URL url= TestPluginLauncher.class.getResource("TestPluginLauncher.class"); + String s= url.toString(); + int index= s.indexOf("/org.eclipse.jdt.ui.tests"); + if (index == -1) + throw new IllegalArgumentException(); + s= s.substring(0, index); + s= s + "/org.eclipse.core.boot/boot.jar"; + return s; + } +} \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/TestWorkbench.java b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/TestWorkbench.java new file mode 100644 index 00000000000..e5da8ce0c43 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/TestWorkbench.java @@ -0,0 +1,79 @@ +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ +package org.eclipse.cdt.debug.testplugin; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; + +import org.eclipse.core.runtime.IPath; + +import org.eclipse.swt.widgets.Display; + +import org.eclipse.ui.internal.Workbench; + +public class TestWorkbench extends Workbench { + + /** + * Run an event loop for the workbench. + */ + protected void runEventLoop() { + // Dispatch all events. + Display display = Display.getCurrent(); + while (true) { + try { + if (!display.readAndDispatch()) + break; + } catch (Throwable e) { + break; + } + } + IPath location= CTestPlugin.getDefault().getWorkspace().getRoot().getLocation(); + System.out.println("Workspace-location: " + location.toString()); + + + try { + String[] args= getCommandLineArgs(); + if (args.length > 0) { + Test test= getTest(args[0]); + TestRunner.run(test); + } else { + System.out.println("TestWorkbench: Argument must be class name"); + } + } catch (Exception e) { + e.printStackTrace(); + } + + + // Close the workbench. + close(); + } + + public Test getTest(String className) throws Exception { + Class testClass= getClass().getClassLoader().loadClass(className); + + Method suiteMethod= null; + try { + suiteMethod= testClass.getMethod(TestRunner.SUITE_METHODNAME, new Class[0]); + } catch (Exception e) { + // try to extract a test suite automatically + return new TestSuite(testClass); + } + try { + return (Test) suiteMethod.invoke(null, new Class[0]); // static method + } catch (InvocationTargetException e) { + System.out.println("Failed to invoke suite():" + e.getTargetException().toString()); + } catch (IllegalAccessException e) { + System.out.println("Failed to invoke suite():" + e.toString()); + } + return null; + + } + + +} \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/test/HelloWorld.java b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/test/HelloWorld.java new file mode 100644 index 00000000000..1e9a2f05689 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/test/HelloWorld.java @@ -0,0 +1,49 @@ +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ +package org.eclipse.cdt.debug.testplugin.test; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.debug.testplugin.CProjectHelper; +import org.eclipse.cdt.debug.testplugin.TestPluginLauncher; + + +public class HelloWorld extends TestCase { + + private ICProject fCProject; + + public static void main(String[] args) { + TestPluginLauncher.run(TestPluginLauncher.getLocationFromProperties(), HelloWorld.class, args); + } + + public static Test suite() { + TestSuite suite= new TestSuite(); + suite.addTest(new HelloWorld("test1")); + return suite; + } + + public HelloWorld(String name) { + super(name); + } + + protected void setUp() throws Exception { + fCProject= CProjectHelper.createCProject("TestProject1", "bin"); + } + + + protected void tearDown() throws Exception { + CProjectHelper.delete(fCProject); + } + + public void test1() throws Exception { + + assertTrue("Exception to test", 0 != 0); + + } + +} \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/AccessibilityTestPass.java b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/AccessibilityTestPass.java new file mode 100644 index 00000000000..8bf67a4ad3a --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/AccessibilityTestPass.java @@ -0,0 +1,66 @@ +package org.eclipse.cdt.debug.testplugin.util; + + +import java.util.ArrayList; + + +public class AccessibilityTestPass implements IDialogTestPass { + private static final int CHECKLIST_SIZE = 5; + + /** + * @see IDialogTestPass#title() + */ + public String title() { + return "Test Pass: Accessibility"; + } + /** + * @see IDialogTestPass#description() + */ + public String description() { + return "Verify the accessibility of the dialogs."; + } + /** + * @see IDialogTestPass#label() + */ + public String label() { + return "&Accessibility"; + } + /** + * @see IDialogTestPass#checkListTexts() + */ + public ArrayList checkListTexts() { + ArrayList list = new ArrayList(CHECKLIST_SIZE); + list.add("&1) all widgets are accessible by tabbing."); + list.add("&2) forwards and backwards tabbing is in a logical order"); + list.add("&3) all the widgets with labels have an appropriate mnemonic."); + list.add("&4) there are no duplicate mnemonics."); + list.add("&5) selectable widgets can be selected using the spacebar."); + return list; + } + /** + * @see IDialogTestPass#failureTexts() + * Size of the return array must be the same size as the checkListTexts' + * ArrayList. + */ + public String[] failureTexts() { + String[] failureText = new String[CHECKLIST_SIZE]; + failureText[0] = "Some widgets aren't accessible by tabbing."; + failureText[1] = "Tabbing order is illogical."; + failureText[2] = "Missing or inappropriate mnemonics."; + failureText[3] = "Duplicate mnemonics."; + failureText[4] = "Some widgets cannot be selected using the spacebar."; + return failureText; + } + /** + * @see IDialogTestPass#queryText() + */ + public String queryText() { + return "Is the accessibility of the dialog acceptable?"; + } + /** + * @see IDialogTestPass#getID() + */ + public int getID() { + return VerifyDialog.TEST_ACCESS; + } +} \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/DialogCheck.java b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/DialogCheck.java new file mode 100644 index 00000000000..2fd5792c78e --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/DialogCheck.java @@ -0,0 +1,225 @@ +package org.eclipse.cdt.debug.testplugin.util; + + +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ + + +import junit.framework.Assert; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; + +import org.eclipse.ui.internal.WorkbenchPlugin; + + +/** + * A <code>DialogCheck</code> is used test a dialog in + * various ways. + * <p> + * For interactive tests use <code>assertDialog</code>. + * For automated tests use <code>assert DialogTexts</code>. + * </p> + */ +public class DialogCheck { + private DialogCheck() { + } + private static VerifyDialog _verifyDialog; + + + /** + * Asserts that a given dialog is not null and that it passes + * certain visual tests. These tests will be verified manually + * by the tester using an input dialog. Use this assert method + * to verify a dialog's sizing, initial focus, or accessiblity. + * To ensure that both the input dialog and the test dialog are + * accessible by the tester, the getShell() method should be used + * when creating the test dialog. + * + * Example usage: + * <code>Dialog dialog = new AboutDialog( DialogCheck.getShell() ); + * DialogCheck.assertDialog(dialog, this);</code> + * + * @param dialog the test dialog to be verified. + * @param assert this is the test case object, assertions will be + * executed on this object. + */ + public static void assertDialog(Dialog dialog, Assert assert) { + assert.assertNotNull(dialog); + if (_verifyDialog.getShell() == null) { + //force the creation of the verify dialog + getShell(); + } + if (_verifyDialog.open(dialog) == IDialogConstants.NO_ID) { + assert.assertTrue(_verifyDialog.getFailureText(), false); + } + } + + + /** + * Automated test that checks all the labels and buttons of a dialog + * to make sure there is enough room to display all the text. Any + * text that wraps is only approximated and is currently not accurate. + * + * @param dialog the test dialog to be verified. + * @param assert this is the test case object, assertions will be + * executed on this object. + */ + public static void assertDialogTexts(Dialog dialog, Assert assert) { + assert.assertNotNull(dialog); + dialog.setBlockOnOpen(false); + dialog.open(); + Shell shell = dialog.getShell(); + verifyCompositeText(shell, assert); + dialog.close(); + } + + + /** + * This method should be called when creating dialogs to test. This + * ensures that the dialog's parent shell will be that of the + * verification dialog. + * + * @return Shell The shell of the verification dialog to be used as + * the parent shell of the test dialog. + */ + public static Shell getShell() { + Shell shell = + WorkbenchPlugin + .getDefault() + .getWorkbench() + .getActiveWorkbenchWindow() + .getShell(); + _verifyDialog = new VerifyDialog(shell); + _verifyDialog.create(); + return _verifyDialog.getShell(); + } + + + /* + * Looks at all the child widgets of a given composite and + * verifies the text on all labels and widgets. + * @param composite The composite to look through + * @param assert The object to invoke assertions on. + */ + private static void verifyCompositeText(Composite composite, Assert assert) { + Control children[] = composite.getChildren(); + for (int i = 0; i < children.length; i++) { + try { + //verify the text if the child is a button + verifyButtonText((Button) children[i], assert); + } catch (ClassCastException exNotButton) { + try { + //child is not a button, maybe a label + verifyLabelText((Label) children[i], assert); + } catch (ClassCastException exNotLabel) { + try { + //child is not a label, make a recursive call if it is a composite + verifyCompositeText((Composite) children[i], assert); + } catch (ClassCastException exNotComposite) { + //the child is not a button, label, or composite - ignore it. + } + } + } + } + } + + /* + * Verifies that a given button is large enough to display its text. + * @param button The button to verify, + * @param assert The object to invoke assertions on. + */ + private static void verifyButtonText(Button button, Assert assert) { + String widget = button.toString(); + Point size = button.getSize(); + + + //compute the size with no line wrapping + Point preferred = button.computeSize(SWT.DEFAULT, SWT.DEFAULT); + //if (size.y/preferred.y) == X, then label spans X lines, so divide + //the calculated value of preferred.x by X + if (preferred.y * size.y > 0) { + preferred.y /= countLines(button.getText()); //check for '\n\' + if (size.y / preferred.y > 1) { + preferred.x /= (size.y / preferred.y); + } + } + + + String message = + new StringBuffer("Warning: ") + .append(widget) + .append("\n\tActual Width -> ") + .append(size.x) + .append("\n\tRecommended Width -> ") + .append(preferred.x) + .toString(); + if (preferred.x > size.x) { + //close the dialog + button.getShell().dispose(); + assert.assertTrue(message.toString(), false); + } + } + + /* + * Verifies that a given label is large enough to display its text. + * @param label The label to verify, + * @param assert The object to invoke assertions on. + */ + private static void verifyLabelText(Label label, Assert assert) { + String widget = label.toString(); + Point size = label.getSize(); + + + //compute the size with no line wrapping + Point preferred = label.computeSize(SWT.DEFAULT, SWT.DEFAULT); + //if (size.y/preferred.y) == X, then label spans X lines, so divide + //the calculated value of preferred.x by X + if (preferred.y * size.y > 0) { + preferred.y /= countLines(label.getText()); + if (size.y / preferred.y > 1) { + preferred.x /= (size.y / preferred.y); + } + } + String message = + new StringBuffer("Warning: ") + .append(widget) + .append("\n\tActual Width -> ") + .append(size.x) + .append("\n\tRecommended Width -> ") + .append(preferred.x) + .toString(); + if (preferred.x > size.x) { + //close the dialog + label.getShell().dispose(); + assert.assertTrue(message.toString(), false); + } + } + + /* + * Counts the number of lines in a given String. + * For example, if a string contains one (1) newline character, + * a value of two (2) would be returned. + * @param text The string to look through. + * @return int the number of lines in text. + */ + private static int countLines(String text) { + int newLines = 1; + for (int i = 0; i < text.length(); i++) { + if (text.charAt(i) == '\n') { + newLines++; + } + } + return newLines; + } +} \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/ExpectedStrings.java b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/ExpectedStrings.java new file mode 100644 index 00000000000..e79254f0211 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/ExpectedStrings.java @@ -0,0 +1,96 @@ +package org.eclipse.cdt.debug.testplugin.util; + + +import java.util.Stack; +/** + * @author Peter Graves + * + * This utility class maintains a list of strings, and as a tests finds strings + * in a structure/list, it will maintain a list of unfound/extra strings. + */ +public class ExpectedStrings { + + public String [] expStrings; + private boolean[] foundStrings; + private Stack extraStrings; /* A stack of the unecpected strings we + * recieved + */ + private boolean extra; + + /** + * Constructor for ExpectedStrings. + */ + public ExpectedStrings() { + } + /** + * Constructor for ExpectedStrings that accepts a list of strings that + * we expect to get. + */ + public ExpectedStrings(String[] values) { + int x; + expStrings=new String[values.length]; + for (x=0;x<values.length;x++) { + expStrings[x]=new String(values[x]); + } + foundStrings=new boolean[values.length]; + for (x=0;x<values.length;x++) { + foundStrings[x]=false; + } + extraStrings=new Stack(); + extra=false; + } + + public int foundString(String current) { + int x; + for (x=0;x<expStrings.length;x++) { + if (current.equals(expStrings[x])) { + foundStrings[x]=true; + return(0); + } + } + /* If we arrive here, the strings was not found, so this is + * and extra string + */ + + extraStrings.push(new String(current)); + extra=true; + return(1); + } + public int getNum(String name) { + int x; + for (x=0;x<expStrings.length;x++) { + if (name.equals(expStrings[x])) + return(x); + } + return(-1); + } + public boolean gotAll() { + int x; + for (x=0;x<expStrings.length;x++) { + if (foundStrings[x]==false) + return(false); + } + return(true); + } + public boolean gotExtra() { + return(extra); + } + public String getMissingString() { + int x; + String missing = new String("Missing elements: "); + for (x=0;x<expStrings.length;x++) { + if (foundStrings[x]==false) + missing+=expStrings[x]; + missing+=" "; + } + return(missing); + } + public String getExtraString() { + String extra= new String("Extra elements: "); + while (!extraStrings.empty()) { + extra+=extraStrings.pop(); + extra+=" "; + } + return(extra); + } +} diff --git a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/ExpectedStringsTests.java b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/ExpectedStringsTests.java new file mode 100644 index 00000000000..fdf7120dc4f --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/ExpectedStringsTests.java @@ -0,0 +1,114 @@ +package org.eclipse.cdt.debug.testplugin.util; + +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * @author Peter Graves + * + *Some simple tests to make sure our ExtraStrings class seems to work. + */ +public class ExpectedStringsTests extends TestCase { + + /** + * Constructor for ExpectedStringsTests. + * @param name + */ + public ExpectedStringsTests(String name) { + super(name); + } + /** + * 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() { + + + } + + /** + * Tears down the test fixture. + * + * Called after every test case method. + */ + protected void tearDown() { + // release resources here and clean-up + } + + public static TestSuite suite() { + return new TestSuite(ExpectedStringsTests.class); + } + + public static void main (String[] args){ + junit.textui.TestRunner.run(suite()); + } + + public void testGotAll() { + ExpectedStrings myExp; + String[] strings= {"stringOne", "stringTwo", "stringThree" }; + + myExp=new ExpectedStrings(strings); + assertTrue("No found strings", !myExp.gotAll()); + myExp.foundString("stringOne"); + assertTrue("1 found strings", !myExp.gotAll()); + myExp.foundString("stringTwo"); + assertTrue("2 found strings", !myExp.gotAll()); + myExp.foundString("stringThree"); + assertTrue("All found strings", myExp.gotAll()); + + + } + public void testGotExtra () { + ExpectedStrings myExp; + String[] strings= {"stringOne", "stringTwo", "stringThree" }; + + myExp=new ExpectedStrings(strings); + assertTrue("No found strings", !myExp.gotExtra()); + myExp.foundString("stringOne"); + assertTrue("1 found strings", !myExp.gotExtra()); + myExp.foundString("stringTwo"); + assertTrue("2 found strings", !myExp.gotExtra()); + myExp.foundString("stringThree"); + assertTrue("All found strings", !myExp.gotExtra()); + myExp.foundString("Somerandomestring"); + assertTrue("Extra String", myExp.gotExtra()); + + } + + public void testGetMissingString() + { + ExpectedStrings myExp; + String[] strings= {"stringOne", "stringTwo", "stringThree" }; + + myExp=new ExpectedStrings(strings); + assertNotNull(myExp.getMissingString()); + myExp.foundString("stringOne"); + assertNotNull(myExp.getMissingString()); + myExp.foundString("stringTwo"); + assertNotNull(myExp.getMissingString()); + myExp.foundString("stringThree"); + assertNotNull(myExp.getMissingString()); + + } + + public void testGetExtraString() + { + ExpectedStrings myExp; + String[] strings= {"stringOne", "stringTwo", "stringThree" }; + + myExp=new ExpectedStrings(strings); + assertNotNull(myExp.getExtraString()); + myExp.foundString("stringOnenot"); + assertNotNull(myExp.getMissingString()); + myExp.foundString("stringTwonot"); + assertNotNull(myExp.getMissingString()); + + } + + + +} diff --git a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/FailureDialog.java b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/FailureDialog.java new file mode 100644 index 00000000000..7f0f74a6509 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/FailureDialog.java @@ -0,0 +1,107 @@ +package org.eclipse.cdt.debug.testplugin.util; + + +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.resource.JFaceResources; + + +/* + * A dialog for collecting notes from the tester regarding + * the failure of a test. + */ +public class FailureDialog extends Dialog { + private Text _text; + private String _log; + private int SIZING_TEXT_WIDTH = 400; + private int SIZING_TEXT_HEIGHT = 200; + + /** + * Constructor for FailureDialog + */ + public FailureDialog(Shell parentShell) { + super(parentShell); + } + /* (non-Javadoc) + * Method declared on Window. + */ + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText("Dialog Test Failed"); + } + /* (non-Javadoc) + * Method declared on Dialog. + */ + protected void createButtonsForButtonBar(Composite parent) { + createButton(parent, IDialogConstants.OK_ID, "&OK", true); + createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); + } + /* (non-Javadoc) + * Method declared on Dialog. + */ + protected Control createDialogArea(Composite parent) { + // page group + Composite composite = (Composite)super.createDialogArea(parent); + composite.setSize( composite.computeSize(SWT.DEFAULT, SWT.DEFAULT) ); + + Label label = new Label(composite, SWT.WRAP); + label.setText("&Enter a note regarding the failure:"); + + _text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); + _text.setFont( JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT) ); + GridData data = new GridData(GridData.FILL_BOTH); + data.widthHint = SIZING_TEXT_WIDTH; + data.heightHint = SIZING_TEXT_HEIGHT; + _text.setLayoutData(data); + + return composite; + } + /* (non-Javadoc) + * Method declared on Dialog. + */ + protected void okPressed() { + _log = _text.getText(); + super.okPressed(); + } + /* + * @return String the text contained in the input area of + * the dialog. + */ + String getText() { + if (_log == null) { + return "Empty entry."; + } else { + return _log; + } + } + /* + * Sets the text of the input area. This should only be + * called to set the initial text so only call before invoking + * open(). + */ + void setText(String text) { + _text.setText(text); + } + /* + * Returns a string representation of this class which + * the text contained in the input area of the dialog. + */ + public String toString() { + return getText(); + } +} + + diff --git a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/FocusTestPass.java b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/FocusTestPass.java new file mode 100644 index 00000000000..d2403b77eab --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/FocusTestPass.java @@ -0,0 +1,68 @@ +package org.eclipse.cdt.debug.testplugin.util; + + +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ + +import java.util.ArrayList; + + +/* + * This test pass verifies the initial focus of a dialog + * when it is given focus. + */ +public class FocusTestPass implements IDialogTestPass { + private static final int CHECKLIST_SIZE = 1; + + + /** + * @see IDialogTestPass#title() + */ + public String title() { + return "Test Pass: Initial Focus"; + } + /** + * @see IDialogTestPass#description() + */ + public String description() { + return "Verify the initial focus of the dialogs."; + } + /** + * @see IDialogTestPass#label() + */ + public String label() { + return "&Initial Focus"; + } + /** + * @see IDialogTestPass#checkListTexts() + */ + public ArrayList checkListTexts() { + ArrayList list = new ArrayList(CHECKLIST_SIZE); + list.add("&1) the initial focus is appropriate."); + return list; + } + /** + * @see IDialogTestPass#failureTexts() + * Size of the return array must be the same size as the checkListTexts' + * ArrayList. + */ + public String[] failureTexts() { + String[] failureText = new String[CHECKLIST_SIZE]; + failureText[0] = "The initial focus is inappropriate."; + return failureText; + } + /** + * @see IDialogTestPass#queryText() + */ + public String queryText() { + return "Is the initial focus of the dialog correct?"; + } + /** + * @see IDialogTestPass#getID() + */ + public int getID() { + return VerifyDialog.TEST_FOCUS; + } +} \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/IDialogTestPass.java b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/IDialogTestPass.java new file mode 100644 index 00000000000..73007b04359 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/IDialogTestPass.java @@ -0,0 +1,48 @@ +package org.eclipse.cdt.debug.testplugin.util; + + +import java.util.ArrayList; + + +/* + * Interface to describe a visual test pass for a dialog test. + */ +public interface IDialogTestPass { + /* + * @return String The title of the test pass. + */ + public String title(); + /* + * @return String The description of the test pass. + */ + public String description(); + /* + * @return String The label of the test pass to be used + * in a selection list. The return includes an '&' + * if a mnemonic is desired. + */ + public String label(); + /* + * @return ArrayList A list of items to appear in a checklist. + * The items in the list must be Strings and should include an + * '&' if a mnemonic is desired. + */ + public ArrayList checkListTexts(); + /* + * @return String[] Associated failure messages that correspond + * to the checklist items. The size of this array should be the + * same size as the checklist. + */ + public String[] failureTexts(); + /* + * @return String The test that corresponds to the test pass to + * which the tester will respond with a 'yes' or 'no'. + */ + public String queryText(); + /* + * @return int A unique number that identifies the test pass. + */ + public int getID(); +} + + diff --git a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/SizingTestPass.java b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/SizingTestPass.java new file mode 100644 index 00000000000..d91b63bca73 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/SizingTestPass.java @@ -0,0 +1,76 @@ +package org.eclipse.cdt.debug.testplugin.util; + + +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ + +import java.util.ArrayList; + + +/* + * This test pass verifies visually the sizing of the dialog and its + * widgets. + */ +class SizingTestPass implements IDialogTestPass { + private static final int CHECKLIST_SIZE = 5; + + + /** + * @see IDialogTestPass#title() + */ + public String title() { + return "Test Pass: Sizing and Display"; + } + /** + * @see IDialogTestPass#description() + */ + public String description() { + return "Verify the sizing and display of the dialogs and widgets."; + } + /** + * @see IDialogTestPass#label() + */ + public String label() { + return "&Sizing and Display"; + } + /** + * @see IDialogTestPass#checkListTexts() + */ + public ArrayList checkListTexts() { + ArrayList list = new ArrayList(CHECKLIST_SIZE); + list.add("&1) the correct dialog displays."); + list.add("&2) the dialog is an appropriate size for the required resolution (1024x768)."); + list.add("&3) the texts are correct and not cut off."); + list.add("&4) all strings have been externalized properly."); + list.add("&5) all the widgets are viewable and not cut off."); + return list; + } + /** + * @see IDialogTestPass#failureTexts() + * Size of the return array must be the same size as the checkListTexts' + * ArrayList. + */ + public String[] failureTexts() { + String[] failureText = new String[CHECKLIST_SIZE]; + failureText[0] = "The wrong dialog displayed."; + failureText[1] = "The dialog is too large for the required resolution."; + failureText[2] = "Text labels are wrong or cut off."; + failureText[3] = "Some strings have not been externalized properly."; + failureText[4] = "Some widgets are cut off."; + return failureText; + } + /** + * @see IDialogTestPass#queryText() + */ + public String queryText() { + return "Is the sizing and display of the dialog correct?"; + } + /** + * @see IDialogTestPass#getID() + */ + public int getID() { + return VerifyDialog.TEST_SIZING; + } +} \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/VerifyDialog.java b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/VerifyDialog.java new file mode 100644 index 00000000000..42361b65506 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/util/VerifyDialog.java @@ -0,0 +1,305 @@ +package org.eclipse.cdt.debug.testplugin.util; + + +import java.util.Iterator; + + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.ShellAdapter; +import org.eclipse.swt.events.ShellEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; + + +/* + * This dialog is intended to verify a dialogs in a testing + * environment. The tester can test for sizing, initial focus, + * or accessibility. + */ +public class VerifyDialog extends TitleAreaDialog { + private int SIZING_WIDTH = 400; + + private static int TEST_TYPE; + public static final int TEST_SIZING = 0; + public static final int TEST_FOCUS = 1; + public static final int TEST_ACCESS = 2; + private IDialogTestPass _dialogTests[] = new IDialogTestPass[3]; + + + private Dialog _testDialog; //the dialog to test + private Point _testDialogSize; + + private Label _queryLabel; + private Button _yesButton; + private Button _noButton; + private Button _checkList[]; + private String _failureText; + + /* + * Create an instance of the verification dialog. + */ + public VerifyDialog(Shell parent) { + super(parent); + if ( !(TEST_TYPE <= 2) && !(TEST_TYPE >= 0) ) { + TEST_TYPE = TEST_SIZING; + } + _failureText = ""; + _dialogTests[0] = new SizingTestPass(); + _dialogTests[1] = new FocusTestPass(); + _dialogTests[2] = new AccessibilityTestPass(); + } + + /* (non-Javadoc) + * Method declared on Window. + */ + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText("Dialog Verification"); + setShellStyle(SWT.NONE); + } + /* (non-Javadoc) + * Method declared on Dialog. + */ + protected void createButtonsForButtonBar(Composite parent) { + _yesButton = createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true); + _noButton = createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, false); + } + /* (non-Javadoc) + * Method declared on Dialog. + */ + protected void buttonPressed(int buttonId) { + if (IDialogConstants.YES_ID == buttonId) { + setReturnCode(IDialogConstants.YES_ID); + if (_testDialog.getShell() != null) { + _testDialog.close(); + } + close(); + } else if (IDialogConstants.NO_ID == buttonId) { + handleFailure(); + } + } + /* (non-Javadoc) + * Method declared on Dialog. + */ + protected Control createDialogArea(Composite parent) { + // top level composite + Composite parentComposite = (Composite)super.createDialogArea(parent); + + + // create a composite with standard margins and spacing + Composite composite = new Composite(parentComposite, SWT.NONE); + composite.setSize(SIZING_WIDTH, SWT.DEFAULT); + GridLayout layout = new GridLayout(); + layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); + layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + composite.setLayout(layout); + composite.setLayoutData(new GridData(GridData.FILL_BOTH)); + + + createTestSelectionGroup(composite); + createCheckListGroup(composite); + + + _queryLabel = new Label(composite, SWT.NONE); + _queryLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + initializeTest(); + return composite; + } + /* + * Group for selecting type of test. + */ + private void createTestSelectionGroup(Composite parent) { + Group group = new Group(parent, SWT.SHADOW_NONE); + group.setText("Testing:"); + group.setLayout( new GridLayout() ); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + group.setLayoutData(data); + + for (int i = 0; i < _dialogTests.length; i++) { + Button radio = new Button(group, SWT.RADIO); + radio.setText( _dialogTests[i].label() ); + final int testID = _dialogTests[i].getID(); + radio.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + TEST_TYPE = testID; + initializeTest(); + _yesButton.setEnabled(true); + } + }); + if ( TEST_TYPE == _dialogTests[i].getID() ) { + radio.setSelection(true); + } + } + } + /* + * Initializes the checklist with empty checks. + */ + private void createCheckListGroup(Composite parent) { + Group group = new Group(parent, SWT.SHADOW_NONE); + group.setText("Verify that:"); + group.setLayout( new GridLayout() ); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + group.setLayoutData(data); + + int checkListSize = 0; + for (int i = 0; i < _dialogTests.length; i++) { + int size = _dialogTests[i].checkListTexts().size(); + if (size > checkListSize) { + checkListSize = size; + } + } + _checkList = new Button[checkListSize]; + SelectionAdapter selectionAdapter = new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + checkYesEnable(); + } + }; + for (int i = 0; i < checkListSize; i++) { + _checkList[i] = new Button(group, SWT.CHECK); + _checkList[i].addSelectionListener(selectionAdapter); + data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + data.grabExcessHorizontalSpace = true; + _checkList[i].setLayoutData(data); + } + } + /* + * Disables the yes button if any of the items in the checklist + * are unchecked. Enables the yes button otherwise. + */ + private void checkYesEnable() { + boolean enable = true; + for (int i = 0; i < _checkList.length; i++) { + if ( !_checkList[i].getSelection() ) { + enable = false; + } + } + _yesButton.setEnabled(enable); + } + /* + * Initializes the checklist, banner texts, and query label + */ + private void initializeTest() { + IDialogTestPass test = _dialogTests[TEST_TYPE]; + setTitle( test.title() ); + setMessage( test.description() ); + Iterator iterator = test.checkListTexts().iterator(); + for (int i = 0; i < _checkList.length; i++) { + if ( iterator.hasNext() ) { + _checkList[i].setText( iterator.next().toString() ); + _checkList[i].setVisible(true); + _checkList[i].update(); + } else { + _checkList[i].setVisible(false); + _checkList[i].update(); + } + _checkList[i].setSelection(true); + } + _queryLabel.setText( test.queryText() ); + } + public String getFailureText() { + return _failureText; + } + /* + * Can't open the verification dialog without a specified + * test dialog, this simply returns a failure and prevents + * opening. Should use open(Dialog) instead. + * + */ + public int open() { + _failureText = "Testing dialog is required, use VerifyDialog::open(Dialog)"; + return IDialogConstants.NO_ID; + } + /* + * Opens the verification dialog to test the specified dialog. + */ + public int open(Dialog testDialog) { + if (getShell() == null) { + create(); + } + getShell().setLocation(0, 0); + getShell().setSize(Math.max(SIZING_WIDTH, getShell().getSize().x), getShell().getSize().y); + _testDialog = testDialog; + if (_testDialog.getShell() == null) { + _testDialog.create(); + } + _testDialogSize = _testDialog.getShell().getSize(); + openNewTestDialog(); + + return super.open(); + } + /* + * Opens the dialog to be verified. + */ + private void openNewTestDialog() { + if (_testDialog.getShell() == null) { + _testDialog.create(); + } + _testDialog.setBlockOnOpen(false); + _testDialog.getShell().setLocation(getShell().getSize().x + 1, 0); + _testDialog.getShell().setSize(_testDialogSize); + _testDialog.getShell().addShellListener(new ShellAdapter() { + public void shellClosed(ShellEvent e) { + e.doit = false; + } + + }); + _testDialog.open(); + } + /* + * The test dialog failed, open the failure dialog. + */ + private void handleFailure() { + IDialogTestPass test = _dialogTests[TEST_TYPE]; + StringBuffer text = new StringBuffer(); + String label = test.label(); + label = label.substring(0, label.indexOf("&")) + + label.substring(label.indexOf("&") + 1); + text.append(label). + append(" failed on the "). + append(SWT.getPlatform()). + append(" platform:\n"); + + String failureMessages[] = test.failureTexts(); + for (int i = 0; i < test.checkListTexts().size(); i++) { + if ( !_checkList[i].getSelection() ) { + text.append("- ").append(failureMessages[i]).append("\n"); + } + } + FailureDialog dialog = new FailureDialog( getShell() ); + dialog.create(); +// String temp = text.toString(); + dialog.setText( text.toString() ); + if (dialog.open() == IDialogConstants.OK_ID) { + _failureText = dialog.toString(); + setReturnCode(IDialogConstants.NO_ID); + if (_testDialog.getShell() != null) { + _testDialog.close(); + } + close(); + } + } + /* + * In case the shell was closed by a means other than + * the NO button. + */ + protected void handleShellCloseEvent() { + handleFailure(); + } +} + + diff --git a/debug/org.eclipse.cdt.debug.ui.tests/test.xml b/debug/org.eclipse.cdt.debug.ui.tests/test.xml new file mode 100644 index 00000000000..45036dab5c6 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui.tests/test.xml @@ -0,0 +1,51 @@ +<?xml version="1.0"?> + +<project name="testsuite" default="run" basedir="."> + <!-- The property ${eclipse-home} should be passed into this script --> + <!-- Set a meaningful default value for when it is not. --> + <property name="eclipse-home" value="${basedir}\..\.."/> + + <!-- sets the properties eclipse-home, and library-file --> + <property name="plugin-name" value="org.eclipse.jdt.ui.tests"/> + <property name="library-file" + value="${eclipse-home}/plugins/org.eclipse.test/library.xml"/> + + <!-- This target holds all initialization code that needs to be done for --> + <!-- all tests that are to be run. Initialization for individual tests --> + <!-- should be done within the body of the suite target. --> + <target name="init"> + <tstamp/> + <delete> + <fileset dir="${eclipse-home}" includes="org*.xml"/> + </delete> + </target> + + <!-- This target defines the tests that need to be run. --> + <target name="suite"> + <property name="jdt-folder" + value="${eclipse-home}/jdt_folder"/> + <delete dir="${jdt-folder}" quiet="true"/> + <ant target="ui-test" antfile="${library-file}" dir="${eclipse-home}"> + <property name="data-dir" value="${jdt-folder}"/> + <property name="plugin-name" value="${plugin-name}"/> + <property name="classname" + value="org.eclipse.jdt.ui.tests.AutomatedSuite"/> + </ant> + </target> + + <!-- This target holds code to cleanup the testing environment after --> + <!-- after all of the tests have been run. You can use this target to --> + <!-- delete temporary files that have been created. --> + <target name="cleanup"> + </target> + + <!-- This target runs the test suite. Any actions that need to happen --> + <!-- after all the tests have been run should go here. --> + <target name="run" depends="init,suite,cleanup"> + <ant target="collect" antfile="${library-file}" dir="${eclipse-home}"> + <property name="includes" value="org*.xml"/> + <property name="output-file" value="${plugin-name}.xml"/> + </ant> + </target> + +</project>