1 /*
2 * Copyright (c) 2013, 2015, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
115
116 private final String testAppName;
117 private final String testPldrName;
118 private final boolean headless;
119 private final int testExitCode;
120
121 public MainLauncherTest(TestData testData) {
122 this.testAppName = testData.appName;
123 this.testPldrName = testData.pldrName;
124 this.headless = testData.headless;
125 this.testExitCode = testData.exitCode;
126 }
127
128 @Test (timeout=5000)
129 public void testMainLauncher() throws Exception {
130 if (headless) {
131 // Headless tests currently only run on Linux
132 assumeTrue(PlatformUtil.isLinux());
133 }
134
135 final String classpath = System.getProperty("java.class.path");
136 ProcessBuilder builder;
137 if (testPldrName != null) {
138 builder = new ProcessBuilder("java", "-cp", classpath,
139 "-Djavafx.preloader=" + testPldrName, testAppName);
140 } else {
141 builder = new ProcessBuilder("java", "-cp", classpath, testAppName);
142 }
143 if (headless) {
144 // Set DISPLAY variable to empty to run in headless mode on Linux
145 builder.environment().put("DISPLAY", "");
146 }
147 builder.redirectError(ProcessBuilder.Redirect.INHERIT);
148 builder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
149 Process process = builder.start();
150 int retVal = process.waitFor();
151 switch (retVal) {
152 case 0:// SUCCESS
153 case ERROR_NONE:
154 if (retVal != testExitCode) {
155 throw new AssertionFailedError(testAppName
156 + ": Unexpected 'success' exit; expected:"
157 + testExitCode + " was:" + retVal);
158 }
159 return;
160 case 1:
161 throw new AssertionFailedError(testAppName
162 + ": unable to launch java application");
|
1 /*
2 * Copyright (c) 2013, 2016, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
115
116 private final String testAppName;
117 private final String testPldrName;
118 private final boolean headless;
119 private final int testExitCode;
120
121 public MainLauncherTest(TestData testData) {
122 this.testAppName = testData.appName;
123 this.testPldrName = testData.pldrName;
124 this.headless = testData.headless;
125 this.testExitCode = testData.exitCode;
126 }
127
128 @Test (timeout=5000)
129 public void testMainLauncher() throws Exception {
130 if (headless) {
131 // Headless tests currently only run on Linux
132 assumeTrue(PlatformUtil.isLinux());
133 }
134
135 final ArrayList<String> cmd =
136 test.util.Util.createApplicationLaunchCommand(
137 testAppName,
138 testPldrName,
139 null
140 );
141
142 final ProcessBuilder builder = new ProcessBuilder(cmd);
143
144 if (headless) {
145 // Set DISPLAY variable to empty to run in headless mode on Linux
146 builder.environment().put("DISPLAY", "");
147 }
148 builder.redirectError(ProcessBuilder.Redirect.INHERIT);
149 builder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
150 Process process = builder.start();
151 int retVal = process.waitFor();
152 switch (retVal) {
153 case 0:// SUCCESS
154 case ERROR_NONE:
155 if (retVal != testExitCode) {
156 throw new AssertionFailedError(testAppName
157 + ": Unexpected 'success' exit; expected:"
158 + testExitCode + " was:" + retVal);
159 }
160 return;
161 case 1:
162 throw new AssertionFailedError(testAppName
163 + ": unable to launch java application");
|