Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/xml/jaxp/parsers/8072081/SupplementaryChars.java
38861 views
1
/*
2
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import java.io.ByteArrayInputStream;
25
import javax.xml.parsers.SAXParser;
26
import javax.xml.parsers.SAXParserFactory;
27
28
import org.testng.annotations.DataProvider;
29
import org.testng.annotations.Test;
30
import org.xml.sax.SAXParseException;
31
import org.xml.sax.helpers.DefaultHandler;
32
33
/**
34
* @test
35
* @bug 8072081
36
* @summary verifies that supplementary characters are supported as character
37
* data in xml 1.0, and also names in xml 1.1.
38
* @run testng/othervm SupplementaryChars
39
*/
40
/*
41
* Joe Wang ([email protected])
42
*/
43
44
public class SupplementaryChars {
45
46
@Test(dataProvider = "supported")
47
public void test(String xml) throws Exception {
48
ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes("UTF-8"));
49
getParser().parse(stream, new DefaultHandler());
50
stream.close();
51
}
52
53
@Test(dataProvider = "unsupported", expectedExceptions = SAXParseException.class)
54
public void testInvalid(String xml) throws Exception {
55
ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes("UTF-8"));
56
getParser().parse(stream, new DefaultHandler());
57
stream.close();
58
}
59
60
@DataProvider(name = "supported")
61
private Object[][] supported() {
62
63
return new Object[][] {
64
{"<?xml version=\"1.0\"?><tag>\uD840\uDC0B</tag>"},
65
{"<?xml version=\"1.0\"?><!-- \uD840\uDC0B --><tag/>"},
66
{"<?xml version=\"1.1\"?><tag\uD840\uDC0B>in tag name</tag\uD840\uDC0B>"},
67
{"<?xml version=\"1.1\"?><tag attr\uD840\uDC0B=\"in attribute\">in attribute name</tag>"},
68
{"<?xml version=\"1.1\"?><tag>\uD840\uDC0B</tag>"},
69
{"<?xml version=\"1.1\"?><!-- \uD840\uDC0B --><dontCare/>"}
70
};
71
}
72
73
@DataProvider(name = "unsupported")
74
private Object[][] unsupported() {
75
return new Object[][] {
76
{"<?xml version=\"1.0\"?><tag\uD840\uDC0B>in tag name</tag\uD840\uDC0B>"},
77
{"<?xml version=\"1.0\"?><tag attr\uD840\uDC0B=\"in attribute\">in attribute name</tag>"}
78
};
79
}
80
81
private SAXParser getParser() {
82
SAXParser parser = null;
83
try {
84
SAXParserFactory factory = SAXParserFactory.newInstance();
85
parser = factory.newSAXParser();
86
} catch (Exception e) {
87
throw new RuntimeException(e.getMessage());
88
}
89
return parser;
90
}
91
}
92
93