summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorCamilo Bernal2013-05-14 17:19:52 (EDT)
committer Alexander Kurtakov2013-05-15 03:48:53 (EDT)
commit550f3906bf2f21eee44a8fc856977a1539be924b (patch)
tree7576e837faa5c07f2879ae2eaba425b3db6c7ceb
parent1e9b20e449cb53bd2d4d904fea3302a90023e3a3 (diff)
downloadorg.eclipse.linuxtools-550f3906bf2f21eee44a8fc856977a1539be924b.zip
org.eclipse.linuxtools-550f3906bf2f21eee44a8fc856977a1539be924b.tar.gz
org.eclipse.linuxtools-550f3906bf2f21eee44a8fc856977a1539be924b.tar.bz2
GCov: Remove ContextMenuHelperrefs/changes/96/12796/3
The ContextMenuHelper class was used to workaround a known bug. This bug has been fixed and is available in the latest swtbot snapshot build. Change-Id: I201c2ffc19719f01952cf25749510cff17dfe328 Reviewed-on: https://git.eclipse.org/r/12796 Tested-by: Hudson CI Reviewed-by: Alexander Kurtakov <akurtako@redhat.com> IP-Clean: Alexander Kurtakov <akurtako@redhat.com> Tested-by: Alexander Kurtakov <akurtako@redhat.com>
-rw-r--r--gcov/org.eclipse.linuxtools.gcov.test/src/org/eclipse/linuxtools/internal/gcov/test/ContextMenuHelper.java187
-rw-r--r--gcov/org.eclipse.linuxtools.gcov.test/src/org/eclipse/linuxtools/internal/gcov/test/GcovTest.java51
2 files changed, 29 insertions, 209 deletions
diff --git a/gcov/org.eclipse.linuxtools.gcov.test/src/org/eclipse/linuxtools/internal/gcov/test/ContextMenuHelper.java b/gcov/org.eclipse.linuxtools.gcov.test/src/org/eclipse/linuxtools/internal/gcov/test/ContextMenuHelper.java
deleted file mode 100644
index 45291a3..0000000
--- a/gcov/org.eclipse.linuxtools.gcov.test/src/org/eclipse/linuxtools/internal/gcov/test/ContextMenuHelper.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010, SAP AG
- *
- * 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:
- * Stefan Seelmann - initial implementation posted to
- * http://www.eclipse.org/forums/index.php?t=msg&th=11863&start=2
- *******************************************************************************/
-package org.eclipse.linuxtools.internal.gcov.test;
-
-import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withMnemonic;
-import static org.hamcrest.core.AllOf.allOf;
-import static org.hamcrest.core.IsInstanceOf.instanceOf;
-
-import java.util.Arrays;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.MenuItem;
-import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
-import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
-import org.eclipse.swtbot.swt.finder.results.VoidResult;
-import org.eclipse.swtbot.swt.finder.results.WidgetResult;
-import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot;
-import org.hamcrest.Matcher;
-
-public class ContextMenuHelper {
-
- /**
- * Clicks the context menu matching the text.
- *
- * @param bot
- *
- * @param texts
- * the text on the context menu.
- * @throws WidgetNotFoundException
- * if the widget is not found.
- * @throws SWTException
- * if the menu item is disabled (the root cause being an
- * {@link IllegalStateException})
- */
- public static void clickContextMenu(final AbstractSWTBot<?> bot,
- final String... texts) {
-
- // show
- final MenuItem menuItem = UIThreadRunnable
- .syncExec(new WidgetResult<MenuItem>() {
- @Override
- public MenuItem run() {
- MenuItem theItem = getMenuItem(bot, texts);
- if (theItem != null && !theItem.isEnabled()) {
- throw new IllegalStateException(
- "Menu item is diabled");
- }
-
- return theItem;
- }
- });
- if (menuItem == null) {
- throw new WidgetNotFoundException("Could not find menu: "
- + Arrays.asList(texts));
- }
-
- // click
- click(menuItem);
-
- // hide
- UIThreadRunnable.syncExec(new VoidResult() {
- @Override
- public void run() {
- if (menuItem.isDisposed()) {
- return; // menu already gone
- }
- hide(menuItem.getParent());
- }
- });
- }
-
- private static MenuItem getMenuItem(final AbstractSWTBot<?> bot,
- final String... texts) {
- MenuItem theItem = null;
- Control control = (Control) bot.widget;
- // for dynamic menus, we need to issue this event
- control.notifyListeners(SWT.MenuDetect, new Event());
- Menu menu = control.getMenu();
- for (String text : texts) {
- Matcher<?> matcher = allOf(instanceOf(MenuItem.class),
- withMnemonic(text));
- theItem = show(menu, matcher);
- if (theItem != null) {
- menu = theItem.getMenu();
- } else {
- hide(menu);
- break;
- }
- }
- return theItem;
- }
-
- /**
- * Checks if the context menu matching the text is enabled
- *
- * @param bot
- *
- * @param texts
- * the text on the context menu.
- * @return true if the context menu is enabled
- * @throws WidgetNotFoundException
- * if the widget is not found.
- */
- public static boolean isContextMenuItemEnabled(final AbstractSWTBot<?> bot,
- final String... texts) {
-
- final AtomicBoolean enabled = new AtomicBoolean(false);
- // show
- final MenuItem menuItem = UIThreadRunnable
- .syncExec(new WidgetResult<MenuItem>() {
- @Override
- public MenuItem run() {
- MenuItem theItem = getMenuItem(bot, texts);
- if (theItem != null && theItem.isEnabled()) {
- enabled.set(true);
- }
- return theItem;
- }
- });
- if (menuItem == null) {
- throw new WidgetNotFoundException("Could not find menu: "
- + Arrays.asList(texts));
- }
- // hide
- UIThreadRunnable.syncExec(new VoidResult() {
- @Override
- public void run() {
- if (menuItem.isDisposed()) {
- return; // menu already gone
- }
- hide(menuItem.getParent());
- }
- });
- return enabled.get();
- }
-
- private static MenuItem show(final Menu menu, final Matcher<?> matcher) {
- if (menu != null) {
- menu.notifyListeners(SWT.Show, new Event());
- MenuItem[] items = menu.getItems();
- for (final MenuItem menuItem : items) {
- if (matcher.matches(menuItem)) {
- return menuItem;
- }
- }
- menu.notifyListeners(SWT.Hide, new Event());
- }
- return null;
- }
-
- private static void click(final MenuItem menuItem) {
- final Event event = new Event();
- event.time = (int) System.currentTimeMillis();
- event.widget = menuItem;
- event.display = menuItem.getDisplay();
- event.type = SWT.Selection;
-
- UIThreadRunnable.asyncExec(menuItem.getDisplay(), new VoidResult() {
- @Override
- public void run() {
- menuItem.notifyListeners(SWT.Selection, event);
- }
- });
- }
-
- private static void hide(final Menu menu) {
- menu.notifyListeners(SWT.Hide, new Event());
- if (menu.getParentMenu() != null) {
- hide(menu.getParentMenu());
- }
- }
-}
diff --git a/gcov/org.eclipse.linuxtools.gcov.test/src/org/eclipse/linuxtools/internal/gcov/test/GcovTest.java b/gcov/org.eclipse.linuxtools.gcov.test/src/org/eclipse/linuxtools/internal/gcov/test/GcovTest.java
index e234e76..d202ab1 100644
--- a/gcov/org.eclipse.linuxtools.gcov.test/src/org/eclipse/linuxtools/internal/gcov/test/GcovTest.java
+++ b/gcov/org.eclipse.linuxtools.gcov.test/src/org/eclipse/linuxtools/internal/gcov/test/GcovTest.java
@@ -2,6 +2,7 @@ package org.eclipse.linuxtools.internal.gcov.test;
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withText;
import static org.eclipse.swtbot.swt.finder.waits.Conditions.waitForShell;
+import static org.eclipse.swtbot.swt.finder.finders.ContextMenuHelper.contextMenu;
import java.io.File;
import java.io.InputStream;
@@ -19,12 +20,17 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.linuxtools.dataviewers.actions.STExportToCSVAction;
import org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.actions.AbstractOpenSourceFileAction;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
+import org.eclipse.swtbot.swt.finder.results.VoidResult;
import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio;
@@ -117,8 +123,7 @@ public abstract class GcovTest {
SWTBot viewBot = bot.viewByTitle("Project Explorer").bot();
SWTBotShell wbShell = bot.activeShell();
-// SWTBotShell wbShell = viewBot.shells()[0];
-// wbShell.activate();
+
SWTBotTree treeBot = viewBot.tree();
treeBot.setFocus();
treeBot.expandNode(projectName).select(file.getName());
@@ -153,9 +158,7 @@ public abstract class GcovTest {
SWTBot viewBot = bot.viewByTitle("Project Explorer").bot();
SWTBotShell wbShell = bot.activeShell();
-// wbShell.activate();
-// SWTBotShell wbShell = viewBot.shells()[0];
-// wbShell.activate();
+
SWTBotTree treeBot = viewBot.tree();
treeBot.setFocus();
treeBot.expandNode(projectName).select(file.getName());
@@ -186,9 +189,7 @@ public abstract class GcovTest {
SWTBot viewBot = bot.viewByTitle("Project Explorer").bot();
SWTBotShell wbShell = bot.activeShell();
-// wbShell.activate();
-// SWTBotShell wbShell = viewBot.shells()[0];
-// wbShell.activate();
+
SWTBotTree treeBot = viewBot.tree();
treeBot.setFocus();
// We need to select the binary, but in the tree, it may have additional info appended to the
@@ -205,19 +206,11 @@ public abstract class GcovTest {
treeBot.expandNode(projectName).select(binNodeName);
String menuItem = "Profiling Tools";
String subMenuItem = "1 Profile Code Coverage";
- ContextMenuHelper.clickContextMenu(treeBot, menuItem, subMenuItem);
-
+ click(contextMenu(treeBot, menuItem, subMenuItem));
wbShell.activate();
SWTBotView botView = bot.viewByTitle("gcov");
- // The following cannot be tested on 4.2 because the SWTBot implementation of toolbarButton()
- // is broken there because it relies PartPane having a method getPane() which is no longer true.
-// botView.toolbarButton("Sort coverage per function").click();
-// dumpCSV(bot, botView, projectName, "function", testProducedReference);
-// botView.toolbarButton("Sort coverage per file").click();
-// dumpCSV(bot, botView, projectName, "file", testProducedReference);
-// botView.toolbarButton("Sort coverage per folder").click();
-// dumpCSV(bot, botView, projectName, "folder", testProducedReference);
+
botView.close();
}
@@ -268,8 +261,22 @@ public abstract class GcovTest {
testGcovLaunchSummary(bot, projectName, "a.out");
}
-
-
-
-
+ /**
+ * Click on the specified MenuItem.
+ * @param menuItem MenuItem item to click
+ */
+ private static void click(final MenuItem menuItem) {
+ final Event event = new Event();
+ event.time = (int) System.currentTimeMillis();
+ event.widget = menuItem;
+ event.display = menuItem.getDisplay();
+ event.type = SWT.Selection;
+
+ UIThreadRunnable.asyncExec(menuItem.getDisplay(), new VoidResult() {
+ @Override
+ public void run() {
+ menuItem.notifyListeners(SWT.Selection, event);
+ }
+ });
+ }
}