Skip to content

Commit 84cee66

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

File tree

2 files changed

+40
-55
lines changed

2 files changed

+40
-55
lines changed

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

Lines changed: 13 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
@@ -16,9 +16,11 @@
1616
import org.eclipse.wb.internal.swing.MigLayout.model.MigLayoutInfo;
1717
import org.eclipse.wb.internal.swing.model.component.ContainerInfo;
1818

19+
import net.miginfocom.layout.PlatformDefaults;
20+
import net.miginfocom.layout.UnitValue;
1921
import net.miginfocom.swing.MigLayout;
2022

21-
import org.junit.jupiter.api.Disabled;
23+
import org.junit.jupiter.api.BeforeAll;
2224
import org.junit.jupiter.api.Test;
2325

2426
import javax.swing.JTable;
@@ -38,6 +40,14 @@ public void _test_exit() throws Exception {
3840
System.exit(0);
3941
}
4042

43+
@BeforeAll
44+
public static void resetMigLayoutDefaults() {
45+
final UnitValue zeroValue = new UnitValue(0.0f);
46+
PlatformDefaults.setPanelInsets(zeroValue, zeroValue, zeroValue, zeroValue);
47+
PlatformDefaults.setGridCellGap(zeroValue, zeroValue);
48+
PlatformDefaults.setDefaultDPI(96);
49+
}
50+
4151
////////////////////////////////////////////////////////////////////////////
4252
//
4353
// Tests
@@ -388,7 +398,6 @@ public void test_oneRow_bottom() throws Exception {
388398
"}");
389399
}
390400

391-
@Disabled
392401
@Test
393402
public void test_oneRow_fill() throws Exception {
394403
ContainerInfo panel =
@@ -483,7 +492,6 @@ public void test_twoRows_spanColumns() throws Exception {
483492
"}");
484493
}
485494

