Skip to content

Commit ef79e89

Browse files
committed
Repair and execute Swing FormLayout tests
These tests were disabled with 2f300b9 and have been adapted to be platform-independent by e.g. using a fixed font or fixed sizes of the Swing components. Additional note: `test_oneRow` was wrongfully adapted with ddb982e, which has been reverted as well.
1 parent 3bed6e1 commit ef79e89

6 files changed

Lines changed: 46 additions & 22 deletions

File tree

org.eclipse.wb.tests/META-INF/MANIFEST.MF

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ Export-Package: org.eclipse.wb.tests.designer;x-internal:=true,
150150
org.eclipse.wb.tests.utils;x-internal:=true
151151
Import-Package: com.jgoodies.forms.factories;version="[1.9.0,2.0.0]",
152152
com.jgoodies.forms.layout;version="[1.9.0,2.0.0]",
153+
com.jgoodies.forms.util;version="[1.9.0,2.0.0)",
153154
net.miginfocom.layout;version="[11.3.0,12.0.0]",
154155
net.miginfocom.swing;version="[11.3.0,12.0.0]",
155156
org.apache.commons.collections4;version="[4.4.0,5.0.0)",

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/FormLayout/DefaultComponentFactoryTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.jgoodies.forms.factories.DefaultComponentFactory;
3030

3131
import org.assertj.core.api.Assertions;
32-
import org.junit.jupiter.api.Disabled;
3332
import org.junit.jupiter.api.Test;
3433

