Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javah/constMacroTest/ConstMacroTest.java
38813 views
/*1* Copyright (c) 2013, 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*/2223/*24* @test25* @bug 4786406 4781221 4780341 621432426* @summary Validates rewritten javah handling of class defined constants and27* ensures that the appropriate macro definitions are placed in the generated28* header file.29* @library /tools/javac/lib30* @build ToolBox31* @run main ConstMacroTest32*/3334import java.io.*;35import java.nio.file.Paths;3637//original test: test/tools/javah/ConstMacroTest.sh38public class ConstMacroTest {3940private static final String subClassConstsGoldenFileTemplate =41"/* DO NOT EDIT THIS FILE - it is machine generated */\n" +42"#include <jni.h>\n" +43"/* Header for class SubClassConsts */\n" +44"\n" +45"#ifndef _Included_SubClassConsts\n" +46"#define _Included_SubClassConsts\n" +47"#ifdef __cplusplus\n" +48"extern \"C\" {\n" +49"#endif\n" +50"#undef SubClassConsts_serialVersionUID\n" +51"#define SubClassConsts_serialVersionUID 6733861379283244755%s\n" +52"#undef SubClassConsts_SUPER_INT_CONSTANT\n" +53"#define SubClassConsts_SUPER_INT_CONSTANT 3L\n" +54"#undef SubClassConsts_SUPER_FLOAT_CONSTANT\n" +55"#define SubClassConsts_SUPER_FLOAT_CONSTANT 99.3f\n" +56"#undef SubClassConsts_SUPER_DOUBLE_CONSTANT\n" +57"#define SubClassConsts_SUPER_DOUBLE_CONSTANT 33.2\n" +58"#undef SubClassConsts_SUPER_BOOLEAN_CONSTANT\n" +59"#define SubClassConsts_SUPER_BOOLEAN_CONSTANT 0L\n" +60"#undef SubClassConsts_SUB_INT_CONSTANT\n" +61"#define SubClassConsts_SUB_INT_CONSTANT 2L\n" +62"#undef SubClassConsts_SUB_DOUBLE_CONSTANT\n" +63"#define SubClassConsts_SUB_DOUBLE_CONSTANT 2.25\n" +64"#undef SubClassConsts_SUB_FLOAT_CONSTANT\n" +65"#define SubClassConsts_SUB_FLOAT_CONSTANT 7.9f\n" +66"#undef SubClassConsts_SUB_BOOLEAN_CONSTANT\n" +67"#define SubClassConsts_SUB_BOOLEAN_CONSTANT 1L\n" +68"#ifdef __cplusplus\n" +69"}\n" +70"#endif\n" +71"#endif";7273private static final String serialVersionUIDSuffix =74ToolBox.isWindows() ? "i64" : "LL"; ;7576public static void main(String[] args) throws Exception {77//first steps are now done by jtreg78// cp "${TESTSRC}${FS}SuperClassConsts.java" .79// cp "${TESTSRC}${FS}SubClassConsts.java" .8081// "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d . "${TESTSRC}${FS}SubClassConsts.java"8283// "${TESTJAVA}${FS}bin${FS}javah" ${TESTTOOLVMOPTS} SubClassConsts84ToolBox.JavaToolArgs successParams =85new ToolBox.JavaToolArgs()86.setAllArgs("-cp", System.getProperty("test.classes"), "SubClassConsts");87ToolBox.javah(successParams);8889// diff ${DIFFOPTS} "${TESTSRC}${FS}${EXPECTED_JAVAH_OUT_FILE}" "${GENERATED_HEADER_FILE}"90String subClassConstGoldenFile = String.format(subClassConstsGoldenFileTemplate,91serialVersionUIDSuffix);92ToolBox.compareLines(Paths.get("SubClassConsts.h"),93ToolBox.splitLines(subClassConstGoldenFile, "\n"), null, true);94}9596}9798class SuperClassConsts implements Serializable {99// Define class constant values, base class is serializable100private static final long serialVersionUID = 6733861379283244755L;101public static final int SUPER_INT_CONSTANT = 3;102public final static float SUPER_FLOAT_CONSTANT = 99.3f;103public final static double SUPER_DOUBLE_CONSTANT = 33.2;104public final static boolean SUPER_BOOLEAN_CONSTANT = false;105// A token instance field106int instanceField;107108public native int numValues();109}110111class SubClassConsts extends SuperClassConsts {112private final static int SUB_INT_CONSTANT = 2;113private final static double SUB_DOUBLE_CONSTANT = 2.25;114private final static float SUB_FLOAT_CONSTANT = 7.90f;115private final static boolean SUB_BOOLEAN_CONSTANT = true;116}117118119