author | herrick |
Fri, 08 Nov 2019 14:53:03 -0500 | |
branch | JDK-8200758-branch |
changeset 58994 | b09ba68c6a19 |
parent 58648 | 3bf53ffa9ae7 |
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; |
58416 | 28 |
import jdk.jpackage.test.TKit; |
58113 | 29 |
import jdk.jpackage.test.JPackageCommand; |
58416 | 30 |
import jdk.jpackage.test.Annotations.Test; |
31 |
import jdk.jpackage.test.Annotations.Parameter; |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
32 |
|
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 |
* @test |
58113 | 35 |
* @summary jpackage with --win-console |
57446 | 36 |
* @library ../helpers |
58416 | 37 |
* @build jdk.jpackage.test.* |
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
38 |
* @requires (os.family == "windows") |
58994
b09ba68c6a19
8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
58648
diff
changeset
|
39 |
* @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal |
58416 | 40 |
* @compile WinConsoleTest.java |
41 |
* |
|
42 |
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main |
|
43 |
* --jpt-before-run=jdk.jpackage.test.JPackageCommand.useToolProviderByDefault |
|
44 |
* --jpt-run=WinConsoleTest |
|
45 |
* |
|
46 |
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main |
|
47 |
* --jpt-run=WinConsoleTest |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
48 |
*/ |
58113 | 49 |
public class WinConsoleTest { |
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
50 |
|
58416 | 51 |
@Test |
52 |
@Parameter("true") |
|
53 |
@Parameter("false") |
|
54 |
public static void test(boolean withWinConsole) throws IOException { |
|
55 |
JPackageCommand cmd = JPackageCommand.helloAppImage(); |
|
56 |
if (!withWinConsole) { |
|
57 |
cmd.removeArgument("--win-console"); |
|
58 |
} |
|
59 |
cmd.executeAndAssertHelloAppImageCreated(); |
|
58648 | 60 |
checkSubsystem(cmd.appLauncherPath(), withWinConsole); |
58113 | 61 |
} |
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
62 |
|
58113 | 63 |
private static void checkSubsystem(Path path, boolean isConsole) throws |
64 |
IOException { |
|
65 |
final int subsystemGui = 2; |
|
66 |
final int subsystemConsole = 3; |
|
67 |
final int bufferSize = 512; |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
68 |
|
58113 | 69 |
final int expectedSubsystem = isConsole ? subsystemConsole : subsystemGui; |
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
70 |
|
57407 | 71 |
try (InputStream inputStream = new FileInputStream(path.toString())) { |
58113 | 72 |
byte[] bytes = new byte[bufferSize]; |
58416 | 73 |
TKit.assertEquals(bufferSize, inputStream.read(bytes), |
58113 | 74 |
String.format("Check %d bytes were read from %s file", |
75 |
bufferSize, path)); |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
76 |
|
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
77 |
// Check PE header for console or Win GUI app. |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
78 |
// https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_image_nt_headers |
58113 | 79 |
for (int i = 0; i < (bytes.length - 4); i++) { |
80 |
if (bytes[i] == 0x50 && bytes[i + 1] == 0x45 |
|
81 |
&& bytes[i + 2] == 0x0 && bytes[i + 3] == 0x0) { |
|
57407 | 82 |
|
83 |
// Signature, File Header and subsystem offset. |
|
84 |
i = i + 4 + 20 + 68; |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
85 |
byte subsystem = bytes[i]; |
58416 | 86 |
TKit.assertEquals(expectedSubsystem, subsystem, |
58113 | 87 |
String.format("Check subsystem of PE [%s] file", |
88 |
path)); |
|
89 |
return; |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
90 |
} |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
91 |
} |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
92 |
} |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
93 |
|
58416 | 94 |
TKit.assertUnexpected(String.format( |
58113 | 95 |
"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
|
96 |
} |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
97 |
} |