jdk/test/tools/launcher/FXLauncherTest.java
author prr
Tue, 01 Jul 2014 10:20:56 -0700
changeset 25211 2476da7d73bf
parent 24254 2da866863b98
child 30371 aa862dad6ad9
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
     1
/*
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
     4
 *
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
     7
 * published by the Free Software Foundation.
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
     8
 *
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    13
 * accompanied this code).
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    14
 *
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    18
 *
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    21
 * questions.
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    22
 */
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    23
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    24
/*
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    25
 * @test
24254
2da866863b98 8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents: 20201
diff changeset
    26
 * @bug 8001533 8004547 8035782
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    27
 * @summary Test launching FX application with java -jar
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    28
 * Test uses main method and blank main method, a jfx app class and an incorrest
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    29
 * jfx app class, a main-class for the manifest, a bogus one and none.
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    30
 * All should execute except the incorrect fx app class entries.
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    31
 * @run main FXLauncherTest
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    32
 */
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    33
import java.io.File;
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    34
import java.io.IOException;
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    35
import java.util.ArrayList;
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    36
import java.util.List;
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    37
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    38
public class FXLauncherTest extends TestHelper {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    39
    private static final String FX_MARKER_CLASS = "javafx.application.Application";
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    40
    private static void line() {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    41
        System.out.println("_____________________________________________");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    42
    }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    43
    private static File MainJavaFile = null;
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    44
    private static final File FXtestJar =  new File("fxtest.jar");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    45
    private static final File ManifestFile = new File("manifest.txt");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    46
    private static final File ScratchDir = new File(".");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    47
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    48
    /* standard main class can be used as java main for fx app class */
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    49
    static final String StdMainClass = "helloworld.HelloWorld";
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
    50
    static final String ExtMainClass = "helloworld.ExtHello";
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
    51
    static final String NonFXMainClass = "helloworld.HelloJava";
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    52
    static int testcount = 0;
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    53
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    54
    /* a main method and a blank. */
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    55
    static final String[] MAIN_METHODS = {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    56
        "public static void main(String[] args) { launch(args); }",
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    57
        " "
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    58
    };
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    59
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    60
    // Array of parameters to pass to fx application.
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    61
    static final String[] APP_PARMS = { "one", "two" };
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    62
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    63
    // Create fx java file for test application
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    64
    static void createJavaFile(String mainmethod) {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    65
        try {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    66
            String mainClass = "HelloWorld";
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    67
            List<String> contents = new ArrayList<>();
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    68
            contents.add("package helloworld;");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    69
            contents.add("import javafx.application.Application;");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    70
            contents.add("import javafx.event.ActionEvent;");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    71
            contents.add("import javafx.event.EventHandler;");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    72
            contents.add("import javafx.scene.Scene;");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    73
            contents.add("import javafx.scene.control.Button;");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    74
            contents.add("import javafx.scene.layout.StackPane;");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    75
            contents.add("import javafx.stage.Stage;");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    76
            contents.add("public class HelloWorld extends Application {");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    77
            contents.add(mainmethod);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    78
            contents.add("@Override");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    79
            contents.add("public void start(Stage primaryStage) {");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    80
            contents.add("    primaryStage.setTitle(\"Hello World!\");");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    81
            contents.add("    Button btn = new Button();");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    82
            contents.add("    btn.setText(\"Say 'Hello World'\");");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    83
            contents.add("    btn.setOnAction(new EventHandler<ActionEvent>() {");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    84
            contents.add("        @Override");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    85
            contents.add("        public void handle(ActionEvent event) {");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    86
            contents.add("            System.out.println(\"Hello World!\");");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    87
            contents.add("        }");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    88
            contents.add("    });");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    89
            contents.add("    StackPane root = new StackPane();");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    90
            contents.add("    root.getChildren().add(btn);");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    91
            contents.add("    primaryStage.setScene(new Scene(root, 300, 250));");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    92
            contents.add("//    primaryStage.show(); no GUI for auto tests. ");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    93
            contents.add("    System.out.println(\"HelloWorld.primaryStage.show();\");");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    94
            contents.add("    System.out.println(\"Parameters:\");" );
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    95
            contents.add("    for(String p : getParameters().getUnnamed())");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    96
            contents.add("        System.out.println(\"parameter: \" + p );" );
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    97
            contents.add("    System.exit(0);");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    98
            contents.add("}");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
    99
            contents.add("}");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   100
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   101
            // Create and compile java source.
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   102
            MainJavaFile = new File(mainClass + JAVA_FILE_EXT);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   103
            createFile(MainJavaFile, contents);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   104
            compile("-d", ".", mainClass + JAVA_FILE_EXT);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   105
        } catch (java.io.IOException ioe) {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   106
            ioe.printStackTrace();
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   107
            throw new RuntimeException("Failed creating HelloWorld.");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   108
        }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   109
    }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   110
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   111
    /*
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   112
     * Create class that extends HelloWorld instead of Application
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   113
     */
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   114
    static void createExtJavaFile(String mainmethod) {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   115
        try {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   116
            String mainClass = "ExtHello";
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   117
            List<String> contents = new ArrayList<>();
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   118
            contents.add("package helloworld;");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   119
            contents.add("public class ExtHello extends HelloWorld {");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   120
            contents.add(mainmethod);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   121
            contents.add("}");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   122
            // Create and compile java source.
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   123
            MainJavaFile = new File(mainClass + JAVA_FILE_EXT);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   124
            createFile(MainJavaFile, contents);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   125
            compile("-cp", ".", "-d", ".", mainClass + JAVA_FILE_EXT);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   126
        } catch (java.io.IOException ioe) {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   127
            ioe.printStackTrace();
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   128
            throw new RuntimeException("Failed creating ExtHello.");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   129
        }
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   130
    }
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   131
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   132
    /*
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   133
     * Create non-JavaFX class for testing if jfxrt.jar is being loaded
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   134
     * when it shouldn't be
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   135
     */
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   136
    static void createNonFXJavaFile() {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   137
        try {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   138
            String mainClass = "HelloJava";
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   139
            List<String> contents = new ArrayList<>();
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   140
            contents.add("package helloworld;");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   141
            contents.add("public class HelloJava {");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   142
            contents.add("    public static void main(String[] args) {");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   143
            contents.add("        for(String aa : args)");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   144
            contents.add("            System.out.println(\"arg: \" + aa);" );
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   145
            contents.add("    }");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   146
            contents.add("}");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   147
            // Create and compile java source.
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   148
            MainJavaFile = new File(mainClass + JAVA_FILE_EXT);
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   149
            createFile(MainJavaFile, contents);
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   150
            compile("-cp", ".", "-d", ".", mainClass + JAVA_FILE_EXT);
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   151
        } catch (java.io.IOException ioe) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   152
            ioe.printStackTrace();
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   153
            throw new RuntimeException("Failed creating HelloJava.");
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   154
        }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   155
    }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   156
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   157
    // Create manifest for test fx application
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   158
    static List<String> createManifestContents(String mainClassEntry, String fxMainEntry) {
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   159
        List<String> mcontents = new ArrayList<>();
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   160
        mcontents.add("Manifest-Version: 1.0");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   161
        mcontents.add("Created-By: FXLauncherTest");
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   162
        if (mainClassEntry != null) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   163
            mcontents.add("Main-Class: " + mainClassEntry);
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   164
            System.out.println("Main-Class: " + mainClassEntry);
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   165
        }
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   166
        if (fxMainEntry != null) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   167
            mcontents.add("JavaFX-Application-Class: " + fxMainEntry);
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   168
            System.out.println("JavaFX-Application-Class: " + fxMainEntry);
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   169
        }
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   170
        return mcontents;
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   171
    }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   172
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   173
    // Method to marshal createJar to TestHelper.createJar()
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   174
    static void createJar(File theJar, File manifestFile) {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   175
        createJar("cvmf", manifestFile.getName(),
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   176
                  theJar.getAbsolutePath(), "helloworld");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   177
    }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   178
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   179
    static void saveFile(String tname, int testcount, File srcFile) {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   180
        File newFile = new File(tname + "-" + testcount + "-" + srcFile.getName());
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   181
        System.out.println("renaming " + srcFile.getName() +
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   182
                           " to " + newFile.getName());
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   183
        srcFile.renameTo(newFile);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   184
    }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   185
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   186
    static void cleanupFiles() throws IOException {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   187
        for(File f : ScratchDir.listFiles()) {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   188
            recursiveDelete(f);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   189
        }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   190
    }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   191
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   192
    static void checkStatus(TestResult tr, String testName, int testCount,
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   193
                            String mainclass) throws Exception {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   194
        if (tr.testStatus) {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   195
            System.out.println("PASS: " + testName + ":" + testCount +
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   196
                               " : test with " + mainclass);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   197
            cleanupFiles();
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   198
        } else {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   199
            saveFile(testName, testcount, FXtestJar);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   200
            System.out.println("FAIL: " + testName + ":" + testCount +
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   201
                               " : test with " + mainclass);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   202
            cleanupFiles();
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   203
            System.err.println(tr);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   204
            throw new Exception("Failed: " + testName + ":" + testCount);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   205
        }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   206
    }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   207
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   208
    /*
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   209
     * Set Main-Class and iterate main_methods.
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   210
     * Try launching with both -jar and -cp methods, with and without FX main
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   211
     * class manifest entry.
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   212
     * All cases should run.
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   213
     *
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   214
     * See sun.launcher.LauncherHelper$FXHelper for more details on how JavaFX
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   215
     * applications are launched.
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   216
     */
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   217
    @Test
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   218
    static void testBasicFXApp() throws Exception {
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   219
        testBasicFXApp(true, false);    // -cp, no JAC
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   220
        testBasicFXApp(false, true);    // -jar, with JAC
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   221
        testBasicFXApp(false, false);   // -jar, no JAC
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   222
    }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   223
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   224
    static void testBasicFXApp(boolean useCP, boolean setFXMainClass) throws Exception {
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   225
        String testname = "testBasicFXApp";
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   226
        if (useCP) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   227
            testname = testname.concat("_useCP");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   228
        }
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   229
        String fxMC = StdMainClass;
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   230
        if (!setFXMainClass) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   231
            testname = testname.concat("_noJAC");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   232
            fxMC = null;
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   233
        }
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   234
        for (String mm : MAIN_METHODS) {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   235
            testcount++;
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   236
            line();
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   237
            System.out.println("test# " + testcount + "-  Main method: " + mm);
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   238
            createJavaFile(mm);
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   239
            createFile(ManifestFile, createManifestContents(StdMainClass, fxMC));
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   240
            createJar(FXtestJar, ManifestFile);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   241
            String sTestJar = FXtestJar.getAbsolutePath();
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   242
            TestResult tr;
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   243
            if (useCP) {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   244
                tr = doExec(javaCmd, "-cp", sTestJar, StdMainClass, APP_PARMS[0], APP_PARMS[1]);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   245
            } else {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   246
                tr = doExec(javaCmd, "-jar", sTestJar, APP_PARMS[0], APP_PARMS[1]);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   247
            }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   248
            tr.checkPositive();
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   249
            if (tr.testStatus && tr.contains("HelloWorld.primaryStage.show()")) {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   250
                for (String p : APP_PARMS) {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   251
                    if (!tr.contains(p)) {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   252
                        System.err.println("ERROR: Did not find "
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   253
                                + p + " in output!");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   254
                    }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   255
                }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   256
            }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   257
            checkStatus(tr, testname, testcount, StdMainClass);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   258
        }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   259
    }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   260
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   261
    /*
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   262
     * Set Main-Class and iterate main methods.
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   263
     * Main class extends another class that extends Application.
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   264
     * Try launching with both -jar and -cp methods.
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   265
     * All cases should run.
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   266
     */
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   267
    @Test
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   268
    static void testExtendFXApp() throws Exception {
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   269
        testExtendFXApp(true, false);   // -cp, no JAC
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   270
        testExtendFXApp(false, true);   // -jar, with JAC
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   271
        testExtendFXApp(false, false);  // -jar, no JAC
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   272
    }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   273
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   274
    static void testExtendFXApp(boolean useCP, boolean setFXMainClass) throws Exception {
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   275
        String testname = "testExtendFXApp";
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   276
        if (useCP) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   277
            testname = testname.concat("_useCP");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   278
        }
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   279
        String fxMC = ExtMainClass;
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   280
        if (!setFXMainClass) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   281
            testname = testname.concat("_noJAC");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   282
            fxMC = null;
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   283
        }
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   284
        for (String mm : MAIN_METHODS) {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   285
            testcount++;
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   286
            line();
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   287
            System.out.println("test# " + testcount + "-  Main method: " + mm);
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   288
            createJavaFile(mm);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   289
            createExtJavaFile(mm);
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   290
            createFile(ManifestFile, createManifestContents(ExtMainClass, fxMC));
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   291
            createJar(FXtestJar, ManifestFile);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   292
            String sTestJar = FXtestJar.getAbsolutePath();
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   293
            TestResult tr;
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   294
            if (useCP) {
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   295
                tr = doExec(javaCmd, "-cp", sTestJar, ExtMainClass, APP_PARMS[0], APP_PARMS[1]);
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   296
            } else {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   297
                tr = doExec(javaCmd, "-jar", sTestJar, APP_PARMS[0], APP_PARMS[1]);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   298
            }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   299
            tr.checkPositive();
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   300
            if (tr.testStatus && tr.contains("HelloWorld.primaryStage.show()")) {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   301
                for (String p : APP_PARMS) {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   302
                    if (!tr.contains(p)) {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   303
                        System.err.println("ERROR: Did not find "
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   304
                                + p + " in output!");
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   305
                    }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   306
                }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   307
            }
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   308
            checkStatus(tr, testname, testcount, ExtMainClass);
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   309
        }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   310
    }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   311
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   312
    /*
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   313
     * Ensure we can NOT launch a FX app jar with no Main-Class manifest entry
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   314
     */
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   315
    @Test
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   316
    static void testMissingMC() throws Exception {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   317
        String testname = "testMissingMC";
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   318
        testcount++;
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   319
        line();
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   320
        System.out.println("test# " + testcount + ": abort on missing Main-Class");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   321
        createJavaFile(" "); // no main() needed
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   322
        createFile(ManifestFile, createManifestContents(null, StdMainClass)); // No MC, but supply JAC
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   323
        createJar(FXtestJar, ManifestFile);
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   324
        String sTestJar = FXtestJar.getAbsolutePath();
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   325
        TestResult tr = doExec(javaCmd, "-jar", sTestJar, APP_PARMS[0], APP_PARMS[1]);
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   326
        tr.checkNegative(); // should abort if no Main-Class
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   327
        if (tr.testStatus) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   328
            if (!tr.contains("no main manifest attribute")) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   329
                System.err.println("ERROR: launcher did not abort properly");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   330
            }
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   331
        } else {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   332
            System.err.println("ERROR: jar executed with no Main-Class!");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   333
        }
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   334
        checkStatus(tr, testname, testcount, StdMainClass);
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   335
    }
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   336
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   337
    /*
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   338
     * test to ensure that we don't load any extraneous fx jars when
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   339
     * launching a standard java application
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   340
     * Test both -cp and -jar methods since they use different code paths.
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   341
     * Neither case should cause jfxrt.jar to be loaded.
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   342
     */
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   343
    @Test
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   344
    static void testExtraneousJars() throws Exception {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   345
        testExtraneousJars(true);
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   346
        testExtraneousJars(false);
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   347
    }
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   348
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   349
    static void testExtraneousJars(boolean useCP) throws Exception {
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   350
        String testname = "testExtraneousJars";
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   351
        if (useCP) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   352
            testname = testname.concat("_useCP");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   353
        }
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   354
        testcount++;
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   355
        line();
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   356
        System.out.println("test# " + testcount
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   357
                + ": test for erroneous jfxrt.jar loading");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   358
        createNonFXJavaFile();
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   359
        createFile(ManifestFile, createManifestContents(NonFXMainClass, null));
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   360
        createJar(FXtestJar, ManifestFile);
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   361
        String sTestJar = FXtestJar.getAbsolutePath();
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   362
        TestResult tr;
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   363
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   364
        if (useCP) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   365
            tr = doExec(javaCmd, "-verbose:class", "-cp", sTestJar, NonFXMainClass, APP_PARMS[0], APP_PARMS[1]);
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   366
        } else {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   367
            tr = doExec(javaCmd, "-verbose:class", "-jar", sTestJar, APP_PARMS[0], APP_PARMS[1]);
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   368
        }
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   369
        tr.checkPositive();
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   370
        if (tr.testStatus) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   371
            if (!tr.notContains("jfxrt.jar")) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   372
                System.out.println("testing for extraneous jfxrt jar");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   373
                System.out.println(tr);
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   374
                throw new Exception("jfxrt.jar is being loaded, it should not be!");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   375
            }
