Skip to content

Commit c1e0e84

Browse files
authored
Merge pull request #11 from apache/XALANJ-2725
Xalanj 2725
2 parents 6650237 + 9d999c2 commit c1e0e84

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

java/src/org/apache/qetest/trax/ToStreamTest.java

+14
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ protected String outputCharacters(ToStream stream, String input) throws SAXExcep
9090
return writer.getBuffer().toString();
9191
}
9292

93+
protected String outputCharacters(ToStream stream, String input, final int bufLength) throws SAXException {
94+
StringWriter writer = new StringWriter();
95+
stream.setOmitXMLDeclaration(true);
96+
stream.setWriter(writer);
97+
char[] chars = new char[bufLength];
98+
for(int i = 0; i < input.length(); i+=bufLength) {
99+
int length = ( i + bufLength > input.length() ? input.length() - i : bufLength );
100+
input.getChars(i, i + length, chars, 0);
101+
stream.characters(chars, 0, length);
102+
}
103+
stream.flushPending();
104+
return writer.getBuffer().toString();
105+
}
106+
93107
protected String outputAttrValue(ToStream stream, String input) throws SAXException, IOException {
94108
StringWriter writer = new StringWriter();
95109
stream.setOmitXMLDeclaration(true);

java/src/org/apache/qetest/trax/ToXMLStreamTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ public boolean testCase1() throws SAXException, IOException
8888

8989
String actual4 = outputCharacters(makeStream("UTF-8"), utf16String);
9090
reporter.check(actual4, utf16String, "Astral characters should come out unscathed");
91+
String actual4b = outputCharacters(makeStream("UTF-8"), utf16String, utf16String.length() - 1);
92+
reporter.check(actual4b, utf16String, "Astral characters should come out unscathed (in split buffer)");
9193
String actual4a = outputAttrValue(makeStream("UTF-8"), utf16String);
9294
reporter.check(actual4a, utf16String, "Astral characters should come out unscathed (as attribute value)");
9395

@@ -103,7 +105,7 @@ public boolean testCase1() throws SAXException, IOException
103105
*/
104106
public boolean testCase2() throws SAXException, IOException
105107
{
106-
reporter.testCaseInit("Verify setting output properties individually or whole blocks.");
108+
reporter.testCaseInit("Verify handling of ISO-8859-1 encoding in ToStream");
107109

108110
String actual1 = outputCharacters(makeStream("ISO-8859-1"), "abc");
109111
reporter.check(actual1, "abc", "Simple characters should come out unscathed");
@@ -142,7 +144,7 @@ public boolean testCase2() throws SAXException, IOException
142144
*/
143145
public boolean testCase3() throws SAXException, IOException
144146
{
145-
reporter.testCaseInit("Verify setting output properties individually or whole blocks.");
147+
reporter.testCaseInit("Verify handling of ASCII encoding in ToStream");
146148

147149
String actual1 = outputCharacters(makeStream("ASCII"), "abc");
148150
reporter.check(actual1, "abc", "Simple characters should come out unscathed");

0 commit comments

Comments
 (0)