Skip to content

Commit 45a17f8

Browse files
committed
Spin event loop in widget tests that access Clipboard
This carries on earlier work, such as PR eclipse-platform#2489 Part of eclipse-platform#2598
1 parent 6347ad3 commit 45a17f8

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CCombo.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void test_ConstructorLorg_eclipse_swt_widgets_CompositeI() {
7676
}
7777

7878
@Test
79-
public void test_copy() {
79+
public void test_copy() throws InterruptedException {
8080
if (SwtTestUtil.isCocoa) {
8181
// TODO Fix Cocoa failure.
8282
if (SwtTestUtil.verbose) {
@@ -90,6 +90,7 @@ public void test_copy() {
9090
ccombo.copy();
9191
ccombo.setSelection(new Point(0,0));
9292
ccombo.paste();
93+
SwtTestUtil.processEvents(1000, () -> "23123456".equals(ccombo.getText()));
9394
assertEquals("23123456", ccombo.getText());
9495
}
9596

@@ -131,7 +132,7 @@ public void test_isFocusControl() {
131132
}
132133

133134
@Test
134-
public void test_paste() {
135+
public void test_paste() throws InterruptedException {
135136
if (SwtTestUtil.isCocoa) {
136137
// TODO Fix Cocoa failure.
137138
if (SwtTestUtil.verbose) {
@@ -143,8 +144,10 @@ public void test_paste() {
143144
ccombo.setText("123456");
144145
ccombo.setSelection(new Point(1,3));
145146
ccombo.cut();
147+
SwtTestUtil.processEvents(1000, () -> "1456".equals(ccombo.getText()));
146148
assertEquals("1456", ccombo.getText());
147149
ccombo.paste();
150+
SwtTestUtil.processEvents(1000, () -> "123456".equals(ccombo.getText()));
148151
assertEquals("123456", ccombo.getText());
149152
}
150153

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Text.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class Test_org_eclipse_swt_widgets_Text extends Test_org_eclipse_swt_widg
4949
public void setUp() {
5050
super.setUp();
5151
shell.pack();
52-
shell.open();
52+
SwtTestUtil.openShell(shell);
5353
makeCleanEnvironment(false); // use multi-line by default
5454
}
5555

@@ -929,7 +929,7 @@ public void test_isVisible() {
929929
}
930930

931931
@Test
932-
public void test_paste() {
932+
public void test_paste() throws InterruptedException {
933933
if (SwtTestUtil.isCocoa) {
934934
// TODO Fix Cocoa failure.
935935
if (SwtTestUtil.verbose) {
@@ -942,20 +942,26 @@ public void test_paste() {
942942
text.setSelection(2, 4);
943943
assertEquals("01234567890", text.getText());
944944
text.copy();
945+
SwtTestUtil.processEvents(100, null);
945946
text.setSelection(0);
946947
text.paste();
948+
SwtTestUtil.processEvents(1000, () -> "2301234567890".equals(text.getText()));
947949
assertEquals("2301234567890", text.getText());
948950
text.copy();
951+
SwtTestUtil.processEvents(100, null);
949952
text.setSelection(3);
950953
text.paste();
954+
SwtTestUtil.processEvents(1000, () -> "230231234567890".equals(text.getText()));
951955
assertEquals("230231234567890", text.getText());
952956

953957
text.setText("0" + delimiterString + "1");
954958
text.selectAll();
955959
text.copy();
956960
text.setSelection(0);
957961
text.paste();
958-
assertEquals("0" + delimiterString + "1" + "0" + delimiterString + "1", text.getText());
962+
String expected = "0" + delimiterString + "1" + "0" + delimiterString + "1";
963+
SwtTestUtil.processEvents(1000, () -> expected.equals(text.getText()));
964+
assertEquals(expected, text.getText());
959965

960966
// tests a SINGLE line text editor
961967
makeCleanEnvironment(true);
@@ -966,10 +972,12 @@ public void test_paste() {
966972
text.copy();
967973
text.setSelection(0);
968974
text.paste();
975+
SwtTestUtil.processEvents(1000, () -> "2301234567890".equals(text.getText()));
969976
assertEquals("2301234567890", text.getText());
970977
text.copy();
971978
text.setSelection(3);
972979
text.paste();
980+
SwtTestUtil.processEvents(1000, () -> "230231234567890".equals(text.getText()));
973981
assertEquals("230231234567890", text.getText());
974982

975983
// tests a SINGLE line text editor
@@ -981,8 +989,11 @@ public void test_paste() {
981989
text.setSelection(0);
982990
text.paste();
983991

984-
if (SwtTestUtil.fCheckSWTPolicy)
992+
if (SwtTestUtil.fCheckSWTPolicy) {
993+
String expected2 = "0" + delimiterString + "1" + "0" + delimiterString + "1";
994+
SwtTestUtil.processEvents(1000, () -> expected2.equals(text.getText()));
985995
assertEquals("0" + delimiterString + "1" + "0" + delimiterString + "1", text.getText());
996+
}
986997
}
987998

988999
@Test

0 commit comments

Comments
 (0)