Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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