Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/tools/jpackage/share/FileAssociationsTest.java
41152 views
1
/*
2
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import java.nio.file.Path;
25
import java.util.Map;
26
import java.util.List;
27
import jdk.jpackage.test.TKit;
28
import jdk.jpackage.test.PackageTest;
29
import jdk.jpackage.test.PackageType;
30
import jdk.jpackage.test.FileAssociations;
31
import jdk.jpackage.test.Annotations.Test;
32
import jdk.jpackage.test.Annotations.Parameter;
33
34
/**
35
* Test --file-associations parameter. Output of the test should be
36
* fileassociationstest*.* installer. The output installer should provide the
37
* same functionality as the default installer (see description of the default
38
* installer in SimplePackageTest.java) plus configure file associations. After
39
* installation files with ".jptest1" and ".jptest2" suffixes should be
40
* associated with the test app.
41
*
42
* Suggested test scenario is to create empty file with ".jptest1" suffix,
43
* double click on it and make sure that test application was launched in
44
* response to double click event with the path to test .jptest1 file on the
45
* commend line. The same applies to ".jptest2" suffix.
46
*
47
* On Linux use "echo > foo.jptest1" and not "touch foo.jptest1" to create test
48
* file as empty files are always interpreted as plain text and will not be
49
* opened with the test app. This is a known bug.
50
*
51
* Icon associated with the main launcher should be associated with files with
52
* ".jptest1" suffix. Different icon should be associated with files with with
53
* ".jptest2" suffix. Icon for files with ".jptest1" suffix is platform specific
54
* and is one of 'icon.*' files in test/jdk/tools/jpackage/resources directory.
55
*/
56
57
/*
58
* @test
59
* @summary jpackage with --file-associations
60
* @library ../helpers
61
* @key jpackagePlatformPackage
62
* @requires jpackage.test.SQETest == null
63
* @build jdk.jpackage.test.*
64
* @modules jdk.jpackage/jdk.jpackage.internal
65
* @compile FileAssociationsTest.java
66
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
67
* --jpt-run=FileAssociationsTest
68
*/
69
70
/*
71
* @test
72
* @summary jpackage with --file-associations
73
* @library ../helpers
74
* @key jpackagePlatformPackage
75
* @requires jpackage.test.SQETest != null
76
* @build jdk.jpackage.test.*
77
* @modules jdk.jpackage/jdk.jpackage.internal
78
* @compile FileAssociationsTest.java
79
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
80
* --jpt-run=FileAssociationsTest.test
81
*/
82
83
public class FileAssociationsTest {
84
@Test
85
@Parameter("true")
86
@Parameter("false")
87
public static void test(boolean includeDescription) {
88
PackageTest packageTest = new PackageTest();
89
90
// Not supported
91
packageTest.excludeTypes(PackageType.MAC_DMG);
92
93
FileAssociations fa = new FileAssociations("jptest1");
94
if (!includeDescription) {
95
fa.setDescription(null);
96
}
97
fa.applyTo(packageTest);
98
99
Path icon = TKit.TEST_SRC_ROOT.resolve(Path.of("resources", "icon"
100
+ TKit.ICON_SUFFIX));
101
102
icon = TKit.createRelativePathCopy(icon);
103
104
new FileAssociations("jptest2")
105
.setFilename("fa2")
106
.setIcon(icon)
107
.applyTo(packageTest);
108
109
packageTest.run();
110
}
111
112
@Test
113
public static void testNoMime() {
114
final Path propFile = TKit.workDir().resolve("fa.properties");
115
116
PackageTest packageTest = new PackageTest().excludeTypes(PackageType.MAC);
117
118
packageTest.configureHelloApp().addRunOnceInitializer(() -> {
119
TKit.createPropertiesFile(propFile, Map.of(
120
"extension", "foo",
121
"description", "bar"
122
));
123
}).addInitializer(cmd -> {
124
cmd.addArguments("--file-associations", propFile).saveConsoleOutput(true);
125
}).setExpectedExitCode(1).addBundleVerifier((cmd, result) -> {
126
TKit.assertTextStream(
127
"No MIME types were specified for File Association number 1")
128
.apply(result.getOutput().stream());
129
TKit.assertTextStream(
130
"Advice to fix: Specify MIME type for File Association number 1")
131
.apply(result.getOutput().stream());
132
}).run();
133
}
134
135
@Test
136
public static void testTooManyMimes() {
137
final Path propFile = TKit.workDir().resolve("fa.properties");
138
139
PackageTest packageTest = new PackageTest().excludeTypes(PackageType.MAC);
140
141
packageTest.configureHelloApp().addRunOnceInitializer(() -> {
142
TKit.createPropertiesFile(propFile, Map.of(
143
"mime-type", "application/x-jpackage-foo, application/x-jpackage-bar",
144
"extension", "foo",
145
"description", "bar"
146
));
147
}).addInitializer(cmd -> {
148
cmd.addArguments("--file-associations", propFile).saveConsoleOutput(true);
149
}).setExpectedExitCode(1).addBundleVerifier((cmd, result) -> {
150
TKit.assertTextStream(
151
"More than one MIME types was specified for File Association number 1")
152
.apply(result.getOutput().stream());
153
TKit.assertTextStream(
154
"Advice to fix: Specify only one MIME type for File Association number 1")
155
.apply(result.getOutput().stream());
156
}).run();
157
}
158
}
159
160