Hi,
I was looking over one of the failures for a jtreg test on openjdk and the
test case did not make sense to me, which led me to make changes to the test
case.
First of all, the test was in java/awt/GridLayout/LayoutExtraGaps.java. The
test currently under the openjdk I believe was trying to test whether a
GridLayout object centre its component properly (based on the message printed
by the exception). It tested that by checking if the origin coordinate of the
first component (each component is a rectangle, and there are 29 rectangles in
a panel and there are 4 panels in the main window) is (0,0). If both x and y
are 0 for any of the panels, then the test fails. I also think that the reason
why they chose (0,0) as the failing point because base on the values they
passed in, x and y cannot both be at (0,0). This is not valid because the error
that was output states, "Test failed. GridLayout doesn't center component.",
but the components are in fact centred, since all opposite boarders have equal
dimension.
When I looked at the gui generated, there are boarders between the
rectangles and its parent panel. And the boarder changes as the gui window
resizes (not sure if that is another problem in java or if it was intentional).
Not surprisingly, two of the panels were initialized such that there is no
boarder between itself and the rectangles, causing the test to fail. Which the
test should not have failed because everything was centred properly.
I created a fix to the test case (attached to this email) that checks if
the boarder at the right equals the boarder at the left, and if the boarder at
the top equals the boarder at the bottom. Instead of checking whether the
origin coordinate of the first component is (0,0).
Thanks for looking things over, and hope to hear from you soon.
Man Lung Wong--- openjdk/jdk/test/java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java.orig 2009-04-24 03:34:39.000000000 -0400
+++ openjdk/jdk/test/java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java 2009-06-15 17:20:08.000000000 -0400
@@ -24,7 +24,8 @@
/*
@test
@bug 4370316
- @summary GridLayout does not fill its Container
+ @summary GridLayout does not centre its component properly
+ @original summary GridLayout does not fill its Container
@library ../../regtesthelpers
@build Util
@author Andrei Dmitriev : area=awt.layout
@@ -90,27 +91,100 @@
setVisible(true);
Util.waitForIdle(Util.createRobot());
- Rectangle r1 = yellowPanel.getComponent(0).getBounds();
- Rectangle r2 = bluePanel.getComponent(0).getBounds();
- Rectangle r3 = blackPanel.getComponent(0).getBounds();
- Rectangle r4 = redPanel.getComponent(0).getBounds();
-
- System.out.println("firstHorizLabel bounds ="+r1);
- System.out.println("firstVertLabel bounds ="+r2);
- System.out.println("firstHorizLabel_RTL bounds ="+r3);
- System.out.println("firstVertLabel_RTL bounds ="+r4);
- if ((r1.getX() == 0 && r1.getY() == 0) ||
- (r2.getX() == 0 && r2.getY() == 0) ||
- (r3.getX() == 0 && r3.getY() == 0) ||
- // RTL only affects horizontal positioning and components lays out from top right corner
- (r4.getX() == blackPanel.getWidth() && r4.getY() == 0))
+
+ if (isComponentCentredLTR(yellowPanel) && isComponentCentredLTR(bluePanel)
+ && isComponentCentredLTR(blackPanel) && isComponentCentredRTL(redPanel))
{
- throw new RuntimeException("Test failed. GridLayout doesn't center component.");
- } else {
System.out.println("Test passed.");
+
+ } else {
+ throw new RuntimeException("Test failed. GridLayout doesn't center component.");
}
}
+ /**
+ * Checks if the components under Panel p are properly centred (i.e.
+ * opposite boarders between the Panel and component are equal). Panel p
+ * must not be affect by RTL orientation (RTL only affects horizontal
+ * positioning and components lay out from top right corner).
+ *
+ * @param p the panel where the components exist and is not affected
+ * by right to left orientation
+ * @return true if components of panel p are properly centre, false
+ * otherwise
+ */
+ public static boolean isComponentCentredLTR(Panel p) {
+ double boarderLeft;
+ double boarderRight;
+ double boarderTop;
+ double boarderBottom;
+
+ //The first component(rectangle) in panel p.
+ Rectangle firstRec = p.getComponent(0).getBounds();
+
+ //The last component(rectangle) in panel p.
+ Rectangle lastRec = p.getComponent(compCount - 1).getBounds();
+
+ System.out.println("bounds of the first rectangle in "+ p.getName() + " = " + firstRec);
+ System.out.println("bounds of the last rectangle in "+ p.getName() + " = " + lastRec);
+
+ boarderLeft = firstRec.getX();
+ boarderRight = p.getWidth() - lastRec.getWidth() - lastRec.getX();
+ boarderTop = firstRec.getY();
+ boarderBottom = p.getHeight() - lastRec.getHeight() - lastRec.getY();
+
+ return areBoardersEqual(boarderLeft, boarderRight) &&
+ areBoardersEqual(boarderTop, boarderBottom);
+ }
+
+ /**
+ * Checks if the components under Panel p are properly centred (i.e.
+ * opposite boarders between the Panel and component are equal). Panel p
+ * must be affect by RTL orientation (RTL only affects horizontal positioning
+ * and components lay out from top right corner).
+ *
+ * @param p the panel where the components exist and is affected by
+ * right to left orientation
+ * @return true if components of panel p are properly centre, false
+ * otherwise
+ */
+ public static boolean isComponentCentredRTL(Panel p) {
+ double boarderLeft;
+ double boarderRight;
+ double boarderTop;
+ double boarderBottom;
+
+ //The first component(rectangle) in panel p.
+ Rectangle firstRec = p.getComponent(0).getBounds();
+
+ //The last component(rectangle) in panel p.
+ Rectangle lastRec = p.getComponent(compCount - 1).getBounds();
+
+ System.out.println("bounds of the first rectangle in "+ p.getName() + " = " + firstRec);
+ System.out.println("bounds of the last rectangle in "+ p.getName() + " = " + lastRec);
+
+ boarderLeft = lastRec.getX();
+ boarderRight = p.getWidth() - firstRec.getWidth() - firstRec.getX();
+ boarderTop = lastRec.getY();
+ boarderBottom = p.getHeight() - firstRec.getHeight() - firstRec.getY();
+
+ return areBoardersEqual(boarderLeft, boarderRight) &&
+ areBoardersEqual(boarderTop, boarderBottom);
+ }
+
+ /**
+ * Given two boarders boarder1 and boarder2 check if they are equal.
+ *
+ * @param boarder1 one of the boarders being compared
+ * @param borader2 the other boarder being compared
+ * @return true if boarder1 and boarder2 are equal to each other (i.e.
+ * their width/height difference is at most 1, assuming the
+ * smallest pixel is of size 1), false otherwise
+ */
+ public static boolean areBoardersEqual(double boarder1, double boarder2) {
+ return Math.abs(boarder1 - boarder2) <= 1;
+ }
+
public static void main(String[] args) {
new LayoutExtraGaps();
}