Skip to content

Commit ca2ecdb

Browse files
committed
Repair and execute disabled MigLayout tests
Replace platform-specific constants with fixed values.
1 parent ff0fa9c commit ca2ecdb

File tree

3 files changed

+37
-57
lines changed

3 files changed

+37
-57
lines changed

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/AbstractMigLayoutTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2024 Google, Inc.
2+
* Copyright (c) 2011, 2025 Google, Inc. and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -19,6 +19,10 @@
1919
import org.eclipse.wb.internal.swing.model.component.ComponentInfo;
2020
import org.eclipse.wb.tests.designer.swing.model.layout.AbstractLayoutTest;
2121

22+
import net.miginfocom.layout.PlatformDefaults;
23+
import net.miginfocom.layout.UnitValue;
24+
25+
import org.junit.jupiter.api.BeforeAll;
2226
import org.junit.jupiter.api.BeforeEach;
2327

2428
/**
@@ -43,6 +47,17 @@ static void do_configureNewProject() throws Exception {
4347
m_testProject.addPlugin("com.miglayout.swing");
4448
}
4549

50+
/**
51+
* Default values used on Windows. Should be used for all platforms to have
52+
* consistent test results.
53+
*/
54+
@BeforeAll
55+
public static void resetMigLayoutDefaults() {
56+
final UnitValue DEFAULT_GAP = new UnitValue(7.0f);
57+
PlatformDefaults.setPanelInsets(DEFAULT_GAP, DEFAULT_GAP, DEFAULT_GAP, DEFAULT_GAP);
58+
PlatformDefaults.setGridCellGap(DEFAULT_GAP, DEFAULT_GAP);
59+
}
60+
4661
@Override
4762
@BeforeEach
4863
public void setUp() throws Exception {

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutConverterTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011 Google, Inc.
2+
* Copyright (c) 2011, 2025 Google, Inc. and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -18,7 +18,6 @@
1818

1919
import net.miginfocom.swing.MigLayout;
2020

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

2423
import javax.swing.JTable;
@@ -388,7 +387,6 @@ public void test_oneRow_bottom() throws Exception {
388387
"}");
389388
}
390389

391-
@Disabled
392390
@Test
393391
public void test_oneRow_fill() throws Exception {
394392
ContainerInfo panel =
@@ -483,7 +481,6 @@ public void test_twoRows_spanColumns() throws Exception {
483481
"}");
484482
}
485483

