author | herrick |
Mon, 01 Jul 2019 18:31:16 -0400 | |
branch | JDK-8200758-branch |
changeset 57446 | 5a5b85f00a63 |
parent 57445 | test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageIconTest.java@405ddd80496e |
child 58114 | 42df7de58e39 |
permissions | -rw-r--r-- |
57307 | 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.io.File; |
|
25 |
import java.nio.file.Files; |
|
26 |
||
27 |
/* |
|
28 |
* @test |
|
29 |
* @summary jpackage create image to verify --icon |
|
30 |
* @library ../helpers |
|
31 |
* @build JPackageHelper |
|
32 |
* @build JPackagePath |
|
33 |
* @modules jdk.jpackage |
|
57446 | 34 |
* @run main/othervm -Xmx512m IconTest |
57307 | 35 |
*/ |
57446 | 36 |
public class IconTest { |
57307 | 37 |
private static final String OUTPUT = "output"; |
38 |
private static final String app = JPackagePath.getApp(); |
|
39 |
private static final String appOutput = JPackagePath.getAppOutputFile(); |
|
40 |
||
41 |
private static final String[] CMD = { |
|
42 |
"--input", "input", |
|
43 |
"--name", "test", |
|
44 |
"--main-jar", "hello.jar", |
|
45 |
"--main-class", "Hello", |
|
46 |
"--icon", getIconPath(), |
|
47 |
"--output", OUTPUT}; |
|
48 |
||
49 |
private static void validateResult(String[] result) throws Exception { |
|
50 |
if (result.length != 2) { |
|
51 |
throw new AssertionError( |
|
52 |
"Unexpected number of lines: " + result.length); |
|
53 |
} |
|
54 |
||
55 |
if (!result[0].trim().equals("jpackage test application")) { |
|
56 |
throw new AssertionError("Unexpected result[0]: " + result[0]); |
|
57 |
} |
|
58 |
||
59 |
if (!result[1].trim().equals("args.length: 0")) { |
|
60 |
throw new AssertionError("Unexpected result[1]: " + result[1]); |
|
61 |
} |
|
62 |
} |
|
63 |
||
64 |
private static void validate() throws Exception { |
|
65 |
int retVal = JPackageHelper.execute(null, app); |
|
66 |
if (retVal != 0) { |
|
67 |
throw new AssertionError( |
|
68 |
"Test application exited with error: " + retVal); |
|
69 |
} |
|
70 |
||
57445
405ddd80496e
8226904: current working directory wrong running jpackage app
herrick
parents:
57414
diff
changeset
|
71 |
File outfile = new File(appOutput); |
57307 | 72 |
if (!outfile.exists()) { |
73 |
throw new AssertionError(appOutput + " was not created"); |
|
74 |
} |
|
75 |
||
76 |
String output = Files.readString(outfile.toPath()); |
|
77 |
String[] result = output.split("\n"); |
|
78 |
validateResult(result); |
|
79 |
} |
|
80 |
||
81 |
private static void validateIcon() throws Exception { |
|
82 |
File origIcon = new File(getIconPath()); |
|
83 |
File icon = new File(JPackagePath.getAppIcon()); |
|
84 |
if (origIcon.length() != icon.length()) { |
|
85 |
System.err.println("origIcon.length(): " + origIcon.length()); |
|
86 |
System.err.println("icon.length(): " + icon.length()); |
|
87 |
throw new AssertionError("Icons size does not match"); |
|
88 |
} |
|
89 |
} |
|
90 |
||
91 |
private static void testIcon() throws Exception { |
|
92 |
JPackageHelper.executeCLI(true, CMD); |
|
93 |
validate(); |
|
94 |
validateIcon(); |
|
95 |
} |
|
96 |
||
97 |
private static void testIconToolProvider() throws Exception { |
|
98 |
JPackageHelper.deleteOutputFolder(OUTPUT); |
|
99 |
JPackageHelper.executeToolProvider(true, CMD); |
|
100 |
validate(); |
|
101 |
validateIcon(); |
|
102 |
} |
|
103 |
||
104 |
private static String getIconPath() { |
|
105 |
String ext = ".ico"; |
|
106 |
if (JPackageHelper.isOSX()) { |
|
107 |
ext = ".icns"; |
|
108 |
} else if (JPackageHelper.isLinux()) { |
|
109 |
ext = ".png"; |
|
110 |
} |
|
111 |
||
112 |
String path = JPackagePath.getTestSrcRoot() + File.separator + "resources" |
|
113 |
+ File.separator + "icon" + ext; |
|
114 |
||
115 |
return path; |
|
116 |
} |
|
117 |
||
118 |
public static void main(String[] args) throws Exception { |
|
119 |
JPackageHelper.createHelloImageJar(); |
|
120 |
testIcon(); |
|
121 |
testIconToolProvider(); |
|
122 |
} |
|
123 |
||
124 |
} |