JRE-430 added new regression test (Font fallback sometimes doesn't work in Swing text components)

(cherry picked from commit d04debc847)
This commit is contained in:
Vitaly Provodin
2018-11-23 17:09:58 +07:00
parent d9bbf267a4
commit 70b5ec36a2
2 changed files with 176 additions and 0 deletions

View File

@@ -0,0 +1,121 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import javax.imageio.ImageIO;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
/*
* Description: The class is used by the test <code>font430.sh</code>.
*/
public class Font430 extends JFrame implements
WindowListener {
private static boolean CALL_GET_FONT_METRICS = false;
private static String FILE_NAME;
static Font430 frame = new Font430("Font430");
private static JEditorPane editorPane;
private Font430(String name) {
super(name);
}
public static void main(String[] args) {
if (args.length > 0)
FILE_NAME = args[0];
if (args.length > 1)
CALL_GET_FONT_METRICS = Boolean.valueOf(args[1]);
SwingUtilities.invokeLater(Font430::createAndShowGUI);
}
private static void createAndShowGUI() {
frame.setSize(200, 100);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.addComponentsToPane();
frame.pack();
frame.setVisible(true);
}
private void addComponentsToPane() {
editorPane = new JEditorPane("text/html",
"<html><head><style>body {font-family:'Segoe UI'; font-size:12pt;}</style></head><body>\u4e2d</body></html>");
if (CALL_GET_FONT_METRICS) {
editorPane.getFontMetrics(new Font("Segoe UI", Font.PLAIN, 12));
}
editorPane.setLocation(0, 0);
editorPane.setSize(200, 100);
frame.add(editorPane);
addWindowListener(this);
}
@Override
public void windowOpened(WindowEvent e) {
BufferedImage screenShoot;
Rectangle rect = editorPane.getBounds();
try {
screenShoot = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_INT_ARGB);
editorPane.paint(screenShoot.getGraphics());
ImageIO.write(screenShoot, "png", new File(FILE_NAME));
} catch (IOException ex) {
ex.printStackTrace();
}
frame.setVisible(false);
frame.dispose();
}
@Override
public void windowClosing(WindowEvent e) {
}
@Override
public void windowClosed(WindowEvent e) {
}
@Override
public void windowIconified(WindowEvent e) {
}
@Override
public void windowDeiconified(WindowEvent e) {
}
@Override
public void windowActivated(WindowEvent e) {
}
@Override
public void windowDeactivated(WindowEvent e) {
}
}

View File

@@ -0,0 +1,55 @@
#!/bin/bash
#
# Copyright 2000-2017 JetBrains s.r.o.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# @test
# @summary font430.sh checks the 'physical' font object, created for 'Segoe UI' font and font-fallback-enabled one
# are not identical
# @run shell font430.sh
if [ -z "${TESTSRC}" ]; then
echo "TESTSRC undefined: set to ."
TESTSRC=.
fi
if [ -z "${TESTCLASSES}" ]; then
echo "TESTCLASSES undefined: set to ."
TESTCLASSES=.
fi
if [ -z "${TESTJAVA}" ]; then
echo "TESTJAVA undefined: testing cancelled"
exit 1
fi
cd ${TESTSRC}
${TESTJAVA}/bin/javac -d ${TESTCLASSES} Font430.java
${TESTJAVA}/bin/java -cp ${TESTCLASSES} Font430 t1.bmp true
${TESTJAVA}/bin/java -cp ${TESTCLASSES} Font430 t2.bmp true
cmp t1.bmp t2.bmp
exit_code=$?
case $exit_code in
0) echo "PASSED"
;;
*) echo "FAILED: $exit_code"
exit 1
;;
esac
exit 0