1 /*
2 * Copyright (c) 2014, 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 package transform;
25
26 import java.io.ByteArrayInputStream;
27 import java.io.ByteArrayOutputStream;
28
29 import javax.xml.parsers.DocumentBuilderFactory;
30 import javax.xml.transform.Transformer;
31 import javax.xml.transform.TransformerFactory;
32 import javax.xml.transform.dom.DOMSource;
33 import javax.xml.transform.stream.StreamResult;
34
35 import org.testng.Assert;
36 import org.testng.annotations.Test;
37 import org.w3c.dom.Document;
38 import org.w3c.dom.Element;
39
40 /*
41 * @bug 6311448
42 * @summary Test XML transformer can output Unicode surrorate pair.
43 */
44 public class Bug6311448 {
45
46 @Test
47 public void test01() {
48 try {
49 String attrKey = "key";
50 String attrValue = "\ud800\udc00"; // 17-bit code point in UTF-16
51
52 // Some obvious assertions for documentation purposes
53 Assert.assertTrue(Character.isSurrogatePair('\ud800', '\udc00'));
54 Assert.assertTrue(Character.toCodePoint('\ud800', '\udc00') == 65536);
55 Assert.assertTrue(Character.charCount(Character.toCodePoint('\ud800', '\udc00')) == 2);
56
57 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
58 Transformer t = TransformerFactory.newInstance().newTransformer();
59
60 // Create a DOM with 'attrValue' in it
61 Document doc = dbf.newDocumentBuilder().getDOMImplementation().createDocument(null, null, null);
62 Element xmlRoot = doc.createElement("root");
63 xmlRoot.setAttribute(attrKey, attrValue);
|
1 /*
2 * Copyright (c) 2014, 2016, 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 package transform;
25
26 import java.io.ByteArrayInputStream;
27 import java.io.ByteArrayOutputStream;
28
29 import javax.xml.parsers.DocumentBuilderFactory;
30 import javax.xml.transform.Transformer;
31 import javax.xml.transform.TransformerFactory;
32 import javax.xml.transform.dom.DOMSource;
33 import javax.xml.transform.stream.StreamResult;
34
35 import org.testng.Assert;
36 import org.testng.annotations.Listeners;
37 import org.testng.annotations.Test;
38 import org.w3c.dom.Document;
39 import org.w3c.dom.Element;
40
41 /*
42 * @bug 6311448
43 * @summary Test XML transformer can output Unicode surrorate pair.
44 */
45 @Listeners({jaxp.library.BasePolicy.class})
46 public class Bug6311448 {
47
48 @Test
49 public void test01() {
50 try {
51 String attrKey = "key";
52 String attrValue = "\ud800\udc00"; // 17-bit code point in UTF-16
53
54 // Some obvious assertions for documentation purposes
55 Assert.assertTrue(Character.isSurrogatePair('\ud800', '\udc00'));
56 Assert.assertTrue(Character.toCodePoint('\ud800', '\udc00') == 65536);
57 Assert.assertTrue(Character.charCount(Character.toCodePoint('\ud800', '\udc00')) == 2);
58
59 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
60 Transformer t = TransformerFactory.newInstance().newTransformer();
61
62 // Create a DOM with 'attrValue' in it
63 Document doc = dbf.newDocumentBuilder().getDOMImplementation().createDocument(null, null, null);
64 Element xmlRoot = doc.createElement("root");
65 xmlRoot.setAttribute(attrKey, attrValue);
|