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 dom;
25
26 import java.io.IOException;
27 import java.io.StringReader;
28
29 import javax.xml.parsers.DocumentBuilder;
30 import javax.xml.parsers.DocumentBuilderFactory;
31 import javax.xml.parsers.ParserConfigurationException;
32
33 import org.testng.Assert;
34 import org.testng.annotations.Test;
35 import org.w3c.dom.Document;
36 import org.xml.sax.InputSource;
37 import org.xml.sax.SAXException;
38
39 /*
40 * @summary Test Document.getInputEncoding().
41 */
42 public class TCKEncodingTest {
43
44 /**
45 * Assertion testing
46 * for public String getInputEncoding(),
47 * An attribute specifying the actual encoding of this document..
48 */
49 @Test
50 public void testGetInputEncoding001() {
51 String data = "<?xml version=\"1.0\"?>" + "<!DOCTYPE root [" + "<!ELEMENT root ANY>" + "]>" + "<root/>";
52
53 Document doc = null;
54 try {
55 DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
56 InputSource inSource = new InputSource(new StringReader(data));
57 inSource.setEncoding("UTF-8");
58 inSource.setSystemId("test.xml");
59 doc = docBuilder.parse(inSource);
60 } catch (ParserConfigurationException e) {
61 Assert.fail(e.toString());
|
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 dom;
25
26 import java.io.IOException;
27 import java.io.StringReader;
28
29 import javax.xml.parsers.DocumentBuilder;
30 import javax.xml.parsers.DocumentBuilderFactory;
31 import javax.xml.parsers.ParserConfigurationException;
32
33 import org.testng.Assert;
34 import org.testng.annotations.Listeners;
35 import org.testng.annotations.Test;
36 import org.w3c.dom.Document;
37 import org.xml.sax.InputSource;
38 import org.xml.sax.SAXException;
39
40 /*
41 * @summary Test Document.getInputEncoding().
42 */
43 @Listeners({jaxp.library.BasePolicy.class})
44 public class TCKEncodingTest {
45
46 /**
47 * Assertion testing
48 * for public String getInputEncoding(),
49 * An attribute specifying the actual encoding of this document..
50 */
51 @Test
52 public void testGetInputEncoding001() {
53 String data = "<?xml version=\"1.0\"?>" + "<!DOCTYPE root [" + "<!ELEMENT root ANY>" + "]>" + "<root/>";
54
55 Document doc = null;
56 try {
57 DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
58 InputSource inSource = new InputSource(new StringReader(data));
59 inSource.setEncoding("UTF-8");
60 inSource.setSystemId("test.xml");
61 doc = docBuilder.parse(inSource);
62 } catch (ParserConfigurationException e) {
63 Assert.fail(e.toString());
|