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 ;
4239import net .miginfocom .swing .MigLayout ;
4340
4441import org .assertj .core .api .Assertions ;
45- import org .junit .jupiter .api .Disabled ;
4642import org .junit .jupiter .api .Test ;
4743
44+ import java .awt .Toolkit ;
4845import java .util .List ;
46+ import java .util .Locale ;
4947
5048import 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 (String . format ( "%.2fcm" , Locale . ENGLISH , ( 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 (String . format ( "%.2fcm" , Locale . ENGLISH , ( 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