8281033: Improve ImageCheckboxTest to test all available LaF

Reviewed-by: serb
This commit is contained in:
Alexander Zuev 2022-02-12 09:26:47 +00:00
parent 6fdfe0458d
commit aa918a6ec4

View File

@ -23,13 +23,14 @@
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.JCheckBox;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
/*
* @test
@ -43,18 +44,43 @@ import javax.swing.JCheckBox;
public class ImageCheckboxTest {
public static void main(String[] args) throws Exception {
new ImageCheckboxTest().performTest();
ImageCheckboxTest test = new ImageCheckboxTest();
boolean passed = true;
// There are bugs found in various LaFs that needs to be fixed
// to enable testing there
String[] skip = {
"GTK+", // JDK-8281580
"Nimbus" // JDK-8281581
};
testloop:
for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
for (String s : skip) {
if (s.equals(laf.getName())) {
continue testloop;
}
}
passed = passed && test.performTest(laf);
}
if(!passed) {
throw new RuntimeException("Test failed");
}
}
public void performTest() throws Exception {
public boolean performTest(UIManager.LookAndFeelInfo laf) throws Exception {
BufferedImage imageNoFocus = new BufferedImage(100, 50,
BufferedImage.TYPE_INT_ARGB);
BufferedImage imageFocus = new BufferedImage(100, 50,
BufferedImage.TYPE_INT_ARGB);
BufferedImage imageFocusNotPainted = new BufferedImage(100, 50,
BufferedImage.TYPE_INT_ARGB);
boolean success = true;
try {
UIManager.setLookAndFeel(laf.getClassName());
} catch (UnsupportedLookAndFeelException ulaf) {
return true;
}
CustomCheckBox checkbox = new CustomCheckBox("Test", new MyIcon(Color.GREEN));
checkbox.setFocusPainted(true);
checkbox.setSize(100, 50);
@ -64,21 +90,32 @@ public class ImageCheckboxTest {
checkbox.paint(imageFocus.createGraphics());
if (Util.compareBufferedImages(imageFocus, imageNoFocus)) {
ImageIO.write(imageFocus, "png", new File("imageFocus.png"));
ImageIO.write(imageNoFocus, "png", new File("imageNoFocus.png"));
throw new Exception("Changing focus is not visualized");
File folder = new File(laf.getName());
if (!folder.exists()) {
folder.mkdir();
}
ImageIO.write(imageFocus, "png", new File(folder, "/imageFocus.png"));
ImageIO.write(imageNoFocus, "png", new File(folder, "/imageNoFocus.png"));
System.err.println(laf.getName() + ": Changing of focus is not visualized");
success = false;
}
checkbox.setFocusPainted(false);
checkbox.paint(imageFocusNotPainted.createGraphics());
if (!Util.compareBufferedImages(imageFocusNotPainted, imageNoFocus)) {
File folder = new File(laf.getName());
if (!folder.exists()) {
folder.mkdir();
}
ImageIO.write(imageFocusNotPainted, "png",
new File("imageFocusNotPainted.png"));
ImageIO.write(imageFocus, "png", new File("imageFocus.png"));
ImageIO.write(imageNoFocus, "png", new File("imageNoFocus.png"));
throw new Exception("setFocusPainted(false) is ignored");
new File(folder,"imageFocusNotPainted.png"));
ImageIO.write(imageFocus, "png", new File(folder, "imageFocus.png"));
ImageIO.write(imageNoFocus, "png", new File(folder, "imageNoFocus.png"));
System.err.println(laf.getName() + ": setFocusPainted(false) is ignored");
success = false;
}
return success;
}
class MyIcon implements Icon {