Skip to content

Commit 19dfb94

Browse files
committed
Add failing test for #42
1 parent d69eeba commit 19dfb94

File tree

8 files changed

+106
-13
lines changed

8 files changed

+106
-13
lines changed

src/test/java/failing/TestBasicSax.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public void testCData() throws Exception
3636
int cdatas = handler.getCDATASectionCount();
3737
int segments = handler.getSegmentCount();
3838

39-
assertEquals("Should only get a single CDATA segments, got "+cdatas+" (for "+segments+" text segments)", 1, cdatas);
39+
assertEquals("Should only get a single CDATA segments, got "+cdatas+" (for "+segments+" text segments)",
40+
1, cdatas);
4041
}
4142

4243
/*
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package failing;
2+
3+
import javax.xml.stream.XMLInputFactory;
4+
import javax.xml.stream.XMLStreamException;
5+
import javax.xml.stream.events.XMLEvent;
6+
7+
import org.codehaus.stax2.XMLEventReader2;
8+
9+
import com.ctc.wstx.api.WstxInputProperties;
10+
11+
import wstxtest.stream.BaseStreamTest;
12+
13+
public class TestParsingModeForEvents
14+
extends BaseStreamTest
15+
{
16+
final static String XML_MULTI_DOC =
17+
"<?xml version='1.0'?><root>text</root><!--comment-->\n"
18+
+"<?xml version='1.0'?><root>text</root>\n"
19+
+"<?xml version='1.0' standalone='yes'?><root>text</root><?proc instr><!--comment-->"
20+
+"<?xml version='1.0'?><root>text</root><!--comment-->"
21+
;
22+
23+
// [woodstox-core#42]
24+
public void testMultiDocumentWithEventReader() throws XMLStreamException
25+
{
26+
XMLInputFactory f = getInputFactory();
27+
setCoalescing(f, true);
28+
f.setProperty(WstxInputProperties.P_INPUT_PARSING_MODE, WstxInputProperties.PARSING_MODE_DOCUMENTS);
29+
XMLEventReader2 er = constructEventReader(f, XML_MULTI_DOC);
30+
31+
_checkEventDoc(er, 0);
32+
_checkEventDoc(er, 1);
33+
_checkEventDoc(er, 2);
34+
_checkEventDoc(er, 3);
35+
36+
// and then the end
37+
assertFalse(er.hasNextEvent());
38+
}
39+
40+
private void _checkEventDoc(XMLEventReader2 er, int seq) throws XMLStreamException
41+
{
42+
if (!er.hasNextEvent()) {
43+
fail("No more events: should start document #"+seq+" in multi-doc mode");
44+
}
45+
XMLEvent event;
46+
assertTokenType(START_DOCUMENT, er.nextEvent());
47+
assertTokenType(START_ELEMENT, (event = er.nextEvent()));
48+
assertEquals("root", event.asStartElement().getName().getLocalPart());
49+
assertTokenType(CHARACTERS, (event = er.nextEvent()));
50+
assertEquals("text", event.asCharacters().getData());
51+
assertTokenType(END_ELEMENT, (event = er.nextEvent()));
52+
assertEquals("root", event.asEndElement().getName().getLocalPart());
53+
54+
// may get other types
55+
while (true) {
56+
event = er.nextEvent();
57+
switch (event.getEventType()) {
58+
case END_DOCUMENT:
59+
return;
60+
case PROCESSING_INSTRUCTION:
61+
case COMMENT:
62+
break;
63+
default:
64+
fail("Unexpected XMLEvent after document: "+event);
65+
}
66+
}
67+
}
68+
}

src/test/java/failing/TestW3CSchemaComplexTypes.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ public class TestW3CSchemaComplexTypes
1414
{
1515
/**
1616
* For problem with MSV: https://github.com/kohsuke/msv/issues/2
17-
*
17+
*
18+
* 29-Mar-2018, tatu: Oddly enough, problem itself allegedly resolved...
1819
*/
19-
public void testGithubIssue2() throws Exception
20+
public void testMSVGithubIssue2() throws Exception
2021
{
2122
XMLValidationSchema schema = parseW3CSchema(
2223
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:tns='http://MySchema' elementFormDefault='qualified' targetNamespace='http://MySchema' version='1.0'>"

src/test/java/failing/W3CSchemaWriteTest.java renamed to src/test/java/stax2/vwstream/W3CSchemaWrite16Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package failing;
1+
package stax2.vwstream;
22

33
import java.io.StringWriter;
44

@@ -9,7 +9,7 @@
99
import wstxtest.vstream.BaseValidationTest;
1010

1111
// for [woodstox-core#16]
12-
public class W3CSchemaWriteTest
12+
public class W3CSchemaWrite16Test
1313
extends BaseValidationTest
1414
{
1515
final static String SIMPLE_WRITE_SCHEMA =

src/test/java/stax2/vwstream/WriteValidate23Test.java renamed to src/test/java/stax2/vwstream/W3CSchemaWrite23Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.codehaus.stax2.XMLStreamReader2;
66
import org.codehaus.stax2.XMLStreamWriter2;
77

8-
public class WriteValidate23Test
8+
public class W3CSchemaWrite23Test
99
extends BaseOutputTest
1010
{
1111
public void testSchemaValidatingCopy23() throws Exception

src/test/java/wstxtest/BaseWstxTest.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.HashMap;
55

66
import javax.xml.stream.*;
7+
import javax.xml.stream.events.XMLEvent;
78

89
import org.codehaus.stax2.*;
910
import org.codehaus.stax2.evt.*;
@@ -253,9 +254,8 @@ protected int streamThrough(XMLStreamReader sr)
253254
int type = sr.next();
254255
result += type;
255256
if (sr.hasText()) {
256-
/* will also do basic verification for text content, to
257-
* see that all text accessor methods return same content
258-
*/
257+
// will also do basic verification for text content, to
258+
// see that all text accessor methods return same content
259259
result += getAndVerifyText(sr).hashCode();
260260
}
261261
if (sr.hasName()) {
@@ -352,6 +352,26 @@ protected static void assertTokenType(int expType, int actType)
352352
}
353353
}
354354

355+
protected static void assertTokenType(int expType, XMLEvent event)
356+
{
357+
if (event == null) {
358+
fail("Expected event of type "+tokenTypeDesc(expType)+"; got `null`");
359+
}
360+
int actType = event.getEventType();
361+
if (expType != actType) {
362+
String expStr = tokenTypeDesc(expType);
363+
String actStr = tokenTypeDesc(actType);
364+
365+
if (expStr == null) {
366+
expStr = ""+expType;
367+
}
368+
if (actStr == null) {
369+
actStr = ""+actType;
370+
}
371+
fail("Expected token "+expStr+"; got "+actStr+".");
372+
}
373+
}
374+
355375
/**
356376
* Helper assertion that assert that the String is either null or
357377
* empty ("").

src/test/java/wstxtest/stream/TestAttributeLimits.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public void close() throws IOException { }
4545
} catch (XMLStreamException ex) {
4646
verifyException(ex, "Attribute limit (50)");
4747
}
48+
reader.close();
4849
}
4950

5051
public void testLongAttribute() throws Exception {

src/test/java/wstxtest/stream/TestParsingMode.java renamed to src/test/java/wstxtest/stream/TestParsingModeForTokens.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package wstxtest.stream;
22

33
import javax.xml.stream.*;
4+
import javax.xml.stream.events.XMLEvent;
5+
6+
import org.codehaus.stax2.XMLEventReader2;
47

58
import com.ctc.wstx.api.WstxInputProperties;
69

@@ -9,7 +12,7 @@
912
* (set via property {@link WstxInputProperties#P_INPUT_PARSING_MODE})
1013
* behave as expected
1114
*/
12-
public class TestParsingMode
15+
public class TestParsingModeForTokens
1316
extends BaseStreamTest
1417
{
1518
final static String XML_SINGLE_DOC =
@@ -61,8 +64,7 @@ public void testSingleDocumentMode()
6164
"Expected an exception for unbalanced xml content");
6265
}
6366

64-
public void testMultiDocumentMode()
65-
throws XMLStreamException
67+
public void testMultiDocumentMode() throws XMLStreamException
6668
{
6769
// First the main valid case:
6870
streamThroughOk(getReader(XML_MULTI_DOC,
@@ -85,7 +87,7 @@ public void testMultiDocumentMode()
8587

8688
// And broken one not
8789
streamThroughFailing(getReader(XML_UNBALANCED,
88-
WstxInputProperties.PARSING_MODE_DOCUMENTS),
90+
WstxInputProperties.PARSING_MODE_DOCUMENTS),
8991
"Expected an exception for unbalanced xml content");
9092
}
9193

0 commit comments

Comments
 (0)