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/stream/8153781/SkipDTDTest.java
38861 views
1
/*
2
* Copyright (c) 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
import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
25
import java.io.StringReader;
26
import javax.xml.stream.XMLEventReader;
27
import javax.xml.stream.XMLInputFactory;
28
import javax.xml.stream.XMLStreamException;
29
import javax.xml.stream.events.XMLEvent;
30
import org.testng.Assert;
31
import org.testng.annotations.Test;
32
33
/*
34
* @test
35
* @bug 8153781
36
* @run testng/othervm SkipDTDTest
37
* @summary Test if method skipDTD of class XMLDTDScannerImpl will correctly skip the DTD section,
38
* even if a call to XMLEntityScanner.scanData for skipping to the closing ']' returns true.
39
*/
40
public class SkipDTDTest {
41
public static int DOCTYPE_SECTION_LENGTH = XMLEntityManager.DEFAULT_BUFFER_SIZE * 2;
42
public static int DOCUMENT_LENGTH = DOCTYPE_SECTION_LENGTH + 4096;
43
44
public String createXMLDocument(int doctypeoffset) {
45
StringBuilder xmlcontentbuilder = new StringBuilder(DOCUMENT_LENGTH);
46
xmlcontentbuilder.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n");
47
xmlcontentbuilder.append("<!DOCTYPE dummy [\r\n");
48
xmlcontentbuilder.append(" <!ELEMENT dummy EMPTY>\r\n");
49
xmlcontentbuilder.append(" <!--\r\n");
50
int doctypelines = DOCTYPE_SECTION_LENGTH / 3;
51
for (int i = 0; i < doctypeoffset; i++)
52
xmlcontentbuilder.append('a');
53
for (int i = 0; i < doctypelines; i++)
54
xmlcontentbuilder.append("a\r\n");
55
xmlcontentbuilder.append(" -->\r\n");
56
xmlcontentbuilder.append(" ]\r\n");
57
xmlcontentbuilder.append(">\r\n");
58
xmlcontentbuilder.append("<dummy>\r\n");
59
xmlcontentbuilder.append("</dummy>\r\n");
60
System.out.println("Document length:" + xmlcontentbuilder.length());
61
return xmlcontentbuilder.toString();
62
}
63
64
public void runReader(XMLInputFactory factory, int offset) throws XMLStreamException {
65
StringReader stringReader = new StringReader(createXMLDocument(offset));
66
XMLEventReader reader = factory.createXMLEventReader(stringReader);
67
68
while (reader.hasNext()) {
69
XMLEvent event = reader.nextEvent();
70
System.out.println("Event Type: " + event.getEventType());
71
}
72
}
73
74
@Test
75
public void test() {
76
try {
77
XMLInputFactory factory = XMLInputFactory.newInstance();
78
factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
79
for (int i = 0; i < 3; i++) {
80
runReader(factory, i);
81
}
82
} catch (XMLStreamException xe) {
83
xe.printStackTrace();
84
Assert.fail(xe.getMessage());
85
}
86
}
87
}
88
89