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