Skip to content

Commit

Permalink
Minor style cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 7, 2024
1 parent 4bc3e9b commit 0f6af6d
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/test/java/com/fasterxml/aalto/sax/TestSaxWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

import java.io.ByteArrayOutputStream;

public class TestSaxWriter extends base.BaseTestCase {

public void testSurrogateMemory1() throws Exception {
public class TestSaxWriter extends base.BaseTestCase
{
public void testSplitSurrogateWithAttributeValue() throws Exception
{
// This test aims to produce the
// javax.xml.stream.XMLStreamException: Incomplete surrogate pair in content: first char 0xd835, second 0x78
// error message. Before fixing the respective issue, it was provoked by a multi-byte character
Expand All @@ -16,12 +17,13 @@ public void testSurrogateMemory1() throws Exception {
// of the original multi-byte character with the first character in the third buffer because
// ByteXmlWriter#_surrogate was not set back to 0 after writing the original multi-byte character.
StringBuilder testText = new StringBuilder();
for (int i = 0; i < 511; i++)
for (int i = 0; i < 511; i++) {
testText.append('x');
}
testText.append("\uD835\uDFCE");
for (int i = 0; i < 512; i++)
for (int i = 0; i < 512; i++) {
testText.append('x');

}
WriterConfig writerConfig = new WriterConfig();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Utf8XmlWriter writer = new Utf8XmlWriter(writerConfig, byteArrayOutputStream);
Expand All @@ -30,19 +32,20 @@ public void testSurrogateMemory1() throws Exception {
writer.writeStartTagEnd();
writer.writeEndTag(writer.constructName("testelement"));
writer.close(false);

}

public void testSurrogateMemory2() throws Exception {
public void testSplitSurrogateWithAttributeValue2() throws Exception
{
// This test aims to produce the
// java.io.IOException: Unpaired surrogate character (0xd835)
// error message. Before fixing the respective issue, it was provoked by a multi-byte character
// where the first byte was exactly at the end of the internal reading buffer and the next
// reading buffer was enough to write all the remaining data. Then, by the missing reset of
// ByteXmlWriter#_surrogate, the code expected another multi-byte surrogate that never came.
StringBuilder testText = new StringBuilder();
for (int i = 0; i < 511; i++)
for (int i = 0; i < 511; i++) {
testText.append('x');
}
testText.append("\uD835\uDFCE");

WriterConfig writerConfig = new WriterConfig();
Expand All @@ -55,18 +58,21 @@ public void testSurrogateMemory2() throws Exception {
writer.close(false);
}

public void testSurrogateMemory3() throws Exception {
public void testSplitSurrogateWithCData() throws Exception
{
// This test aims to produce the
// javax.xml.stream.XMLStreamException: Incomplete surrogate pair in content: first char 0xdfce, second 0x78
// error message. The issue was similar to the one described in testSurrogateMemory1(), except it happened in
// ByteXmlWriter#writeCDataContents(), where check for existing _surrogate was missing prior to the fix,
// as opposed to ByteXmlWriter#writeCharacters().
StringBuilder testText = new StringBuilder();
for (int i = 0; i < 511; i++)
for (int i = 0; i < 511; i++) {
testText.append('x');
}
testText.append("\uD835\uDFCE");
for (int i = 0; i < 512; i++)
for (int i = 0; i < 512; i++) {
testText.append('x');
}

WriterConfig writerConfig = new WriterConfig();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Expand All @@ -76,7 +82,5 @@ public void testSurrogateMemory3() throws Exception {
writer.writeStartTagEnd();
writer.writeEndTag(writer.constructName("testelement"));
writer.close(false);

}

}

0 comments on commit 0f6af6d

Please sign in to comment.