Skip to content

Commit

Permalink
8281170: Test jdk/tools/jpackage/windows/WinInstallerIconTest always …
Browse files Browse the repository at this point in the history
…fails on Windows 11

Backport-of: bb4dece246a56f2b225089c331e9f3d092dfbfa1
  • Loading branch information
GoeLin committed Feb 15, 2023
1 parent 9e26f38 commit 036029e
Showing 1 changed file with 27 additions and 34 deletions.
61 changes: 27 additions & 34 deletions test/jdk/tools/jpackage/windows/WinInstallerIconTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -21,12 +21,9 @@
* questions.
*/

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.nio.file.Path;
import javax.swing.Icon;
import javax.swing.filechooser.FileSystemView;
import java.util.Optional;
import java.util.stream.Stream;
import jdk.jpackage.test.PackageTest;
import jdk.jpackage.test.Annotations.Test;
import jdk.jpackage.test.JPackageCommand;
Expand All @@ -46,43 +43,41 @@
* @build jdk.jpackage.test.*
* @build WinInstallerIconTest
* @requires (os.family == "windows")
* @requires !vm.debug
* @modules jdk.jpackage/jdk.jpackage.internal
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
* --jpt-run=WinInstallerIconTest
*/

/*
* note: AWT can throw assertion from GetDiBits() extracting icon
* bits in fastdebug mode on windows headless systems. That is why
* we have @requires !vm.debug" above.
*/
public class WinInstallerIconTest {

@Test
public void test() throws IOException {
public void test() {
Path customIcon = iconPath("icon");

BufferedImage[] defaultInstallerIconImg = new BufferedImage[1];

// Create installer with the default icon
long size1 = createInstaller(null, "WithDefaultIcon");
var size1 = createInstaller(null, "WithDefaultIcon");

// Create installer with custom icon.
long size2 = createInstaller(customIcon, "WithCustomIcon");
var size2 = createInstaller(customIcon, "WithCustomIcon");

// Create another installer with custom icon.
long size3 = createInstaller(customIcon, null);
var size3 = createInstaller(customIcon, null);

TKit.assertTrue(size2 < size1, "Installer 2 built with custom icon " +
"should be smaller than Installer 1 built with default icon");
if (Stream.of(size1, size2, size3).allMatch(Optional::<Long>isEmpty)) {
TKit.trace(
"Not verifying sizes of installers because they were not created");
return;
}

TKit.assertTrue(size2.get() < size1.get(), "Check installer 2 built with custom icon " +
"is smaller than Installer 1 built with default icon");

TKit.assertTrue(size3 < size1, "Installer 3 built with custom icon " +
"should be smaller than Installer 1 built with default icon");
TKit.assertTrue(size3.get() < size1.get(), "Check installer 3 built with custom icon " +
"is smaller than Installer 1 built with default icon");

}

private long createInstaller(Path icon, String nameSuffix) throws IOException {
private Optional<Long> createInstaller(Path icon, String nameSuffix) {

PackageTest test = new PackageTest()
.forTypes(PackageType.WIN_EXE)
Expand All @@ -96,26 +91,24 @@ private long createInstaller(Path icon, String nameSuffix) throws IOException {
test.addInitializer(cmd -> {
String name = cmd.name() + nameSuffix;
cmd.setArgumentValue("--name", name);
// Create installer bundle in the test work directory, ignore
// value of jpackage.test.output system property.
cmd.setDefaultInputOutput();
});
}

Path installerExePath[] = new Path[1];
Long installerExeByteCount[] = new Long[1];

test.addBundleVerifier(cmd -> {
installerExePath[0] = cmd.outputBundle();
Path installerExePath = cmd.outputBundle();
installerExeByteCount[0] = installerExePath.toFile().length();
TKit.trace(String.format("Size of [%s] is %d bytes",
installerExePath, installerExeByteCount[0]));
});

test.run(CREATE);

long size = 0L;
if (installerExePath[0] != null) {
size = installerExePath[0].toFile().length();
TKit.trace(" installer: " + installerExePath[0] + " - size: " + size);
if (nameSuffix != null) {
TKit.deleteIfExists(installerExePath[0]);
}
}
return size;
return Optional.ofNullable(installerExeByteCount[0]);
}

private static Path iconPath(String name) {
Expand Down

1 comment on commit 036029e

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