diff --git a/core/org.eclipse.cdt.core.tests/.classpath b/core/org.eclipse.cdt.core.tests/.classpath
new file mode 100644
index 00000000000..ce3964a9e41
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/.classpath
@@ -0,0 +1,18 @@
+
+
20th June, 2002
+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 http://www.eclipse.org/legal/cpl-v10.html. +For purposes of the CPL, "Program" will mean the Content.
+ +The Content includes items that may be have been sourced from third parties as follows:
+ +JUnit 3.7
+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 +http://oss.software.ibm.com/developerworks/opensource/license10.html. +The source code is located in testresources/junit37-noUI-src.zip.
+ +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;
+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;
+iii) IBM states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party.
+ +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.
+ +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.
+ + + \ No newline at end of file diff --git a/core/org.eclipse.cdt.core.tests/build.properties b/core/org.eclipse.cdt.core.tests/build.properties new file mode 100644 index 00000000000..b12f9371bcd --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/build.properties @@ -0,0 +1,19 @@ +source.cdtuitests.jar = src/,\ + ui/,\ + core/,\ + model/,\ + build/,\ + parser/,\ + failures/,\ + suite/ +bin.includes = plugin.xml,\ + about.html,\ + plugin.properties,\ + test.xml,\ + resources/ +src.includes = plugin.xml,\ + about.html,\ + plugin.properties,\ + test.xml,\ + resources/ +about.html = diff --git a/core/org.eclipse.cdt.core.tests/build/org/eclipse/cdt/core/build/managed/tests/AllBuildTests.java b/core/org.eclipse.cdt.core.tests/build/org/eclipse/cdt/core/build/managed/tests/AllBuildTests.java new file mode 100644 index 00000000000..21b46572e36 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/build/org/eclipse/cdt/core/build/managed/tests/AllBuildTests.java @@ -0,0 +1,553 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.build.managed.tests; + +import java.util.Arrays; +import java.util.List; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.build.managed.BuildException; +import org.eclipse.cdt.core.build.managed.IConfiguration; +import org.eclipse.cdt.core.build.managed.IOption; +import org.eclipse.cdt.core.build.managed.IOptionCategory; +import org.eclipse.cdt.core.build.managed.IResourceBuildInfo; +import org.eclipse.cdt.core.build.managed.ITarget; +import org.eclipse.cdt.core.build.managed.ITool; +import org.eclipse.cdt.core.build.managed.ManagedBuildManager; +import org.eclipse.cdt.internal.core.build.managed.ToolReference; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; + +/** + * + */ +public class AllBuildTests extends TestCase { + private static final boolean boolVal = true; + private static final String testConfigName = "test.config.override"; + private static final String enumVal = "Another Enum"; + private static final String[] listVal = {"_DEBUG", "/usr/include", "libglade.a"}; + private static final String projectName = "BuildTest"; + private static final String rootExt = "toor"; + private static final String stringVal = "-c -Wall"; + private static final String subExt = "bus"; + + public AllBuildTests(String name) { + super(name); + } + + public static Test suite() { + TestSuite suite = new TestSuite(AllBuildTests.class.getName()); + + suite.addTest(new AllBuildTests("testExtensions")); + suite.addTest(new AllBuildTests("testProject")); + suite.addTest(new AllBuildTests("testConfigurations")); + suite.addTest(new AllBuildTests("testTargetArtifacts")); + suite.addTest(new AllBuildTests("cleanup")); + + return suite; + } + + /** + * Navigates through the build info as defined in the extensions + * defined in this plugin + */ + public void testExtensions() throws Exception { + ITarget testRoot = null; + ITarget testSub = null; + + // Note secret null parameter which means just extensions + ITarget[] targets = ManagedBuildManager.getDefinedTargets(null); + + for (int i = 0; i < targets.length; ++i) { + ITarget target = targets[i]; + + if (target.getName().equals("Test Root")) { + testRoot = target; + checkRootTarget(testRoot, "x"); + + } else if (target.getName().equals("Test Sub")) { + testSub = target; + checkSubTarget(testSub); + } + } + + assertNotNull(testRoot); + assertNotNull(testSub); + } + + /** + * Create a new configuration based on one defined in the plugin file. + * Overrides all of the configuration settings. Saves, closes, and reopens + * the project. Then calls a method to check the overridden options. + * + * Tests creating a new configuration. + * Tests setting options. + * Tests persisting overridden options between project sessions. + * + */ + public void testConfigurations() throws CoreException, BuildException { + // Open the test project + IProject project = createProject(projectName); + + // Make sure there is one and only one target with 2 configs + ITarget[] definedTargets = ManagedBuildManager.getTargets(project); + assertEquals(1, definedTargets.length); + ITarget rootTarget = definedTargets[0]; + IConfiguration[] definedConfigs = rootTarget.getConfigurations(); + assertEquals(2, definedConfigs.length); + IConfiguration baseConfig = definedConfigs[0]; + + // Create a new configuration + IConfiguration newConfig = rootTarget.createConfiguration(baseConfig, testConfigName); + assertEquals(3, rootTarget.getConfigurations().length); + + // There is only one tool + ITool[] definedTools = newConfig.getTools(); + assertEquals(1, definedTools.length); + ITool rootTool = definedTools[0]; + + // Override options in the new configuration + IOptionCategory topCategory = rootTool.getTopOptionCategory(); + assertEquals("Root Tool", topCategory.getName()); + IOption[] options = topCategory.getOptions(null); + assertEquals(2, options.length); + ManagedBuildManager.setOption(newConfig, options[0], listVal); + ManagedBuildManager.setOption(newConfig, options[1], boolVal); + + IOptionCategory[] categories = topCategory.getChildCategories(); + assertEquals(1, categories.length); + options = categories[0].getOptions(null); + assertEquals(2, options.length); + ManagedBuildManager.setOption(newConfig, options[0], stringVal); + ManagedBuildManager.setOption(newConfig, options[1], enumVal); + + // Save, close, reopen and test again + ManagedBuildManager.saveBuildInfo(project); + project.close(null); + ManagedBuildManager.removeBuildInfo(project); + project.open(null); + + // Test the values in the new configuration + checkOptionReferences(project); + } + + public void testProject() throws CoreException, BuildException { + // Create new project + IProject project = createProject(projectName); + // There should not be any targets defined for this project yet + assertEquals(0, ManagedBuildManager.getTargets(project).length); + + // Find the base target definition + ITarget targetDef = ManagedBuildManager.getTarget(project, "test.root"); + assertNotNull(targetDef); + + // Create the target for our project that builds a dummy executable + ITarget newTarget = ManagedBuildManager.createTarget(project, targetDef); + assertEquals(newTarget.getName(), targetDef.getName()); + assertFalse(newTarget.equals(targetDef)); + String buildArtifactName = projectName + "." + newTarget.getDefaultExtension(); + newTarget.setBuildArtifact(buildArtifactName); + + ITarget[] targets = ManagedBuildManager.getTargets(project); + assertEquals(1, targets.length); + ITarget target = targets[0]; + assertEquals(target, newTarget); + assertFalse(target.equals(targetDef)); + + // Copy over the configs + IConfiguration defaultConfig = null; + IConfiguration[] configs = targetDef.getConfigurations(); + for (int i = 0; i < configs.length; ++i) { + // Make the first configuration the default + if (i == 0) { + defaultConfig = target.createConfiguration(configs[i], target.getId() + "." + i); + } else { + target.createConfiguration(configs[i], target.getId() + "." + i); + } + } + ManagedBuildManager.setDefaultConfiguration(project, defaultConfig); + checkRootTarget(target, "x"); + + // Override the "String Option in Category" option value + configs = target.getConfigurations(); + ITool[] tools = configs[0].getTools(); + IOptionCategory topCategory = tools[0].getTopOptionCategory(); + IOptionCategory[] categories = topCategory.getChildCategories(); + IOption[] options = categories[0].getOptions(configs[0]); + configs[0].setOption(options[0], "z"); + options = categories[0].getOptions(null); + assertEquals("x", options[0].getStringValue()); + options = categories[0].getOptions(configs[0]); + assertEquals("z", options[0].getStringValue()); + + // Save, close, reopen and test again + ManagedBuildManager.saveBuildInfo(project); + project.close(null); + ManagedBuildManager.removeBuildInfo(project); + project.open(null); + + // Test that the default config was remembered + IResourceBuildInfo info = ManagedBuildManager.getBuildInfo(project); + assertEquals(defaultConfig.getId(), info.getDefaultConfiguration(target).getId()); + + // Get the targets + targets = ManagedBuildManager.getTargets(project); + assertEquals(1, targets.length); + // See if the artifact name is remembered + assertEquals(targets[0].getArtifactName(), buildArtifactName); + // Check the rest of the default information + checkRootTarget(targets[0], "z"); + + // Now test the information the makefile builder needs + checkBuildSettings(project); + } + + /** + * Tests the tool settings through the interface the makefile generator + * uses. + * + * @param project + */ + private void checkBuildSettings(IProject project) { + String ext1 = "foo"; + String ext2 = "bar"; + String badExt = "cpp"; + String expectedOutput = "toor"; + String expectedCmd = "doIt"; + + // Get that interface, Rover. Go get it. That's a good doggie! Good boy. + IResourceBuildInfo info = ManagedBuildManager.getBuildInfo(project); + assertNotNull(info); + assertEquals(info.getBuildArtifactName(), "BuildTest.toor"); + + // There should be a default configuration defined for the project + ITarget buildTarget = info.getDefaultTarget(); + assertNotNull(buildTarget); + assertEquals(buildTarget.getId(), "test.root.1"); + IConfiguration buildConfig = info.getDefaultConfiguration(buildTarget); + assertNotNull(buildConfig); + assertEquals(buildConfig.getId(), "test.root.1.0"); + + // The default target should be the same as the one-and-only target in the project + List targets = info.getTargets(); + assertEquals(targets.size(), 1); + ITarget target = (ITarget) targets.get(0); + assertEquals(target, buildTarget); + + // Check that tool handles resources with extensions foo and bar by building a baz + assertEquals(info.getOutputExtension(ext1), expectedOutput); + assertEquals(info.getOutputExtension(ext2), expectedOutput); + + // Check that it ignores others based on filename extensions + assertNull(info.getOutputExtension(badExt)); + + // Now see what the tool command line invocation is for foo and bar + assertEquals(info.getToolForSource(ext1), expectedCmd); + assertEquals(info.getToolForSource(ext2), expectedCmd); + // Make sure that there is no tool to build files of type foo and bar + assertNull(info.getToolForTarget(ext1)); + assertNull(info.getToolForTarget(ext2)); + + // There is no target that builds toor + assertNull(info.getToolForSource(expectedOutput)); + // but there is one that produces it + assertEquals(info.getToolForTarget(expectedOutput), expectedCmd); + + // Now check the build flags + assertEquals(info.getFlagsForSource(ext1), "-La -Lb z -e1"); + assertEquals(info.getFlagsForSource(ext1), info.getFlagsForSource(ext2)); + + } + + /** + * Tests that overridden options are properly read into build model. + * Test that option values that are not overridden remain the same. + * + * @param project The project to get build model information for. + * @throws BuildException + */ + private void checkOptionReferences(IProject project) throws BuildException { + // Get the targets out of the project + ITarget[] definedTargets = ManagedBuildManager.getTargets(project); + assertEquals(1, definedTargets.length); + ITarget rootTarget = definedTargets[0]; + + // Now get the configs + IConfiguration[] definedConfigs = rootTarget.getConfigurations(); + assertEquals(3, definedConfigs.length); + IConfiguration newConfig = rootTarget.getConfiguration(testConfigName); + assertNotNull(newConfig); + + // Now get the tool options and make sure the values are correct + ITool[] definedTools = newConfig.getTools(); + assertEquals(1, definedTools.length); + ITool rootTool = definedTools[0]; + + // Check that the options in the new config contain overridden values + IOption[] rootOptions = rootTool.getOptions(); + assertEquals(4, rootOptions.length); + // First is the new list + assertEquals("List Option in Top", rootOptions[0].getName()); + assertEquals(IOption.STRING_LIST, rootOptions[0].getValueType()); + String[] list = rootOptions[0].getStringListValue(); + assertEquals(3, list.length); + assertTrue(Arrays.equals(listVal, list)); + assertEquals(rootOptions[0].getCommand(), "-L"); + // Next option is a boolean in top + assertEquals("Boolean Option in Top", rootOptions[1].getName()); + assertEquals(IOption.BOOLEAN, rootOptions[1].getValueType()); + assertEquals(boolVal, rootOptions[1].getBooleanValue()); + assertEquals("-b", rootOptions[1].getCommand()); + // Next option is a string category + assertEquals("String Option in Category", rootOptions[2].getName()); + assertEquals(IOption.STRING, rootOptions[2].getValueType()); + assertEquals(stringVal, rootOptions[2].getStringValue()); + // Final option is an enumerated + assertEquals("Enumerated Option in Category", rootOptions[3].getName()); + assertEquals(IOption.ENUMERATED, rootOptions[3].getValueType()); + String selEnum = rootOptions[3].getSelectedEnum(); + assertEquals(enumVal, selEnum); + String[] enums = rootOptions[3].getApplicableValues(); + assertEquals(2, enums.length); + assertEquals("Default Enum", enums[0]); + assertEquals("Another Enum", enums[1]); + assertEquals("-e1", rootOptions[3].getEnumCommand(enums[0])); + assertEquals("-e2", rootOptions[3].getEnumCommand(enums[1])); + assertEquals("-e2", rootOptions[3].getEnumCommand(selEnum)); + } + + + private void checkRootTarget(ITarget target, String oicValue) throws BuildException { + // Target stuff + assertTrue(target.isTestTarget()); + assertEquals(target.getDefaultExtension(), rootExt); + + // Tools + ITool[] tools = target.getTools(); + // Root Tool + ITool rootTool = tools[0]; + assertEquals("Root Tool", rootTool.getName()); + // 4 Options are defined in the root tool + IOption[] options = rootTool.getOptions(); + assertEquals(4, options.length); + // First option is a 2-element list + assertEquals("List Option in Top", options[0].getName()); + assertEquals(IOption.STRING_LIST, options[0].getValueType()); + String[] valueList = options[0].getStringListValue(); + assertEquals(2, valueList.length); + assertEquals("a", valueList[0]); + assertEquals("b", valueList[1]); + assertEquals(options[0].getCommand(), "-L"); + // Next option is a boolean in top + assertEquals("Boolean Option in Top", options[1].getName()); + assertEquals(IOption.BOOLEAN, options[1].getValueType()); + assertEquals(false, options[1].getBooleanValue()); + assertEquals("-b", options[1].getCommand()); + // Next option is a string category + assertEquals("String Option in Category", options[2].getName()); + assertEquals(IOption.STRING, options[2].getValueType()); + assertEquals("x", options[2].getStringValue()); + // Final option is an enumerated + assertEquals("Enumerated Option in Category", options[3].getName()); + assertEquals(IOption.ENUMERATED, options[3].getValueType()); + assertEquals("Default Enum", options[3].getSelectedEnum()); + valueList = options[3].getApplicableValues(); + assertEquals(2, valueList.length); + assertEquals("Default Enum", valueList[0]); + assertEquals("Another Enum", valueList[1]); + assertEquals("-e1", options[3].getEnumCommand(valueList[0])); + assertEquals("-e2", options[3].getEnumCommand(valueList[1])); + + // Option Categories + IOptionCategory topCategory = rootTool.getTopOptionCategory(); + assertEquals("Root Tool", topCategory.getName()); + options = topCategory.getOptions(null); + assertEquals(2, options.length); + assertEquals("List Option in Top", options[0].getName()); + assertEquals("Boolean Option in Top", options[1].getName()); + IOptionCategory[] categories = topCategory.getChildCategories(); + assertEquals(1, categories.length); + assertEquals("Category", categories[0].getName()); + options = categories[0].getOptions(null); + assertEquals(2, options.length); + assertEquals("String Option in Category", options[0].getName()); + assertEquals("Enumerated Option in Category", options[1].getName()); + + // Configs + IConfiguration[] configs = target.getConfigurations(); + // Root Config + IConfiguration rootConfig = configs[0]; + assertEquals("Root Config", rootConfig.getName()); + // Tools + tools = rootConfig.getTools(); + assertEquals(1, tools.length); + assertEquals("Root Tool", tools[0].getName()); + topCategory = tools[0].getTopOptionCategory(); + options = topCategory.getOptions(configs[0]); + assertEquals(2, options.length); + assertEquals("List Option in Top", options[0].getName()); + valueList = options[0].getStringListValue(); + assertEquals("a", valueList[0]); + assertEquals("b", valueList[1]); + assertEquals("Boolean Option in Top", options[1].getName()); + categories = topCategory.getChildCategories(); + options = categories[0].getOptions(configs[0]); + assertEquals(2, options.length); + assertEquals("String Option in Category", options[0].getName()); + assertEquals(oicValue, options[0].getStringValue()); + assertEquals("Enumerated Option in Category", options[1].getName()); + + // Root Override Config + assertEquals("Root Override Config", configs[1].getName()); + tools = configs[1].getTools(); + assertEquals(1, tools.length); + assertTrue(tools[0] instanceof ToolReference); + assertEquals("Root Tool", tools[0].getName()); + topCategory = tools[0].getTopOptionCategory(); + options = topCategory.getOptions(configs[1]); + assertEquals(2, options.length); + assertEquals("List Option in Top", options[0].getName()); + valueList = options[0].getStringListValue(); + assertEquals("a", valueList[0]); + assertEquals("b", valueList[1]); + assertEquals("Boolean Option in Top", options[1].getName()); + categories = topCategory.getChildCategories(); + options = categories[0].getOptions(configs[1]); + assertEquals(2, options.length); + assertEquals("String Option in Category", options[0].getName()); + assertEquals("y", options[0].getStringValue()); + assertEquals("Enumerated Option in Category", options[1].getName()); + valueList = options[1].getApplicableValues(); + assertEquals(2, valueList.length); + assertEquals("Default Enum", valueList[0]); + assertEquals("Another Enum", valueList[1]); + assertEquals("-e1", options[1].getEnumCommand(valueList[0])); + assertEquals("-e2", options[1].getEnumCommand(valueList[1])); + } + + private void checkSubTarget(ITarget target) { + // Make sure this is a test target + assertTrue(target.isTestTarget()); + // Make sure the build artifact extension is there + assertEquals(target.getDefaultExtension(), subExt); + + // Tools + ITool[] tools = target.getTools(); + // Root Tool + ITool rootTool = tools[0]; + assertEquals("Root Tool", rootTool.getName()); + // Sub Tool + ITool subTool = tools[1]; + assertEquals("Sub Tool", subTool.getName()); + + // Configs + IConfiguration[] configs = target.getConfigurations(); + // Root Config + IConfiguration rootConfig = configs[0]; + assertEquals("Root Config", rootConfig.getName()); + assertEquals("Root Override Config", configs[1].getName()); + // Sub Config + IConfiguration subConfig = configs[2]; + assertEquals("Sub Config", subConfig.getName()); + } + + /** + * Remove all the project information associated with the project used during test. + */ + public void cleanup() { + removeProject(projectName); + } + + /** + * Create a new project namedname
or return the project in
+ * the workspace of the same name if it exists.
+ *
+ * @param name The name of the project to create or retrieve.
+ * @return
+ * @throws CoreException
+ */
+ private IProject createProject(String name) throws CoreException {
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IProject project = root.getProject(name);
+ if (!project.exists()) {
+ project.create(null);
+ } else {
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ }
+
+ if (!project.isOpen()) {
+ project.open(null);
+ }
+
+ //CCorePlugin.getDefault().convertProjectToC(project, null, CCorePlugin.PLUGIN_ID + ".make", true);
+
+ return project;
+ }
+
+ /**
+ * Remove the IProject
with the name specified in the argument from the
+ * receiver's workspace.
+ *
+ * @param name
+ */
+ private void removeProject(String name) {
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IProject project = root.getProject(name);
+ if (project.exists()) {
+ try {
+ project.delete(true, false, null);
+ } catch (CoreException e) {
+ assertTrue(false);
+ }
+ }
+ }
+
+ /**
+ * Test that the build artifact of a ITarget
can be modified
+ * programmatically.
+ */
+ public void testTargetArtifacts () throws CoreException {
+ // Open the test project
+ IProject project = createProject(projectName);
+
+ // Make sure there is one and only one target
+ ITarget[] definedTargets = ManagedBuildManager.getTargets(project);
+ assertEquals(1, definedTargets.length);
+ ITarget rootTarget = definedTargets[0];
+
+ // Set the build artifact of the target
+ String ext = rootTarget.getDefaultExtension();
+ String name = project.getName() + "." + ext;
+ rootTarget.setBuildArtifact(name);
+
+ // Save, close, reopen and test again
+ ManagedBuildManager.saveBuildInfo(project);
+ project.close(null);
+ ManagedBuildManager.removeBuildInfo(project);
+ project.open(null);
+
+ // Make sure there is one and only one target
+ definedTargets = ManagedBuildManager.getTargets(project);
+ assertEquals(1, definedTargets.length);
+ rootTarget = definedTargets[0];
+ assertEquals(name, rootTarget.getArtifactName());
+ }
+
+ public void testThatAlwaysFails() {
+ assertTrue(false);
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/model/failedTests/CModelElementsFailedTests.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/model/failedTests/CModelElementsFailedTests.java
new file mode 100644
index 00000000000..67d0efcb55a
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/model/failedTests/CModelElementsFailedTests.java
@@ -0,0 +1,116 @@
+package org.eclipse.cdt.core.model.failedTests;
+
+/**********************************************************************
+ * Copyright (c) 2002,2003 Rational Software Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * Rational Software - Initial API and implementation
+***********************************************************************/
+
+import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.Map;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.CCProjectNature;
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.model.INamespace;
+import org.eclipse.cdt.core.model.IStructure;
+import org.eclipse.cdt.internal.core.model.CElement;
+import org.eclipse.cdt.internal.core.model.TranslationUnit;
+import org.eclipse.cdt.testplugin.CProjectHelper;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+
+
+/**
+ * @author vhirsl
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class CModelElementsFailedTests extends TestCase {
+ private ICProject fCProject;
+ private IFile headerFile;
+ private NullProgressMonitor monitor;
+
+ public static Test suite() {
+ TestSuite suite= new TestSuite(CModelElementsFailedTests.class.getName());
+ suite.addTest(new CModelElementsFailedTests("testBug36379"));
+ return suite;
+ }
+
+ public CModelElementsFailedTests(String name) {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ monitor = new NullProgressMonitor();
+ String pluginRoot=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.core.tests").find(new Path("/")).getFile();
+
+ fCProject= CProjectHelper.createCProject("TestProject1", "bin");
+ headerFile = fCProject.getProject().getFile("CModelElementsTest.h");
+ if (!headerFile.exists()) {
+ try{
+ FileInputStream fileIn = new FileInputStream(pluginRoot+ "resources/cfiles/CModelElementsTestStart.h");
+ headerFile.create(fileIn,false, monitor);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+ if (!fCProject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) {
+ addNatureToProject(fCProject.getProject(), CCProjectNature.CC_NATURE_ID, null);
+ }
+
+ CCorePlugin.getDefault().setUseNewParser(true);
+ }
+
+ 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);
+ }
+
+ protected void tearDown() throws Exception {
+ CProjectHelper.delete(fCProject);
+ }
+
+ public void testBug36379() {
+ TranslationUnit tu = new TranslationUnit(fCProject, headerFile);
+ // parse the translation unit to get the elements tree
+ Map newElement = tu.parse(true); // require line numbers
+
+ // tu ---> namespace: MyPackage
+ ArrayList tuPackages = tu.getChildrenOfType(ICElement.C_NAMESPACE);
+ INamespace namespace = (INamespace) tuPackages.get(0);
+ assertEquals(namespace.getElementName(), new String("MyPackage"));
+
+ // MyPackage ---> class: Hello
+ ArrayList nsClasses = namespace.getChildrenOfType(ICElement.C_CLASS);
+ IStructure classHello = (IStructure) nsClasses.get(0);
+ assertEquals(classHello.getElementName(), new String("Hello"));
+
+ // Bug 36379: parser does not provide line number information for nested definitions
+ assertEquals(0, ((CElement)classHello).getStartLine());
+ assertEquals(0, ((CElement)classHello).getEndLine());
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/DOMFailedTest.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/DOMFailedTest.java
new file mode 100644
index 00000000000..1bdb96ea75a
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/DOMFailedTest.java
@@ -0,0 +1,27 @@
+/**********************************************************************
+ * Copyright (c) 2002,2003 Rational Software Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Rational Software - Initial API and implementation
+***********************************************************************/
+package org.eclipse.cdt.core.parser.failedTests;
+
+import org.eclipse.cdt.core.parser.tests.BaseDOMTest;
+
+/**
+ * @author jcamelon
+ */
+public class DOMFailedTest extends BaseDOMTest {
+
+ public DOMFailedTest(String name) {
+ super(name);
+ }
+
+ public void testBug36730()throws Exception {
+ failTest("FUNCTION_MACRO( 1, a )\n int i;");
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/LokiFailures.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/LokiFailures.java
new file mode 100644
index 00000000000..22a0e21718a
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/LokiFailures.java
@@ -0,0 +1,40 @@
+/**********************************************************************
+ * Copyright (c) 2002,2003 Rational Software Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Rational Software - Initial API and implementation
+***********************************************************************/
+package org.eclipse.cdt.core.parser.failedTests;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import org.eclipse.cdt.core.parser.tests.BaseDOMTest;
+
+/**
+ * @author jcamelon
+ */
+public class LokiFailures extends BaseDOMTest {
+
+ public LokiFailures(String name) {
+ super(name);
+ }
+
+ public void testBugTypeManip151()
+ {
+ Writer code = new StringWriter();
+ try
+ {
+ code.write( "template BootLoader
which can be used to start
+ * up and run the platform. The given base, if not null
,
+ * is the location of the boot loader code. If the value is null
+ * 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 URL
-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 URL
-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., -application com.example.application
).
+ * After running the application System.exit(N)
is executed.
+ * The value of N is derived from the value returned from running the application.
+ * If the application's return value is an Integer
, N is this value.
+ * In all other cases, N = 0.
+ *
+ * Clients wishing to run the platform without a following System.exit
+ * call should use run()
.
+ *
+ * @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/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/NewMain.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/NewMain.java
new file mode 100644
index 00000000000..66161e7a7bf
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/NewMain.java
@@ -0,0 +1,73 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.cdt.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/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/TestPluginLauncher.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/TestPluginLauncher.java
new file mode 100644
index 00000000000..4ee939df6b5
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/TestPluginLauncher.java
@@ -0,0 +1,57 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.cdt.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/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/TestWorkbench.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/TestWorkbench.java
new file mode 100644
index 00000000000..0222d528e3d
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/TestWorkbench.java
@@ -0,0 +1,79 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.cdt.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.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/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/util/AccessibilityTestPass.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/util/AccessibilityTestPass.java
new file mode 100644
index 00000000000..2a6e8fe44bd
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/util/AccessibilityTestPass.java
@@ -0,0 +1,66 @@
+package org.eclipse.cdt.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/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/util/DialogCheck.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/util/DialogCheck.java
new file mode 100644
index 00000000000..a365df68d8f
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/util/DialogCheck.java
@@ -0,0 +1,225 @@
+package org.eclipse.cdt.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 DialogCheck
is used test a dialog in
+ * various ways.
+ *
+ * For interactive tests use assertDialog
.
+ * For automated tests use assert DialogTexts
.
+ *
Dialog dialog = new AboutDialog( DialogCheck.getShell() );
+ * DialogCheck.assertDialog(dialog, this);
+ *
+ * @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/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/util/ExpectedStrings.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/util/ExpectedStrings.java
new file mode 100644
index 00000000000..d7cc8c48187
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/util/ExpectedStrings.java
@@ -0,0 +1,96 @@
+package org.eclipse.cdt.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