Skip to content

Commit

Permalink
8284535: Fix PrintLatinCJKTest.java test that is failing with Parse E…
Browse files Browse the repository at this point in the history
…xception

8283712: Create a manual test framework class

Backport-of: 3f26d84f6a03030080328e36a1fd1a08c982838c
  • Loading branch information
GoeLin committed Aug 3, 2022
1 parent fb82b73 commit 7ac74ca
Showing 1 changed file with 55 additions and 50 deletions.
105 changes: 55 additions & 50 deletions test/jdk/java/awt/print/PrinterJob/PrintLatinCJKTest.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -21,57 +21,74 @@
* questions.
*/

/**
/*
* @test
* @bug 800535 8022536
* @bug 8008535 8022536
* @library ../../regtesthelpers
* @build PassFailJFrame
* @summary JDK7 Printing: CJK and Latin Text in string overlap
* @run main/manual=yesno PrintLatinCJKTest
* @run main/manual PrintLatinCJKTest
*/

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.print.PageFormat;
import java.awt.print.Pageable;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.lang.reflect.InvocationTargetException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;

import javax.swing.SwingUtilities;
import static javax.swing.SwingUtilities.invokeAndWait;

public class PrintLatinCJKTest implements Printable {

private static PrintLatinCJKTest testInstance = new PrintLatinCJKTest();
private static JFrame frame;
private static final String info = """
You need a printer for this test. If you have none, let
the test pass. If there is a printer, press Print, send
the output to the printer, and examine it. It should have
text looking like this : \u4e00\u4e01\u4e02\u4e03\u4e04English
public class PrintLatinCJKTest implements Printable, ActionListener {
To test 8022536, if a remote printer is the system default,
it should show in the dialog as the selected printer.
""";

static PrintLatinCJKTest testInstance = new PrintLatinCJKTest();
private PageFormat pf;
public static void showFrame() throws InterruptedException, InvocationTargetException {
invokeAndWait( () -> {
frame = new JFrame("Test Frame");
JButton b = new JButton("Print");
b.addActionListener((ae) -> {
try {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(testInstance);
if (job.printDialog()) {
job.print();
}
} catch (PrinterException ex) {
ex.printStackTrace();
}
});
frame.getContentPane().add(b, BorderLayout.SOUTH);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);

static String info =
"To test 8022536, if a remote printer is the system default,"+
"it should show in the dialog as the selected printer.\n"+
"You need a printer for this test. If you have none, let "+
"the test pass. If there is a printer, press Print, send "+
"the output to the printer, and examine it. It should have "+
"text looking like this : \u4e00\u4e01\u4e02\u4e03\u4e04English.";
// add the test frame to dispose
PassFailJFrame.addTestFrame(frame);

public static void showFrame() {
JFrame f = new JFrame();
JTextArea jta = new JTextArea(info, 4, 30);
jta.setLineWrap(true);
jta.setWrapStyleWord(true);
f.add("Center", jta);
JButton b = new JButton("Print");
b.addActionListener(testInstance);
f.add("South", b);
f.pack();
f.setVisible(true);
// Arrange the test instruction frame and test frame side by side
PassFailJFrame.positionTestFrame(frame,
PassFailJFrame.Position.HORIZONTAL);
});
}

@Override
public int print(Graphics g, PageFormat pf, int pageIndex)
throws PrinterException {

if (pageIndex > 0) {
return Printable.NO_SUCH_PAGE;
}
Expand All @@ -81,24 +98,12 @@ public int print(Graphics g, PageFormat pf, int pageIndex)
return Printable.PAGE_EXISTS;
}

public void actionPerformed(ActionEvent e) {
try {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(testInstance);
if (job.printDialog()) {
job.print();
}
} catch (PrinterException ex) {
ex.printStackTrace();
}
}

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
showFrame();
}
});
public static void main(String[] args) throws InterruptedException, InvocationTargetException {
PassFailJFrame passFailJFrame = new PassFailJFrame("Test Instruction" +
"Frame", info, 10, 40, 5);
showFrame();
passFailJFrame.awaitAndCheck();
}
}


1 comment on commit 7ac74ca

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