author | herrick |
Tue, 24 Sep 2019 13:41:16 -0400 | |
branch | JDK-8200758-branch |
changeset 58301 | e0efb29609bd |
parent 58113 | 885b0543f6e4 |
child 58416 | f09bf58c1f17 |
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 |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
40 |
* @run main/othervm/timeout=360 -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 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
44 |
public static void main(String[] args) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
45 |
Test.run(args, () -> { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
46 |
JPackageCommand cmd = JPackageCommand.helloAppImage(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
47 |
final Path launcherPath = cmd.appImage().resolve( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
48 |
cmd.launcherPathInAppImage()); |
58113 | 49 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
50 |
IOUtils.deleteRecursive(cmd.outputDir().toFile()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
51 |
cmd.execute().assertExitCodeIsZero(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
52 |
HelloApp.executeLauncherAndVerifyOutput(cmd); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
53 |
checkSubsystem(launcherPath, false); |
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
54 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
55 |
IOUtils.deleteRecursive(cmd.outputDir().toFile()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
56 |
cmd.addArgument("--win-console").execute().assertExitCodeIsZero(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
57 |
HelloApp.executeLauncherAndVerifyOutput(cmd); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
58 |
checkSubsystem(launcherPath, true); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
59 |
}); |
58113 | 60 |
} |
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
61 |
|
58113 | 62 |
private static void checkSubsystem(Path path, boolean isConsole) throws |
63 |
IOException { |
|
64 |
final int subsystemGui = 2; |
|
65 |
final int subsystemConsole = 3; |
|
66 |
final int bufferSize = 512; |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
67 |
|
58113 | 68 |
final int expectedSubsystem = isConsole ? subsystemConsole : subsystemGui; |
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
69 |
|
57407 | 70 |
try (InputStream inputStream = new FileInputStream(path.toString())) { |
58113 | 71 |
byte[] bytes = new byte[bufferSize]; |
72 |
Test.assertEquals(bufferSize, inputStream.read(bytes), |
|
73 |
String.format("Check %d bytes were read from %s file", |
|
74 |
bufferSize, path)); |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
75 |
|
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
76 |
// Check PE header for console or Win GUI app. |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
77 |
// https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_image_nt_headers |
58113 | 78 |
for (int i = 0; i < (bytes.length - 4); i++) { |
79 |
if (bytes[i] == 0x50 && bytes[i + 1] == 0x45 |
|
80 |
&& bytes[i + 2] == 0x0 && bytes[i + 3] == 0x0) { |
|
57407 | 81 |
|
82 |
// Signature, File Header and subsystem offset. |
|
83 |
i = i + 4 + 20 + 68; |
|
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
84 |
byte subsystem = bytes[i]; |
58113 | 85 |
Test.assertEquals(expectedSubsystem, subsystem, |
86 |
String.format("Check subsystem of PE [%s] file", |
|
87 |
path)); |
|
88 |
return; |
|
57405
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 |
} |
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 |
|
58113 | 93 |
Test.assertUnexpected(String.format( |
94 |
"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
|
95 |
} |
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
diff
changeset
|
96 |
} |