diff --git a/build/org.eclipse.cdt.autotools.ui.tests/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.autotools.ui.tests/META-INF/MANIFEST.MF index 11a75fbd745..9ed6f542ed9 100644 --- a/build/org.eclipse.cdt.autotools.ui.tests/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.autotools.ui.tests/META-INF/MANIFEST.MF @@ -3,27 +3,26 @@ Bundle-ManifestVersion: 2 Bundle-Name: %bundleName Bundle-SymbolicName: org.eclipse.cdt.autotools.ui.tests Bundle-Version: 1.0.0.qualifier -Bundle-Activator: org.eclipse.cdt.autotools.ui.tests.Activator Bundle-Localization: plugin Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, - org.eclipse.swtbot.eclipse.core;bundle-version="2.0.0", - org.eclipse.swtbot.eclipse.finder;bundle-version="2.0.0", - org.eclipse.swtbot.junit4_x;bundle-version="2.0.0", - org.eclipse.swtbot.swt.finder;bundle-version="2.0.0", - org.junit;bundle-version="4.8.1", - org.apache.log4j;bundle-version="1.2.13", - org.eclipse.core.resources;bundle-version="3.5.1", - org.eclipse.cdt.autotools.core;bundle-version="1.0.0", - org.eclipse.cdt.autotools.ui;bundle-version="1.0.0", - org.eclipse.cdt.core;bundle-version="5.1.1", - org.eclipse.cdt.launch;bundle-version="6.0.0", - org.eclipse.cdt.make.core;bundle-version="6.0.0", - org.eclipse.cdt.make.ui;bundle-version="6.0.1", - org.eclipse.cdt.managedbuilder.core;bundle-version="6.0.0", - org.eclipse.cdt.managedbuilder.gnu.ui;bundle-version="5.0.100", - org.eclipse.cdt.managedbuilder.ui;bundle-version="5.1.0", - org.eclipse.cdt.ui;bundle-version="5.1.1" + org.eclipse.swtbot.eclipse.core, + org.eclipse.swtbot.eclipse.finder, + org.eclipse.swtbot.junit4_x, + org.eclipse.swtbot.swt.finder, + org.eclipse.swtbot.go, + org.apache.log4j, + org.eclipse.core.resources, + org.eclipse.cdt.autotools.core, + org.eclipse.cdt.autotools.ui, + org.eclipse.cdt.core, + org.eclipse.cdt.launch, + org.eclipse.cdt.make.core, + org.eclipse.cdt.make.ui, + org.eclipse.cdt.managedbuilder.core, + org.eclipse.cdt.managedbuilder.gnu.ui, + org.eclipse.cdt.managedbuilder.ui, + org.eclipse.cdt.ui Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Bundle-Vendor: %provider diff --git a/build/org.eclipse.cdt.autotools.ui.tests/pom.xml b/build/org.eclipse.cdt.autotools.ui.tests/pom.xml new file mode 100644 index 00000000000..3f00c18624d --- /dev/null +++ b/build/org.eclipse.cdt.autotools.ui.tests/pom.xml @@ -0,0 +1,50 @@ + + + + 4.0.0 + + + org.eclipse.cdt + cdt-parent + 8.4.0-SNAPSHOT + ../../pom.xml + + + 1.0.0-SNAPSHOT + org.eclipse.cdt.autotools.ui.tests + eclipse-test-plugin + + + + + org.eclipse.tycho + tycho-surefire-plugin + ${tycho-version} + + true + false + org.eclipse.platform.ide + org.eclipse.ui.ide.workbench + ${base.ui.test.vmargs} + + **/AllTests.* + + + + org.eclipse.platform.feature.group + p2-installable-unit + + + + + + + \ No newline at end of file diff --git a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/AbstractTest.java b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/AbstractTest.java new file mode 100644 index 00000000000..155fbc44a9b --- /dev/null +++ b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/AbstractTest.java @@ -0,0 +1,340 @@ +/******************************************************************************* + * Copyright (c) 2014 Red Hat Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.autotools.ui.tests; + +import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.allOf; +import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.inGroup; +import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType; +import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withRegex; +import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withStyle; +import static org.eclipse.swtbot.swt.finder.waits.Conditions.waitForWidget; +import static org.eclipse.swtbot.swt.finder.waits.Conditions.widgetIsEnabled; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectNature; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.jface.bindings.keys.KeyStroke; +import org.eclipse.jface.bindings.keys.ParseException; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.Widget; +import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; +import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; +import org.eclipse.swtbot.swt.finder.finders.ContextMenuHelper; +import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; +import org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory; +import org.eclipse.swtbot.swt.finder.results.VoidResult; +import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; +import org.eclipse.swtbot.swt.finder.waits.Conditions; +import org.eclipse.swtbot.swt.finder.waits.DefaultCondition; +import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarDropDownButton; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; +import org.hamcrest.Matcher; +import org.junit.After; + +public abstract class AbstractTest { + protected static SWTWorkbenchBot bot; + protected static String projectName; + protected static SWTBotShell mainShell; + protected static SWTBotView projectExplorer; + + public static void init(String projectName) throws Exception { + SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; + bot = new SWTWorkbenchBot(); + mainShell = null; + for (int i = 0, attempts = 100; i < attempts; i++) { + for (SWTBotShell shell : bot.shells()) { + if (shell.getText().contains("Eclipse Platform")) { + mainShell = shell; + shell.setFocus(); + break; + } + } + } + assertNotNull(mainShell); + // Close the Welcome view if it exists + try { + bot.viewByTitle("Welcome").close(); + } catch (Exception e) { + // do nothing + } + // Turn off automatic building by default + clickMainMenu("Window", "Preferences"); + SWTBotShell shell = bot.shell("Preferences"); + shell.activate(); + bot.text().setText("Workspace"); + bot.waitUntil(new NodeAvailableAndSelect(bot.tree(), "General", + "Workspace")); + SWTBotCheckBox buildAuto = bot.checkBox("Build automatically"); + if (buildAuto != null && buildAuto.isChecked()) { + buildAuto.click(); + } + bot.button("Apply").click(); + // Ensure that the C/C++ perspective is chosen automatically + // and doesn't require user intervention + bot.text().setText("Perspectives"); + bot.waitUntil(new NodeAvailableAndSelect(bot.tree(), "General", + "Perspectives")); + clickRadioButtonInGroup("Always open", + "Open the associated perspective when creating a new project"); + bot.button("OK").click(); + + AbstractTest.projectName = projectName; + clickMainMenu("File", "New", "Project..."); + shell = bot.shell("New Project"); + shell.activate(); + bot.text().setText("C Project"); + bot.waitUntil(new NodeAvailableAndSelect(bot.tree(), "C/C++", + "C Project")); + bot.button("Next >").click(); + + bot.textWithLabel("Project name:").setText(projectName); + bot.tree().expandNode("GNU Autotools") + .select("Hello World ANSI C Autotools Project"); + bot.button("Finish").click(); + bot.waitUntil(Conditions.shellCloses(shell)); + + IProjectNature nature = checkProject().getNature( + "org.eclipse.cdt.autotools.core.autotoolsNatureV2"); + assertTrue(nature != null); + + projectExplorer = bot.viewByTitle("Project Explorer"); + } + + public static class NodeAvailableAndSelect extends DefaultCondition { + + private SWTBotTree tree; + private String parent; + private String node; + + /** + * Wait for a tree node (with a known parent) to become visible, and + * select it when it does. Note that this wait condition should only be + * used after having made an attempt to reveal the node. + * + * @param tree + * The SWTBotTree that contains the node to select. + * @param parent + * The text of the parent node that contains the node to + * select. + * @param node + * The text of the node to select. + */ + public NodeAvailableAndSelect(SWTBotTree tree, String parent, + String node) { + this.tree = tree; + this.node = node; + this.parent = parent; + } + + @Override + public boolean test() { + try { + SWTBotTreeItem parentNode = tree.getTreeItem(parent); + parentNode.getNode(node).select(); + return true; + } catch (WidgetNotFoundException e) { + return false; + } + } + + @Override + public String getFailureMessage() { + return "Timed out waiting for " + node; //$NON-NLS-1$ + } + } + + /** + * Enter the project folder so as to avoid expanding trees later + */ + public static void enterProjectFolder() { + projectExplorer.setFocus(); + projectExplorer.bot().tree().select(projectName).contextMenu("Go Into") + .click(); + bot.waitUntil(waitForWidget(WidgetMatcherFactory.withText(projectName), + projectExplorer.getWidget())); + } + + /** + * Exit from the project tree. + */ + public static void exitProjectFolder() { + projectExplorer.setFocus(); + SWTBotToolbarButton forwardButton; + try { + forwardButton = projectExplorer.toolbarPushButton("Forward"); + } catch (WidgetNotFoundException e) { + // If the "Forward" button is not found, already at the top level. + return; + } + SWTBotToolbarButton backButton = projectExplorer + .toolbarPushButton("Back to Workspace"); + if (backButton.isEnabled()) { + backButton.click(); + bot.waitUntil(widgetIsEnabled(forwardButton)); + } + } + + /** + * Selects a radio button with the given mnemonicText in a + * group with the given label , while also deselecting whatever + * other radio button in the group that is already selected. Workaround for + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=344484 + */ + public static void clickRadioButtonInGroup(String mnemonicText, + final String inGroup) { + UIThreadRunnable.syncExec(new VoidResult() { + @Override + public void run() { + @SuppressWarnings("unchecked") + Matcher matcher = allOf(inGroup(inGroup), + widgetOfType(Button.class), + withStyle(SWT.RADIO, "SWT.RADIO")); + int i = 0; + while (true) { + Button b; + try { + b = (Button) bot.widget(matcher, i++); + } catch (IndexOutOfBoundsException e) { + return; + } + if (b.getSelection()) { + b.setSelection(false); + return; + } + } + } + }); + bot.radioInGroup(mnemonicText, inGroup).click(); + } + + public static void clickContextMenu(AbstractSWTBot bot, + String... texts) { + new SWTBotMenu(ContextMenuHelper.contextMenu(bot, texts)).click(); + } + + public static void clickVolatileContextMenu( + AbstractSWTBot bot, String... texts) { + int tries = 0; + final int maxTries = 2; + while (true) { + try { + clickContextMenu(bot, texts); + return; + } catch (Exception e) { + if (++tries > maxTries) { + throw e; + } + } + } + } + + public static void clickProjectContextMenu(String... texts) { + clickVolatileContextMenu(bot.viewByTitle("Project Explorer").bot() + .tree().select(projectName), texts); + } + + /** + * Click an item from the main Eclipse menu, with a guarantee that the main + * shell will be in focus. + * + * @param items + */ + public static void clickMainMenu(String... items) { + if (items.length == 0) { + return; + } + mainShell.setFocus(); + SWTBotMenu menu = bot.menu(items[0]); + for (int i = 1; i < items.length; i++) { + menu = menu.menu(items[i]); + } + menu.click(); + } + + public static SWTBotShell openProperties(String parentCategory, + String category) { + clickContextMenu(projectExplorer.bot().tree().select(projectName), + "Properties"); + SWTBotShell shell = bot.shell("Properties for " + projectName); + shell.activate(); + bot.text().setText(category); + bot.waitUntil(new NodeAvailableAndSelect(bot.tree(), parentCategory, + category)); + shell.activate(); + return shell; + } + + public static IProject checkProject() { + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + assertTrue(workspace != null); + IWorkspaceRoot root = workspace.getRoot(); + assertTrue(root != null); + IProject project = root.getProject(projectName); + assertTrue(project != null); + return project; + } + + public static SWTBotView viewConsole(String consoleType) { + SWTBotView view = bot.viewByPartName("Console"); + view.setFocus(); + SWTBotToolbarDropDownButton b = view + .toolbarDropDownButton("Display Selected Console"); + org.hamcrest.Matcher withRegex = withRegex(".*" + consoleType + + ".*"); + bot.shell("C/C++ - Eclipse Platform").activate(); + b.menuItem(withRegex).click(); + try { + b.pressShortcut(KeyStroke.getInstance("ESC")); + } catch (ParseException e) { + } + view.setFocus(); + return view; + } + + @After + public void cleanUp() { + exitProjectFolder(); + SWTBotShell[] shells = bot.shells(); + for (final SWTBotShell shell : shells) { + if (!shell.equals(mainShell)) { + String shellTitle = shell.getText(); + if (shellTitle.length() > 0 + && !shellTitle.startsWith("Quick Access")) { + UIThreadRunnable.syncExec(new VoidResult() { + @Override + public void run() { + if (shell.widget.getParent() != null + && !shell.isOpen()) { + shell.close(); + } + } + }); + } + } + } + bot.closeAllEditors(); + mainShell.activate(); + } +} diff --git a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/Activator.java b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/Activator.java deleted file mode 100644 index 5386a4ed2e6..00000000000 --- a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/Activator.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Red Hat Inc.. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Red Hat Incorporated - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.autotools.ui.tests; - -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.osgi.framework.BundleContext; - -/** - * The activator class controls the plug-in life cycle - */ -public class Activator extends AbstractUIPlugin { - - // The plug-in ID - public static final String PLUGIN_ID = "org.eclipse.cdt.autotools.ui.tests"; - - // The shared instance - private static Activator plugin; - - /** - * The constructor - */ - public Activator() { - } - - /* - * (non-Javadoc) - * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) - */ - public void start(BundleContext context) throws Exception { - super.start(context); - plugin = this; - } - - /* - * (non-Javadoc) - * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) - */ - public void stop(BundleContext context) throws Exception { - plugin = null; - super.stop(context); - } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static Activator getDefault() { - return plugin; - } - -} diff --git a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/AllTests.java b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/AllTests.java index 8ffac6185c3..c745f6f15c2 100644 --- a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/AllTests.java +++ b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/AllTests.java @@ -18,7 +18,7 @@ import org.junit.runners.Suite; SetConfigurationParameter.class, TestToolActions.class, TestEnvironmentVars.class, - TestMakeTargets.class, + TestMakeTargets.class }) public class AllTests { // needed for this class to compile diff --git a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/SetConfigurationParameter.java b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/SetConfigurationParameter.java index fb515049746..b7e02b08dda 100644 --- a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/SetConfigurationParameter.java +++ b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/SetConfigurationParameter.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.cdt.autotools.ui.tests; -import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withRegex; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -23,27 +22,17 @@ import java.util.regex.Pattern; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; -import org.eclipse.cdt.ui.newui.UIMessages; import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectNature; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; -import org.eclipse.jface.bindings.keys.KeyStroke; -import org.eclipse.swt.widgets.MenuItem; -import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; -import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; -import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox; +import org.eclipse.swtbot.swt.finder.waits.Conditions; import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio; import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; import org.eclipse.swtbot.swt.finder.widgets.SWTBotText; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarDropDownButton; -import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -54,96 +43,74 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; @RunWith(SWTBotJunit4ClassRunner.class) -public class SetConfigurationParameter { - - private static SWTWorkbenchBot bot; +public class SetConfigurationParameter extends AbstractTest { @BeforeClass public static void beforeClass() throws Exception { - SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; - bot = new SWTWorkbenchBot(); - // Close the Welcome view if it exists - try { - bot.viewByTitle("Welcome").close(); - // Turn off automatic building by default - } catch (Exception e) { - // do nothing - } - // Turn off automatic building by default - bot.menu("Window").menu("Preferences").click(); - SWTBotShell shell = bot.shell("Preferences"); - shell.activate(); - bot.tree().expandNode("General").select("Workspace"); - SWTBotCheckBox buildAuto = bot.checkBox("Build automatically"); - if (buildAuto != null && buildAuto.isChecked()) - buildAuto.click(); - bot.button("Apply").click(); - // Ensure that the C/C++ perspective is chosen automatically - // and doesn't require user intervention - bot.tree().expandNode("General").select("Perspectives"); - SWTBotRadio radio = bot.radio("Always open"); - if (radio != null && !radio.isSelected()) - radio.click(); - bot.button("OK").click(); + AbstractTest.init("GnuProject0"); + initConfigParm(); } - - @Test - // Verify we can create a sample Autotools project using the New C Project UI - public void canCreateANewAutotoolsProject() throws Exception { - bot.menu("File").menu("New").menu("Project...").click(); - - SWTBotShell shell = bot.shell("New Project"); - shell.activate(); - bot.tree().expandNode("C/C++").select("C Project"); - bot.button("Next >").click(); - - bot.textWithLabel("Project name:").setText("GnuProject0"); - bot.tree().expandNode("GNU Autotools").select("Hello World ANSI C Autotools Project"); - - bot.button("Finish").click(); - - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - assertTrue(workspace != null); - IWorkspaceRoot root = workspace.getRoot(); - assertTrue(root != null); - IProject project = root.getProject("GnuProject0"); - assertTrue(project != null); - IProjectNature nature = project.getNature("org.eclipse.cdt.autotools.core.autotoolsNatureV2"); - assertTrue(nature != null); - } - - @Test - // Verify we can set a configuration parameter and that it is recorded in - // the .autotools file for the project - public void canSetConfigParm() throws Exception { - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject0"); - bot.menu("Project", 1).menu("Properties").click(); - SWTBotShell shell = bot.shell("Properties for GnuProject0"); - shell.activate(); - bot.tree().expandNode("Autotools").select("Configure Settings"); - bot.treeWithLabel("Configure Settings").expandNode("configure").select("Advanced"); - // Set the configure parameters to be --enable-jeff via user-defined options + + // Prepare initial settings that will be tested. + private static void initConfigParm() { + // Set the configure parameters to be --enable-jeff via user-defined + // options + SWTBotShell shell = openProperties("Autotools", "Configure Settings"); + bot.treeWithLabel("Configure Settings").expandNode("configure") + .select("Advanced"); SWTBotText text = bot.textWithLabel("Additional command-line options"); text.typeText("--enable-jeff"); bot.button("OK").click(); - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - assertTrue(workspace != null); - IWorkspaceRoot root = workspace.getRoot(); - assertTrue(root != null); - IProject project = root.getProject("GnuProject0"); + bot.waitUntil(Conditions.shellCloses(shell), 120000); + + // Create new build configurations that will be used throughout tests + projectExplorer.bot().tree().select(projectName); + clickContextMenu(projectExplorer.bot().tree().select(projectName), + "Build Configurations", "Manage..."); + shell = bot.shell(projectName + ": Manage Configurations"); + shell.activate(); + bot.button("New...").click(); + shell = bot.shell("Create New Configuration"); + shell.activate(); + SWTBotText t = bot.textWithLabel("Name:"); + t.setText("debug"); + AbstractTest.clickRadioButtonInGroup("Existing configuration", + "Copy settings from"); + bot.button("OK").click(); + shell = bot.shell(projectName + ": Manage Configurations"); + shell.activate(); + bot.button("New...").click(); + shell = bot.shell("Create New Configuration"); + shell.activate(); + t = bot.textWithLabel("Name:"); + t.setText("default"); + AbstractTest.clickRadioButtonInGroup("Default configuration", + "Copy settings from"); + bot.button("OK").click(); + shell = bot.shell(projectName + ": Manage Configurations"); + shell.activate(); + bot.button("OK").click(); + bot.waitUntil(Conditions.shellCloses(shell)); + } + + // Verify we can set a configuration parameter and that it is recorded in + // the .autotools file for the project + @Test + public void canSetConfigParm() throws Exception { + IProject project = checkProject(); assertTrue(project != null); IPath path = project.getLocation(); path = path.append(".autotools"); File f = new File(path.toOSString()); assertTrue(f.exists()); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document d = db.parse(f); Element e = d.getDocumentElement(); // Get the stored configuration data NodeList cfgs = e.getElementsByTagName("configuration"); // $NON-NLS-1$ - assertEquals(1, cfgs.getLength()); + assertTrue(cfgs.getLength() > 0); Node n = cfgs.item(0); NodeList l = n.getChildNodes(); // Verify user field in .autotools file is set to --enable-jeff @@ -167,198 +134,183 @@ public class SetConfigurationParameter { assertTrue(foundUser); } - @Test // Verify we can build the project with a configuration parameter and that // the configuration parameter can be found in the config.status file. + @Test public void canBuildWithConfigParm() throws Exception { - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject0"); - bot.menu("Project", 1).menu("Build Project").click(); + projectExplorer.bot().tree().select(projectName); + clickContextMenu(projectExplorer.bot().tree().select(projectName), + "Build Project"); + + // Wait until the project is built + SWTBotShell shell = bot.shell("Build Project"); + bot.waitUntil(Conditions.shellCloses(shell), 120000); + IWorkspace workspace = ResourcesPlugin.getWorkspace(); assertTrue(workspace != null); IWorkspaceRoot root = workspace.getRoot(); assertTrue(root != null); - IProject project = root.getProject("GnuProject0"); + IProject project = root.getProject(projectName); assertTrue(project != null); IPath path = project.getLocation(); - // We need to wait until the a.out file is created so - // sleep a bit and look for it...give up after 120 seconds - for (int i = 0; i < 240; ++i) { - bot.sleep(500); - File f = new File(path.append("src/a.out").toOSString()); - if (f.exists()) - break; - } - File f = new File(path.append("config.status").toOSString()); + File f = new File(path.append("src/a.out").toOSString()); assertTrue(f.exists()); - BufferedReader r = new BufferedReader(new FileReader(f)); - int ch; - boolean optionFound = false; - // Read config.status and look for the string --enable-jeff - // which is a simple verification that the option was used in the - // configure step. - while ((ch = r.read()) != -1) { - if (ch == '-') { - char[] buf = new char[12]; - r.mark(100); - int count = r.read(buf); - if (count < 12) - break; - String s = new String(buf); - if (s.equals("-enable-jeff")) { - optionFound = true; - break; - } else { - r.reset(); + f = new File(path.append("config.status").toOSString()); + assertTrue(f.exists()); + + try (BufferedReader r = new BufferedReader(new FileReader(f))) { + int ch; + boolean optionFound = false; + // Read config.status and look for the string --enable-jeff + // which is a simple verification that the option was used in the + // configure step. + while ((ch = r.read()) != -1) { + if (ch == '-') { + char[] buf = new char[12]; + r.mark(100); + int count = r.read(buf); + if (count < 12) { + break; + } + String s = new String(buf); + if (s.equals("-enable-jeff")) { + optionFound = true; + break; + } else { + r.reset(); + } } } + assertTrue(optionFound); } - assertTrue(optionFound); - view = bot.viewByTitle("Console"); - view.setFocus(); - SWTBotToolbarDropDownButton b = bot.toolbarDropDownButtonWithTooltip("Display Selected Console"); - org.hamcrest.Matcher withRegex = withRegex(".*Configure.*"); - b.menuItem(withRegex).click(); - b.pressShortcut(KeyStroke.getInstance("ESC")); - String output = view.bot().styledText().getText(); + + String output = viewConsole("Configure").bot().styledText().getText(); // Verify we got some help output to the console - Pattern p = Pattern.compile(".*WARNING:.*unrecognized.*--enable-jeff.*", Pattern.DOTALL); + Pattern p = Pattern.compile( + ".*WARNING:.*unrecognized.*--enable-jeff.*", Pattern.DOTALL); Matcher m = p.matcher(output); assertTrue(m.matches()); + // Verify that if we build again, we don't reconfigure. // Verifies fix for bug: #308261 long oldDate = f.lastModified(); - view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject0"); - bot.menu("Project", 1).menu("Build Project").click(); + projectExplorer.bot().tree().select(projectName); + clickContextMenu(projectExplorer.bot().tree().select(projectName), + "Build Project"); path = project.getLocation(); // We need to wait until the a.out file is created so // sleep a bit and look for it...give up after 120 seconds for (int i = 0; i < 240; ++i) { bot.sleep(500); - File tmp = new File(path.append("src/a.out").toOSString()); - if (tmp.exists()) + f = new File(path.append("src/a.out").toOSString()); + if (f.exists()) { break; + } } + assertTrue(f.exists()); f = new File(path.append("config.status").toOSString()); assertTrue(f.exists()); long newDate = f.lastModified(); assertEquals(newDate, oldDate); } - @Test // Verify a new configuration will copy the configuration parameters // of its base configuration. + @Test public void newConfigCopiesParms() throws Exception { - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject0"); - bot.menu("Project", 1).menu("Build Configurations").menu("Manage...").click(); - SWTBotShell shell = bot.shell("GnuProject0: Manage Configurations"); + projectExplorer.bot().tree().select(projectName); + clickContextMenu(projectExplorer.bot().tree().select(projectName), + "Build Configurations", "Manage..."); + SWTBotShell shell = bot.shell(projectName + ": Manage Configurations"); shell.activate(); - bot.button("New...").click(); - shell = bot.shell("Create New Configuration"); - shell.activate(); - SWTBotText t = bot.textWithLabel("Name:"); - t.typeText("debug"); - SWTBotRadio radio = bot.radio("Existing configuration"); - if (!radio.isSelected()) - radio.click(); - bot.button("OK").click(); - shell = bot.shell("GnuProject0: Manage Configurations"); - shell.activate(); - bot.button("New...").click(); - shell = bot.shell("Create New Configuration"); - shell.activate(); - t = bot.textWithLabel("Name:"); - t.typeText("default"); - radio = bot.radio("Default configuration"); - if (!radio.isSelected()) - radio.click(); - bot.button("OK").click(); - shell = bot.shell("GnuProject0: Manage Configurations"); + shell = bot.shell(projectName + ": Manage Configurations"); shell.activate(); SWTBotTable table = bot.table(); assertTrue(table.containsItem("debug")); table.getTableItem("debug").select(); bot.button("Set Active").click(); bot.button("OK").click(); - // Verify the debug configuration is active and has a user parameter: --enable-jeff - view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject0"); - bot.menu("Project", 1).menu("Properties").click(); - shell = bot.shell("Properties for GnuProject0"); - shell.activate(); - bot.tree().expandNode("Autotools").select("Configure Settings"); - SWTBotCombo configs = bot.comboBoxWithLabel(UIMessages.getString("AbstractPage.6")); + // Verify the debug configuration is active and has a user parameter: + // --enable-jeff + openProperties("Autotools", "Configure Settings"); + SWTBotCombo configs = bot.comboBoxWithLabel("Configuration: "); configs.setFocus(); String[] items = configs.items(); for (int i = 0; i < items.length; ++i) { - if (items[i].contains("debug") && items[i].contains("Active")) + if (items[i].contains("debug") && items[i].contains("Active")) { configs.setSelection(i); + } } assertTrue(configs.getText().contains("debug")); - bot.treeWithLabel("Configure Settings").expandNode("configure").select("Advanced"); + bot.treeWithLabel("Configure Settings").expandNode("configure") + .select("Advanced"); SWTBotText text = bot.textWithLabel("Additional command-line options"); String val = text.getText(); - assertEquals(val, "--enable-jeff"); + assertEquals("--enable-jeff", val); // Verify that the build directory for the new configuration has been // switched to build-debug - bot.tree().expandNode("C/C++ Build").select(); + bot.tree().select("C/C++ Build"); String buildDir = bot.textWithLabel("Build directory:").getText(); assertTrue(buildDir.endsWith("build-debug")); // Verify the default configuration has no user setting bot.tree().expandNode("Autotools").select("Configure Settings"); - configs = bot.comboBoxWithLabel(UIMessages.getString("AbstractPage.6")); + configs = bot.comboBoxWithLabel("Configuration: "); configs.setSelection("default"); - bot.treeWithLabel("Configure Settings").expandNode("configure").select("Advanced"); + bot.treeWithLabel("Configure Settings").expandNode("configure") + .select("Advanced"); text = bot.textWithLabel("Additional command-line options"); val = text.getText(); - assertEquals(val, ""); + assertEquals("", val); bot.button("OK").click(); // Build the project again and verify we get a build-debug directory - view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject0"); - bot.menu("Project", 1).menu("Build Project").click(); + projectExplorer.bot().tree().select(projectName); + clickContextMenu(projectExplorer.bot().tree().select(projectName), + "Build Project"); IWorkspace workspace = ResourcesPlugin.getWorkspace(); assertTrue(workspace != null); IWorkspaceRoot root = workspace.getRoot(); assertTrue(root != null); - IProject project = root.getProject("GnuProject0"); + IProject project = root.getProject(projectName); assertTrue(project != null); IPath path = project.getLocation(); // We need to wait until the config.status file is created so // sleep a bit and look for it...give up after 20 seconds + File f = null; for (int i = 0; i < 40; ++i) { bot.sleep(500); - File f = new File(path.append("build-debug/src/a.out").toOSString()); - if (f.exists()) + f = new File(path.append("build-debug/src/a.out").toOSString()); + if (f.exists()) { break; - } - File f = new File(path.append("build-debug/config.status").toOSString()); - assertTrue(f.exists()); - BufferedReader r = new BufferedReader(new FileReader(f)); - int ch; - boolean optionFound = false; - // Read config.status and look for the string --enable-jeff - // which is a simple verification that the option was used in the - // configure step. - while ((ch = r.read()) != -1) { - if (ch == '-') { - char[] buf = new char[12]; - r.mark(100); - int count = r.read(buf); - if (count < 12) - break; - String s = new String(buf); - if (s.equals("-enable-jeff")) { - optionFound = true; - break; - } else { - r.reset(); - } } } - assertTrue(optionFound); + assertTrue(f.exists()); + f = new File(path.append("build-debug/config.status").toOSString()); + assertTrue(f.exists()); + try (BufferedReader r = new BufferedReader(new FileReader(f))) { + int ch; + boolean optionFound = false; + // Read config.status and look for the string --enable-jeff + // which is a simple verification that the option was used in the + // configure step. + while ((ch = r.read()) != -1) { + if (ch == '-') { + char[] buf = new char[12]; + r.mark(100); + int count = r.read(buf); + if (count < 12) { + break; + } + String s = new String(buf); + if (s.equals("-enable-jeff")) { + optionFound = true; + break; + } else { + r.reset(); + } + } + } + assertTrue(optionFound); + } // Verify we cleaned out the top-level build directory (i.e. that there // is no config.status there anymore). path = project.getLocation().append("config.status"); @@ -378,7 +330,8 @@ public class SetConfigurationParameter { for (int x = 0; x < cfgs.getLength(); ++x) { Node n = cfgs.item(x); NodeList l = n.getChildNodes(); - // Verify two of the user fields in .autotools file are set to --enable-jeff + // Verify two of the user fields in .autotools file are set to + // --enable-jeff for (int y = 0; y < l.getLength(); ++y) { Node child = l.item(y); if (child.getNodeName().equals("option")) { // $NON-NLS-1$ @@ -390,65 +343,54 @@ public class SetConfigurationParameter { String id = idNode.getNodeValue(); String value = valueNode.getNodeValue(); if (id.equals("user")) { - if (value.equals("--enable-jeff")) + if (value.equals("--enable-jeff")) { ++foundUser; + } } } } } - assertEquals(foundUser, 2); + assertEquals(2, foundUser); + + clickContextMenu(projectExplorer.bot().tree().select(projectName), + "Build Configurations", "Manage..."); + shell = bot.shell(projectName + ": Manage Configurations"); + shell.activate(); + table = bot.table(); + assertTrue(table.containsItem("Build (GNU)")); + table.getTableItem("Build (GNU)").select(); + bot.button("Set Active").click(); + bot.button("OK").click(); + bot.waitUntil(Conditions.shellCloses(shell)); } - @Test - // Verify we can do a double rename of configurations, renaming one configuration to + // Verify we can do a double rename of configurations, renaming one + // configuration to // another and then cancel without changing configuration settings. + @Test public void doubleRenameCancel() throws Exception { - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject0"); - bot.menu("Project", 1).menu("Properties").click(); - SWTBotShell shell = bot.shell("Properties for GnuProject0"); - shell.activate(); - bot.tree().expandNode("Autotools").select("Configure Settings"); - SWTBotCombo configs = bot.comboBoxWithLabel(UIMessages.getString("AbstractPage.6")); - assertTrue(configs.getText().contains("debug")); + openProperties("Autotools", "Configure Settings"); + SWTBotCombo configs = bot.comboBoxWithLabel("Configuration: "); bot.button("Manage Configurations...").click(); - shell = bot.shell("GnuProject0: Manage Configurations"); - shell.activate(); - bot.table().select("debug"); // Rename "debug" to "release" and rename "default" to "debug". // The settings should follow the rename operation. - bot.button("Rename...").click(); - shell = bot.shell("Rename Configuration"); - shell.activate(); - SWTBotText text = bot.textWithLabel("Name:"); - text.setText(""); - text.typeText("release"); - bot.button("OK").click(); - shell = bot.shell("GnuProject0: Manage Configurations"); - shell.activate(); - bot.table().select("default"); - bot.button("Rename...").click(); - shell = bot.shell("Rename Configuration"); - shell.activate(); - text = bot.textWithLabel("Name:"); - text.setText(""); - text.typeText("debug"); - bot.button("OK").click(); - shell = bot.shell("GnuProject0: Manage Configurations"); - shell.activate(); + renameConfiguration("debug", "release"); + renameConfiguration("default", "debug"); bot.button("OK").click(); // Verify that "release" has --enable-jeff set and that // the new "debug" configuration has no user setting. - shell = bot.shell("Properties for GnuProject0"); + SWTBotShell shell = bot.shell("Properties for " + projectName); shell.activate(); - configs = bot.comboBoxWithLabel(UIMessages.getString("AbstractPage.6")); - bot.treeWithLabel("Configure Settings").expandNode("configure").select("Advanced"); - text = bot.textWithLabel("Additional command-line options"); + configs = bot.comboBoxWithLabel("Configuration: "); + bot.treeWithLabel("Configure Settings").expandNode("configure") + .select("Advanced"); + SWTBotText text = bot.textWithLabel("Additional command-line options"); String setting = text.getText(); assertEquals("--enable-jeff", setting); configs.setFocus(); configs.setSelection("debug"); - bot.treeWithLabel("Configure Settings").expandNode("configure").select("Advanced"); + bot.treeWithLabel("Configure Settings").expandNode("configure") + .select("Advanced"); text = bot.textWithLabel("Additional command-line options"); setting = text.getText(); assertEquals("", setting); @@ -456,96 +398,96 @@ public class SetConfigurationParameter { // Cancel and then verify that "debug" is back to normal with // --enable-jeff set and that "default" is back to normal with // no user setting. - view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject0"); - bot.menu("Project", 1).menu("Properties").click(); - shell = bot.shell("Properties for GnuProject0"); - shell.activate(); - bot.tree().expandNode("Autotools").select("Configure Settings"); - configs = bot.comboBoxWithLabel(UIMessages.getString("AbstractPage.6")); + openProperties("Autotools", "Configure Settings"); + configs = bot.comboBoxWithLabel("Configuration: "); + configs.setSelection("debug"); assertTrue(configs.getText().contains("debug")); - bot.treeWithLabel("Configure Settings").expandNode("configure").select("Advanced"); + bot.treeWithLabel("Configure Settings").expandNode("configure") + .select("Advanced"); text = bot.textWithLabel("Additional command-line options"); setting = text.getText(); assertEquals("--enable-jeff", setting); configs.setFocus(); configs.setSelection("default"); assertTrue(configs.getText().contains("default")); - bot.treeWithLabel("Configure Settings").expandNode("configure").select("Advanced"); + bot.treeWithLabel("Configure Settings").expandNode("configure") + .select("Advanced"); text = bot.textWithLabel("Additional command-line options"); setting = text.getText(); assertEquals("", setting); bot.button("OK").click(); + bot.waitUntil(Conditions.shellCloses(shell)); } - @Test - // Verify we can do a double rename of configurations, renaming one configuration to + // Verify we can do a double rename of configurations, renaming one + // configuration to // another and inheriting the settings properly. + @Test public void doubleRenameOk() throws Exception { - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject0"); - bot.menu("Project", 1).menu("Properties").click(); - SWTBotShell shell = bot.shell("Properties for GnuProject0"); - shell.activate(); - bot.tree().expandNode("Autotools").select("Configure Settings"); - SWTBotCombo configs = bot.comboBoxWithLabel(UIMessages.getString("AbstractPage.6")); - assertTrue(configs.getText().contains("debug")); + openProperties("Autotools", "Configure Settings"); + SWTBotCombo configs = bot.comboBoxWithLabel("Configuration: "); bot.button("Manage Configurations...").click(); - shell = bot.shell("GnuProject0: Manage Configurations"); + SWTBotShell shell = bot.shell(projectName + ": Manage Configurations"); shell.activate(); bot.table().select("debug"); + bot.button("Set Active").click(); // Rename "debug" to "release" and rename "default" to "debug". // The settings should follow the rename operation. - bot.button("Rename...").click(); - shell = bot.shell("Rename Configuration"); - shell.activate(); - SWTBotText text = bot.textWithLabel("Name:"); - text.setText(""); - text.typeText("release"); + renameConfiguration("debug", "release"); + renameConfiguration("default", "debug"); bot.button("OK").click(); - shell = bot.shell("GnuProject0: Manage Configurations"); - shell.activate(); - bot.table().select("default"); - bot.button("Rename...").click(); - shell = bot.shell("Rename Configuration"); - shell.activate(); - text = bot.textWithLabel("Name:"); - text.setText(""); - text.typeText("debug"); - bot.button("OK").click(); - shell = bot.shell("GnuProject0: Manage Configurations"); - shell.activate(); - bot.button("OK").click(); - shell = bot.shell("Properties for GnuProject0"); + shell = bot.shell("Properties for " + projectName); shell.activate(); bot.button("OK").click(); + // Verify changes have taken effect permanently - view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject0"); - bot.menu("Project", 1).menu("Properties").click(); - shell = bot.shell("Properties for GnuProject0"); - shell.activate(); - bot.tree().expandNode("Autotools").select("Configure Settings"); - configs = bot.comboBoxWithLabel(UIMessages.getString("AbstractPage.6")); + openProperties("Autotools", "Configure Settings"); + configs = bot.comboBoxWithLabel("Configuration: "); assertTrue(configs.getText().contains("release")); assertTrue(configs.getText().contains("Active")); - bot.treeWithLabel("Configure Settings").expandNode("configure").select("Advanced"); - text = bot.textWithLabel("Additional command-line options"); + bot.treeWithLabel("Configure Settings").expandNode("configure") + .select("Advanced"); + SWTBotText text = bot.textWithLabel("Additional command-line options"); String setting = text.getText(); assertEquals("--enable-jeff", setting); configs.setFocus(); configs.setSelection("debug"); assertTrue(configs.getText().contains("debug")); - bot.treeWithLabel("Configure Settings").expandNode("configure").select("Advanced"); + bot.treeWithLabel("Configure Settings").expandNode("configure") + .select("Advanced"); text = bot.textWithLabel("Additional command-line options"); setting = text.getText(); assertEquals("", setting); + + // Undo the changes made by this test + configs = bot.comboBoxWithLabel("Configuration: "); + bot.button("Manage Configurations...").click(); + shell = bot.shell(projectName + ": Manage Configurations"); + shell.activate(); + bot.table().select("Build (GNU)"); + bot.button("Set Active").click(); + renameConfiguration("debug", "default"); + renameConfiguration("release", "debug"); bot.button("OK").click(); + shell = bot.shell("Properties for " + projectName); + shell.activate(); + bot.button("OK").click(); + bot.waitUntil(Conditions.shellCloses(shell)); } - @AfterClass - public static void sleep() { - bot.sleep(4000); + // Renames a configuration. Assumes the "Manage Configurations" dialog will + // be open. + private void renameConfiguration(String original, String newname) { + SWTBotShell shell = bot.shell(projectName + ": Manage Configurations"); + shell.activate(); + bot.table().select(original); + bot.button("Rename...").click(); + shell = bot.shell("Rename Configuration"); + shell.activate(); + bot.textWithLabel("Name:").setText(newname); + bot.button("OK").click(); + shell = bot.shell(projectName + ": Manage Configurations"); + shell.activate(); } } diff --git a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestEnvironmentVars.java b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestEnvironmentVars.java index 01b6a9479cc..d53f70fd9e7 100644 --- a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestEnvironmentVars.java +++ b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestEnvironmentVars.java @@ -18,172 +18,114 @@ import java.io.FileWriter; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; -import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; -import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio; +import org.eclipse.swtbot.swt.finder.waits.Conditions; import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; import org.eclipse.swtbot.swt.finder.widgets.SWTBotText; -import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(SWTBotJunit4ClassRunner.class) -public class TestEnvironmentVars { - private static SWTWorkbenchBot bot; +public class TestEnvironmentVars extends AbstractTest { @BeforeClass public static void beforeClass() throws Exception { - SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; - bot = new SWTWorkbenchBot(); - // Close the Welcome view if it exists - try { - bot.viewByTitle("Welcome").close(); - // Turn off automatic building by default - } catch (Exception e) { - // do nothing - } - bot.menu("Window").menu("Preferences").click(); - SWTBotShell shell = bot.shell("Preferences"); - shell.activate(); - bot.tree().expandNode("General").select("Workspace"); - SWTBotCheckBox buildAuto = bot.checkBox("Build automatically"); - if (buildAuto != null && buildAuto.isChecked()) - buildAuto.click(); - bot.button("Apply").click(); - // Ensure that the C/C++ perspective is chosen automatically - // and doesn't require user intervention - bot.tree().expandNode("General").select("Perspectives"); - SWTBotRadio radio = bot.radio("Always open"); - if (radio != null && !radio.isSelected()) - radio.click(); - bot.button("OK").click(); - bot.menu("File").menu("New").menu("Project...").click(); - - shell = bot.shell("New Project"); - shell.activate(); - bot.tree().expandNode("C/C++").select("C Project"); - bot.button("Next >").click(); - - bot.textWithLabel("Project name:").setText("GnuProject2"); - bot.tree().expandNode("GNU Autotools").select("Hello World ANSI C Autotools Project"); - - bot.button("Finish").click(); + AbstractTest.init("GnuProject2"); } - - @Test - // Verify we can pass an unknown env var in configure options and it will be nulled out + + // Verify we can pass an unknown env var in configure options and it will be + // nulled out // Verifies fix for Bug: #303616 + @Test public void referenceUnknownEnvVar() throws Exception { - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject2"); - bot.menu("Project", 1).menu("Properties").click(); - SWTBotShell shell = bot.shell("Properties for GnuProject2"); - shell.activate(); - bot.tree().expandNode("Autotools").select("Configure Settings"); - bot.treeWithLabel("Configure Settings").expandNode("configure").select("Advanced"); - // Set the configure parameters to be --enable-jeff via user-defined options + SWTBotShell shell = openProperties("Autotools", "Configure Settings"); + // Set the configure parameters to be --enable-jeff via user-defined + // options + bot.treeWithLabel("Configure Settings").expandNode("configure") + .select("Advanced"); SWTBotText text = bot.textWithLabel("Additional command-line options"); text.typeText("${some_var}"); bot.button("OK").click(); - view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject2"); - bot.menu("Project", 1).menu("Reconfigure Project").click(); - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - assertTrue(workspace != null); - IWorkspaceRoot root = workspace.getRoot(); - assertTrue(root != null); - IProject project = root.getProject("GnuProject2"); - assertTrue(project != null); - IPath path = project.getLocation(); + bot.waitUntil(Conditions.shellCloses(shell), 120000); + + clickContextMenu(projectExplorer.bot().tree().select(projectName), + "Reconfigure Project"); + IPath path = checkProject().getLocation(); File f = null; // We need to wait until the config.status file is created so // sleep a bit and look for it...give up after 40 seconds for (int i = 0; i < 80; ++i) { bot.sleep(500); f = new File(path.append("config.status").toOSString()); - if (f.exists()) + if (f.exists()) { break; + } } + assertTrue(f.exists()); bot.sleep(1000); - SWTBotView consoleView = bot.viewByTitle("Console"); + SWTBotView consoleView = viewConsole("Configure"); consoleView.setFocus(); String output = consoleView.bot().styledText().getText(); Pattern p = Pattern.compile(".*some_var.*", Pattern.DOTALL); Matcher m = p.matcher(output); // We shouldn't see some_var anywhere in the console assertTrue(!m.matches()); + + setEnvVar(); } - @Test - // Verify we can set an environment variable and use it as a configure parameter + // Verify we can set an environment variable and use it as a configure + // parameter // Verifies fix for Bug: #303616 public void setEnvVar() throws Exception { - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject2"); - bot.menu("Project", 1).menu("Properties").click(); - SWTBotShell shell = bot.shell("Properties for GnuProject2"); - shell.activate(); - bot.tree().expandNode("C/C++ Build").select("Environment"); + openProperties("C/C++ Build", "Environment"); bot.button("Add...").click(); - shell = bot.shell("New variable"); + SWTBotShell shell = bot.shell("New variable"); shell.activate(); SWTBotText text = bot.textWithLabel("Name:"); - text.typeText("some_var"); + text.setText("some_var"); text = bot.textWithLabel("Value:"); - text.typeText("--enable-somevar"); + text.setText("--enable-somevar"); bot.button("OK").click(); - shell = bot.shell("Properties for GnuProject2"); + bot.waitUntil(Conditions.shellCloses(shell)); + shell = bot.shell("Properties for " + projectName); shell.activate(); bot.button("OK").click(); - view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject2"); - bot.menu("Project", 1).menu("Reconfigure Project").click(); - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - assertTrue(workspace != null); - IWorkspaceRoot root = workspace.getRoot(); - assertTrue(root != null); - IProject project = root.getProject("GnuProject2"); - assertTrue(project != null); - IPath path = project.getLocation(); + bot.waitUntil(Conditions.shellCloses(shell)); + clickContextMenu(projectExplorer.bot().tree().select(projectName), + "Reconfigure Project"); + + IPath path = checkProject().getLocation(); File f = null; // We need to wait until the config.status file is created so // sleep a bit and look for it...give up after 40 seconds for (int i = 0; i < 80; ++i) { bot.sleep(500); f = new File(path.append("config.status").toOSString()); - if (f.exists()) + if (f.exists()) { break; + } } + assertTrue(f.exists()); bot.sleep(1000); - SWTBotView consoleView = bot.viewByTitle("Console"); - consoleView.setFocus(); + SWTBotView consoleView = viewConsole("Configure"); String output = consoleView.bot().styledText().getText(); Pattern p = Pattern.compile(".*--enable-somevar.*", Pattern.DOTALL); Matcher m = p.matcher(output); // We should see the expanded some_var variable in the console assertTrue(m.matches()); + + setEnvVarOnCommandLine(); } - - @Test - // Verify we can set an environment variable prior to the configuration command and + + // Verify we can set an environment variable prior to the configuration + // command and // it will be seen by the configure script public void setEnvVarOnCommandLine() throws Exception { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - assertTrue(workspace != null); - IWorkspaceRoot root = workspace.getRoot(); - assertTrue(root != null); - IProject project = root.getProject("GnuProject2"); - assertTrue(project != null); - IPath path = project.getLocation(); + IPath path = checkProject().getLocation(); // Create a fake configure script which prints out the values of // envvars some_var1, some_var2, and some_var3 File f = new File(path.append("fake_configure").toOSString()); @@ -201,34 +143,32 @@ public class TestEnvironmentVars { w.append("echo VAR6 is ${some_var6}"); w.newLine(); w.close(); - // Now change the configure script command to be the fake configure script + // Now change the configure script command to be the fake configure + // script // and set the three envvars on the command itself - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject2"); - bot.menu("Project", 1).menu("Properties").click(); - SWTBotShell shell = bot.shell("Properties for GnuProject2"); - shell.activate(); - bot.tree().expandNode("Autotools").select("Configure Settings"); + openProperties("Autotools", "Configure Settings"); bot.treeWithLabel("Configure Settings").select("configure"); bot.textWithLabel("Command").setText(""); - // Choose three different forms, some using quotes to allow blanks in them - bot.textWithLabel("Command").typeText("some_var1=\"a boat\" some_var2='a train' some_var3=car fake_configure some_var4=\"a wagon\" some_var5='a plane' some_var6=skates"); + // Choose three different forms, some using quotes to allow blanks in + // them + bot.textWithLabel("Command") + .typeText( + "some_var1=\"a boat\" some_var2='a train' some_var3=car fake_configure some_var4=\"a wagon\" some_var5='a plane' some_var6=skates"); bot.button("OK").click(); - // Reconfigure the project and make sure the env variables are seen in the script - view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject2"); - bot.menu("Project", 1).menu("Reconfigure Project").click(); + // Reconfigure the project and make sure the env variables are seen in + // the script + clickContextMenu(projectExplorer.bot().tree().select(projectName), + "Reconfigure Project"); + bot.shell("C/C++ - Eclipse Platform").activate(); bot.sleep(3000); - SWTBotView consoleView = bot.viewByTitle("Console"); + SWTBotView consoleView = bot.viewByPartName("Console"); consoleView.setFocus(); String output = consoleView.bot().styledText().getText(); - Pattern p = Pattern.compile(".*VAR1 is a boat.*VAR2 is a train.*VAR3 is car.*VAR4 is a wagon.*VAR5 is a plane.*VAR6 is skates.*", Pattern.DOTALL); + Pattern p = Pattern.compile( + ".*a boat.*a train.*car.*a wagon.*a plane.*skates.*", + Pattern.DOTALL); Matcher m = p.matcher(output); assertTrue(m.matches()); } - @AfterClass - public static void sleep() { - bot.sleep(2000); - } } \ No newline at end of file diff --git a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestMakeTargets.java b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestMakeTargets.java index 3d3bd1f785c..266a41c6bb2 100644 --- a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestMakeTargets.java +++ b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestMakeTargets.java @@ -10,13 +10,9 @@ *******************************************************************************/ package org.eclipse.cdt.autotools.ui.tests; -import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.allOf; -import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType; -import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withMnemonic; import static org.junit.Assert.assertTrue; import java.io.File; -import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -25,160 +21,73 @@ import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.MenuItem; -import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; -import org.eclipse.swtbot.swt.finder.SWTBot; -import org.eclipse.swtbot.swt.finder.finders.ContextMenuFinder; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; -import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; -import org.eclipse.swtbot.swt.finder.waits.DefaultCondition; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio; +import org.eclipse.swtbot.swt.finder.waits.Conditions; import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; -import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(SWTBotJunit4ClassRunner.class) -public class TestMakeTargets { - - private static SWTWorkbenchBot bot; +public class TestMakeTargets extends AbstractTest { @BeforeClass public static void beforeClass() throws Exception { - SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; - bot = new SWTWorkbenchBot(); - // Close the Welcome view if it exists - try { - bot.viewByTitle("Welcome").close(); - // Turn off automatic building by default - } catch (Exception e) { - // do nothing - } - bot.menu("Window").menu("Preferences").click(); - SWTBotShell shell = bot.shell("Preferences"); - shell.activate(); - bot.tree().expandNode("General").select("Workspace"); - SWTBotCheckBox buildAuto = bot.checkBox("Build automatically"); - if (buildAuto != null && buildAuto.isChecked()) - buildAuto.click(); - bot.button("Apply").click(); - // Ensure that the C/C++ perspective is chosen automatically - // and doesn't require user intervention - bot.tree().expandNode("General").select("Perspectives"); - SWTBotRadio radio = bot.radio("Always open"); - if (radio != null && !radio.isSelected()) - radio.click(); - bot.button("OK").click(); - bot.menu("File").menu("New").menu("Project...").click(); - - shell = bot.shell("New Project"); - shell.activate(); - bot.tree().expandNode("C/C++").select("C Project"); - bot.button("Next >").click(); - - bot.textWithLabel("Project name:").setText("GnuProject3"); - bot.tree().expandNode("GNU Autotools").select("Hello World ANSI C Autotools Project"); - - bot.button("Finish").click(); + AbstractTest.init("GnuProject3"); } - + @Test // Verify we can build and run the info MakeTarget tool public void canBuildAndAccessInfoTarget() throws Exception { - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject3"); - bot.menu("Project", 1).menu("Build Project").click(); + clickProjectContextMenu("Build Project"); + + // Wait until the project is built + SWTBotShell shell = bot.shell("Build Project"); + bot.waitUntil(Conditions.shellCloses(shell), 120000); + IWorkspace workspace = ResourcesPlugin.getWorkspace(); assertTrue(workspace != null); IWorkspaceRoot root = workspace.getRoot(); assertTrue(root != null); - IProject project = root.getProject("GnuProject3"); + IProject project = root.getProject(projectName); assertTrue(project != null); IPath path = project.getLocation(); path = path.append("config.status"); - // We need to wait until the config.status file is created so - // sleep a bit and look for it...give up after 120 seconds - for (int i = 0; i < 240; ++i) { - bot.sleep(500); - File f = new File(path.toOSString()); - if (f.exists()) - break; - } File f = new File(path.toOSString()); assertTrue(f.exists()); - view = bot.viewByTitle("Project Explorer"); - // FIXME: there is a problem with the CDT adding multiple MakeTargets - // so the Autotools plugin adds them into the saved data all at - // once. The targets aren't refreshed until the project is reopened. - // We do this by manually closing and opening the project. This - // will not be needed as of CDT 7.0.0. - SWTBotTreeItem node = view.bot().tree().getTreeItem("GnuProject3"); - node.setFocus(); - node.select().contextMenu("Close Project").click(); - node.setFocus(); - node.select().contextMenu("Open Project").click(); - view.bot().tree().select("GnuProject3"); - bot.menu("Project", 1).menu("Make Target").menu("Build...").click(); - SWTBotShell shell = bot.shell("Make Targets"); + f = new File(path.toOSString()); + assertTrue(f.exists()); + + projectExplorer.bot().tree().getTreeItem(projectName).select(); + clickContextMenu(projectExplorer.bot().tree().select(projectName), + "Make Targets", "Build..."); + shell = bot.shell("Make Targets"); shell.activate(); - bot.table().getTableItem("info").setFocus(); bot.table().getTableItem("info").select(); bot.button("Build").click(); bot.sleep(3000); - SWTBotView consoleView = bot.viewByTitle("Console"); - consoleView.setFocus(); + + SWTBotView consoleView = viewConsole("CDT Build Console"); String output = consoleView.bot().styledText().getText(); Pattern p = Pattern.compile(".*make info.*", Pattern.DOTALL); Matcher m = p.matcher(output); assertTrue(m.matches()); - view = bot.viewByTitle("Project Explorer"); - view.setFocus(); - node = view.bot().tree().getTreeItem("GnuProject3"); - node.setFocus(); - node.select(); - // FIXME: when context menus work properly, add test to try out + // Make Targets using right-click on project. -// node.contextMenu("Make Targets").contextMenu("Build...").click(); -// org.hamcrest.Matcher withMnemonic = withMnemonic("Make Targets"); -// final org.hamcrest.Matcher matcher = allOf(widgetOfType(MenuItem.class)); -// final ContextMenuFinder menuFinder = new ContextMenuFinder((Control)view.bot().tree().widget); -// new SWTBot().waitUntil(new DefaultCondition() { -// public String getFailureMessage() { -// return "Could not find context menu with text: Make Targets"; //$NON-NLS-1$ -// } -// -// public boolean test() throws Exception { -// return !menuFinder.findMenus(matcher).isEmpty(); -// } -// }); -// List list = menuFinder.findMenus(matcher); -// bot.sleep(23000); -// // Following does not work but should -// SWTBotMenu menu = node.select().contextMenu("Make Targets"); -// bot.sleep(4000); -// shell = bot.shell("Make Targets"); -// shell.activate(); -// bot.table().getTableItem("check").setFocus(); -// bot.table().getTableItem("check").select(); -// bot.button("Build").click(); -// bot.sleep(3000); -// consoleView = bot.viewByTitle("Console"); -// consoleView.setFocus(); -// output = consoleView.bot().styledText().getText(); -// p = Pattern.compile(".*make check.*Making check in src.*", Pattern.DOTALL); -// m = p.matcher(output); -// assertTrue(m.matches()); - } - - @AfterClass - public static void sleep() { - bot.sleep(4000); + clickProjectContextMenu("Make Targets", "Build..."); + shell = bot.shell("Make Targets"); + shell.activate(); + bot.table().getTableItem("check").select(); + bot.button("Build").click(); + bot.sleep(3000); + consoleView = bot.viewByPartName("Console"); + consoleView.setFocus(); + output = consoleView.bot().styledText().getText(); + p = Pattern.compile(".*make check.*Making check in src.*", + Pattern.DOTALL); + m = p.matcher(output); + assertTrue(m.matches()); } } diff --git a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestToolActions.java b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestToolActions.java index 9b35752c11b..7db9381c78d 100644 --- a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestToolActions.java +++ b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestToolActions.java @@ -16,76 +16,26 @@ import java.io.File; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; -import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; -import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio; import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; -import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(SWTBotJunit4ClassRunner.class) -public class TestToolActions { - private static SWTWorkbenchBot bot; +public class TestToolActions extends AbstractTest { @BeforeClass public static void beforeClass() throws Exception { - SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; - bot = new SWTWorkbenchBot(); - // Close the Welcome view if it exists - try { - bot.viewByTitle("Welcome").close(); - // Turn off automatic building by default - } catch (Exception e) { - // do nothing - } - bot.menu("Window").menu("Preferences").click(); - SWTBotShell shell = bot.shell("Preferences"); - shell.activate(); - bot.tree().expandNode("General").select("Workspace"); - SWTBotCheckBox buildAuto = bot.checkBox("Build automatically"); - if (buildAuto != null && buildAuto.isChecked()) - buildAuto.click(); - bot.button("Apply").click(); - // Ensure that the C/C++ perspective is chosen automatically - // and doesn't require user intervention - bot.tree().expandNode("General").select("Perspectives"); - SWTBotRadio radio = bot.radio("Always open"); - if (radio != null && !radio.isSelected()) - radio.click(); - bot.button("OK").click(); - bot.menu("File").menu("New").menu("Project...").click(); - - shell = bot.shell("New Project"); - shell.activate(); - bot.tree().expandNode("C/C++").select("C Project"); - bot.button("Next >").click(); - - bot.textWithLabel("Project name:").setText("GnuProject1"); - bot.tree().expandNode("GNU Autotools").select("Hello World ANSI C Autotools Project"); - - bot.button("Finish").click(); + AbstractTest.init("GnuProject1"); } - + @Test // Verify we can set the tools via the Autotools Tools page public void canSeeTools() throws Exception { - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Properties").click(); - SWTBotShell shell = bot.shell("Properties for GnuProject1"); - shell.activate(); - bot.tree().expandNode("Autotools").select("General"); + openProperties("Autotools", "General"); bot.tabItem("Tools Settings").activate(); String aclocalName = bot.textWithLabel("aclocal").getText(); assertTrue(aclocalName.equals("aclocal")); @@ -101,34 +51,29 @@ public class TestToolActions { assertTrue(libtoolizeName.equals("libtoolize")); bot.button("Cancel").click(); } - - @Test + // Verify we can access the aclocal tool + @Test public void canAccessAclocal() throws Exception { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - assertTrue(workspace != null); - IWorkspaceRoot root = workspace.getRoot(); - assertTrue(root != null); - IProject project = root.getProject("GnuProject1"); - assertTrue(project != null); - IPath path = project.getLocation(); + IPath path = checkProject().getLocation(); // Verify configure does not exist initially path = path.append("aclocal.m4"); File f = new File(path.toOSString()); - assertTrue(!f.exists()); - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Aclocal").click(); + if (f.exists()) { + f.delete(); + } + clickProjectContextMenu("Invoke Autotools", "Invoke Aclocal"); SWTBotShell shell = bot.shell("Aclocal Options"); shell.activate(); bot.text(0).typeText("--help"); bot.button("OK").click(); bot.sleep(1000); - SWTBotView consoleView = bot.viewByTitle("Console"); + SWTBotView consoleView = bot.viewByPartName("Console"); consoleView.setFocus(); String output = consoleView.bot().styledText().getText(); // Verify we got some help output to the console - Pattern p = Pattern.compile(".*Invoking aclocal in.*GnuProject1.*aclocal --help.*Usage: aclocal.*", Pattern.DOTALL); + Pattern p = Pattern.compile(".*Invoking aclocal in.*" + projectName + + ".*aclocal --help.*Usage: aclocal.*", Pattern.DOTALL); Matcher m = p.matcher(output); assertTrue(m.matches()); // Verify we still don't have an aclocal.m4 file yet @@ -136,17 +81,16 @@ public class TestToolActions { assertTrue(!f.exists()); // Now lets run aclocal for our hello world project which hasn't had any // autotool files generated yet. - view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Aclocal").click(); + clickProjectContextMenu("Invoke Autotools", "Invoke Aclocal"); shell = bot.shell("Aclocal Options"); shell.activate(); bot.button("OK").click(); bot.sleep(1000); - consoleView = bot.viewByTitle("Console"); + consoleView = bot.viewByPartName("Console"); consoleView.setFocus(); output = consoleView.bot().styledText().getText(); - p = Pattern.compile(".*Invoking aclocal in.*GnuProject1.*aclocal.*", Pattern.DOTALL); + p = Pattern.compile(".*Invoking aclocal in.*" + projectName + + ".*aclocal.*", Pattern.DOTALL); m = p.matcher(output); assertTrue(m.matches()); // We need to wait until the aclocal.m4 file is created so @@ -154,36 +98,32 @@ public class TestToolActions { for (int i = 0; i < 40; ++i) { bot.sleep(500); f = new File(path.toOSString()); - if (f.exists()) + if (f.exists()) { break; + } } // Verify we now have an aclocal.m4 file created assertTrue(f.exists()); } - @Test // Verify we can access the autoconf tool + @Test public void canAccessAutoconf() throws Exception { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - assertTrue(workspace != null); - IWorkspaceRoot root = workspace.getRoot(); - assertTrue(root != null); - IProject project = root.getProject("GnuProject1"); - assertTrue(project != null); - IPath path = project.getLocation(); + IPath path = checkProject().getLocation(); // Verify configure does not exist initially path = path.append("configure"); File f = new File(path.toOSString()); - assertTrue(!f.exists()); - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Autoconf").click(); + if (f.exists()) { + f.delete(); + } + clickProjectContextMenu("Invoke Autotools", "Invoke Autoconf"); bot.sleep(1000); - SWTBotView consoleView = bot.viewByTitle("Console"); + SWTBotView consoleView = bot.viewByPartName("Console"); consoleView.setFocus(); String output = consoleView.bot().styledText().getText(); // Verify we got some help output to the console - Pattern p = Pattern.compile(".*Invoking autoconf in.*GnuProject1.*autoconf.*", Pattern.DOTALL); + Pattern p = Pattern.compile(".*Invoking autoconf in.*" + projectName + + ".*autoconf.*", Pattern.DOTALL); Matcher m = p.matcher(output); assertTrue(m.matches()); // We need to wait until the configure file is created so @@ -191,24 +131,26 @@ public class TestToolActions { for (int i = 0; i < 40; ++i) { bot.sleep(500); f = new File(path.toOSString()); - if (f.exists()) + if (f.exists()) { break; + } } // Verify we now have a configure script f = new File(path.toOSString()); assertTrue(f.exists()); - // Now lets delete the configure file and run autoconf from the project explorer - // menu directly from the configure.ac file. + // Now lets delete the configure file and run autoconf from the project + // explorer menu directly from the configure.ac file. assertTrue(f.delete()); - view = bot.viewByTitle("Project Explorer"); - SWTBotTreeItem node = view.bot().tree().expandNode("GnuProject1").getNode("configure.ac"); - node.setFocus(); - node.select().contextMenu("Invoke Autoconf").click(); + enterProjectFolder(); + clickVolatileContextMenu( + projectExplorer.bot().tree().select("configure.ac"), + "Invoke Autotools", "Invoke Autoconf"); bot.sleep(1000); - consoleView = bot.viewByTitle("Console"); + consoleView = bot.viewByPartName("Console"); consoleView.setFocus(); output = consoleView.bot().styledText().getText(); - p = Pattern.compile(".*Invoking autoconf in.*GnuProject1.*autoconf.*", Pattern.DOTALL); + p = Pattern.compile(".*Invoking autoconf in.*" + projectName + + ".*autoconf.*", Pattern.DOTALL); m = p.matcher(output); assertTrue(m.matches()); // We need to wait until the configure file is created so @@ -216,44 +158,44 @@ public class TestToolActions { for (int i = 0; i < 40; ++i) { bot.sleep(500); f = new File(path.toOSString()); - if (f.exists()) + if (f.exists()) { break; + } } // Verify we now have a configure script again f = new File(path.toOSString()); assertTrue(f.exists()); + + exitProjectFolder(); } - - @Test + // Verify we can access the automake tool + @Test public void canAccessAutomake() throws Exception { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - assertTrue(workspace != null); - IWorkspaceRoot root = workspace.getRoot(); - assertTrue(root != null); - IProject project = root.getProject("GnuProject1"); - assertTrue(project != null); - IPath path = project.getLocation(); + IPath path = checkProject().getLocation(); // Verify configure does not exist initially IPath path2 = path.append("src/Makefile.in"); path = path.append("Makefile.in"); File f = new File(path.toOSString()); - assertTrue(!f.exists()); + if (f.exists()) { + f.delete(); + } File f2 = new File(path2.toOSString()); - assertTrue(!f2.exists()); - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Automake").click(); + if (f2.exists()) { + f2.delete(); + } + clickProjectContextMenu("Invoke Autotools", "Invoke Automake"); SWTBotShell shell = bot.shell("Automake Options"); shell.activate(); bot.text(0).typeText("--help"); bot.button("OK").click(); bot.sleep(1000); - SWTBotView consoleView = bot.viewByTitle("Console"); + SWTBotView consoleView = bot.viewByPartName("Console"); consoleView.setFocus(); String output = consoleView.bot().styledText().getText(); // Verify we got some help output to the console - Pattern p = Pattern.compile(".*Invoking automake in.*GnuProject1.*automake --help.*Usage:.*", Pattern.DOTALL); + Pattern p = Pattern.compile(".*Invoking automake in.*" + projectName + + ".*automake --help.*Usage:.*", Pattern.DOTALL); Matcher m = p.matcher(output); assertTrue(m.matches()); // Verify we still don't have Makefile.in files yet @@ -261,21 +203,23 @@ public class TestToolActions { assertTrue(!f.exists()); f2 = new File(path2.toOSString()); assertTrue(!f2.exists()); - // Now lets run automake for our hello world project which hasn't had any + // Now lets run automake for our hello world project which hasn't had + // any // Makefile.in files generated yet. - view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Automake").click(); + clickProjectContextMenu("Invoke Autotools", "Invoke Automake"); shell = bot.shell("Automake Options"); shell.activate(); - bot.text(0).typeText("--add-missing"); // need this to successfully run here + bot.text(0).typeText("--add-missing"); // need this to successfully run + // here bot.text(1).typeText("Makefile src/Makefile"); bot.button("OK").click(); bot.sleep(2000); - consoleView = bot.viewByTitle("Console"); + consoleView = bot.viewByPartName("Console"); consoleView.setFocus(); output = consoleView.bot().styledText().getText(); - p = Pattern.compile(".*Invoking automake in.*GnuProject1.*automake --add-missing Makefile src/Makefile.*", Pattern.DOTALL); + p = Pattern.compile(".*Invoking automake in.*" + projectName + + ".*automake --add-missing Makefile src/Makefile.*", + Pattern.DOTALL); m = p.matcher(output); assertTrue(m.matches()); // We need to wait until the Makefile.in files are created so @@ -284,125 +228,106 @@ public class TestToolActions { bot.sleep(500); f = new File(path.toOSString()); f2 = new File(path2.toOSString()); - if (f.exists() && f2.exists()) + if (f.exists() && f2.exists()) { break; + } } + assertTrue(f.exists() && f2.exists()); // Verify we now have Makefile.in files created f = new File(path.toOSString()); assertTrue(f.exists()); f2 = new File(path2.toOSString()); assertTrue(f2.exists()); } - - @Test + // Verify we can access the libtoolize tool + @Test public void canAccessLibtoolize() throws Exception { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - assertTrue(workspace != null); - IWorkspaceRoot root = workspace.getRoot(); - assertTrue(root != null); - IProject project = root.getProject("GnuProject1"); - assertTrue(project != null); - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Libtoolize").click(); + clickProjectContextMenu("Invoke Autotools", "Invoke Libtoolize"); SWTBotShell shell = bot.shell("Libtoolize Options"); shell.activate(); bot.text(0).typeText("--help"); bot.button("OK").click(); bot.sleep(1000); - SWTBotView consoleView = bot.viewByTitle("Console"); + SWTBotView consoleView = bot.viewByPartName("Console"); consoleView.setFocus(); String output = consoleView.bot().styledText().getText(); // Verify we got some help output to the console - Pattern p = Pattern.compile(".*Invoking libtoolize in.*GnuProject1.*libtoolize --help.*Usage: libtoolize.*", Pattern.DOTALL); + Pattern p = Pattern.compile(".*Invoking libtoolize in.*" + projectName + + ".*libtoolize --help.*Usage: libtoolize.*", Pattern.DOTALL); Matcher m = p.matcher(output); assertTrue(m.matches()); } - @Test // Verify we can access the libtoolize tool + @Test public void canAccessAutoheader() throws Exception { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - assertTrue(workspace != null); - IWorkspaceRoot root = workspace.getRoot(); - assertTrue(root != null); - IProject project = root.getProject("GnuProject1"); - assertTrue(project != null); - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Autoheader").click(); + clickProjectContextMenu("Invoke Autotools", "Invoke Autoheader"); SWTBotShell shell = bot.shell("Autoheader Options"); shell.activate(); bot.text(0).typeText("--help"); bot.button("OK").click(); bot.sleep(1000); - SWTBotView consoleView = bot.viewByTitle("Console"); + SWTBotView consoleView = bot.viewByPartName("Console"); consoleView.setFocus(); String output = consoleView.bot().styledText().getText(); // Verify we got some help output to the console - Pattern p = Pattern.compile(".*Invoking autoheader in.*GnuProject1.*autoheader --help.*Usage:.*autoheader.*", Pattern.DOTALL); + Pattern p = Pattern.compile(".*Invoking autoheader in.*" + projectName + + ".*autoheader --help.*Usage:.*autoheader.*", Pattern.DOTALL); Matcher m = p.matcher(output); assertTrue(m.matches()); } - @Test // Verify we can access the autoreconf tool + @Test public void canAccessAutoreconf() throws Exception { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - assertTrue(workspace != null); - IWorkspaceRoot root = workspace.getRoot(); - assertTrue(root != null); - IProject project = root.getProject("GnuProject1"); - assertTrue(project != null); - IPath path = project.getLocation(); + IPath path = checkProject().getLocation(); // Remove a number of generated files File f = new File(path.append("src/Makefile.in").toOSString()); - if (f.exists()) + if (f.exists()) { f.delete(); + } f = new File(path.append("Makefile.in").toOSString()); - if (f.exists()) + if (f.exists()) { f.delete(); + } f = new File(path.append("configure").toOSString()); - if (f.exists()) + if (f.exists()) { f.delete(); + } f = new File(path.append("config.status").toOSString()); - if (f.exists()) + if (f.exists()) { f.delete(); + } f = new File(path.append("config.sub").toOSString()); - if (f.exists()) + if (f.exists()) { f.delete(); - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Autoreconf").click(); + } + clickProjectContextMenu("Invoke Autotools", "Invoke Autoreconf"); SWTBotShell shell = bot.shell("Autoreconf Options"); shell.activate(); bot.text(0).typeText("--help"); bot.button("OK").click(); bot.sleep(1000); - SWTBotView consoleView = bot.viewByTitle("Console"); + SWTBotView consoleView = bot.viewByPartName("Console"); consoleView.setFocus(); String output = consoleView.bot().styledText().getText(); // Verify we got some help output to the console - Pattern p = Pattern.compile(".*Invoking autoreconf in.*GnuProject1.*autoreconf --help.*Usage: .*autoreconf.*", Pattern.DOTALL); + Pattern p = Pattern.compile(".*Invoking autoreconf in.*" + projectName + + ".*autoreconf --help.*Usage: .*autoreconf.*", Pattern.DOTALL); Matcher m = p.matcher(output); assertTrue(m.matches()); - view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Autoreconf").click(); + clickProjectContextMenu("Invoke Autotools", "Invoke Autoreconf"); shell = bot.shell("Autoreconf Options"); shell.activate(); bot.text(0).typeText("-i"); bot.button("OK").click(); // We need to wait until the Makefile.in file is created so - // sleep a bit and look for it...give up after 20 seconds - for (int i = 0; i < 40; ++i) { - bot.sleep(500); - f = new File(path.append("Makefile.in").toOSString()); - if (f.exists()) - break; - } + // sleep a bit and look for it + bot.sleep(3000); // Verify a number of generated files now exist + f = new File(path.append("Makefile.in").toOSString()); + assertTrue(f.exists()); f = new File(path.append("src/Makefile.in").toOSString()); assertTrue(f.exists()); f = new File(path.append("Makefile.in").toOSString()); @@ -410,48 +335,46 @@ public class TestToolActions { f = new File(path.append("configure").toOSString()); assertTrue(f.exists()); f = new File(path.append("config.status").toOSString()); - assertTrue(!f.exists()); //shouldn't have run configure + assertTrue(!f.exists()); // shouldn't have run configure f = new File(path.append("config.sub").toOSString()); assertTrue(f.exists()); } @Test - // Verify we can access the autoreconf tool public void canReconfigureProject() throws Exception { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - assertTrue(workspace != null); - IWorkspaceRoot root = workspace.getRoot(); - assertTrue(root != null); - IProject project = root.getProject("GnuProject1"); - assertTrue(project != null); - IPath path = project.getLocation(); + IPath path = checkProject().getLocation(); // Remove a number of generated files File f = new File(path.append("src/Makefile.in").toOSString()); - if (f.exists()) + if (f.exists()) { f.delete(); + } f = new File(path.append("Makefile.in").toOSString()); - if (f.exists()) + if (f.exists()) { f.delete(); + } f = new File(path.append("configure").toOSString()); - if (f.exists()) + if (f.exists()) { f.delete(); + } f = new File(path.append("config.status").toOSString()); - if (f.exists()) + if (f.exists()) { f.delete(); + } f = new File(path.append("config.sub").toOSString()); - if (f.exists()) + if (f.exists()) { f.delete(); - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Reconfigure Project").click(); + } + clickProjectContextMenu("Reconfigure Project"); // We need to wait until the config.status file is created so // sleep a bit and look for it...give up after 40 seconds for (int i = 0; i < 40; ++i) { bot.sleep(500); f = new File(path.append("config.status").toOSString()); - if (f.exists()) + if (f.exists()) { break; + } } + assertTrue(f.exists()); // Verify a number of generated files now exist f = new File(path.append("src/Makefile.in").toOSString()); assertTrue(f.exists()); @@ -465,16 +388,11 @@ public class TestToolActions { assertTrue(f.exists()); } - @Test // Verify we can set and reset the tools via the Autotools Tools page // Verifies bug #317345 + @Test public void canResetTools() throws Exception { - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Properties").click(); - SWTBotShell shell = bot.shell("Properties for GnuProject1"); - shell.activate(); - bot.tree().expandNode("Autotools").select("General"); + openProperties("Autotools", "General"); bot.tabItem("Tools Settings").activate(); bot.textWithLabel("aclocal").setText(""); bot.textWithLabel("aclocal").typeText("automake"); @@ -517,378 +435,10 @@ public class TestToolActions { bot.button("OK").click(); } - @Test - // Verify we can access the aclocal tool - public void canAccessAclocal2() throws Exception { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - assertTrue(workspace != null); - IWorkspaceRoot root = workspace.getRoot(); - assertTrue(root != null); - IProject project = root.getProject("GnuProject1"); - assertTrue(project != null); - IPath path = project.getLocation(); - // Verify configure does not exist initially - path = path.append("aclocal.m4"); - File f = new File(path.toOSString()); - f.delete(); - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Aclocal").click(); - SWTBotShell shell = bot.shell("Aclocal Options"); - shell.activate(); - bot.text(0).typeText("--help"); - bot.button("OK").click(); - bot.sleep(1000); - SWTBotView consoleView = bot.viewByTitle("Console"); - consoleView.setFocus(); - String output = consoleView.bot().styledText().getText(); - // Verify we got some help output to the console - Pattern p = Pattern.compile(".*Invoking aclocal in.*GnuProject1.*aclocal --help.*Usage: aclocal.*", Pattern.DOTALL); - Matcher m = p.matcher(output); - assertTrue(m.matches()); - // Verify we still don't have an aclocal.m4 file yet - f = new File(path.toOSString()); - assertTrue(!f.exists()); - // Now lets run aclocal for our hello world project which hasn't had any - // autotool files generated yet. - view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Aclocal").click(); - shell = bot.shell("Aclocal Options"); - shell.activate(); - bot.button("OK").click(); - bot.sleep(1000); - consoleView = bot.viewByTitle("Console"); - consoleView.setFocus(); - output = consoleView.bot().styledText().getText(); - p = Pattern.compile(".*Invoking aclocal in.*GnuProject1.*aclocal.*", Pattern.DOTALL); - m = p.matcher(output); - assertTrue(m.matches()); - // We need to wait until the aclocal.m4 file is created so - // sleep a bit and look for it...give up after 20 seconds - for (int i = 0; i < 40; ++i) { - bot.sleep(500); - f = new File(path.toOSString()); - if (f.exists()) - break; - } - // Verify we now have an aclocal.m4 file created - assertTrue(f.exists()); - } - - @Test - // Verify we can access the autoconf tool - public void canAccessAutoconf2() throws Exception { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - assertTrue(workspace != null); - IWorkspaceRoot root = workspace.getRoot(); - assertTrue(root != null); - IProject project = root.getProject("GnuProject1"); - assertTrue(project != null); - IPath path = project.getLocation(); - // Verify configure does not exist initially - path = path.append("configure"); - File f = new File(path.toOSString()); - f.delete(); - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Autoconf").click(); - bot.sleep(1000); - SWTBotView consoleView = bot.viewByTitle("Console"); - consoleView.setFocus(); - String output = consoleView.bot().styledText().getText(); - // Verify we got some help output to the console - Pattern p = Pattern.compile(".*Invoking autoconf in.*GnuProject1.*autoconf.*", Pattern.DOTALL); - Matcher m = p.matcher(output); - assertTrue(m.matches()); - // We need to wait until the configure file is created so - // sleep a bit and look for it...give up after 20 seconds - for (int i = 0; i < 40; ++i) { - bot.sleep(500); - f = new File(path.toOSString()); - if (f.exists()) - break; - } - // Verify we now have a configure script - f = new File(path.toOSString()); - assertTrue(f.exists()); - // Now lets delete the configure file and run autoconf from the project explorer - // menu directly from the configure.ac file. - assertTrue(f.delete()); - view = bot.viewByTitle("Project Explorer"); - SWTBotTreeItem node = view.bot().tree().expandNode("GnuProject1").getNode("configure.ac"); - node.setFocus(); - node.select().contextMenu("Invoke Autoconf").click(); - bot.sleep(1000); - consoleView = bot.viewByTitle("Console"); - consoleView.setFocus(); - output = consoleView.bot().styledText().getText(); - p = Pattern.compile(".*Invoking autoconf in.*GnuProject1.*autoconf.*", Pattern.DOTALL); - m = p.matcher(output); - assertTrue(m.matches()); - // We need to wait until the configure file is created so - // sleep a bit and look for it...give up after 20 seconds - for (int i = 0; i < 40; ++i) { - bot.sleep(500); - f = new File(path.toOSString()); - if (f.exists()) - break; - } - // Verify we now have a configure script again - f = new File(path.toOSString()); - assertTrue(f.exists()); - } - - @Test - // Verify we can access the automake tool - public void canAccessAutomake2() throws Exception { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - assertTrue(workspace != null); - IWorkspaceRoot root = workspace.getRoot(); - assertTrue(root != null); - IProject project = root.getProject("GnuProject1"); - assertTrue(project != null); - IPath path = project.getLocation(); - // Verify configure does not exist initially - IPath path2 = path.append("src/Makefile.in"); - path = path.append("Makefile.in"); - File f = new File(path.toOSString()); - f.delete(); - File f2 = new File(path2.toOSString()); - f2.delete(); - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Automake").click(); - SWTBotShell shell = bot.shell("Automake Options"); - shell.activate(); - bot.text(0).typeText("--help"); - bot.button("OK").click(); - bot.sleep(1000); - SWTBotView consoleView = bot.viewByTitle("Console"); - consoleView.setFocus(); - String output = consoleView.bot().styledText().getText(); - // Verify we got some help output to the console - Pattern p = Pattern.compile(".*Invoking automake in.*GnuProject1.*automake --help.*Usage:.*", Pattern.DOTALL); - Matcher m = p.matcher(output); - assertTrue(m.matches()); - // Verify we still don't have Makefile.in files yet - f = new File(path.toOSString()); - assertTrue(!f.exists()); - f2 = new File(path2.toOSString()); - assertTrue(!f2.exists()); - // Now lets run automake for our hello world project which hasn't had any - // Makefile.in files generated yet. - view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Automake").click(); - shell = bot.shell("Automake Options"); - shell.activate(); - bot.text(0).typeText("--add-missing"); // need this to successfully run here - bot.text(1).typeText("Makefile src/Makefile"); - bot.button("OK").click(); - bot.sleep(2000); - consoleView = bot.viewByTitle("Console"); - consoleView.setFocus(); - output = consoleView.bot().styledText().getText(); - p = Pattern.compile(".*Invoking automake in.*GnuProject1.*automake --add-missing Makefile src/Makefile.*", Pattern.DOTALL); - m = p.matcher(output); - assertTrue(m.matches()); - // We need to wait until the Makefile.in files are created so - // sleep a bit and look for it...give up after 20 seconds - for (int i = 0; i < 40; ++i) { - bot.sleep(500); - f = new File(path.toOSString()); - f2 = new File(path2.toOSString()); - if (f.exists() && f2.exists()) - break; - } - // Verify we now have Makefile.in files created - f = new File(path.toOSString()); - assertTrue(f.exists()); - f2 = new File(path2.toOSString()); - assertTrue(f2.exists()); - } - - @Test - // Verify we can access the libtoolize tool - public void canAccessLibtoolize2() throws Exception { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - assertTrue(workspace != null); - IWorkspaceRoot root = workspace.getRoot(); - assertTrue(root != null); - IProject project = root.getProject("GnuProject1"); - assertTrue(project != null); - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Libtoolize").click(); - SWTBotShell shell = bot.shell("Libtoolize Options"); - shell.activate(); - bot.text(0).typeText("--help"); - bot.button("OK").click(); - bot.sleep(1000); - SWTBotView consoleView = bot.viewByTitle("Console"); - consoleView.setFocus(); - String output = consoleView.bot().styledText().getText(); - // Verify we got some help output to the console - Pattern p = Pattern.compile(".*Invoking libtoolize in.*GnuProject1.*libtoolize --help.*Usage: libtoolize.*", Pattern.DOTALL); - Matcher m = p.matcher(output); - assertTrue(m.matches()); - } - - @Test - // Verify we can access the libtoolize tool - public void canAccessAutoheader2() throws Exception { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - assertTrue(workspace != null); - IWorkspaceRoot root = workspace.getRoot(); - assertTrue(root != null); - IProject project = root.getProject("GnuProject1"); - assertTrue(project != null); - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Autoheader").click(); - SWTBotShell shell = bot.shell("Autoheader Options"); - shell.activate(); - bot.text(0).typeText("--help"); - bot.button("OK").click(); - bot.sleep(1000); - SWTBotView consoleView = bot.viewByTitle("Console"); - consoleView.setFocus(); - String output = consoleView.bot().styledText().getText(); - // Verify we got some help output to the console - Pattern p = Pattern.compile(".*Invoking autoheader in.*GnuProject1.*autoheader --help.*Usage:.*autoheader.*", Pattern.DOTALL); - Matcher m = p.matcher(output); - assertTrue(m.matches()); - } - - @Test - // Verify we can access the autoreconf tool - public void canAccessAutoreconf2() throws Exception { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - assertTrue(workspace != null); - IWorkspaceRoot root = workspace.getRoot(); - assertTrue(root != null); - IProject project = root.getProject("GnuProject1"); - assertTrue(project != null); - IPath path = project.getLocation(); - // Remove a number of generated files - File f = new File(path.append("src/Makefile.in").toOSString()); - if (f.exists()) - f.delete(); - f = new File(path.append("Makefile.in").toOSString()); - if (f.exists()) - f.delete(); - f = new File(path.append("configure").toOSString()); - if (f.exists()) - f.delete(); - f = new File(path.append("config.status").toOSString()); - if (f.exists()) - f.delete(); - f = new File(path.append("config.sub").toOSString()); - if (f.exists()) - f.delete(); - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Autoreconf").click(); - SWTBotShell shell = bot.shell("Autoreconf Options"); - shell.activate(); - bot.text(0).typeText("--help"); - bot.button("OK").click(); - bot.sleep(1000); - SWTBotView consoleView = bot.viewByTitle("Console"); - consoleView.setFocus(); - String output = consoleView.bot().styledText().getText(); - // Verify we got some help output to the console - Pattern p = Pattern.compile(".*Invoking autoreconf in.*GnuProject1.*autoreconf --help.*Usage: .*autoreconf.*", Pattern.DOTALL); - Matcher m = p.matcher(output); - assertTrue(m.matches()); - view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Autoreconf").click(); - shell = bot.shell("Autoreconf Options"); - shell.activate(); - bot.text(0).typeText("-i"); - bot.button("OK").click(); - // We need to wait until the Makefile.in file is created so - // sleep a bit and look for it...give up after 20 seconds - for (int i = 0; i < 40; ++i) { - bot.sleep(500); - f = new File(path.append("Makefile.in").toOSString()); - if (f.exists()) - break; - } - // Verify a number of generated files now exist - f = new File(path.append("src/Makefile.in").toOSString()); - assertTrue(f.exists()); - f = new File(path.append("Makefile.in").toOSString()); - assertTrue(f.exists()); - f = new File(path.append("configure").toOSString()); - assertTrue(f.exists()); - f = new File(path.append("config.status").toOSString()); - assertTrue(!f.exists()); //shouldn't have run configure - f = new File(path.append("config.sub").toOSString()); - assertTrue(f.exists()); - } - - @Test - // Verify we can access the autoreconf tool - public void canReconfigureProject2() throws Exception { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - assertTrue(workspace != null); - IWorkspaceRoot root = workspace.getRoot(); - assertTrue(root != null); - IProject project = root.getProject("GnuProject1"); - assertTrue(project != null); - IPath path = project.getLocation(); - // Remove a number of generated files - File f = new File(path.append("src/Makefile.in").toOSString()); - if (f.exists()) - f.delete(); - f = new File(path.append("Makefile.in").toOSString()); - if (f.exists()) - f.delete(); - f = new File(path.append("configure").toOSString()); - if (f.exists()) - f.delete(); - f = new File(path.append("config.status").toOSString()); - if (f.exists()) - f.delete(); - f = new File(path.append("config.sub").toOSString()); - if (f.exists()) - f.delete(); - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Reconfigure Project").click(); - // We need to wait until the config.status file is created so - // sleep a bit and look for it...give up after 40 seconds - for (int i = 0; i < 40; ++i) { - bot.sleep(500); - f = new File(path.append("config.status").toOSString()); - if (f.exists()) - break; - } - // Verify a number of generated files now exist - f = new File(path.append("src/Makefile.in").toOSString()); - assertTrue(f.exists()); - f = new File(path.append("Makefile.in").toOSString()); - assertTrue(f.exists()); - f = new File(path.append("configure").toOSString()); - assertTrue(f.exists()); - f = new File(path.append("config.status").toOSString()); - assertTrue(f.exists()); - f = new File(path.append("config.sub").toOSString()); - assertTrue(f.exists()); - } - - @Test // Verify we can set the tools via the Autotools Tools page + @Test public void canSetTools() throws Exception { - SWTBotView view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Properties").click(); - SWTBotShell shell = bot.shell("Properties for GnuProject1"); - shell.activate(); - bot.tree().expandNode("Autotools").select("General"); + openProperties("Autotools", "General"); bot.tabItem("Tools Settings").activate(); bot.textWithLabel("aclocal").setText(""); bot.textWithLabel("aclocal").typeText("automake"); @@ -903,95 +453,81 @@ public class TestToolActions { bot.textWithLabel("libtoolize").setText(""); bot.textWithLabel("libtoolize").typeText("aclocal"); bot.button("OK").click(); - view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Aclocal").click(); - shell = bot.shell("Aclocal Options"); + clickProjectContextMenu("Invoke Autotools", "Invoke Aclocal"); + SWTBotShell shell = bot.shell("Aclocal Options"); shell.activate(); bot.text(0).typeText("--help"); bot.button("OK").click(); bot.sleep(1000); - SWTBotView consoleView = bot.viewByTitle("Console"); + SWTBotView consoleView = viewConsole("Autotools"); consoleView.setFocus(); String output = consoleView.bot().styledText().getText(); // Verify we got some help output to the console - Pattern p = Pattern.compile(".*Invoking aclocal in.*GnuProject1.*automake --help.*Usage:.*automake.*", Pattern.DOTALL); + Pattern p = Pattern.compile(".*Invoking aclocal in.*" + projectName + + ".*automake --help.*Usage:.*automake.*", Pattern.DOTALL); Matcher m = p.matcher(output); assertTrue(m.matches()); - view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Automake").click(); + clickProjectContextMenu("Invoke Autotools", "Invoke Automake"); shell = bot.shell("Automake Options"); shell.activate(); bot.text(0).typeText("--help"); bot.button("OK").click(); bot.sleep(1000); - consoleView = bot.viewByTitle("Console"); + consoleView = bot.viewByPartName("Console"); consoleView.setFocus(); output = consoleView.bot().styledText().getText(); // Verify we got some help output to the console - p = Pattern.compile(".*Invoking automake in.*GnuProject1.*autoconf --help.*Usage:.*autoconf.*", Pattern.DOTALL); + p = Pattern.compile(".*Invoking automake in.*" + projectName + + ".*autoconf --help.*Usage:.*autoconf.*", Pattern.DOTALL); m = p.matcher(output); assertTrue(m.matches()); - view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Autoheader").click(); + clickProjectContextMenu("Invoke Autotools", "Invoke Autoheader"); shell = bot.shell("Autoheader Options"); shell.activate(); bot.text(0).typeText("--help"); bot.button("OK").click(); bot.sleep(1000); - consoleView = bot.viewByTitle("Console"); + consoleView = bot.viewByPartName("Console"); consoleView.setFocus(); output = consoleView.bot().styledText().getText(); // Verify we got some help output to the console - p = Pattern.compile(".*Invoking autoheader in.*GnuProject1.*autoreconf --help.*Usage:.*autoreconf.*", Pattern.DOTALL); + p = Pattern.compile(".*Invoking autoheader in.*" + projectName + + ".*autoreconf --help.*Usage:.*autoreconf.*", Pattern.DOTALL); m = p.matcher(output); assertTrue(m.matches()); - view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Autoreconf").click(); + clickProjectContextMenu("Invoke Autotools", "Invoke Autoreconf"); shell = bot.shell("Autoreconf Options"); shell.activate(); bot.text(0).typeText("--help"); bot.button("OK").click(); bot.sleep(1000); - consoleView = bot.viewByTitle("Console"); + consoleView = bot.viewByPartName("Console"); consoleView.setFocus(); output = consoleView.bot().styledText().getText(); // Verify we got some help output to the console - p = Pattern.compile(".*Invoking autoreconf in.*GnuProject1.*libtoolize --help.*Usage:.*libtoolize.*", Pattern.DOTALL); + p = Pattern.compile(".*Invoking autoreconf in.*" + projectName + + ".*libtoolize --help.*Usage:.*libtoolize.*", Pattern.DOTALL); m = p.matcher(output); assertTrue(m.matches()); - view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - view = bot.viewByTitle("Project Explorer"); - view.bot().tree().select("GnuProject1"); - bot.menu("Project", 1).menu("Invoke Autotools").menu("Invoke Libtoolize").click(); + clickProjectContextMenu("Invoke Autotools", "Invoke Libtoolize"); shell = bot.shell("Libtoolize Options"); shell.activate(); bot.text(0).typeText("--help"); bot.button("OK").click(); bot.sleep(1000); - consoleView = bot.viewByTitle("Console"); + consoleView = bot.viewByPartName("Console"); consoleView.setFocus(); output = consoleView.bot().styledText().getText(); // Verify we got some help output to the console - p = Pattern.compile(".*Invoking libtoolize in.*GnuProject1.*aclocal --help.*Usage:.*aclocal.*", Pattern.DOTALL); + p = Pattern.compile(".*Invoking libtoolize in.*" + projectName + + ".*aclocal --help.*Usage:.*aclocal.*", Pattern.DOTALL); m = p.matcher(output); assertTrue(m.matches()); } - @AfterClass - public static void sleep() { - bot.sleep(2000); - } - }