author | herrick |
Tue, 10 Sep 2019 09:18:19 -0400 | |
branch | JDK-8200758-branch |
changeset 58113 | 885b0543f6e4 |
parent 57740 | 9b19a9cd651c |
child 58301 | e0efb29609bd |
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 |
|
57407 | 24 |
import java.nio.file.Path; |
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
25 |
import java.io.InputStream; |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
26 |
import java.io.FileInputStream; |
58113 | 27 |
import java.io.IOException; |
28 |
||
29 |
import jdk.jpackage.internal.IOUtils; |
|
30 |
import jdk.jpackage.test.Test; |
|
31 |
import jdk.jpackage.test.HelloApp; |
|
32 |
import jdk.jpackage.test.JPackageCommand; |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
33 |
|
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
34 |
/* |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
35 |
* @test |
58113 | 36 |
* @summary jpackage with --win-console |
57446 | 37 |
* @library ../helpers |
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
38 |
* @requires (os.family == "windows") |
58113 | 39 |
* @modules jdk.jpackage/jdk.jpackage.internal |
57446 | 40 |
* @run main/othervm -Xmx512m WinConsoleTest |
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
41 |
*/ |
58113 | 42 |
public class WinConsoleTest { |
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
43 |
|
58113 | 44 |
public static void main(String[] args) throws IOException { |
45 |
JPackageCommand cmd = JPackageCommand.helloAppImage(); |
|
46 |
final Path launcherPath = cmd.appImage().resolve( |
|
47 |
cmd.launcherPathInAppImage()); |
|
48 |
||
49 |
IOUtils.deleteRecursive(cmd.outputDir().toFile()); |
|
50 |
cmd.execute().assertExitCodeIsZero(); |
|
51 |
HelloApp.executeAndVerifyOutput(launcherPath); |
|
52 |
checkSubsystem(launcherPath, false); |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
53 |
|
58113 | 54 |
IOUtils.deleteRecursive(cmd.outputDir().toFile()); |
55 |
cmd.addArgument("--win-console").execute().assertExitCodeIsZero(); |
|
56 |
HelloApp.executeAndVerifyOutput(launcherPath); |
|
57 |
checkSubsystem(launcherPath, true); |
|
58 |
} |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
59 |
|
58113 | 60 |
private static void checkSubsystem(Path path, boolean isConsole) throws |
61 |
IOException { |
|
62 |
final int subsystemGui = 2; |
|
63 |
final int subsystemConsole = 3; |
|
64 |
final int bufferSize = 512; |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
65 |
|
58113 | 66 |
final int expectedSubsystem = isConsole ? subsystemConsole : subsystemGui; |
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
67 |
|
57407 | 68 |
try (InputStream inputStream = new FileInputStream(path.toString())) { |
58113 | 69 |
byte[] bytes = new byte[bufferSize]; |
70 |
Test.assertEquals(bufferSize, inputStream.read(bytes), |
|
71 |
String.format("Check %d bytes were read from %s file", |
|
72 |
bufferSize, path)); |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
73 |
|
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
74 |
// Check PE header for console or Win GUI app. |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
75 |
// https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_image_nt_headers |
58113 | 76 |
for (int i = 0; i < (bytes.length - 4); i++) { |
77 |
if (bytes[i] == 0x50 && bytes[i + 1] == 0x45 |
|
78 |
&& bytes[i + 2] == 0x0 && bytes[i + 3] == 0x0) { |
|
57407 | 79 |
|
80 |
// Signature, File Header and subsystem offset. |
|
81 |
i = i + 4 + 20 + 68; |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
82 |
byte subsystem = bytes[i]; |
58113 | 83 |
Test.assertEquals(expectedSubsystem, subsystem, |
84 |
String.format("Check subsystem of PE [%s] file", |
|
85 |
path)); |
|
86 |
return; |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
87 |
} |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
88 |
} |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
89 |
} |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
90 |
|
58113 | 91 |
Test.assertUnexpected(String.format( |
92 |
"Subsystem not found in PE header of [%s] file", path)); |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
93 |
} |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
94 |
} |