486-
@Disabled
487495
@Test
488496
public void test_Switching_fromGridBagLayout() throws Exception {
489497
ContainerInfo panel =
@@ -544,7 +552,7 @@ public void test_Switching_fromGridBagLayout() throws Exception {
544552
assertEditor(
545553
"public class Test extends JPanel {",
546554
" public Test() {",
547-
" setLayout(new MigLayout('', '[46px][305px][5px][89px]', '[20px][20px][23px]'));",
555+
" setLayout(new MigLayout('', '[60px][275px][5px][105px]', '[26px][21px][27px]'));",
548556
" {",
549557
" JComboBox comboBox = new JComboBox();",
550558
" 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: 27 additions & 50 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;
@@ -39,13 +36,16 @@
3936
import org.eclipse.swt.widgets.Display;
4037

4138
import net.miginfocom.layout.LC;
39+
import net.miginfocom.layout.PlatformDefaults;
40+
import net.miginfocom.layout.UnitValue;
4241
import net.miginfocom.swing.MigLayout;
4342

4443
import org.assertj.core.api.Assertions;
45-
import org.junit.jupiter.api.Disabled;
44+
import org.junit.jupiter.api.BeforeAll;
4645
import org.junit.jupiter.api.Test;
4746

4847
import java.util.List;
48+
import java.util.Locale;
4949

5050
import javax.swing.JButton;
5151

@@ -64,6 +64,14 @@ public void _test_exit() throws Exception {
6464
System.exit(0);
6565
}
6666

67+
@BeforeAll
68+
public static void resetMigLayoutDefaults() {
69+
final UnitValue zeroValue = new UnitValue(0.0f);
70+
PlatformDefaults.setPanelInsets(zeroValue, zeroValue, zeroValue, zeroValue);
71+
PlatformDefaults.setGridCellGap(zeroValue, zeroValue);
72+
PlatformDefaults.setDefaultDPI(96);
73+
}
74+
6775
////////////////////////////////////////////////////////////////////////////
6876
//
6977
// Activator
@@ -234,7 +242,6 @@ public void test_writeDimensions_LC() throws Exception {
234242
/**
235243
* Test for {@link IGridInfo}.
236244
*/
237-
@Disabled
238245
@Test
239246
public void test_IGridInfo() throws Exception {
240247
ContainerInfo panel =
@@ -258,21 +265,17 @@ public void test_IGridInfo() throws Exception {
258265
assertEquals(3, gridInfo.getColumnCount());
259266
Interval[] columnIntervals = gridInfo.getColumnIntervals();
260267
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());
268+
assertEquals("Interval[begin=0, length=100]", columnIntervals[0].toString());
269+
assertEquals("Interval[begin=100, length=150]", columnIntervals[1].toString());
270+
assertEquals("Interval[begin=250, length=50]", columnIntervals[2].toString());
264271
}
265272
// rows
266273
{
267274
assertEquals(2, gridInfo.getRowCount());
268275
Interval[] rowIntervals = gridInfo.getRowIntervals();
269276
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());
277+
assertEquals("Interval[begin=0, length=40]", rowIntervals[0].toString());
278+
assertEquals("Interval[begin=40, length=27]", rowIntervals[1].toString());
276279
}
277280
// cells
278281
{
@@ -282,28 +285,17 @@ public void test_IGridInfo() throws Exception {
282285
//
283286
{
284287
Rectangle cells = new Rectangle(0, 0, 1, 1);
285-
Rectangle expected = new Rectangle(7, 7, 100 + 1, 40 + 1);
288+
Rectangle expected = new Rectangle(0, 0, 100 + 1, 40 + 1);
286289
assertEquals(expected, gridInfo.getCellsRectangle(cells));
287290
}
288291
{
289292
Rectangle cells = new Rectangle(2, 0, 1, 1);
290-
Rectangle expected = new Rectangle(265, 7, 50 + 1, 40 + 1);
293+
Rectangle expected = new Rectangle(250, 0, 50 + 1, 40 + 1);
291294
assertEquals(expected, gridInfo.getCellsRectangle(cells));
292295
}
293296
{
294297
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))});
298+
Rectangle expected = new Rectangle(0, 0, 100 + 150 + 1, 40 + 27 + 1);
307299
assertEquals(expected, gridInfo.getCellsRectangle(cells));
308300
}
309301
}
@@ -1341,7 +1333,6 @@ public void test_dimensionSize_setCheck() throws Exception {
13411333
/**
13421334
* Test for {@link MigDimensionInfo#toUnitString(int, String)}.
13431335
*/
1344-
@Disabled
13451336
@Test
13461337
public void test_dimensionSize_toUnitString() throws Exception {
13471338
ContainerInfo panel =
@@ -1358,32 +1349,18 @@ public void test_dimensionSize_toUnitString() throws Exception {
13581349
assertEquals("2.65cm", column.toUnitString(100, "cm"));
13591350
assertEquals("22.22%", column.toUnitString(100, "%"));
13601351
// 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"));
1352+
int monitorWidth = Display.getCurrent().getPrimaryMonitor().getBounds().width;
1353+
assertEquals(String.format(Locale.ENGLISH, "%.2fsp", 100.0 * (100.0 / monitorWidth)),
1354+
column.toUnitString(100, "sp"));
13711355
}
13721356
{
13731357
MigRowInfo row = layout.getRows().get(0);
13741358
assertEquals("2.65cm", row.toUnitString(100, "cm"));
13751359
assertEquals("33.33%", row.toUnitString(100, "%"));
13761360
// 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"));
1361+
int monitorHeight = Display.getCurrent().getPrimaryMonitor().getBounds().height;
1362+
assertEquals(String.format(Locale.ENGLISH, "%.2fsp", 100.0 * (100.0 / monitorHeight)),
1363+
row.toUnitString(100, "sp"));
13871364
}
13881365
}
13891366

0 commit comments

Comments
 (0)