mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-14 18:03:44 +00:00
8290557: tools/jpackage/share/AddLauncherTest.java#id1 failed with "ERROR: Failed: Check icon file"
Reviewed-by: almatvee
This commit is contained in:
parent
0ca74f538e
commit
7c3cfd13e3
@ -23,12 +23,14 @@
|
||||
|
||||
package jdk.jpackage.test;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public final class LauncherIconVerifier {
|
||||
public LauncherIconVerifier() {
|
||||
@ -99,13 +101,56 @@ public final class LauncherIconVerifier {
|
||||
iconWorkDir, iconContainer, "expected");
|
||||
Path extractedActualIcon = extractIconFromExecutable(iconWorkDir,
|
||||
launcher, "actual");
|
||||
TKit.assertTrue(-1 == Files.mismatch(extractedExpectedIcon,
|
||||
extractedActualIcon),
|
||||
String.format(
|
||||
"Check icon file [%s] of %s launcher is a copy of source icon file [%s]",
|
||||
extractedActualIcon,
|
||||
Optional.ofNullable(launcherName).orElse("main"),
|
||||
extractedExpectedIcon));
|
||||
|
||||
TKit.trace(String.format(
|
||||
"Check icon file [%s] of %s launcher is a copy of source icon file [%s]",
|
||||
extractedActualIcon,
|
||||
Optional.ofNullable(launcherName).orElse("main"),
|
||||
extractedExpectedIcon));
|
||||
|
||||
if (Files.mismatch(extractedExpectedIcon, extractedActualIcon)
|
||||
!= -1) {
|
||||
// On Windows11 .NET API extracting icons from executables
|
||||
// produce slightly different output for the same icon.
|
||||
// To workaround it, compare pixels of images and if the
|
||||
// number of off pixels is below a threshold, assume
|
||||
// equality.
|
||||
BufferedImage expectedImg = ImageIO.read(
|
||||
extractedExpectedIcon.toFile());
|
||||
BufferedImage actualImg = ImageIO.read(
|
||||
extractedActualIcon.toFile());
|
||||
|
||||
int w = expectedImg.getWidth();
|
||||
int h = expectedImg.getHeight();
|
||||
|
||||
TKit.assertEquals(w, actualImg.getWidth(),
|
||||
"Check expected and actual icons have the same width");
|
||||
TKit.assertEquals(h, actualImg.getHeight(),
|
||||
"Check expected and actual icons have the same height");
|
||||
|
||||
int diffPixelCount = 0;
|
||||
|
||||
for (int i = 0; i != w; ++i) {
|
||||
for (int j = 0; j != h; ++j) {
|
||||
int expectedRGB = expectedImg.getRGB(i, j);
|
||||
int actualRGB = actualImg.getRGB(i, j);
|
||||
|
||||
if (expectedRGB != actualRGB) {
|
||||
TKit.trace(String.format(
|
||||
"Images mismatch at [%d, %d] pixel", i,
|
||||
j));
|
||||
diffPixelCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double threshold = 0.1;
|
||||
TKit.assertTrue(((double) diffPixelCount) / (w * h)
|
||||
< threshold,
|
||||
String.format(
|
||||
"Check the number of mismatched pixels [%d] of [%d] is < [%f] threshold",
|
||||
diffPixelCount, (w * h), threshold));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user