Navigation Menu

Skip to content

Commit

Permalink
8293811: Provide a reason for PassFailJFrame.forceFail
Browse files Browse the repository at this point in the history
Reviewed-by: honkar, jdv
  • Loading branch information
aivanov-jdk committed Sep 19, 2022
1 parent f91762f commit 64b96e5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
27 changes: 20 additions & 7 deletions test/jdk/java/awt/regtesthelpers/PassFailJFrame.java
Expand Up @@ -56,6 +56,11 @@ public class PassFailJFrame {
private static final int ROWS = 10;
private static final int COLUMNS = 40;

/**
* Prefix for the user-provided failure reason.
*/
private static final String FAILURE_REASON = "Failure Reason:\n";

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 @@ -135,8 +140,8 @@ private static void createUI(String title, String instructions,
long leftTime = tTimeout - (System.currentTimeMillis() - startTime);
if ((leftTime < 0) || failed) {
timer.stop();
testFailedReason = "Failure Reason:\n"
+ "Timeout User did not perform testing.";
testFailedReason = FAILURE_REASON
+ "Timeout User did not perform testing.";
timeout = true;
latch.countDown();
}
Expand Down Expand Up @@ -166,8 +171,8 @@ private static void createUI(String title, String instructions,
@Override
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
testFailedReason = "Failure Reason:\n"
+ "User closed the instruction Frame";
testFailedReason = FAILURE_REASON
+ "User closed the instruction Frame";
failed = true;
latch.countDown();
}
Expand Down Expand Up @@ -240,7 +245,7 @@ private static void getFailureReason() {

JButton okButton = new JButton("OK");
okButton.addActionListener((ae) -> {
testFailedReason = "Failure Reason:\n" + jTextArea.getText();
testFailedReason = FAILURE_REASON + jTextArea.getText();
dialog.setVisible(false);
});

Expand Down Expand Up @@ -403,9 +408,17 @@ public static void forcePass() {
* Forcibly fail the test.
*/
public static void forceFail() {
forceFail("forceFail called");
}

/**
* Forcibly fail the test and provide a reason.
*
* @param reason the reason why the test is failed
*/
public static void forceFail(String reason) {
failed = true;
testFailedReason = "Failure Reason:\n" +
"forceFail called";
testFailedReason = FAILURE_REASON + reason;
latch.countDown();
}
}
7 changes: 4 additions & 3 deletions test/jdk/javax/swing/JTable/PrintAllPagesTest.java
Expand Up @@ -41,7 +41,6 @@
public class PrintAllPagesTest {
static JFrame f;
static JTable table;
static volatile boolean ret = false;

static final String INSTRUCTIONS = """
Note: You must have a printer installed for this test.
Expand Down Expand Up @@ -71,13 +70,15 @@ public static void main(String[] args) throws Exception {
// Arrange the test instruction frame and test frame side by side
PassFailJFrame.positionTestWindow(f, PassFailJFrame.Position.HORIZONTAL);
f.setVisible(true);

boolean ret;
try {
ret = table.print();
} catch (PrinterException ex) {
ret = false;
}
if (!ret) {
throw new RuntimeException("Printing cancelled/failed");
PassFailJFrame.forceFail("Printing cancelled/failed");
}
});
passFailJFrame.awaitAndCheck();
Expand Down Expand Up @@ -108,6 +109,6 @@ public Object getValueAt(int row, int col) {

f = new JFrame("Table test");
f.add(scrollpane);
f.setSize(1000, 800);
f.setSize(500, 400);
}
}

1 comment on commit 64b96e5

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