77
88public class TestSaxWriter extends base .BaseTestCase
99{
10+ private final String TEXT_WITH_SURROGATE ;
11+ {
12+ StringBuilder testText = new StringBuilder (1025 );
13+ for (int i = 0 ; i < 511 ; i ++) {
14+ testText .append ('x' );
15+ }
16+ testText .append ("\uD835 \uDFCE " );
17+ for (int i = 0 ; i < 512 ; i ++) {
18+ testText .append ('x' );
19+ }
20+ TEXT_WITH_SURROGATE = testText .toString ();
21+ }
22+
1023 public void testSplitSurrogateWithAttributeValue () throws Exception
1124 {
1225 // This test aims to produce the
@@ -16,19 +29,11 @@ public void testSplitSurrogateWithAttributeValue() throws Exception
1629 // to also fill the next two internal reading buffers. Then, the code would try to fuse the first byte
1730 // of the original multi-byte character with the first character in the third buffer because
1831 // ByteXmlWriter#_surrogate was not set back to 0 after writing the original multi-byte character.
19- StringBuilder testText = new StringBuilder ();
20- for (int i = 0 ; i < 511 ; i ++) {
21- testText .append ('x' );
22- }
23- testText .append ("\uD835 \uDFCE " );
24- for (int i = 0 ; i < 512 ; i ++) {
25- testText .append ('x' );
26- }
2732 WriterConfig writerConfig = new WriterConfig ();
2833 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ();
2934 Utf8XmlWriter writer = new Utf8XmlWriter (writerConfig , byteArrayOutputStream );
3035 writer .writeStartTagStart (writer .constructName ("testelement" ));
31- writer .writeAttribute (writer .constructName ("testattr" ), testText . toString () );
36+ writer .writeAttribute (writer .constructName ("testattr" ), TEXT_WITH_SURROGATE );
3237 writer .writeStartTagEnd ();
3338 writer .writeEndTag (writer .constructName ("testelement" ));
3439 writer .close (false );
@@ -61,43 +66,37 @@ public void testSplitSurrogateWithAttributeValue2() throws Exception
6166 public void testSplitSurrogateWithCData () throws Exception
6267 {
6368 // Modification of "testSplitSurrogateWithAttributeValue()" but for CDATA
64- StringBuilder testText = new StringBuilder ();
65- for (int i = 0 ; i < 511 ; i ++) {
66- testText .append ('x' );
67- }
68- testText .append ("\uD835 \uDFCE " );
69- for (int i = 0 ; i < 512 ; i ++) {
70- testText .append ('x' );
71- }
72-
7369 WriterConfig writerConfig = new WriterConfig ();
7470 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ();
7571 Utf8XmlWriter writer = new Utf8XmlWriter (writerConfig , byteArrayOutputStream );
7672 writer .writeStartTagStart (writer .constructName ("testelement" ));
77- writer .writeCData (testText . toString () );
73+ writer .writeCData (TEXT_WITH_SURROGATE );
7874 writer .writeStartTagEnd ();
7975 writer .writeEndTag (writer .constructName ("testelement" ));
8076 writer .close (false );
8177 }
8278
83-
8479 public void testSplitSurrogateWithComment () throws Exception
8580 {
8681 // Modification of "testSplitSurrogateWithAttributeValue()" but for Comment
87- StringBuilder testText = new StringBuilder ();
88- for (int i = 0 ; i < 511 ; i ++) {
89- testText .append ('x' );
90- }
91- testText .append ("\uD835 \uDFCE " );
92- for (int i = 0 ; i < 512 ; i ++) {
93- testText .append ('x' );
94- }
82+ WriterConfig writerConfig = new WriterConfig ();
83+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ();
84+ Utf8XmlWriter writer = new Utf8XmlWriter (writerConfig , byteArrayOutputStream );
85+ writer .writeStartTagStart (writer .constructName ("testelement" ));
86+ writer .writeComment (TEXT_WITH_SURROGATE );
87+ writer .writeStartTagEnd ();
88+ writer .writeEndTag (writer .constructName ("testelement" ));
89+ writer .close (false );
90+ }
9591
92+ public void testSplitSurrogateWithPI () throws Exception
93+ {
94+ // Modification of "testSplitSurrogateWithAttributeValue()" but for Processing instructions
9695 WriterConfig writerConfig = new WriterConfig ();
9796 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ();
9897 Utf8XmlWriter writer = new Utf8XmlWriter (writerConfig , byteArrayOutputStream );
9998 writer .writeStartTagStart (writer .constructName ("testelement" ));
100- writer .writeComment ( testText . toString () );
99+ writer .writePI ( writer . constructName ( "target" ), TEXT_WITH_SURROGATE );
101100 writer .writeStartTagEnd ();
102101 writer .writeEndTag (writer .constructName ("testelement" ));
103102 writer .close (false );
0 commit comments