< prev index next >

test/javax/xml/jaxp/unittest/parsers/Bug6341770.java

Print this page

        

*** 26,35 **** --- 26,36 ---- import static jaxp.library.JAXPTestUtilities.tryRunWithTmpPermission; import java.io.File; import java.io.FileWriter; import java.io.PrintWriter; + import java.nio.charset.Charset; import java.util.PropertyPermission; import javax.xml.parsers.SAXParserFactory; import org.testng.Assert;
*** 51,62 **** public class Bug6341770 { // naming a file "aux" would fail on windows. @Test public void testNonAsciiURI() { try { ! File dir = new File("sko\u0159ice"); dir.delete(); dir.mkdir(); File main = new File(dir, "main.xml"); PrintWriter w = new PrintWriter(new FileWriter(main)); w.println("<!DOCTYPE r [<!ENTITY aux SYSTEM \"aux1.xml\">]>"); --- 52,69 ---- public class Bug6341770 { // naming a file "aux" would fail on windows. @Test public void testNonAsciiURI() { + if (!isNonAsciiSupported()) { + // @bug 8167478 + // if it doesn't support non-ascii, the following test is invalid even if test is passed. + System.out.println("Current environment doesn't support non-ascii, exit the test."); + return; + } try { ! File dir = new File(alpha); dir.delete(); dir.mkdir(); File main = new File(dir, "main.xml"); PrintWriter w = new PrintWriter(new FileWriter(main)); w.println("<!DOCTYPE r [<!ENTITY aux SYSTEM \"aux1.xml\">]>");
*** 80,85 **** --- 87,101 ---- e.printStackTrace(); Assert.fail("Exception: " + e.getMessage()); } System.out.println("OK."); } + + private boolean isNonAsciiSupported() { + // if equals method returns true, the non-ascii character information was not lost in this environment + return alpha.equals(Charset.defaultCharset().decode(Charset.defaultCharset().encode(alpha)).toString()); + } + + // Select alpha because it's a very common non-ascii character in different charsets. + // That this test can run in as many as possible environments if it's possible. + private static final String alpha = "\u03b1"; }
< prev index next >