Skip to content

Commit 3aadcfd

Browse files
committed
Spin event loop to process pending UI updates before checking the pasted
content on the Text. As content copy/paste works well manually junit fails because junit checks the text content well before it is updated by GTK. So it is a timing delay. Processing all the pending events make sure text is updated(Either by introducing some delay in junit or really processing any pending UI updates). see #2491
1 parent c6a29a9 commit 3aadcfd

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,12 @@ Rectangle computeTrimInPixels (int x, int y, int width, int height) {
739739
* <p>
740740
* The current selection is copied to the clipboard.
741741
* </p>
742-
*
742+
* <p>
743+
* <strong>Note:</strong> Copy data to the Clipboard may be asynchronous. This
744+
* means that the new clipboard content may not be immediately available right
745+
* after calling this method. To ensure the update is visible, use
746+
* {@link Display#asyncExec(Runnable)} before accessing the clipboard data.
747+
* </p>
743748
* @exception SWTException <ul>
744749
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
745750
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ public void test_copy() {
288288

289289
text.setText("");
290290
text.paste();
291+
// Spin the event loop to let GTK process the clipboard + entry update
292+
Display display = text.getDisplay();
293+
while (display.readAndDispatch()) {
294+
// loop until no more events
295+
}
291296
assertEquals("00000", text.getText());
292297

293298
// tests a SINGLE line text editor
@@ -307,6 +312,9 @@ public void test_copy() {
307312

308313
text.setText("");
309314
text.paste();
315+
while (display.readAndDispatch()) {
316+
// loop until no more events
317+
}
310318
assertEquals("00000", text.getText());
311319
}
312320

0 commit comments

Comments
 (0)