Skip to content

Commit

Permalink
8289238: Refactoring changes to PassFailJFrame Test Framework
Browse files Browse the repository at this point in the history
Reviewed-by: mbaesken, phh
Backport-of: 15efb2bdeb73e4e255dcc864be1a83450a2beaa8
  • Loading branch information
TheRealMDoerr committed Jun 28, 2023
1 parent d27e56e commit 8204dfa
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 36 deletions.
Expand Up @@ -125,8 +125,8 @@ public static void createTestUI() {
frame.pack();
frame.setVisible(true);

PassFailJFrame.addTestFrame(frame);
PassFailJFrame.positionTestFrame(frame, PassFailJFrame.Position.HORIZONTAL);
PassFailJFrame.addTestWindow(frame);
PassFailJFrame.positionTestWindow(frame, PassFailJFrame.Position.HORIZONTAL);
}

private static void printOne() {
Expand Down
4 changes: 2 additions & 2 deletions test/jdk/java/awt/print/PrinterJob/PrintGlyphVectorTest.java
Expand Up @@ -152,10 +152,10 @@ private static void createTestUI() {
f.setVisible(true);

// add the test frame to dispose
PassFailJFrame.addTestFrame(f);
PassFailJFrame.addTestWindow(f);

// Arrange the test instruction frame and test frame side by side
PassFailJFrame.positionTestFrame(f, PassFailJFrame.Position.HORIZONTAL);
PassFailJFrame.positionTestWindow(f, PassFailJFrame.Position.HORIZONTAL);
}

public static void main(String[] arg) throws Exception {
Expand Down
4 changes: 2 additions & 2 deletions test/jdk/java/awt/print/PrinterJob/PrintLatinCJKTest.java
Expand Up @@ -78,10 +78,10 @@ public static void showFrame() throws InterruptedException, InvocationTargetExce
frame.setVisible(true);

// add the test frame to dispose
PassFailJFrame.addTestFrame(frame);
PassFailJFrame.addTestWindow(frame);

// Arrange the test instruction frame and test frame side by side
PassFailJFrame.positionTestFrame(frame,
PassFailJFrame.positionTestWindow(frame,
PassFailJFrame.Position.HORIZONTAL);
});
}
Expand Down
53 changes: 27 additions & 26 deletions test/jdk/java/awt/regtesthelpers/PassFailJFrame.java
Expand Up @@ -23,8 +23,8 @@

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.lang.reflect.InvocationTargetException;
Expand All @@ -51,7 +51,7 @@ public class PassFailJFrame {
private static final int ROWS = 10;
private static final int COLUMNS = 40;

private static final List<Frame> frameList = new ArrayList<>();
private static final List<Window> windowList = new ArrayList<>();
private static final Timer timer = new Timer(0, null);
private static final CountDownLatch latch = new CountDownLatch(1);

Expand Down Expand Up @@ -172,7 +172,7 @@ public void windowClosing(WindowEvent e) {
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frameList.add(frame);
windowList.add(frame);
}

private static String convertMillisToTimeStr(long millis) {
Expand Down Expand Up @@ -201,7 +201,7 @@ public void awaitAndCheck() throws InterruptedException, InvocationTargetExcepti
throw new IllegalStateException("awaitAndCheck() should not be called on EDT");
}
latch.await();
invokeAndWait(PassFailJFrame::disposeFrames);
invokeAndWait(PassFailJFrame::disposeWindows);

if (timeout) {
throw new RuntimeException(testFailedReason);
Expand All @@ -215,12 +215,12 @@ public void awaitAndCheck() throws InterruptedException, InvocationTargetExcepti
}

/**
* Dispose all the frame(s) i,e both the test instruction frame as
* well as the frame that is added via addTestFrame(Frame frame)
* Dispose all the window(s) i,e both the test instruction frame and
* the window(s) that is added via addTestWindow(Window testWindow)
*/
private static synchronized void disposeFrames() {
for (Frame f : frameList) {
f.dispose();
private static synchronized void disposeWindows() {
for (Window win : windowList) {
win.dispose();
}
}

Expand Down Expand Up @@ -257,42 +257,42 @@ private static void getFailureReason() {
}

/**
* Position the instruction frame with testFrame ( testcase created
* frame) by the specified position
* Position the instruction frame with testWindow (testcase created
* window) by the specified position.
* Note: This method should be invoked from the method that creates
* testFrame
* testWindow.
*
* @param testFrame test frame that the test is created
* @param testWindow test window that the test is created
* @param position position can be either HORIZONTAL (both test
* instruction frame and test frame as arranged side by
* side or VERTICAL ( both test instruction frame and
* test frame as arranged up and down)
* instruction frame and test window as arranged
* side by side) or VERTICAL (both test instruction
* frame and test window as arranged up and down)
*/
public static void positionTestFrame(Frame testFrame, Position position) {
public static void positionTestWindow(Window testWindow, Position position) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
if (position.equals(Position.HORIZONTAL)) {
int newX = ((screenSize.width / 2) - frame.getWidth());
frame.setLocation(newX, frame.getY());

testFrame.setLocation((frame.getLocation().x + frame.getWidth() + 5), frame.getY());
testWindow.setLocation((frame.getLocation().x + frame.getWidth() + 5), frame.getY());
} else if (position.equals(Position.VERTICAL)) {
int newY = ((screenSize.height / 2) - frame.getHeight());
frame.setLocation(frame.getX(), newY);

testFrame.setLocation(frame.getX(),
testWindow.setLocation(frame.getX(),
(frame.getLocation().y + frame.getHeight() + 5));
}
}

/**
* Add the testFrame to the frameList so that test instruction frame
* and testFrame and any other frame used in this test is disposed
* via disposeFrames()
* Add the testWindow to the windowList so that test instruction frame
* and testWindow and any other windows used in this test is disposed
* via disposeWindows().
*
* @param testFrame testFrame that needs to be disposed
* @param testWindow testWindow that needs to be disposed
*/
public static synchronized void addTestFrame(Frame testFrame) {
frameList.add(testFrame);
public static synchronized void addTestWindow(Window testWindow) {
windowList.add(testWindow);
}

/**
Expand All @@ -315,7 +315,8 @@ public static void forcePass() {
*/
public static void forceFail() {
failed = true;
testFailedReason = "Failure Reason:\n" +
"forceFail called";
latch.countDown();
}
}

4 changes: 2 additions & 2 deletions test/jdk/javax/swing/JRadioButton/bug4380543.java
Expand Up @@ -68,8 +68,8 @@ public void run() {
passFailJFrame = new PassFailJFrame(instructions);
testObj = new TestFrame();
//Adding the Test Frame to handle dispose
PassFailJFrame.addTestFrame(testObj);
PassFailJFrame.positionTestFrame(testObj, PassFailJFrame.Position.HORIZONTAL);
PassFailJFrame.addTestWindow(testObj);
PassFailJFrame.positionTestWindow(testObj, PassFailJFrame.Position.HORIZONTAL);
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
4 changes: 2 additions & 2 deletions test/jdk/javax/swing/JTabbedPane/4209065/bug4209065.java
Expand Up @@ -67,8 +67,8 @@ public static void createAndShowGUI() throws InterruptedException,
frame.setVisible(true);


PassFailJFrame.addTestFrame(frame);
PassFailJFrame.positionTestFrame(frame,
PassFailJFrame.addTestWindow(frame);
PassFailJFrame.positionTestWindow(frame,
PassFailJFrame.Position.HORIZONTAL);
});
}
Expand Down

1 comment on commit 8204dfa

@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.