486-
@Disabled
487484
@Test
488485
public void test_Switching_fromGridBagLayout() throws Exception {
489486
ContainerInfo panel =
@@ -544,7 +541,7 @@ public void test_Switching_fromGridBagLayout() throws Exception {
544541
assertEditor(
545542
"public class Test extends JPanel {",
546543
" public Test() {",
547-
" setLayout(new MigLayout('', '[46px][305px][5px][89px]', '[20px][20px][23px]'));",
544+
" setLayout(new MigLayout('', '[60px][275px][5px][105px]', '[26px][21px][27px]'));",
548545
" {",
549546
" JComboBox comboBox = new JComboBox();",
550547
" add(comboBox, 'cell 1 0,growx,aligny center');",

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/MigLayout/MigLayoutTest.java

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2024 Google, Inc. and others.
2+
* Copyright (c) 2011, 2025 Google, Inc. and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -25,9 +25,6 @@
2525
import org.eclipse.wb.internal.swing.model.CoordinateUtils;
2626
import org.eclipse.wb.internal.swing.model.component.ComponentInfo;
2727
import org.eclipse.wb.internal.swing.model.component.ContainerInfo;
28-
import org.eclipse.wb.tests.designer.Expectations;
29-
import org.eclipse.wb.tests.designer.Expectations.RectValue;
30-
import org.eclipse.wb.tests.designer.Expectations.StrValue;
3128
import org.eclipse.wb.tests.designer.core.annotations.DisposeProjectAfter;
3229

3330
import org.eclipse.draw2d.geometry.Interval;
@@ -42,10 +39,11 @@
4239
import net.miginfocom.swing.MigLayout;
4340

4441
import org.assertj.core.api.Assertions;
45-
import org.junit.jupiter.api.Disabled;
4642
import org.junit.jupiter.api.Test;
4743

44+
import java.awt.Toolkit;
4845
import java.util.List;
46+
import java.util.Locale;
4947

5048
import javax.swing.JButton;
5149

@@ -234,7 +232,6 @@ public void test_writeDimensions_LC() throws Exception {
234232
/**
235233
* Test for {@link IGridInfo}.
236234
*/
237-
@Disabled
238235
@Test
239236
public void test_IGridInfo() throws Exception {
240237
ContainerInfo panel =
@@ -258,21 +255,17 @@ public void test_IGridInfo() throws Exception {
258255
assertEquals(3, gridInfo.getColumnCount());
259256
Interval[] columnIntervals = gridInfo.getColumnIntervals();
260257
Assertions.assertThat(columnIntervals).hasSize(3);
261-
assertEquals("Interval(7, 100)", columnIntervals[0].toString());
262-
assertEquals("Interval(111, 150)", columnIntervals[1].toString());
263-
assertEquals("Interval(265, 50)", columnIntervals[2].toString());
258+
assertEquals("Interval[begin=7, length=100]", columnIntervals[0].toString());
259+
assertEquals("Interval[begin=114, length=150]", columnIntervals[1].toString());
260+
assertEquals("Interval[begin=271, length=50]", columnIntervals[2].toString());
264261
}
265262
// rows
266263
{
267264
assertEquals(2, gridInfo.getRowCount());
268265
Interval[] rowIntervals = gridInfo.getRowIntervals();
269266
Assertions.assertThat(rowIntervals).hasSize(2);
270-
assertEquals("Interval(7, 40)", rowIntervals[0].toString());
271-
assertEquals(
272-
Expectations.get("Interval(51, 23)", new StrValue[]{
273-
new StrValue("kosta-home", "Interval(51, 25)"),
274-
new StrValue("scheglov-win", "Interval(51, 23)")}),
275-
rowIntervals[1].toString());
267+
assertEquals("Interval[begin=7, length=40]", rowIntervals[0].toString());
268+
assertEquals("Interval[begin=54, length=27]", rowIntervals[1].toString());
276269
}
277270
// cells
278271
{
@@ -287,23 +280,12 @@ public void test_IGridInfo() throws Exception {
287280
}
288281
{
289282
Rectangle cells = new Rectangle(2, 0, 1, 1);
290-
Rectangle expected = new Rectangle(265, 7, 50 + 1, 40 + 1);
283+
Rectangle expected = new Rectangle(271, 7, 50 + 1, 40 + 1);
291284
assertEquals(expected, gridInfo.getCellsRectangle(cells));
292285
}
293286
{
294287
Rectangle cells = new Rectangle(0, 0, 2, 2);
295-
Rectangle expected =
296-
Expectations.get(
297-
new Rectangle(7, 7, 100 + 4 + 150 + 1, 40 + 4 + 23 + 1),
298-
new RectValue[]{
299-
new RectValue("kosta-home", new Rectangle(7,
300-
7,
301-
100 + 4 + 150 + 1,
302-
40 + 4 + 25 + 1)),
303-
new RectValue("scheglov-win", new Rectangle(7,
304-
7,
305-
100 + 4 + 150 + 1,
306-
40 + 4 + 23 + 1))});
288+
Rectangle expected = new Rectangle(7, 7, 100 + 150 + 7 + 1, 40 + 7 + 27 + 1);
307289
assertEquals(expected, gridInfo.getCellsRectangle(cells));
308290
}
309291
}
@@ -1341,7 +1323,6 @@ public void test_dimensionSize_setCheck() throws Exception {
13411323
/**
13421324
* Test for {@link MigDimensionInfo#toUnitString(int, String)}.
13431325
*/
1344-
@Disabled
13451326
@Test
13461327
public void test_dimensionSize_toUnitString() throws Exception {
13471328
ContainerInfo panel =
@@ -1353,37 +1334,24 @@ public void test_dimensionSize_toUnitString() throws Exception {
13531334
"}");
13541335
panel.refresh();
13551336
MigLayoutInfo layout = (MigLayoutInfo) panel.getLayout();
1337+
int dpi = Toolkit.getDefaultToolkit().getScreenResolution();
13561338
{
13571339
MigColumnInfo column = layout.getColumns().get(0);
1358-
assertEquals("2.65cm", column.toUnitString(100, "cm"));
1340+
assertEquals("%.2fcm".formatted((2.54 * 100 / dpi)), column.toUnitString(100, "cm"));
13591341
assertEquals("22.22%", column.toUnitString(100, "%"));
13601342
// check "sp" unit
1361-
String expected_sp;
1362-
int displayWidth = Display.getDefault().getBounds().width;
1363-
if (displayWidth == 1920) {
1364-
expected_sp = "5.21sp";
1365-
} else if (displayWidth == 1680) {
1366-
expected_sp = "5.95sp";
1367-
} else {
1368-
throw new AssertionError("Unknown display width: " + displayWidth);
1369-
}
1370-
assertEquals(expected_sp, column.toUnitString(100, "sp"));
1343+
int monitorWidth = Display.getCurrent().getPrimaryMonitor().getBounds().width;
1344+
assertEquals(String.format(Locale.ENGLISH, "%.2fsp", 100.0 * (100.0 / monitorWidth)),
1345+
column.toUnitString(100, "sp"));
13711346
}
13721347
{
13731348
MigRowInfo row = layout.getRows().get(0);
1374-
assertEquals("2.65cm", row.toUnitString(100, "cm"));
1349+
assertEquals("%.2fcm".formatted((2.54 * 100 / dpi)), row.toUnitString(100, "cm"));
13751350
assertEquals("33.33%", row.toUnitString(100, "%"));
13761351
// check "sp" unit
1377-
int displayHeight = Display.getDefault().getBounds().height;
1378-
String expected_sp;
1379-
if (displayHeight == 1200) {
1380-
expected_sp = "8.33sp";
1381-
} else if (displayHeight == 1050) {
1382-
expected_sp = "9.52sp";
1383-
} else {
1384-
throw new AssertionError("Unknown display width: " + displayHeight);
1385-
}
1386-
assertEquals(expected_sp, row.toUnitString(100, "sp"));
1352+
int monitorHeight = Display.getCurrent().getPrimaryMonitor().getBounds().height;
1353+
assertEquals(String.format(Locale.ENGLISH, "%.2fsp", 100.0 * (100.0 / monitorHeight)),
1354+
row.toUnitString(100, "sp"));
13871355
}
13881356
}
13891357

0 commit comments

Comments
 (0)