Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/xml/jaxp/parsers/8072081/SupplementaryChars.java
38861 views
/*1* Copyright (c) 2015, 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.ByteArrayInputStream;24import javax.xml.parsers.SAXParser;25import javax.xml.parsers.SAXParserFactory;2627import org.testng.annotations.DataProvider;28import org.testng.annotations.Test;29import org.xml.sax.SAXParseException;30import org.xml.sax.helpers.DefaultHandler;3132/**33* @test34* @bug 807208135* @summary verifies that supplementary characters are supported as character36* data in xml 1.0, and also names in xml 1.1.37* @run testng/othervm SupplementaryChars38*/39/*40* Joe Wang ([email protected])41*/4243public class SupplementaryChars {4445@Test(dataProvider = "supported")46public void test(String xml) throws Exception {47ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes("UTF-8"));48getParser().parse(stream, new DefaultHandler());49stream.close();50}5152@Test(dataProvider = "unsupported", expectedExceptions = SAXParseException.class)53public void testInvalid(String xml) throws Exception {54ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes("UTF-8"));55getParser().parse(stream, new DefaultHandler());56stream.close();57}5859@DataProvider(name = "supported")60private Object[][] supported() {6162return new Object[][] {63{"<?xml version=\"1.0\"?><tag>\uD840\uDC0B</tag>"},64{"<?xml version=\"1.0\"?><!-- \uD840\uDC0B --><tag/>"},65{"<?xml version=\"1.1\"?><tag\uD840\uDC0B>in tag name</tag\uD840\uDC0B>"},66{"<?xml version=\"1.1\"?><tag attr\uD840\uDC0B=\"in attribute\">in attribute name</tag>"},67{"<?xml version=\"1.1\"?><tag>\uD840\uDC0B</tag>"},68{"<?xml version=\"1.1\"?><!-- \uD840\uDC0B --><dontCare/>"}69};70}7172@DataProvider(name = "unsupported")73private Object[][] unsupported() {74return new Object[][] {75{"<?xml version=\"1.0\"?><tag\uD840\uDC0B>in tag name</tag\uD840\uDC0B>"},76{"<?xml version=\"1.0\"?><tag attr\uD840\uDC0B=\"in attribute\">in attribute name</tag>"}77};78}7980private SAXParser getParser() {81SAXParser parser = null;82try {83SAXParserFactory factory = SAXParserFactory.newInstance();84parser = factory.newSAXParser();85} catch (Exception e) {86throw new RuntimeException(e.getMessage());87}88return parser;89}90}919293