7
7
8
8
public class TestSaxWriter extends base .BaseTestCase
9
9
{
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
+
10
23
public void testSplitSurrogateWithAttributeValue () throws Exception
11
24
{
12
25
// This test aims to produce the
@@ -16,19 +29,11 @@ public void testSplitSurrogateWithAttributeValue() throws Exception
16
29
// to also fill the next two internal reading buffers. Then, the code would try to fuse the first byte
17
30
// of the original multi-byte character with the first character in the third buffer because
18
31
// 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
- }
27
32
WriterConfig writerConfig = new WriterConfig ();
28
33
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ();
29
34
Utf8XmlWriter writer = new Utf8XmlWriter (writerConfig , byteArrayOutputStream );
30
35
writer .writeStartTagStart (writer .constructName ("testelement" ));
31
- writer .writeAttribute (writer .constructName ("testattr" ), testText . toString () );
36
+ writer .writeAttribute (writer .constructName ("testattr" ), TEXT_WITH_SURROGATE );
32
37
writer .writeStartTagEnd ();
33
38
writer .writeEndTag (writer .constructName ("testelement" ));
34
39
writer .close (false );
@@ -61,43 +66,37 @@ public void testSplitSurrogateWithAttributeValue2() throws Exception
61
66
public void testSplitSurrogateWithCData () throws Exception
62
67
{
63
68
// 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
-
73
69
WriterConfig writerConfig = new WriterConfig ();
74
70
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ();
75
71
Utf8XmlWriter writer = new Utf8XmlWriter (writerConfig , byteArrayOutputStream );
76
72
writer .writeStartTagStart (writer .constructName ("testelement" ));
77
- writer .writeCData (testText . toString () );
73
+ writer .writeCData (TEXT_WITH_SURROGATE );
78
74
writer .writeStartTagEnd ();
79
75
writer .writeEndTag (writer .constructName ("testelement" ));
80
76
writer .close (false );
81
77
}
82
78
83
-
84
79
public void testSplitSurrogateWithComment () throws Exception
85
80
{
86
81
// 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
+ }
95
91
92
+ public void testSplitSurrogateWithPI () throws Exception
93
+ {
94
+ // Modification of "testSplitSurrogateWithAttributeValue()" but for Processing instructions
96
95
WriterConfig writerConfig = new WriterConfig ();
97
96
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ();
98
97
Utf8XmlWriter writer = new Utf8XmlWriter (writerConfig , byteArrayOutputStream );
99
98
writer .writeStartTagStart (writer .constructName ("testelement" ));
100
- writer .writeComment ( testText . toString () );
99
+ writer .writePI ( writer . constructName ( "target" ), TEXT_WITH_SURROGATE );
101
100
writer .writeStartTagEnd ();
102
101
writer .writeEndTag (writer .constructName ("testelement" ));
103
102
writer .close (false );
0 commit comments