Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorArne Deutsch2017-08-02 03:49:06 -0400
committerLeo Ufimtsev2017-08-10 12:57:03 -0400
commitdf00db27130a9ef611d589c174507240572c20ac (patch)
tree8d8ddaafde221a547bda98d6bfb6d2b376c58166 /tests
parent1a824dc95731ccc896ed8db58ce51604b2acd78c (diff)
downloadeclipse.platform.swt-df00db27130a9ef611d589c174507240572c20ac.tar.gz
eclipse.platform.swt-df00db27130a9ef611d589c174507240572c20ac.tar.xz
eclipse.platform.swt-df00db27130a9ef611d589c174507240572c20ac.zip
[Bug 520442] Add test cases to cover StyledText.handleMouseDown.
Change-Id: Id5d5c5a4d05f05dff9b9142572cd07d40a7c7593 Signed-off-by: Arne Deutsch <arne@idedeluxe.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java101
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java
index 9792f47a6e..5582363661 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java
@@ -55,6 +55,7 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.printing.Printer;
import org.eclipse.swt.widgets.Caret;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -4837,6 +4838,106 @@ public void test_isTextSelected() {
assertTrue(text.isTextSelected());
}
+@Test
+public void test_clickUpdatesCaretPosition() {
+ text.setText("1\n2\n3\n");
+
+ Event event = new Event();
+ event.button = 1;
+ event.count = 1;
+ event.x = 0;
+ event.y = text.getLinePixel(1);
+ text.notifyListeners(SWT.MouseDown, event);
+
+ assertEquals(2, text.getCaretOffset());
+}
+
+@Test
+public void test_doubleClickSelectsWord() {
+ text.setText("Test1 Test2");
+
+ Event event = new Event();
+ event.button = 1;
+ event.count = 2;
+ event.x = 0;
+ event.y = 0;
+ text.notifyListeners(SWT.MouseDown, event);
+
+ assertEquals("Test1", text.getSelectionText());
+}
+
+@Test
+public void test_doubleClickWithRightMouseButtonDoesNotSelectWord() {
+ text.setText("Test1 Test2");
+
+ Event event = new Event();
+ event.button = 3;
+ event.count = 2;
+ event.x = 0;
+ event.y = 0;
+ text.notifyListeners(SWT.MouseDown, event);
+
+ assertEquals("", text.getSelectionText());
+}
+
+@Test
+public void test_doubleClickDoesNotSelectIfDoubleClickIsDisabled() {
+ text.setText("Test1 Test2");
+ text.setDoubleClickEnabled(false);
+
+ Event event = new Event();
+ event.button = 1;
+ event.count = 2;
+ event.x = 0;
+ event.y = 0;
+ text.notifyListeners(SWT.MouseDown, event);
+
+ assertEquals("", text.getSelectionText());
+}
+
+@Test
+public void test_trippleClickSelectsSentance() {
+ text.setText("Test1 Test2\nTest3 Test4");
+
+ Event event = new Event();
+ event.button = 1;
+ event.count = 3;
+ event.x = 0;
+ event.y = 0;
+ text.notifyListeners(SWT.MouseDown, event);
+
+ assertEquals("Test1 Test2\n", text.getSelectionText());
+}
+
+@Test
+public void test_trippleClickOnLastLineSelectsSentance() {
+ text.setText("Test1 Test2\nTest3 Test4");
+
+ Event event = new Event();
+ event.button = 1;
+ event.count = 3;
+ event.x = 0;
+ event.y = text.getLinePixel(1);
+ text.notifyListeners(SWT.MouseDown, event);
+
+ assertEquals("Test3 Test4", text.getSelectionText());
+}
+
+@Test
+public void test_trippleClickDoesNotSelectIfDoubleClickIsDisabled() {
+ text.setText("Test1 Test2\nTest3 Test4");
+ text.setDoubleClickEnabled(false);
+
+ Event event = new Event();
+ event.button = 1;
+ event.count = 3;
+ event.x = 0;
+ event.y = 0;
+ text.notifyListeners(SWT.MouseDown, event);
+
+ assertEquals("", text.getSelectionText());
+}
+
/**
* Regression test for bug 19985
*/

Back to the top