Skip to content

Commit 69ccb90

Browse files
committed
Spin event loop in widget tests that access Clipboard
This carries on earlier work, such as PR #2489 Part of #2598
1 parent a56c6b6 commit 69ccb90

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
@@ -78,7 +78,7 @@ public void test_ConstructorLorg_eclipse_swt_widgets_CompositeI() {
7878

7979
@Tag("clipboard")
8080
@Test
81-
public void test_copy() {
81+
public void test_copy() throws InterruptedException {
8282
if (SwtTestUtil.isCocoa) {
8383
// TODO Fix Cocoa failure.
8484
if (SwtTestUtil.verbose) {
@@ -92,6 +92,7 @@ public void test_copy() {
9292
ccombo.copy();
9393
ccombo.setSelection(new Point(0,0));
9494
ccombo.paste();
95+
SwtTestUtil.processEvents(1000, () -> "23123456".equals(ccombo.getText()));
9596
assertEquals("23123456", ccombo.getText());
9697
}
9798

@@ -135,7 +136,7 @@ public void test_isFocusControl() {
135136

136137
@Tag("clipboard")
137138
@Test
138-
public void test_paste() {
139+
public void test_paste() throws InterruptedException {
139140
if (SwtTestUtil.isCocoa) {
140141
// TODO Fix Cocoa failure.
141142
if (SwtTestUtil.verbose) {
@@ -147,8 +148,10 @@ public void test_paste() {
147148
ccombo.setText("123456");
148149
ccombo.setSelection(new Point(1,3));
149150
ccombo.cut();
151+
SwtTestUtil.processEvents(1000, () -> "1456".equals(ccombo.getText()));
150152
assertEquals("1456", ccombo.getText());
151153
ccombo.paste();
154+
SwtTestUtil.processEvents(1000, () -> "123456".equals(ccombo.getText()));
152155
assertEquals("123456", ccombo.getText());
153156
}
154157

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
@@ -50,7 +50,7 @@ public class Test_org_eclipse_swt_widgets_Text extends Test_org_eclipse_swt_widg
5050
public void setUp() {
5151
super.setUp();
5252
shell.pack();
53-
shell.open();
53+
SwtTestUtil.openShell(shell);
5454
makeCleanEnvironment(false); // use multi-line by default
5555
}
5656

@@ -932,7 +932,7 @@ public void test_isVisible() {
932932

933933
@Tag("clipboard")
934934
@Test
935-
public void test_paste() {
935+
public void test_paste() throws InterruptedException {
936936
if (SwtTestUtil.isCocoa) {
937937
// TODO Fix Cocoa failure.
938938
if (SwtTestUtil.verbose) {
@@ -945,20 +945,26 @@ public void test_paste() {
945945
text.setSelection(2, 4);
946946
assertEquals("01234567890", text.getText());
947947
text.copy();
948+
SwtTestUtil.processEvents(100, null);
948949
text.setSelection(0);
949950
text.paste();
951+
SwtTestUtil.processEvents(1000, () -> "2301234567890".equals(text.getText()));
950952
assertEquals("2301234567890", text.getText());
951953
text.copy();
954+
SwtTestUtil.processEvents(100, null);
952955
text.setSelection(3);
953956
text.paste();
957+
SwtTestUtil.processEvents(1000, () -> "230231234567890".equals(text.getText()));
954958
assertEquals("230231234567890", text.getText());
955959

956960
text.setText("0" + delimiterString + "1");
957961
text.selectAll();
958962
text.copy();
959963
text.setSelection(0);
960964
text.paste();
961-
assertEquals("0" + delimiterString + "1" + "0" + delimiterString + "1", text.getText());
965+
String expected = "0" + delimiterString + "1" + "0" + delimiterString + "1";
966+
SwtTestUtil.processEvents(1000, () -> expected.equals(text.getText()));
967+
assertEquals(expected, text.getText());
962968

963969
// tests a SINGLE line text editor
964970
makeCleanEnvironment(true);
@@ -969,10 +975,12 @@ public void test_paste() {
969975
text.copy();
970976
text.setSelection(0);
971977
text.paste();
978+
SwtTestUtil.processEvents(1000, () -> "2301234567890".equals(text.getText()));
972979
assertEquals("2301234567890", text.getText());
973980
text.copy();
974981
text.setSelection(3);
975982
text.paste();
983+
SwtTestUtil.processEvents(1000, () -> "230231234567890".equals(text.getText()));
976984
assertEquals("230231234567890", text.getText());
977985

978986
// tests a SINGLE line text editor
@@ -984,8 +992,11 @@ public void test_paste() {
984992
text.setSelection(0);
985993
text.paste();
986994

987-
if (SwtTestUtil.fCheckSWTPolicy)
995+
if (SwtTestUtil.fCheckSWTPolicy) {
996+
String expected2 = "0" + delimiterString + "1" + "0" + delimiterString + "1";
997+
SwtTestUtil.processEvents(1000, () -> expected2.equals(text.getText()));
988998
assertEquals("0" + delimiterString + "1" + "0" + delimiterString + "1", text.getText());
999+
}
9891000
}
9901001

9911002
@Test

0 commit comments

Comments
 (0)