Path: blob/master/test/jdk/tools/jpackage/windows/Win8282351Test.java
66644 views
/*1* Copyright (c) 2022, 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.io.IOException;24import java.nio.file.Files;25import java.nio.file.Path;26import jdk.jpackage.test.PackageTest;27import jdk.jpackage.test.JPackageCommand;28import jdk.jpackage.test.Annotations.Test;29import jdk.jpackage.test.PackageType;30import jdk.jpackage.test.RunnablePackageTest.Action;31import jdk.jpackage.test.TKit;3233/**34* Test packaging of files with paths containing multiple dollar ($$, $$$)35* character sequences.36*/3738/*39* @test40* @summary Test case for JDK-824825441* @library ../helpers42* @build jdk.jpackage.test.*43* @build Win8282351Test44* @requires (os.family == "windows")45* @modules jdk.jpackage/jdk.jpackage.internal46* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main47* --jpt-run=Win8282351Test48*/49public class Win8282351Test {5051@Test52public void test() throws IOException {53Path appimageOutput = TKit.createTempDirectory("appimage");5455JPackageCommand appImageCmd = JPackageCommand.helloAppImage()56.setFakeRuntime().setArgumentValue("--dest", appimageOutput);5758String[] filesWithDollarCharsInNames = new String[]{59"Pane$$anon$$greater$1.class",60"$",61"$$",62"$$$",63"$$$$",64"$$$$$",65"foo$.class",66"1$b$$a$$$r$$$$.class"67};6869String[] dirsWithDollarCharsInNames = new String[]{70Path.of("foo", String.join("/", filesWithDollarCharsInNames)).toString()71};7273String name = appImageCmd.name() + "$-$$-$$$";7475new PackageTest()76.addRunOnceInitializer(() -> {77appImageCmd.execute();78for (var path : filesWithDollarCharsInNames) {79createImageFile(appImageCmd, Path.of(path));80}8182for (var path : dirsWithDollarCharsInNames) {83Files.createDirectories(84appImageCmd.outputBundle().resolve(path));85}86})87.addInitializer(cmd -> {88cmd.setArgumentValue("--name", name);89cmd.addArguments("--app-image", appImageCmd.outputBundle());90cmd.removeArgumentWithValue("--input");91cmd.addArgument("--win-menu");92cmd.addArgument("--win-shortcut");93})94.addInstallVerifier(cmd -> {95for (var path : filesWithDollarCharsInNames) {96verifyImageFile(appImageCmd, Path.of(path));97}9899for (var path : dirsWithDollarCharsInNames) {100TKit.assertDirectoryExists(101appImageCmd.outputBundle().resolve(path));102}103}).run(Action.CREATE_AND_UNPACK);104}105106private static void createImageFile(JPackageCommand cmd, Path name) throws107IOException {108Files.writeString(cmd.outputBundle().resolve(name), name.toString());109}110111private static void verifyImageFile(JPackageCommand cmd, Path name) throws112IOException {113TKit.assertEquals(name.toString(), Files.readString(114(cmd.outputBundle().resolve(name))), String.format(115"Test contents of [%s] image file are euqal to [%s]", name, name));116}117}118119120