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

Reviewed-by: almatvee
  • Loading branch information
Alexey Semenyuk committed Feb 16, 2022
1 parent 9b74c3f commit bb4dece
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

3 comments on commit bb4dece

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on bb4dece Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on bb4dece Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin the backport was successfully created on the branch GoeLin-backport-bb4dece2 in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit bb4dece2 from the openjdk/jdk repository.

The commit being backported was authored by Alexey Semenyuk on 16 Feb 2022 and was reviewed by Alexander Matveev.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev GoeLin-backport-bb4dece2:GoeLin-backport-bb4dece2
$ git checkout GoeLin-backport-bb4dece2
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev GoeLin-backport-bb4dece2

Please sign in to comment.