1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-03 14:25:37 +02:00

Add SWTBot tests including one to test creating launch configs.

Change-Id: Ia5032df7094be215ebefd9c2fb7caa35a9cb7f43
This commit is contained in:
Doug Schaefer 2017-10-14 15:40:27 -04:00
parent bc661996aa
commit 8227915473
16 changed files with 428 additions and 11 deletions

View file

@ -19,4 +19,4 @@ Require-Bundle: org.eclipse.osgi.services;bundle-version="3.5.0",
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
Export-Package: org.eclipse.launchbar.ui.controls.internal;x-internal:=true
Export-Package: org.eclipse.launchbar.ui.controls.internal;x-friends:="org.eclipse.launchbar.ui.tests"

View file

@ -264,6 +264,7 @@ public abstract class CSelector extends Composite {
arrow.addMouseListener(mouseListener);
if (editable) {
final EditButton editButton = new EditButton(buttonComposite, SWT.NONE);
editButton.setData(LaunchBarWidgetIds.ID, LaunchBarWidgetIds.EDIT);
editButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));
editButton.setBackground(getBackground());
editButton.addSelectionListener(new SelectionAdapter() {
@ -303,6 +304,7 @@ public abstract class CSelector extends Composite {
popup.dispose();
}
popup = new Shell(getShell(), SWT.TOOL | SWT.ON_TOP | SWT.RESIZE);
popup.setData(LaunchBarWidgetIds.ID, LaunchBarWidgetIds.POPUP);
popup.setLayout(GridLayoutFactory.fillDefaults().spacing(0, 0).create());
popup.setBackground(getBackground());
listViewer = new LaunchBarListViewer(popup);

View file

@ -51,6 +51,7 @@ public class ConfigSelector extends CSelector {
public ConfigSelector(Composite parent, int style) {
super(parent, style);
setData(LaunchBarWidgetIds.ID, LaunchBarWidgetIds.CONFIG_SELECTOR);
setToolTipText(Messages.ConfigSelector_1);
defaultProvider = new DefaultDescriptorLabelProvider();
@ -166,6 +167,7 @@ public class ConfigSelector extends CSelector {
@Override
public void createActionArea(Composite parent) {
final Composite createButton = new Composite(parent, SWT.BORDER);
createButton.setData(LaunchBarWidgetIds.ID, LaunchBarWidgetIds.NEW);
GridDataFactory.fillDefaults().grab(true, false).applyTo(createButton);
GridLayoutFactory.fillDefaults().margins(7, 7).applyTo(createButton);
createButton.setBackground(getBackground());
@ -230,9 +232,4 @@ public class ConfigSelector extends CSelector {
super.setSelection(element);
}
@Override
public void openPopup() {
super.openPopup();
}
}

View file

@ -0,0 +1,20 @@
/*******************************************************************************
* Copyright (c) 2017 QNX Software Systems and others.
* 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
*******************************************************************************/
package org.eclipse.launchbar.ui.controls.internal;
public interface LaunchBarWidgetIds {
public static final String ID = "org.eclipse.swtbot.widget.key"; //$NON-NLS-1$
public static final String CONFIG_SELECTOR = "org.eclipse.launchbar.selector.config"; //$NON-NLS-1$
public static final String POPUP = "org.eclipse.launchbar.popup"; //$NON-NLS-1$
public static final String EDIT = "org.eclipse.launchbar.edit"; //$NON-NLS-1$
public static final String NEW = "org.eclipse.launchbar.new"; //$NON-NLS-1$
}

16
pom.xml
View file

@ -40,7 +40,7 @@
<repositories>
<repository>
<id>platform</id>
<url>http://download.eclipse.org/eclipse/updates/4.6/</url>
<url>http://download.eclipse.org/eclipse/updates/4.7/</url>
<layout>p2</layout>
</repository>
<repository>
@ -48,19 +48,24 @@
<url>http://download.eclipse.org/cbi/updates/license/</url>
<layout>p2</layout>
</repository>
<repository>
<!-- repository>
<id>orbit</id>
<url>http://download.eclipse.org/tools/orbit/downloads/drops/R20160520211859/repository/</url>
<layout>p2</layout>
</repository>
</repository-->
<repository>
<id>cdt</id>
<url>http://download.eclipse.org/tools/cdt/releases/9.0</url>
<url>http://download.eclipse.org/tools/cdt/releases/9.2/</url>
<layout>p2</layout>
</repository>
<repository>
<id>remote</id>
<url>http://download.eclipse.org/tools/ptp/updates/remote/neon/</url>
<url>http://download.eclipse.org/tools/ptp/builds/remote/oxygen/milestones/</url>
<layout>p2</layout>
</repository>
<repository>
<id>swtbot</id>
<url>http://download.eclipse.org/technology/swtbot/snapshots/</url>
<layout>p2</layout>
</repository>
</repositories>
@ -71,6 +76,7 @@
<module>bundles/org.eclipse.launchbar.ui.controls</module>
<module>features/org.eclipse.launchbar</module>
<module>tests/org.eclipse.launchbar.core.tests</module>
<module>tests/org.eclipse.launchbar.ui.tests</module>
<module>bundles/org.eclipse.launchbar.remote.core</module>
<module>bundles/org.eclipse.launchbar.remote.ui</module>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.launchbar.ui.tests</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

View file

@ -0,0 +1,15 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Launch Bar UI Tests
Bundle-SymbolicName: org.eclipse.launchbar.ui.tests
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: Eclipse CDT
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.junit;bundle-version="4.12.0",
org.eclipse.swtbot.go;bundle-version="2.7.0",
org.eclipse.debug.core;bundle-version="3.11.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Import-Package: org.eclipse.launchbar.ui.controls.internal
Bundle-Activator: org.eclipse.launchbar.ui.tests.internal.Activator

View file

@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.

View file

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.launchbar</groupId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
<artifactId>parent</artifactId>
</parent>
<artifactId>org.eclipse.launchbar.ui.tests</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<!-- Default configuration, UI tests may have to override these -->
<useUIHarness>true</useUIHarness>
<useUIThread>false</useUIThread>
<includes>
<include>**/AutomatedIntegrationSuite.*</include>
</includes>
<testFailureIgnore>true</testFailureIgnore>
<dependencies>
<dependency>
<type>p2-installable-unit</type>
<artifactId>org.eclipse.sdk.feature.group</artifactId>
</dependency>
</dependencies>
<product>org.eclipse.sdk.ide</product>
<argLine></argLine>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright (c) 2017 QNX Software Systems and others.
* 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
*******************************************************************************/
package org.eclipse.launchbar.ui.tests;
import org.eclipse.launchbar.ui.controls.internal.CSelector;
import org.eclipse.launchbar.ui.controls.internal.LaunchBarWidgetIds;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.SWTBotWidget;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory;
import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl;
@SWTBotWidget(clasz = CSelector.class, preferredName = "cselector")
public class SWTBotCSelector extends AbstractSWTBotControl<CSelector> {
public static SWTBotCSelector withId(String id) throws WidgetNotFoundException {
return new SWTBotCSelector(new SWTBot().widget(WidgetMatcherFactory.withId(id)));
}
public SWTBotCSelector(CSelector w) throws WidgetNotFoundException {
super(w);
}
public SWTBot bot() {
return new SWTBot(widget);
}
public void click(int x, int y) {
notify(SWT.MouseEnter);
notify(SWT.MouseMove);
notify(SWT.Activate);
notify(SWT.FocusIn);
notify(SWT.MouseDown, createMouseEvent(x, y, 1, SWT.NONE, 1));
notify(SWT.MouseUp, createMouseEvent(x, y, 1, SWT.BUTTON1, 1));
}
@Override
public SWTBotCSelector click() {
Point size = syncExec(new Result<Point>() {
@Override
public Point run() {
return widget.getSize();
}
});
click(size.x / 2, size.y / 2);
return this;
}
public void clickEdit() {
bot().buttonWithId(LaunchBarWidgetIds.EDIT).click(); // $NON-NLS-1$
}
public void select(String text) {
click();
}
}

View file

@ -0,0 +1,93 @@
/*******************************************************************************
* Copyright (c) 2017 QNX Software Systems and others.
* 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
*******************************************************************************/
package org.eclipse.launchbar.ui.tests;
import org.eclipse.launchbar.ui.controls.internal.ConfigSelector;
import org.eclipse.launchbar.ui.controls.internal.LaunchBarWidgetIds;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory;
import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
@SuppressWarnings("nls")
public class SWTBotConfigSelector extends SWTBotCSelector {
private class ActionArea extends AbstractSWTBotControl<Composite> {
public ActionArea(SWTBotShell shell) throws WidgetNotFoundException {
super(shell.bot().widget(WidgetMatcherFactory.withId(LaunchBarWidgetIds.NEW)));
}
public void click(int x, int y) {
notify(SWT.MouseEnter);
notify(SWT.MouseMove);
notify(SWT.Activate);
notify(SWT.FocusIn);
notify(SWT.MouseDown, createMouseEvent(x, y, 1, SWT.NONE, 1));
notify(SWT.MouseUp, createMouseEvent(x, y, 1, SWT.BUTTON1, 1));
}
@Override
public ActionArea click() {
Point size = syncExec(new Result<Point>() {
@Override
public Point run() {
return widget.getSize();
}
});
click(size.x / 2, size.y / 2);
return this;
}
}
public static class NewConfigDialog extends SWTBotShell {
public NewConfigDialog(Shell shell) {
super(shell);
}
public NewConfigDialog setMode(String mode) {
bot().tableInGroup("Launch Mode").select(mode);
return this;
}
public NewConfigDialog setType(String type) {
bot().tableInGroup("Launch Configuration Type").select(type);
return this;
}
public NewConfigDialog next() {
bot().button("Next >").click();
return this;
}
public NewConfigDialog finish() {
bot().button("Finish").click();
return this;
}
}
public SWTBotConfigSelector(ConfigSelector configSelector) {
super(configSelector);
}
public SWTBotConfigSelector(SWTBot bot) {
this(bot.widget(WidgetMatcherFactory.withId(LaunchBarWidgetIds.CONFIG_SELECTOR)));
}
public NewConfigDialog newConfigDialog() {
click();
new ActionArea(bot().shellWithId(LaunchBarWidgetIds.POPUP)).click();
return new NewConfigDialog(bot().shell("Create Launch Configuration").widget);
}
}

View file

@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2017 QNX Software Systems and others.
* 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
*******************************************************************************/
package org.eclipse.launchbar.ui.tests.internal;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
public class Activator extends AbstractUIPlugin {
private static BundleContext bundleContext;
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
bundleContext = context;
}
public static <T> T getService(Class<T> service) {
ServiceReference<T> ref = bundleContext.getServiceReference(service);
return ref != null ? bundleContext.getService(ref) : null;
}
}

View file

@ -0,0 +1,17 @@
/*******************************************************************************
* Copyright (c) 2017 QNX Software Systems and others.
* 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
*******************************************************************************/
package org.eclipse.launchbar.ui.tests.internal;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({ CreateLaunchConfigTests.class })
public class AutomatedIntegrationSuite {
}

View file

@ -0,0 +1,83 @@
/*******************************************************************************
* Copyright (c) 2017 QNX Software Systems and others.
* 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
*******************************************************************************/
package org.eclipse.launchbar.ui.tests.internal;
import static org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory.withPartName;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.launchbar.ui.tests.SWTBotConfigSelector;
import org.eclipse.launchbar.ui.tests.SWTBotConfigSelector.NewConfigDialog;
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.utils.SWTBotPreferences;
import org.eclipse.swtbot.swt.finder.waits.ICondition;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@SuppressWarnings("nls")
public class CreateLaunchConfigTests {
private static SWTWorkbenchBot bot;
@BeforeClass
public static void beforeClass() {
SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
SWTBotPreferences.TIMEOUT = 10000;
bot = new SWTWorkbenchBot();
}
@Before
public void before() {
bot.resetWorkbench();
for (SWTBotView view : bot.views(withPartName("Welcome"))) {
view.close();
}
}
@Test
public void createEclipseApplication() throws Exception {
String configName = "Test Config";
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
for (ILaunchConfiguration config : launchManager.getLaunchConfigurations()) {
if (config.getName().equals(configName)) {
config.delete();
}
}
bot.waitUntil(new ICondition() {
@Override
public void init(SWTBot bot) {
NewConfigDialog dialog = new SWTBotConfigSelector(bot).newConfigDialog();
dialog.setMode("Debug").setType("Eclipse Application").next();
dialog.bot().textWithLabel("Name:").setText(configName);
dialog.finish();
}
@Override
public boolean test() throws Exception {
for (ILaunchConfiguration config : launchManager.getLaunchConfigurations()) {
if (config.getName().equals(configName)) {
return true;
}
}
return false;
}
@Override
public String getFailureMessage() {
return "Test config not found";
}
});
}
}