24254
2da866863b98 8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents: 20201
diff changeset
   376
            if (!tr.notContains("sun.launcher.LauncherHelper$FXHelper")) {
2da866863b98 8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents: 20201
diff changeset
   377
                System.out.println("testing for extraneous 'sun.launcher.LauncherHelper$FXHelper'");
2da866863b98 8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents: 20201
diff changeset
   378
                System.out.println(tr);
2da866863b98 8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents: 20201
diff changeset
   379
                throw new Exception("FXHelper is being loaded, it should not be!");
2da866863b98 8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents: 20201
diff changeset
   380
            }
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   381
            for (String p : APP_PARMS) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   382
                if (!tr.contains(p)) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   383
                    System.err.println("ERROR: Did not find "
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   384
                            + p + " in output!");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   385
                }
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   386
            }
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   387
        }
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14519
diff changeset
   388
        checkStatus(tr, testname, testcount, NonFXMainClass);
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   389
    }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   390
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   391
    public static void main(String... args) throws Exception {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   392
        //check if fx is part of jdk
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   393
        Class<?> fxClass = null;
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   394
        try {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   395
            fxClass = Class.forName(FX_MARKER_CLASS);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   396
        } catch (ClassNotFoundException ex) {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   397
            // do nothing
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   398
        }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   399
        if (fxClass != null) {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   400
            FXLauncherTest fxt = new FXLauncherTest();
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   401
            fxt.run(args);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   402
            if (testExitValue > 0) {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   403
                System.out.println("Total of " + testExitValue
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   404
                        + " failed. Test cases covered: "
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   405
                        + FXLauncherTest.testcount);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   406
                System.exit(1);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   407
            } else {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   408
                System.out.println("All tests pass. Test cases covered: "
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   409
                        + FXLauncherTest.testcount);
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   410
            }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   411
        } else {
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   412
            System.err.println("Warning: JavaFX components missing or not supported");
20201
50cc2d25a60b 8020552: [launcher] changes to support removal of Solaris 32-bit distribution
ksrini
parents: 15003
diff changeset
   413
            System.err.println("         test passes vacuously.");
14519
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   414
         }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   415
    }
73d8a1fdacd6 8003660: (launcher) 8001533 regression tests
ksrini
parents:
diff changeset
   416
}