Path: blob/master/test/jdk/tools/launcher/TestXcheckJNIWarnings.java
41144 views
/*1* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.File;24import java.io.IOException;2526/**27* @test28* @bug 818744229* @summary Launching app shouldn't produce any jni warnings.30* @modules jdk.compiler31* jdk.zipfs32* @compile TestXcheckJNIWarnings.java33* @run main TestXcheckJNIWarnings34*/35public final class TestXcheckJNIWarnings extends TestHelper {3637static void createJarFile(File testJar) throws IOException {38StringBuilder tsrc = new StringBuilder();39tsrc.append("public static void main(String... args) {\n");40tsrc.append(" System.out.println(\"Hello World\");\n");41tsrc.append("}\n");42createJar(testJar, new File("Foo"), tsrc.toString());43}4445public static void main(String... args) throws IOException {46File testJarFile = new File("test.jar");47createJarFile(testJarFile);48TestResult tr = doExec(javaCmd, "-jar", "-Xcheck:jni",49testJarFile.getName());50if (!tr.isOK()) {51System.out.println(tr);52throw new RuntimeException("test returned non-positive value");53}54if (!tr.contains("Hello World")) {55System.out.println(tr);56throw new RuntimeException("expected output not found");57}58if (tr.contains("WARNING")) {59System.out.println(tr);60throw new RuntimeException("WARNING was found in the output");61}62}63}646566