Skip to content

Commit

Permalink
8290557: tools/jpackage/share/AddLauncherTest.java#id1 failed with "E…
Browse files Browse the repository at this point in the history
…RROR: Failed: Check icon file"

Reviewed-by: almatvee
  • Loading branch information
Alexey Semenyuk committed Jul 25, 2022
1 parent 0ca74f5 commit 7c3cfd1
Showing 1 changed file with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -99,13 +101,56 @@ void verifyLauncherIcon(JPackageCommand cmd, String launcherName,
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));
}
});
}

Expand Down

1 comment on commit 7c3cfd1

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