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
2525import org .eclipse .wb .internal .swing .model .CoordinateUtils ;
2626import org .eclipse .wb .internal .swing .model .component .ComponentInfo ;
2727import 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 ;
3128import org .eclipse .wb .tests .designer .core .annotations .DisposeProjectAfter ;
3229
3330import org .eclipse .draw2d .geometry .Interval ;
3936import org .eclipse .swt .widgets .Display ;
4037
4138import net .miginfocom .layout .LC ;
39+ import net .miginfocom .layout .PlatformDefaults ;
40+ import net .miginfocom .layout .UnitValue ;
4241import net .miginfocom .swing .MigLayout ;
4342
4443import org .assertj .core .api .Assertions ;
45- import org .junit .jupiter .api .Disabled ;
44+ import org .junit .jupiter .api .BeforeAll ;
4645import org .junit .jupiter .api .Test ;
4746
4847import java .util .List ;
48+ import java .util .Locale ;
4949
5050import 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