3534
/**
@@ -108,7 +107,6 @@ public Test() {
108107
* Test for {@link DefaultComponentFactoryCreateLabelEntryInfo}.
109108
*/
110109
@DisposeProjectAfter
111-
@Disabled
112110
@Test
113111
public void test_createLabel_tool() throws Exception {
114112
do_projectDispose();
@@ -140,7 +138,7 @@ public Test() {
140138
Image image = newComponent.getImage();
141139
assertNotNull(image);
142140
org.eclipse.swt.graphics.Rectangle bounds = image.getBounds();
143-
Assertions.assertThat(bounds.width).isGreaterThan(50).isLessThan(100);
141+
Assertions.assertThat(bounds.width).isGreaterThan(50).isLessThan(150);
144142
Assertions.assertThat(bounds.height).isGreaterThan(10).isLessThan(20);
145143
image.dispose();
146144
}

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/FormLayout/FormDimensionInfoTest.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.jgoodies.forms.layout.Size;
2525
import com.jgoodies.forms.layout.Sizes;
2626

27-
import org.junit.jupiter.api.Disabled;
2827
import org.junit.jupiter.api.Test;
2928

3029
import java.lang.reflect.Method;
@@ -264,22 +263,17 @@ public void test_rowTemplates() throws Exception {
264263
// Convert to GAP template
265264
//
266265
////////////////////////////////////////////////////////////////////////////
267-
@Disabled
268266
@Test
269267
public void test_convertToNearestGap_columns() throws Exception {
270268
check_convertToNearestGap_column("4px", 5, "LABEL_COMPONENT_GAP_COLSPEC");
271269
check_convertToNearestGap_column("3px", 0, null);
272270
check_convertToNearestGap_column("5px", 1, "LABEL_COMPONENT_GAP_COLSPEC");
273-
{
274-
String desc = "8px";
275-
check_convertToNearestGap_column(desc, 10, "RELATED_GAP_COLSPEC");
276-
}
271+
check_convertToNearestGap_column("8px", 10, "RELATED_GAP_COLSPEC");
277272
check_convertToNearestGap_column("12px", 10, "UNRELATED_GAP_COLSPEC");
278273
check_convertToNearestGap_column("20px", 10, "UNRELATED_GAP_COLSPEC");
279274
check_convertToNearestGap_column("20px", 5, null);
280275
}
281276

282-
@Disabled
283277
@Test
284278
public void test_convertToNearestGap_rows() throws Exception {
285279
check_convertToNearestGap_row("4px", 5, "LABEL_COMPONENT_GAP_ROWSPEC");

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/FormLayout/FormLayoutConverterTest.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import com.jgoodies.forms.layout.FormLayout;
2020

21-
import org.junit.jupiter.api.Disabled;
2221
import org.junit.jupiter.api.Test;
2322

2423
/**
@@ -59,7 +58,6 @@ public Test() {
5958
}""");
6059
}
6160

62-
@Disabled
6361
@Test
6462
public void test_oneRow() throws Exception {
6563
ContainerInfo panel = parseContainer("""
@@ -94,7 +92,7 @@ public Test() {
9492
setLayout(new FormLayout(new ColumnSpec[] {
9593
FormSpecs.LABEL_COMPONENT_GAP_COLSPEC,
9694
ColumnSpec.decode("100px"),
97-
ColumnSpec.decode("16px"),
95+
FormSpecs.UNRELATED_GAP_COLSPEC,
9896
ColumnSpec.decode("80px"),},
9997
new RowSpec[] {
10098
FormSpecs.UNRELATED_GAP_ROWSPEC,
@@ -116,7 +114,6 @@ public Test() {
116114
}
117115
}
118116

119-
@Disabled
120117
@Test
121118
public void test_twoRows_spanColumns() throws Exception {
122119
ContainerInfo panel = parseContainer("""
@@ -178,7 +175,6 @@ public Test() {
178175
}""");
179176
}
180177

181-
@Disabled
182178
@Test
183179
public void test_Switching_fromGridBagLayout() throws Exception {
184180
ContainerInfo panel = parseContainer("""
@@ -192,6 +188,7 @@ public Test() {
192188
setLayout(gridBagLayout);
193189
{
194190
JComboBox comboBox = new JComboBox();
191+
comboBox.setPreferredSize(new Dimension(216, 20));
195192
GridBagConstraints gbc = new GridBagConstraints();
196193
gbc.insets = new Insets(0, 0, 5, 5);
197194
gbc.fill = GridBagConstraints.HORIZONTAL;
@@ -201,6 +198,7 @@ public Test() {
201198
}
202199
{
203200
JLabel label = new JLabel("New label");
201+
label.setPreferredSize(new Dimension(46, 20));
204202
GridBagConstraints gbc = new GridBagConstraints();
205203
gbc.insets = new Insets(0, 0, 5, 5);
206204
gbc.anchor = GridBagConstraints.EAST;
@@ -210,6 +208,7 @@ public Test() {
210208
}
211209
{
212210
JTextField textField = new JTextField();
211+
textField.setPreferredSize(new Dimension(216, 20));
213212
GridBagConstraints gbc = new GridBagConstraints();
214213
gbc.gridwidth = 2;
215214
gbc.insets = new Insets(0, 0, 5, 5);
@@ -221,6 +220,7 @@ public Test() {
221220
}
222221
{
223222
JButton button = new JButton("New button");
223+
button.setPreferredSize(new Dimension(89, 23));
224224
GridBagConstraints gbc = new GridBagConstraints();
225225
gbc.gridx = 2;
226226
gbc.gridy = 2;
@@ -252,19 +252,23 @@ public Test() {
252252
RowSpec.decode("23px"),}));
253253
{
254254
JComboBox comboBox = new JComboBox();
255+
comboBox.setPreferredSize(new Dimension(216, 20));
255256
add(comboBox, "3, 1, fill, center");
256257
}
257258
{
258259
JLabel label = new JLabel("New label");
260+
label.setPreferredSize(new Dimension(46, 20));
259261
add(label, "1, 3, right, center");
260262
}
261263
{
262264
JTextField textField = new JTextField();
265+
textField.setPreferredSize(new Dimension(216, 20));
263266
add(textField, "3, 3, 3, 1, fill, center");
264267
textField.setColumns(10);
265268
}
266269
{
267270
JButton button = new JButton("New button");
271+
button.setPreferredSize(new Dimension(89, 23));
268272
add(button, "5, 5, center, center");
269273
}
270274
}

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/FormLayout/FormLayoutGefTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,6 @@ public Test() {
861861
{
862862
ComponentInfo button_2 = getJavaInfoByName("button_2");
863863
canvas.target(button_2).inX(0.5).outY(ROW_GAP + 1).move();
864-
waitEventLoop(1000 * 5);
865864
canvas.assertCommandNull();
866865
}
867866
}

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/FormLayout/FormSizeInfoTest.java

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*******************************************************************************/
1313
package org.eclipse.wb.tests.designer.swing.model.layout.FormLayout;
1414

15+
import org.eclipse.wb.internal.core.utils.reflect.ReflectionUtils;
1516
import org.eclipse.wb.internal.swing.FormLayout.model.FormSizeConstantInfo;
1617
import org.eclipse.wb.internal.swing.FormLayout.model.FormSizeInfo;
1718
import org.eclipse.wb.internal.swing.laf.LafSupport;
@@ -21,11 +22,17 @@
2122
import com.jgoodies.forms.layout.ConstantSize.Unit;
2223
import com.jgoodies.forms.layout.Size;
2324
import com.jgoodies.forms.layout.Sizes;
25+
import com.jgoodies.forms.util.DefaultUnitConverter;
2426

27+
import org.junit.jupiter.api.AfterAll;
28+
import org.junit.jupiter.api.BeforeAll;
2529
import org.junit.jupiter.api.BeforeEach;
26-
import org.junit.jupiter.api.Disabled;
2730
import org.junit.jupiter.api.Test;
2831

32+
import java.awt.Font;
33+
34+
import javax.swing.JFrame;
35+
2936
/**
3037
* Test for {@link FormSizeInfo}.
3138
*
@@ -44,6 +51,30 @@ public void setUp() throws Exception {
4451
LafSupport.applySelectedLAF(LafSupport.getDefaultLAF());
4552
}
4653

54+
private static Font defaultFont;
55+
private static JFrame toolkitComponent;
56+
private static int defaultScreenResolution;
57+
58+
@BeforeAll
59+
public static void setUpJGoodies() {
60+
defaultFont = DefaultUnitConverter.getInstance().getDefaultDialogFont();
61+
DefaultUnitConverter.getInstance().setDefaultDialogFont(new Font("Tahoma", Font.PLAIN, 10));
62+
63+
// Make sure all tests are executed as if at 96DPI
64+
defaultScreenResolution = ReflectionUtils.getFieldInt(DefaultUnitConverter.class, "defaultScreenResolution");
65+
ReflectionUtils.setField(DefaultUnitConverter.class, "defaultScreenResolution", 96);
66+
67+
toolkitComponent = (JFrame) ReflectionUtils.getFieldObject(FormSizeConstantInfo.class, "m_toolkitComponent");
68+
ReflectionUtils.setField(FormSizeConstantInfo.class, "m_toolkitComponent", null);
69+
}
70+
71+
@AfterAll
72+
public static void tearDownJGoodies() {
73+
DefaultUnitConverter.getInstance().setDefaultDialogFont(defaultFont);
74+
ReflectionUtils.setField(DefaultUnitConverter.class, "defaultScreenResolution", defaultScreenResolution);
75+
ReflectionUtils.setField(FormSizeConstantInfo.class, "m_toolkitComponent", toolkitComponent);
76+
}
77+
4778
////////////////////////////////////////////////////////////////////////////
4879
//
4980
// Exit zone :-) XXX
@@ -61,7 +92,6 @@ public void _test_exit() throws Exception {
6192
/**
6293
* Test for {@link FormSizeConstantInfo}.
6394
*/
64-
@Disabled
6595
@Test
6696
public void test_FormSizeConstantInfo() throws Exception {
6797
FormSizeConstantInfo size = new FormSizeConstantInfo(25, ConstantSize.PIXEL);
@@ -131,19 +161,18 @@ public void test_FormSizeConstantInfo_convertSpecial() throws Exception {
131161
/**
132162
* Test for {@link FormSizeConstantInfo#convertFromPixels(int, Unit)}
133163
*/
134-
@Disabled
135164
@Test
136165
public void test_FormSizeConstantInfo_convertFromPixels() throws Exception {
137166
{
138167
double expected = 50.0;
139168
check_convertFromPixels(50, ConstantSize.PIXEL, expected);
140169
}
141170
{
142-
double expected = 39.0;
171+
double expected = 38.0;
143172
check_convertFromPixels(50, ConstantSize.POINT, expected);
144173
}
145174
{
146-
double expected = 34.0;
175+
double expected = 35.0;
147176
check_convertFromPixels(50, ConstantSize.DIALOG_UNITS_X, expected);
148177
}
149178
{
@@ -171,7 +200,6 @@ private void check_convertFromPixels(int pixels, Unit unit, double expected) thr
171200
/**
172201
* Test for {@link FormSizeConstantInfo#convertToPixels(double, Unit)}
173202
*/
174-
@Disabled
175203
@Test
176204
public void test_FormSizeConstantInfo_convertToPixels() throws Exception {
177205
{

0 commit comments

Comments
 (0)