Path: blob/master/test/jdk/tools/jpackage/windows/WinShortcutPromptTest.java
41149 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.util.ArrayList;24import jdk.jpackage.test.PackageTest;25import jdk.jpackage.test.JPackageCommand;26import jdk.jpackage.test.Annotations.Test;27import jdk.jpackage.test.Annotations.Parameters;28import java.util.List;29import jdk.jpackage.test.PackageType;3031/**32* Test all possible combinations of --win-shortcut-prompt, --win-menu and33* --win-shortcut parameters.34*/3536/*37* @test38* @summary jpackage with --win-shortcut-prompt, --win-menu and --win-shortcut parameters39* @library ../helpers40* @key jpackagePlatformPackage41* @build jdk.jpackage.test.*42* @build WinShortcutPromptTest43* @requires (os.family == "windows")44* @modules jdk.jpackage/jdk.jpackage.internal45* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main46* --jpt-run=WinShortcutPromptTest47*/48public class WinShortcutPromptTest {4950public WinShortcutPromptTest(Boolean withStartMenuShortcut,51Boolean withDesktopShortcut, Boolean withShortcutPrompt) {52this.withStartMenuShortcut = withStartMenuShortcut;53this.withDesktopShortcut = withDesktopShortcut;54this.withShortcutPrompt = withShortcutPrompt;55}5657@Parameters58public static List<Object[]> data() {59List<Object[]> data = new ArrayList<>();60for (var withStartMenuShortcut : List.of(Boolean.TRUE, Boolean.FALSE)) {61for (var withDesktopShortcut : List.of(Boolean.TRUE, Boolean.FALSE)) {62for (var withShortcutPrompt : List.of(Boolean.TRUE, Boolean.FALSE)) {63if (withShortcutPrompt && withStartMenuShortcut64&& withDesktopShortcut) {65// Duplicates WinInstallerUiTestWithShortcutPromptTest (WinInstallerUiTest(withShortcutPrompt=true))66continue;67}6869if (!withShortcutPrompt && !withStartMenuShortcut70&& !withDesktopShortcut) {71// Duplicates SimplePackageTest72continue;73}7475if (!withShortcutPrompt && !withStartMenuShortcut76&& withDesktopShortcut) {77// Duplicates WinShortcutTest78continue;79}8081if (!withShortcutPrompt && withStartMenuShortcut82&& !withDesktopShortcut) {83// Duplicates WinMenuTest84continue;85}8687data.add(new Object[]{withStartMenuShortcut,88withDesktopShortcut, withShortcutPrompt});89}90}91}9293return data;94}9596@Test97public void test() {98PackageTest test = new PackageTest()99.forTypes(PackageType.WINDOWS)100.configureHelloApp();101102test.addInitializer(JPackageCommand::setFakeRuntime);103test.addInitializer(this::setPackageName);104105if (withShortcutPrompt) {106test.addInitializer(cmd -> cmd.addArgument("--win-shortcut-prompt"));107}108109if (withStartMenuShortcut) {110test.addInitializer(cmd -> cmd.addArgument("--win-menu"));111}112113if (withDesktopShortcut) {114test.addInitializer(cmd -> cmd.addArgument("--win-shortcut"));115}116117test.run();118}119120private void setPackageName(JPackageCommand cmd) {121StringBuilder sb = new StringBuilder(cmd.name());122sb.append("With");123if (withShortcutPrompt) {124sb.append("ShortcutPrompt");125}126if (withStartMenuShortcut) {127sb.append("StartMenu");128}129if (withDesktopShortcut) {130sb.append("Desktop");131}132cmd.setArgumentValue("--name", sb.toString());133}134135private final boolean withStartMenuShortcut;136private final boolean withDesktopShortcut;137private final boolean withShortcutPrompt;138}139140141