Skip to content

Commit ffba498

Browse files
committed
Avoid reading org.eclipse.swt.internal.gdk.backend too early
The value of org.eclipse.swt.internal.gdk.backend is not set until a display is created at least once since this value is assigned in the Display constructor. Normally tests are run in such an order that SwtTestUtil isn't accessed until after the first Display is created. Make sure to create a display before calling SwtTestUtil.isX11.getAsBoolean(). This is a fix for a regression caused by moving the setting of org.eclipse.swt.internal.gdk.backend from OS to Display in 5d67ce6. That commit fixed an unrelated bug, but sometimes bad initialization of isX11 is an unintended side effect causing tests to be skipped or run in unexpected ways since isX11 was not correct. Signed-off-by: Jonah Graham <[email protected]>
1 parent 7bff548 commit ffba498

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,16 @@ public class SwtTestUtil {
100100
/** Useful if you want some tests not to run on Jenkins with user "genie.platform" */
101101
public final static boolean isRunningOnContinousIntegration = isGTK && ("genie.platform".equalsIgnoreCase(System.getProperty("user.name")));
102102

103-
public final static boolean isX11 = isGTK
103+
/**
104+
* The value of org.eclipse.swt.internal.gdk.backend is not set until a display
105+
* is created at least once since this value is assigned in the Display
106+
* constructor. Normally tests are run in such an order that SwtTestUtil isn't
107+
* accessed until after the first Display is created.
108+
*
109+
* Rather than requiring all users of SwtTestUtil to be careful with their access,
110+
* instead defer checking x11 by using a supplier to defer getting the value.
111+
*/
112+
public final static BooleanSupplier isX11 = () -> isGTK
104113
&& "x11".equals(System.getProperty("org.eclipse.swt.internal.gdk.backend"));
105114
public final static boolean isGTK4 = isGTK
106115
&& System.getProperty("org.eclipse.swt.internal.gtk.version", "").startsWith("4");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ public void test_setContents() throws Exception {
351351
String result = runOperationInThread(remote::getStringContents);
352352
assertEquals(helloWorld, result);
353353
} catch (Exception | AssertionError e) {
354-
if (SwtTestUtil.isGTK4 && !SwtTestUtil.isX11) {
354+
if (SwtTestUtil.isGTK4 && !SwtTestUtil.isX11.getAsBoolean()) {
355355
// TODO make the code + test stable
356356
throw new RuntimeException(
357357
"This test is really unstable on wayland backend, at least with Ubuntu 25.04", e);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ public void test_setCursorLocationII(TestInfo info) {
12471247
display.setCursorLocation(location.x, location.y); // don't put cursor into a corner, since that could trigger special platform events
12481248
drainEventQueue(display, 150); // workaround for https://bugs.eclipse.org/492569
12491249
Point actual = display.getCursorLocation();
1250-
if (!BUG_492569 && SwtTestUtil.isX11) {
1250+
if (!BUG_492569 && SwtTestUtil.isX11.getAsBoolean()) {
12511251
if (!location.equals(actual)) {
12521252
Screenshots.takeScreenshot(getClass(), info.getDisplayName()); // Bug 528968 This call causes crash on Wayland.
12531253
fail("\nExpected:"+location.toString()+" Actual:"+actual.toString());
@@ -1279,7 +1279,7 @@ public void test_setCursorLocationLorg_eclipse_swt_graphics_Point(TestInfo info)
12791279
}
12801280
drainEventQueue(display, 150); // workaround for https://bugs.eclipse.org/492569
12811281
Point actual = display.getCursorLocation();
1282-
if (!BUG_492569 && SwtTestUtil.isX11) {
1282+
if (!BUG_492569 && SwtTestUtil.isX11.getAsBoolean()) {
12831283
if (!location.equals(actual)) {
12841284
Screenshots.takeScreenshot(getClass(), info.getDisplayName()); // Bug 528968 This call causes crash on Wayland.
12851285
fail("\nExpected:"+location.toString()+" Actual:"+actual.toString());

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ public void test_setBoundsLorg_eclipse_swt_graphics_Rectangle() {
655655
*/
656656
@RepeatedTest(value = 1000)
657657
public void test_activateEventSend() throws InterruptedException {
658-
if (SwtTestUtil.isGTK && SwtTestUtil.isX11) {
658+
if (SwtTestUtil.isGTK && SwtTestUtil.isX11.getAsBoolean()) {
659659
Shell testShell = new Shell(shell, SWT.SHELL_TRIM);
660660
testShell.addListener(SWT.Activate, e -> {
661661
listenerCalled = true;
@@ -681,7 +681,7 @@ public void test_activateEventSend() throws InterruptedException {
681681
*/
682682
@Test
683683
public void test_setBounds() throws Exception {
684-
if (SwtTestUtil.isX11) {
684+
if (SwtTestUtil.isX11.getAsBoolean()) {
685685
Rectangle bounds = new Rectangle(100, 200, 200, 200);
686686
Rectangle bounds2 = new Rectangle(150, 250, 250, 250);
687687

0 commit comments

Comments
 (0)