/* * Copyright (c) 2007, 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 * @bug 5030265 8260265 * @modules jdk.compiler * jdk.zipfs * @compile -XDignore.symbol.file UnicodeTest.java * @run main/othervm UnicodeTest * @summary Verify that the J2RE can handle all legal Unicode characters * in class names unless limited by the file system encoding * or the encoding used for command line arguments. * @author Norbert Lindenberg, ksrini
*/
/* * This class creates Java source files using Unicode characters * that test the limits of what's possible * - in situations where the platform encoding imposes limits * (command line arguments, non-Unicode file system) * - in situations where full Unicode is supported * (file system access in UTF-8 locales and on Windows 2000++, * jar file contents) * * This test needs to be run in othervm as the locale is reset.
*/
publicclass UnicodeTest extends TestHelper { staticfinal File UnicodeTestSrc = new File("UnicodeTest-src"); staticfinal File UnicodeTestClasses = new File("UnicodeTest-classes"); staticfinal String UnicodeTestJarName = "UnicodeTest" + JAR_FILE_EXT; staticfinal File UnicodeTestJar = new File(UnicodeTestJarName); staticfinal File SolarisUnicodeTestJar = new File(TEST_SOURCES_DIR,
UnicodeTestJarName);
/* * the main method is a port of the shell based test to a java, this * eliminates the need for MKS on windows, thus we can rely on consistent * results regardless of the shell being used.
*/ publicstaticvoid main(String... args) throws Exception {
System.out.println("creating test source files");
UnicodeTestSrc.mkdirs();
UnicodeTestClasses.mkdirs();
String classname = generateSources();
File javaFile = new File(UnicodeTestSrc, classname + JAVA_FILE_EXT);
System.out.println("building test apps");
compile("-encoding", "UTF-8", "-sourcepath", UnicodeTestSrc.getAbsolutePath(), "-d", UnicodeTestClasses.getAbsolutePath(),
javaFile.getAbsolutePath());
createJar("-cvfm", UnicodeTestJar.getAbsolutePath(), new File(UnicodeTestSrc, "MANIFEST.MF").getAbsolutePath(), "-C", UnicodeTestClasses.getAbsolutePath(), ".");
if (!UnicodeTestJar.exists()) { thrownew Error("failed to create " + UnicodeTestJar.getAbsolutePath());
}
System.out.println("running test app using class file");
TestResult tr = doExec(javaCmd, "-cp", UnicodeTestClasses.getAbsolutePath(), classname); if (!tr.isOK()) {
System.out.println(tr); thrownew RuntimeException("test fails");
}
System.out.println("delete generated files with non-ASCII names");
recursiveDelete(UnicodeTestSrc);
recursiveDelete(UnicodeTestClasses);
/* * test in whatever the default locale is
*/
runJarTests();
/* * if the Japanese locale is available, test in that locale as well
*/ if (setLocale(Locale.JAPANESE)) {
runJarTests();
}
/* * if we can switch to a C locale, then test whether jar files with * non-ASCII characters in the manifest still work in this crippled * environment
*/ if (setLocale(Locale.ENGLISH)) {
runJarTests();
} // thats it we are outta here
}
staticvoid runJarTests() {
System.out.println("running test app using newly built jar file in " +
Locale.getDefault());
runTest(UnicodeTestJar);
System.out.println("running test app using jar file " + "(built with Solaris UTF-8 locale) in " + Locale.getDefault());
runTest(SolarisUnicodeTestJar);
}
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.