Skip to content

Commit 93b6661

Browse files
AddLauncherTest: add test cases for the main/additional launcher descriptions
1 parent 7227492 commit 93b6661

File tree

1 file changed

+66
-7
lines changed

1 file changed

+66
-7
lines changed

test/jdk/tools/jpackage/share/AddLauncherTest.java

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,22 @@
2121
* questions.
2222
*/
2323

24-
import java.nio.file.Path;
25-
import java.util.Map;
2624
import java.lang.invoke.MethodHandles;
27-
import jdk.jpackage.test.PackageTest;
28-
import jdk.jpackage.test.FileAssociations;
25+
import java.nio.file.Path;
26+
import java.util.function.Consumer;
27+
import jdk.internal.util.OperatingSystem;
2928
import jdk.jpackage.test.AdditionalLauncher;
29+
import jdk.jpackage.test.Annotations.Parameter;
30+
import jdk.jpackage.test.Annotations.Test;
31+
import jdk.jpackage.test.CfgFile;
32+
import jdk.jpackage.test.ConfigurationTarget;
33+
import jdk.jpackage.test.FileAssociations;
3034
import jdk.jpackage.test.JPackageCommand;
3135
import jdk.jpackage.test.JavaAppDesc;
36+
import jdk.jpackage.test.PackageTest;
37+
import jdk.jpackage.test.PackageType;
38+
import jdk.jpackage.test.RunnablePackageTest.Action;
3239
import jdk.jpackage.test.TKit;
33-
import jdk.jpackage.test.Annotations.Test;
34-
import jdk.jpackage.test.Annotations.Parameter;
35-
import jdk.jpackage.test.CfgFile;
3640

3741
/**
3842
* Test --add-launcher parameter. Output of the test should be
@@ -233,6 +237,61 @@ public void testMainLauncherIsModular(boolean mainLauncherIsModular) {
233237
"Check app.classpath value in ModularAppLauncher cfg file");
234238
}
235239

240+
/**
241+
* Test --description option
242+
*/
243+
@Test(ifNotOS = OperatingSystem.MACOS) // Don't run on macOS as launcher description is ignored on this platform
244+
@Parameter("true")
245+
@Parameter("fase")
246+
public void testDescription(boolean withPredefinedAppImage) {
247+
248+
ConfigurationTarget target;
249+
if (TKit.isWindows() || withPredefinedAppImage) {
250+
target = new ConfigurationTarget(JPackageCommand.helloAppImage());
251+
} else {
252+
target = new ConfigurationTarget(new PackageTest().configureHelloApp());
253+
}
254+
255+
target.addInitializer(cmd -> {
256+
cmd.setArgumentValue("--name", "Foo").setArgumentValue("--description", "Hello");
257+
cmd.setFakeRuntime();
258+
cmd.setStandardAsserts(JPackageCommand.StandardAssert.MAIN_LAUNCHER_DESCRIPTION);
259+
});
260+
261+
target.add(new AdditionalLauncher("x"));
262+
target.add(new AdditionalLauncher("bye").setProperty("description", "Bye"));
263+
264+
target.test().ifPresent(test -> {
265+
// Make all launchers have shortcuts and thus .desktop files.
266+
// Launcher description is recorded in a desktop file and verified automatically.
267+
test.mutate(addLinuxShortcuts());
268+
});
269+
270+
target.cmd().ifPresent(withPredefinedAppImage ? JPackageCommand::execute : JPackageCommand::executeAndAssertImageCreated);
271+
target.test().ifPresent(test -> {
272+
test.run(Action.CREATE_AND_UNPACK);
273+
});
274+
275+
if (withPredefinedAppImage) {
276+
new PackageTest().addInitializer(cmd -> {
277+
cmd.setArgumentValue("--name", "Bar");
278+
// Should not have impact of launcher descriptions, but it does.
279+
cmd.setArgumentValue("--description", "Installer");
280+
cmd.removeArgumentWithValue("--input").setArgumentValue("--app-image", target.cmd().orElseThrow().outputBundle());
281+
}).mutate(addLinuxShortcuts()).run(Action.CREATE_AND_UNPACK);
282+
}
283+
}
284+
285+
private static Consumer<PackageTest> addLinuxShortcuts() {
286+
return test -> {
287+
test.forTypes(PackageType.LINUX, () -> {
288+
test.addInitializer(cmd -> {
289+
cmd.addArgument("--linux-shortcut");
290+
});
291+
});
292+
};
293+
}
294+
236295
private static final Path GOLDEN_ICON = TKit.TEST_SRC_ROOT.resolve(Path.of(
237296
"resources", "icon" + TKit.ICON_SUFFIX));
238297
}

0 commit comments

Comments
 (0)