author | herrick |
Fri, 14 Jun 2019 12:04:12 -0400 | |
branch | JDK-8200758-branch |
changeset 57407 | 2c14fbeff1dc |
parent 57405 | 539d8b3f9e1e |
child 57414 | 6eda749d3117 |
permissions | -rw-r--r-- |
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
1 |
/* |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
4 |
* |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
8 |
* |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
13 |
* accompanied this code). |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
14 |
* |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
18 |
* |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
21 |
* questions. |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
22 |
*/ |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
23 |
|
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
24 |
import java.io.IOException; |
57407 | 25 |
import java.nio.file.Path; |
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
26 |
import java.io.InputStream; |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
27 |
import java.io.FileInputStream; |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
28 |
|
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
29 |
/* |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
30 |
* @test |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
31 |
* @summary jpackage create image win console test |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
32 |
* @library ../../helpers |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
33 |
* @library ../ |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
34 |
* @build JPackageHelper |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
35 |
* @build JPackagePath |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
36 |
* @build JPackageCreateAppImageBase |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
37 |
* @requires (os.family == "windows") |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
38 |
* @modules jdk.jpackage |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
39 |
* @run main/othervm -Xmx512m JPackageCreateAppImageWinConsoleTest |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
40 |
*/ |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
41 |
|
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
42 |
public class JPackageCreateAppImageWinConsoleTest { |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
43 |
private static final String NAME = "test"; |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
44 |
private static final String OUTPUT = "output"; |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
45 |
private static final String OUTPUT_WIN_CONSOLE = "outputWinConsole"; |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
46 |
private static final int BUFFER_SIZE = 512; |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
47 |
private static final int GUI_SUBSYSTEM = 2; |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
48 |
private static final int CONSOLE_SUBSYSTEM = 3; |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
49 |
|
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
50 |
private static final String [] CMD = { |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
51 |
"create-app-image", |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
52 |
"--input", "input", |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
53 |
"--output", OUTPUT, |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
54 |
"--name", NAME, |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
55 |
"--main-jar", "hello.jar", |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
56 |
"--main-class", "Hello", |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
57 |
}; |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
58 |
|
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
59 |
private static final String [] CMD_WIN_CONSOLE = { |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
60 |
"create-app-image", |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
61 |
"--input", "input", |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
62 |
"--output", OUTPUT_WIN_CONSOLE, |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
63 |
"--name", NAME, |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
64 |
"--main-jar", "hello.jar", |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
65 |
"--main-class", "Hello", |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
66 |
"--win-console" |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
67 |
}; |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
68 |
|
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
69 |
private static void checkSubsystem(boolean console) throws Exception { |
57407 | 70 |
Path path = Path.of(console ? OUTPUT_WIN_CONSOLE : OUTPUT, |
71 |
NAME, "bin", NAME + ".exe"); |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
72 |
|
57407 | 73 |
System.out.println("validate path: " + path.toString()); |
74 |
JPackageCreateAppImageBase.validate(path.toString()); |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
75 |
|
57407 | 76 |
try (InputStream inputStream = new FileInputStream(path.toString())) { |
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
77 |
byte [] bytes = new byte[BUFFER_SIZE]; |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
78 |
if (inputStream.read(bytes) != BUFFER_SIZE) { |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
79 |
throw new AssertionError("Wrong number of bytes read"); |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
80 |
} |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
81 |
|
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
82 |
// Check PE header for console or Win GUI app. |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
83 |
// https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_image_nt_headers |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
84 |
for (int i = 0; i < (bytes.length - 4); i++) { |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
85 |
if (bytes[i] == 0x50 && bytes[i + 1] == 0x45 && |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
86 |
bytes[i + 2] == 0x0 && bytes[i + 3] == 0x0) { |
57407 | 87 |
|
88 |
// Signature, File Header and subsystem offset. |
|
89 |
i = i + 4 + 20 + 68; |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
90 |
byte subsystem = bytes[i]; |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
91 |
if (console) { |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
92 |
if (subsystem != CONSOLE_SUBSYSTEM) { |
57407 | 93 |
throw new AssertionError("Unexpected subsystem: " |
94 |
+ subsystem); |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
95 |
} else { |
57407 | 96 |
return; |
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
97 |
} |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
98 |
} else { |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
99 |
if (subsystem != GUI_SUBSYSTEM) { |
57407 | 100 |
throw new AssertionError("Unexpected subsystem: " |
101 |
+ subsystem); |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
102 |
} else { |
57407 | 103 |
return; |
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
104 |
} |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
105 |
} |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
106 |
} |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
107 |
} |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
108 |
} |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
109 |
|
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
110 |
throw new AssertionError("Unable to verify PE header"); |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
111 |
} |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
112 |
|
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
113 |
private static void validate() throws Exception { |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
114 |
checkSubsystem(false); |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
115 |
checkSubsystem(true); |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
116 |
} |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
117 |
|
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
118 |
private static void testCreateAppImage(String [] cmd) throws Exception { |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
119 |
JPackageHelper.executeCLI(true, cmd); |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
120 |
} |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
121 |
|
57407 | 122 |
private static void testCreateAppImageToolProvider(String [] cmd) |
123 |
throws Exception { |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
124 |
JPackageHelper.executeToolProvider(true, cmd); |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
125 |
} |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
126 |
|
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
127 |
public static void main(String[] args) throws Exception { |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
128 |
JPackageHelper.createHelloImageJar(); |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
129 |
testCreateAppImage(CMD); |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
130 |
testCreateAppImage(CMD_WIN_CONSOLE); |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
131 |
validate(); |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
132 |
JPackageHelper.deleteOutputFolder(OUTPUT); |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
133 |
JPackageHelper.deleteOutputFolder(OUTPUT_WIN_CONSOLE); |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
134 |
testCreateAppImageToolProvider(CMD); |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
135 |
testCreateAppImageToolProvider(CMD_WIN_CONSOLE); |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
136 |
validate(); |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
137 |
} |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
138 |
} |