/* * Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * @test * @library /test/lib * @build FXLauncherTest jdk.test.lib.compiler.CompilerUtils * @bug 8001533 8004547 8035782 8202553 * @summary Test launching FX application with java -jar * Test uses main method and blank main method, a jfx app class and an incorrect * jfx app class, a main-class for the manifest, a bogus one and none. * Now that FX is no longer bundled with the JDK, this test uses a * "mock" javafx.graphics module to test the FX launcher. It also verifies * that FX is, in fact, not included with the JDK. * All should execute except the incorrect fx app class entries. * @run main/othervm FXLauncherTest
*/ import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List;
/* standard main class can be used as java main for fx app class */ staticfinal String StdMainClass = "helloworld.HelloWorld"; staticfinal String ExtMainClass = "helloworld.ExtHello"; staticfinal String NonFXMainClass = "helloworld.HelloJava"; staticint testcount = 0;
/* * Set Main-Class and iterate main_methods. * Try launching with both -jar and -cp methods, with and without FX main * class manifest entry. * All cases should run. * * See sun.launcher.LauncherHelper$FXHelper for more details on how JavaFX * applications are launched.
*/
@Test staticvoid testBasicFXApp() throws Exception {
testBasicFXApp(true, false); // -cp, no JAC
testBasicFXApp(false, true); // -jar, with JAC
testBasicFXApp(false, false); // -jar, no JAC
}
staticvoid testBasicFXApp(boolean useCP, boolean setFXMainClass) throws Exception {
String testname = "testBasicFXApp"; if (useCP) {
testname = testname.concat("_useCP");
}
String fxMC = StdMainClass; if (!setFXMainClass) {
testname = testname.concat("_noJAC");
fxMC = null;
} for (String mm : MAIN_METHODS) {
testcount++;
line();
System.out.println("test# " + testcount + "- Main method: " + mm);
createJavaFile(mm);
createFile(ManifestFile, createManifestContents(StdMainClass, fxMC));
createJar(FXtestJar, ManifestFile);
String sTestJar = FXtestJar.getAbsolutePath();
String launchMode; final TestResult tr; if (useCP) {
tr = doFxExec(javaCmd, "-cp", sTestJar, StdMainClass, APP_PARMS[0], APP_PARMS[1]);
launchMode = LAUNCH_MODE_CLASS;
} else {
tr = doFxExec(javaCmd, "-jar", sTestJar, APP_PARMS[0], APP_PARMS[1]);
launchMode = LAUNCH_MODE_JAR;
}
tr.checkPositive(); if (tr.testStatus) { if (!tr.contains(launchMode)) {
System.err.println("ERROR: Did not find "
+ launchMode + " in output!");
} for (String p : APP_PARMS) { if (!tr.contains(p)) {
System.err.println("ERROR: Did not find "
+ p + " in output!");
}
}
}
checkStatus(tr, testname, testcount, StdMainClass);
}
}
/* * Set Main-Class and iterate main methods. * Main class extends another class that extends Application. * Try launching with both -jar and -cp methods. * All cases should run.
*/
@Test staticvoid testExtendFXApp() throws Exception {
testExtendFXApp(true, false); // -cp, no JAC
testExtendFXApp(false, true); // -jar, with JAC
testExtendFXApp(false, false); // -jar, no JAC
}
staticvoid testExtendFXApp(boolean useCP, boolean setFXMainClass) throws Exception {
String testname = "testExtendFXApp"; if (useCP) {
testname = testname.concat("_useCP");
}
String fxMC = ExtMainClass; if (!setFXMainClass) {
testname = testname.concat("_noJAC");
fxMC = null;
} for (String mm : MAIN_METHODS) {
testcount++;
line();
System.out.println("test# " + testcount + "- Main method: " + mm);
createJavaFile(mm);
createExtJavaFile(mm);
createFile(ManifestFile, createManifestContents(ExtMainClass, fxMC));
createJar(FXtestJar, ManifestFile);
String sTestJar = FXtestJar.getAbsolutePath();
String launchMode; final TestResult tr; if (useCP) {
tr = doFxExec(javaCmd, "-cp", sTestJar, ExtMainClass, APP_PARMS[0], APP_PARMS[1]);
launchMode = LAUNCH_MODE_CLASS;
} else {
tr = doFxExec(javaCmd, "-jar", sTestJar, APP_PARMS[0], APP_PARMS[1]);
launchMode = LAUNCH_MODE_JAR;
}
tr.checkPositive(); if (tr.testStatus) { if (!tr.contains(launchMode)) {
System.err.println("ERROR: Did not find "
+ launchMode + " in output!");
} for (String p : APP_PARMS) { if (!tr.contains(p)) {
System.err.println("ERROR: Did not find "
+ p + " in output!");
}
}
}
checkStatus(tr, testname, testcount, ExtMainClass);
}
}
/* * Ensure we can NOT launch a FX app jar with no Main-Class manifest entry
*/
@Test staticvoid testMissingMC() throws Exception { if (!isEnglishLocale()) { return;
}
String testname = "testMissingMC";
testcount++;
line();
System.out.println("test# " + testcount + ": abort on missing Main-Class");
createJavaFile(" "); // no main() needed
createFile(ManifestFile, createManifestContents(null, StdMainClass)); // No MC, but supply JAC
createJar(FXtestJar, ManifestFile);
String sTestJar = FXtestJar.getAbsolutePath();
TestResult tr = doFxExec(javaCmd, "-jar", sTestJar, APP_PARMS[0], APP_PARMS[1]);
tr.checkNegative(); // should abort if no Main-Class if (tr.testStatus) { if (!tr.contains("no main manifest attribute")) {
System.err.println("ERROR: launcher did not abort properly");
}
} else {
System.err.println("ERROR: jar executed with no Main-Class!");
}
checkStatus(tr, testname, testcount, StdMainClass);
}
/* * test to ensure that we don't load any extraneous fx jars when * launching a standard java application * Test both -cp and -jar methods since they use different code paths. * Neither case should cause jfxrt.jar to be loaded.
*/
@Test staticvoid testExtraneousJars() throws Exception {
testExtraneousJars(true);
testExtraneousJars(false);
}
if (useCP) {
tr = doFxExec(javaCmd, "-verbose:class", "-cp", sTestJar, NonFXMainClass, APP_PARMS[0], APP_PARMS[1]);
} else {
tr = doFxExec(javaCmd, "-verbose:class", "-jar", sTestJar, APP_PARMS[0], APP_PARMS[1]);
}
tr.checkPositive(); if (tr.testStatus) { if (!tr.notContains("jfxrt.jar")) {
System.out.println("testing for extraneous jfxrt jar");
System.out.println(tr); thrownew Exception("jfxrt.jar is being loaded, it should not be!");
} if (!tr.notContains("sun.launcher.LauncherHelper$FXHelper")) {
System.out.println("testing for extraneous 'sun.launcher.LauncherHelper$FXHelper'");
System.out.println(tr); thrownew Exception("FXHelper is being loaded, it should not be!");
} for (String p : APP_PARMS) { if (!tr.contains(p)) {
System.err.println("ERROR: Did not find "
+ p + " in output!");
}
}
}
checkStatus(tr, testname, testcount, NonFXMainClass);
}
// Ensure that FX is not part of jdk Class<?> fxClass = null; try {
fxClass = Class.forName(FX_MARKER_CLASS);
} catch (ClassNotFoundException ex) { // do nothing
} if (fxClass != null) { thrownew RuntimeException("JavaFX modules erroneously included in the JDK");
}
FXLauncherTest fxt = new FXLauncherTest();
fxt.run(args); if (testExitValue > 0) {
System.out.println("Total of " + testExitValue
+ " failed. Test cases covered: "
+ FXLauncherTest.testcount);
System.exit(1);
} else {
System.out.println("All tests pass. Test cases covered: "
+ FXLauncherTest.testcount);
}
}
}
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.