Path: blob/master/test/jdk/tools/jpackage/windows/WinInstallerIconTest.java
66644 views
/*1* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.Graphics;24import java.awt.image.BufferedImage;25import java.io.IOException;26import java.nio.file.Path;27import javax.swing.Icon;28import javax.swing.filechooser.FileSystemView;29import jdk.jpackage.test.PackageTest;30import jdk.jpackage.test.Annotations.Test;31import jdk.jpackage.test.JPackageCommand;32import jdk.jpackage.test.PackageType;33import static jdk.jpackage.test.RunnablePackageTest.Action.CREATE;34import jdk.jpackage.test.TKit;3536/**37* Test that --icon also changes icon of exe installer.38*/3940/*41* @test42* @summary jpackage with --icon parameter for exe installer43* @library ../helpers44* @key jpackagePlatformPackage45* @build jdk.jpackage.test.*46* @build WinInstallerIconTest47* @requires (os.family == "windows")48* @requires !vm.debug49* @modules jdk.jpackage/jdk.jpackage.internal50* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main51* --jpt-run=WinInstallerIconTest52*/5354/*55* note: AWT can throw assertion from GetDiBits() extracting icon56* bits in fastdebug mode on windows headless systems. That is why57* we have @requires !vm.debug" above.58*/59public class WinInstallerIconTest {6061@Test62public void test() throws IOException {63Path customIcon = iconPath("icon");6465BufferedImage[] defaultInstallerIconImg = new BufferedImage[1];6667// Create installer with the default icon68long size1 = createInstaller(null, "WithDefaultIcon");6970// Create installer with custom icon.71long size2 = createInstaller(customIcon, "WithCustomIcon");7273// Create another installer with custom icon.74long size3 = createInstaller(customIcon, null);7576TKit.assertTrue(size2 < size1, "Installer 2 built with custom icon " +77"should be smaller than Installer 1 built with default icon");7879TKit.assertTrue(size3 < size1, "Installer 3 built with custom icon " +80"should be smaller than Installer 1 built with default icon");8182}8384private long createInstaller(Path icon, String nameSuffix) throws IOException {8586PackageTest test = new PackageTest()87.forTypes(PackageType.WIN_EXE)88.addInitializer(JPackageCommand::setFakeRuntime)89.configureHelloApp();90if (icon != null) {91test.addInitializer(cmd -> cmd.addArguments("--icon", icon));92}9394if (nameSuffix != null) {95test.addInitializer(cmd -> {96String name = cmd.name() + nameSuffix;97cmd.setArgumentValue("--name", name);98});99}100101Path installerExePath[] = new Path[1];102103test.addBundleVerifier(cmd -> {104installerExePath[0] = cmd.outputBundle();105});106107test.run(CREATE);108109long size = 0L;110if (installerExePath[0] != null) {111size = installerExePath[0].toFile().length();112TKit.trace(" installer: " + installerExePath[0] + " - size: " + size);113if (nameSuffix != null) {114TKit.deleteIfExists(installerExePath[0]);115}116}117return size;118}119120private static Path iconPath(String name) {121return TKit.TEST_SRC_ROOT.resolve(Path.of("resources", name122+ TKit.ICON_SUFFIX));123}124}125126127