Skip to content

Commit

Permalink
8284619: javax/swing/JTable/8236907/LastVisibleRow.java failed with "…
Browse files Browse the repository at this point in the history
…Test Case Failed!!, Last Row not Visible!!!"

Reviewed-by: psadhukhan, honkar
  • Loading branch information
Tejesh R authored and prsadhuk committed Jun 16, 2022
1 parent a179590 commit 39526e2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 52 deletions.
1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,6 @@ javax/swing/JFrame/8175301/ScaledFrameBackgroundTest.java 8274106 macosx-aarch64

sanity/client/SwingSet/src/ToolTipDemoTest.java 8225012 windows-all,macosx-all
sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java 8265770 macosx-all
javax/swing/JTable/8236907/LastVisibleRow.java 8284619 macosx-all

############################################################################

Expand Down
73 changes: 22 additions & 51 deletions test/jdk/javax/swing/JTable/8236907/LastVisibleRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ public static void main(String[] args) throws Exception {
Point clkPoint;
try {
testRobot = new Robot();

SwingUtilities.invokeAndWait(new Runnable() {

public void run() {
createAndShowGUI();
}
Expand All @@ -75,38 +73,32 @@ public void run() {
mouseEvents(clkPoint);
testRobot.waitForIdle();
clearSelect();
testRobot.delay(1000);
testRobot.waitForIdle();
BufferedImage bufferedImageAfter = testRobot.createScreenCapture(getCaptureRect());

testRobot.delay(1000);

if (!compare(bufferedImageBefore, bufferedImageAfter)) {
ImageIO.write(bufferedImageBefore, "png", new File("bufferedImageBefore.png"));
ImageIO.write(bufferedImageAfter, "png", new File("bufferedImageAfter.png"));
ImageIO.write(bufferedImageBefore, "png",
new File("bufferedImageBefore.png"));
ImageIO.write(bufferedImageAfter, "png",
new File("bufferedImageAfter.png"));
throw new RuntimeException("Test Case Failed!!, Last Row not Visible!!!");
}
} finally {
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
}
}

/*
*
* Get clickable screen point for particular row and column of a table
* param row Row Number
* param column Column Number
* return Point
*/
// Get clickable screen point for particular row and column of a table
private static Point getCellClickPoint(final int row, final int column) {
Point result;

Rectangle rect = table.getCellRect(row, column, false);
Point point = new Point(rect.x + rect.width / 2,
Point clickPoint = new Point(rect.x + rect.width / 2,
rect.y + rect.height / 2);
SwingUtilities.convertPointToScreen(point, table);
result = point;
SwingUtilities.convertPointToScreen(clickPoint, table);

return result;
return clickPoint;
}

private static void createAndShowGUI() {
Expand All @@ -119,7 +111,10 @@ private static void createAndShowGUI() {
centerPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
JPanel tablePaneContainer = new JPanel(new BorderLayout());
JPanel tablePane = new JPanel(new BorderLayout());
table = new JTable(new Object[][]{{"row_1_col_1", "row_1_col_2", "row_1_col_3"}, {"row_2_col_1", "row_2_col_2", "row_2_col_3"}, {"row_3_col_1", "row_3_col_2", "row_3_col_3"}, {"row_4_col_1", "row_4_col_2", "row_4_col_3"}}, new String[]{"Col1", "Col2", "Col3"});
table = new JTable(new Object[][]{{"row_1_col_1", "row_1_col_2", "row_1_col_3"},
{"row_2_col_1", "row_2_col_2", "row_2_col_3"}, {"row_3_col_1", "row_3_col_2",
"row_3_col_3"}, {"row_4_col_1", "row_4_col_2", "row_4_col_3"}},
new String[]{"Col1", "Col2", "Col3"});
table.setPreferredSize(new Dimension(0, (table.getRowHeight() * 3)));

tablePane.add(table.getTableHeader(), BorderLayout.NORTH);
Expand All @@ -130,29 +125,19 @@ private static void createAndShowGUI() {
frame.setSize(400, 120);
frame.setVisible(true);
frame.setLocationRelativeTo(null);

}

/*
*
* mouseEvents for last row click
*/

private static void mouseEvents(Point clkPnt) {
// mouseEvents for last row click
private static void mouseEvents(Point clkPnt) {
testRobot.mouseMove(clkPnt.x, clkPnt.y);
testRobot.delay(50);
testRobot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
testRobot.delay(50);
testRobot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
testRobot.delay(50);
}
/*
*
* getMousePosition Actions for last row click
* returns Point
* throws Exception
*/

// getMousePosition Actions for last row click
private static Point getMousePosition() throws Exception {
final Point[] clickPoint = new Point[1];
SwingUtilities.invokeAndWait(new Runnable() {
Expand All @@ -164,12 +149,7 @@ public void run() {
return clickPoint[0];
}

/*
*
* Clears the selected table row
* throws Exception
*/

// Clears the selected table row
private static void clearSelect() throws Exception {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
Expand All @@ -180,12 +160,7 @@ public void run() {
});
}

/*
* getCaptureRect Method - To Compute the Rectangle for
* Screen Capturing the Last Row for comparison
* return Rectangle
*/

// getCaptureRect Method - To Compute the Rectangle Area of last row
private static Rectangle getCaptureRect() throws InterruptedException, InvocationTargetException {
final Rectangle[] captureRect = new Rectangle[1];
SwingUtilities.invokeAndWait(new Runnable() {
Expand All @@ -195,19 +170,15 @@ public void run() {
Point point = new Point(cellRect.x, cellRect.y);
SwingUtilities.convertPointToScreen(point, table);

captureRect[0] = new Rectangle(point.x, point.y, table.getColumnCount() * cellRect.width, cellRect.height);
captureRect[0] = new Rectangle(point.x+5, point.y+2,
table.getColumnCount() * cellRect.width - 10,
cellRect.height-2);
}
});
return captureRect[0];
}

/*
* Compare method - to compare two images.
* param bufferedImage1 Buffered Image Before click
* param bufferedImage2 Buffered Image After click
* return Boolean
*/

// Compare method - to compare two images.
static Boolean compare(BufferedImage bufferedImage1, BufferedImage bufferedImage2) {
if (bufferedImage1.getWidth() == bufferedImage2.getWidth()
&& bufferedImage1.getHeight() == bufferedImage2.getHeight()) {
Expand Down

1 comment on commit 39526e2

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.