Skip to content

Commit 149d92c

Browse files
committed
Avoid reading org.eclipse.swt.* properties 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(). A similar problem exists for org.eclipse.swt.internal.gtk.version in relation to OS. 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.
1 parent 1460543 commit 149d92c

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,30 @@ 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
104-
&& "x11".equals(System.getProperty("org.eclipse.swt.internal.gdk.backend"));
105-
public final static boolean isGTK4 = isGTK
106-
&& System.getProperty("org.eclipse.swt.internal.gtk.version", "").startsWith("4");
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
110+
* access to SwtTestUtil, this "is..." is a method instead of a constant.
111+
*/
112+
public final static boolean isX11() {
113+
return isGTK && "x11".equals(System.getProperty("org.eclipse.swt.internal.gdk.backend"));
114+
}
115+
116+
/**
117+
* The value of org.eclipse.swt.internal.gtk.version is not set until after OS
118+
* is accessed for the first time. Normally tests are run in such an order that
119+
* SwtTestUtil isn't accessed until after the first time OS is used.
120+
*
121+
* Rather than requiring all users of SwtTestUtil to be careful with their
122+
* access to SwtTestUtil, this "is..." is a method instead of a constant.
123+
*/
124+
public final static boolean isGTK4() {
125+
return isGTK && System.getProperty("org.eclipse.swt.internal.gtk.version", "").startsWith("4");
126+
}
107127

108128
/**
109129
* The palette used by images. See {@link #getAllPixels(Image)} and {@link #createImage}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void setUp() {
8080
}
8181

8282
private void sleep() throws InterruptedException {
83-
if (SwtTestUtil.isGTK4) {
83+
if (SwtTestUtil.isGTK4()) {
8484
/**
8585
* TODO remove all uses of sleep and change them to processEvents with the
8686
* suitable conditional, or entirely remove them
@@ -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()) {
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()) {
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()) {
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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ public void test_getImeInputMode() {
460460
@Test
461461
public void test_getLocation() {
462462
//Setting location for Windows is not supported in GTK4
463-
if (SwtTestUtil.isGTK4) {
463+
if (SwtTestUtil.isGTK4()) {
464464
return;
465465
}
466466
shell.setLocation(10,15);
@@ -656,7 +656,7 @@ public void test_setBoundsLorg_eclipse_swt_graphics_Rectangle() {
656656
*/
657657
@Test
658658
public void test_activateEventSend() throws InterruptedException {
659-
assumeTrue((SwtTestUtil.isGTK && SwtTestUtil.isX11) || SwtTestUtil.isGTK4,
659+
assumeTrue((SwtTestUtil.isGTK && SwtTestUtil.isX11()) || SwtTestUtil.isGTK4(),
660660
"Feature only works on GTK3 in x11 or GTK4 - https://bugs.eclipse.org/436841");
661661

662662
AtomicBoolean activateCalled = new AtomicBoolean();
@@ -708,7 +708,7 @@ public void test_activateEventSend() throws InterruptedException {
708708
*/
709709
@Test
710710
public void test_setBounds() throws Exception {
711-
if (SwtTestUtil.isX11) {
711+
if (SwtTestUtil.isX11()) {
712712
Rectangle bounds = new Rectangle(100, 200, 200, 200);
713713
Rectangle bounds2 = new Rectangle(150, 250, 250, 250);
714714

@@ -1037,7 +1037,7 @@ public void test_Issue450_NoShellActivateOnSetFocus() {
10371037
@Override
10381038
public void test_setLocationLorg_eclipse_swt_graphics_Point() {
10391039
//Setting location for Windows is not supported in GTK4
1040-
if (SwtTestUtil.isGTK4) {
1040+
if (SwtTestUtil.isGTK4()) {
10411041
return;
10421042
}
10431043
super.test_setLocationLorg_eclipse_swt_graphics_Point();
@@ -1047,7 +1047,7 @@ public void test_setLocationLorg_eclipse_swt_graphics_Point() {
10471047
@Override
10481048
public void test_setLocationII() {
10491049
//Setting location for Windows is not supported in GTK4
1050-
if (SwtTestUtil.isGTK4) {
1050+
if (SwtTestUtil.isGTK4()) {
10511051
return;
10521052
}
10531053
super.test_setLocationII();

0 commit comments

Comments
 (0)