Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAparna Argade2016-05-03 13:21:56 +0000
committerAparna Argade2016-05-05 19:37:40 +0000
commitfe03559e90ca0b9ca7d2556694eb14421d2b4799 (patch)
tree398a472ce4ad03cc379c2fd2c5ddcf51688245f0
parent5c78a8b7325dc8fb0e1a908f0881f3f89de55852 (diff)
downloadorg.eclipse.swtbot-fe03559e90ca0b9ca7d2556694eb14421d2b4799.tar.gz
org.eclipse.swtbot-fe03559e90ca0b9ca7d2556694eb14421d2b4799.tar.xz
org.eclipse.swtbot-fe03559e90ca0b9ca7d2556694eb14421d2b4799.zip
Make SWTBotNatTable.rightClick public
Add test to verify the implementation. Bug: 489179 Change-Id: I9efdfc8307c1e7915cf9beab5568ec339c231073 Signed-off-by: Aparna Argade <aprsac@yahoo.com>
-rw-r--r--org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test/AllTests.java4
-rw-r--r--org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test1/TestRightClickXY.java123
-rw-r--r--org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test1/_5015_AutomaticDataSpanningExample.java2
-rw-r--r--org.eclipse.swtbot.nebula.nattable.finder/src/org/eclipse/swtbot/nebula/nattable/finder/widgets/SWTBotNatTable.java41
4 files changed, 168 insertions, 2 deletions
diff --git a/org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test/AllTests.java b/org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test/AllTests.java
index d1034219..c9f12d63 100644
--- a/org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test/AllTests.java
+++ b/org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test/AllTests.java
@@ -11,13 +11,15 @@
package org.eclipse.swtbot.nebula.nattable.finder.test;
import org.eclipse.swtbot.nebula.nattable.finder.test1.TestNatTableContextMenu;
+import org.eclipse.swtbot.nebula.nattable.finder.test1.TestRightClickXY;
import org.eclipse.swtbot.nebula.nattable.finder.test2.TestNatTableOtherFeatures;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
-@SuiteClasses({ TestNatTableContextMenu.class, TestNatTableOtherFeatures.class })
+@SuiteClasses({ TestNatTableContextMenu.class, TestNatTableOtherFeatures.class,
+ TestRightClickXY.class })
public class AllTests {
}
diff --git a/org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test1/TestRightClickXY.java b/org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test1/TestRightClickXY.java
new file mode 100644
index 00000000..ba34f2fe
--- /dev/null
+++ b/org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test1/TestRightClickXY.java
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Cadence Design Systems, Inc. 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
+ *
+ * Contributors:
+ * Aparna Argade(Cadence Design Systems, Inc.) - Test case of Bug 489179
+ *******************************************************************************/
+package org.eclipse.swtbot.nebula.nattable.finder.test1;
+
+import static org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable.syncExec;
+import static org.hamcrest.Matchers.containsString;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swtbot.nebula.nattable.finder.widgets.SWTBotNatTable;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.results.VoidResult;
+import org.eclipse.swtbot.swt.finder.utils.SWTBotEvents;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class TestRightClickXY extends _5015_AutomaticDataSpanningExample {
+ private boolean showEventOccurance = false;
+ private int row = 0, column = 0;
+ /**
+ * The test adds event handler. After right clicking on a cell of NatTable,
+ * it reads MouseDown, MouseUp and Show events and validates event
+ * parameters.
+ */
+ @Test
+ public void testRightClickXY() {
+ SWTBotNatTable nattable = bot.nattable();
+ final Display display = nattable.widget.getDisplay();
+ syncExec(new VoidResult() {
+ @Override
+ public void run() {
+ Listener listener = new EventListener();
+ for (int event : SWTBotEvents.events()) {
+ display.addFilter(event, listener);
+ }
+ }
+ });
+ nattable.rightClick(row, column);
+ syncExec(new VoidResult() {
+ @Override
+ public void run() {
+ if (!shell.isDisposed()) {
+ display.readAndDispatch();
+ display.sleep();
+ }
+ }
+ });
+ assertTrue(showEventOccurance);
+ }
+
+ /**
+ * Event descriptions before fixing Bug 489179
+ * MouseDown: button=1 stateMask=0x200000 count=1
+ * MouseUp: button=0 stateMask=0x0 count=0
+ * Show event was not occurring.
+ *
+ * Event descriptions after fixing Bug 489179
+ * MouseDown : button=3 stateMask=0x0 count=1
+ * MouseUp: button=3 stateMask=0x200000 count=1
+ * Show:MenuEvent{Menu {}}
+ */
+ class EventListener implements Listener {
+ @Override
+ public void handleEvent(Event event) {
+ if (!(event.type == SWT.MouseDown || event.type == SWT.MouseUp || event.type == SWT.Show))
+ return;
+ String description = SWTBotEvents.toString(event);
+ switch (event.type) {
+ case SWT.MouseDown:
+ assertThat(description, containsString("button=3 stateMask=0x0"));
+ assertThat(description, containsString("count=1"));
+ verifyRowColumnFromXY(description);
+ break;
+ case SWT.MouseUp:
+ assertThat(description, containsString("button=3 stateMask=0x200000"));
+ assertThat(description, containsString("count=1"));
+ verifyRowColumnFromXY(description);
+ break;
+ case SWT.Show:
+ showEventOccurance = true;
+ assertThat(description, containsString("MenuEvent{Menu {}"));
+ }
+ }
+ }
+
+ /**
+ * This method derives x, y coordinates from the description string and
+ * obtains row and column positions from x, y using NatTable APIs
+ *
+ * @param description
+ * description of SWTBotEvent containing x, y coordinates
+ */
+ private void verifyRowColumnFromXY(String description)
+ {
+ /*
+ * split the string, get x or y part out of it, replace all non-digit
+ * with blank: the remaining string contains only digits
+ */
+ int x = Integer.parseInt(description.split(" ")[8].replaceAll("[\\D]", ""));
+ int obtainedColumn = bot.nattable().widget.getColumnPositionByX(x);
+
+ int y = Integer.parseInt(description.split(" ")[9].replaceAll("[\\D]", ""));;
+ int obtainedRow = bot.nattable().widget.getRowPositionByY(y);
+
+ assertEquals("Row number is verified", row, obtainedRow);
+ assertEquals("Column number is verified", column, obtainedColumn);
+ }
+
+}
diff --git a/org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test1/_5015_AutomaticDataSpanningExample.java b/org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test1/_5015_AutomaticDataSpanningExample.java
index 1aa36deb..6a97b543 100644
--- a/org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test1/_5015_AutomaticDataSpanningExample.java
+++ b/org.eclipse.swtbot.nebula.nattable.finder.test/src/org/eclipse/swtbot/nebula/nattable/finder/test1/_5015_AutomaticDataSpanningExample.java
@@ -55,7 +55,7 @@ public class _5015_AutomaticDataSpanningExample {
public SWTNatTableBot bot;
public static NatTable nattable;
- private Shell shell;
+ public Shell shell;
@Before
public void setUp() {
diff --git a/org.eclipse.swtbot.nebula.nattable.finder/src/org/eclipse/swtbot/nebula/nattable/finder/widgets/SWTBotNatTable.java b/org.eclipse.swtbot.nebula.nattable.finder/src/org/eclipse/swtbot/nebula/nattable/finder/widgets/SWTBotNatTable.java
index eaf89824..c45a7424 100644
--- a/org.eclipse.swtbot.nebula.nattable.finder/src/org/eclipse/swtbot/nebula/nattable/finder/widgets/SWTBotNatTable.java
+++ b/org.eclipse.swtbot.nebula.nattable.finder/src/org/eclipse/swtbot/nebula/nattable/finder/widgets/SWTBotNatTable.java
@@ -18,6 +18,7 @@ import org.eclipse.swtbot.nebula.nattable.finder.finders.NatTableContextMenuFind
import org.eclipse.swtbot.swt.finder.ReferenceBy;
import org.eclipse.swtbot.swt.finder.SWTBotWidget;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.results.IntResult;
import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.results.VoidResult;
@@ -165,6 +166,46 @@ public class SWTBotNatTable extends AbstractSWTBot<NatTable> {
}
/**
+ * RightClick on the NatTable on given cell.
+ *
+ * @param row
+ * the visible row number in the NatTable
+ * @param column
+ * the visible column number in the NatTable
+ * @return itself
+ */
+ public SWTBotNatTable rightClick(final int row, final int column) {
+ assertIsLegalCell(row, column);
+ setFocus();
+ UIThreadRunnable.syncExec(new VoidResult() {
+ @Override
+ public void run() {
+ Rectangle cellBounds = widget.getBoundsByPosition(column, row);
+ rightClick(cellBounds.x + (cellBounds.width / 2), cellBounds.y + (cellBounds.height / 2), false);
+ }
+ });
+ return this;
+ }
+
+ /**
+ * RightClick on the NatTable at the center of widget.
+ *
+ * @return itself
+ */
+ @Override
+ public SWTBotNatTable rightClick() {
+ setFocus();
+ UIThreadRunnable.syncExec(new VoidResult() {
+ @Override
+ public void run() {
+ Rectangle widgetBounds = widget.getBounds();
+ rightClick(widgetBounds.width / 2, widgetBounds.height / 2, false);
+ }
+ });
+ return this;
+ }
+
+ /**
* Get the bounds of the Widget
*
* @return the bounds of the Widget relative to its parent

Back to the top