1
1
package com .fasterxml .jackson .dataformat .cbor .failing ;
2
2
3
+ import java .nio .charset .StandardCharsets ;
4
+
3
5
import com .fasterxml .jackson .core .JsonParser ;
4
6
import com .fasterxml .jackson .core .JsonToken ;
5
7
import com .fasterxml .jackson .databind .ObjectMapper ;
6
8
import com .fasterxml .jackson .dataformat .cbor .CBORTestBase ;
7
9
10
+ // For [dataformats-binary#312]: null handling
8
11
public class SymbolTable312Test extends CBORTestBase
9
12
{
10
13
private final ObjectMapper MAPPER = cborMapper ();
11
14
12
- // [dataformats-binary#312]: null handling
13
- public void testNullHandling () throws Exception
15
+ public void testNullHandling1Quad () throws Exception
14
16
{
15
- final String FIELD1 = " \u0000 " ;
16
- final String FIELD2 = FIELD1 + FIELD1 ;
17
- final String FIELD3 = FIELD2 + FIELD1 ;
17
+ _testNullHandling ( 1 ) ;
18
+ _testNullHandling ( 2 ) ;
19
+ }
18
20
19
- final String QUOTED_NULL = "\\ u0000" ;
21
+ public void testNullHandling2Quads () throws Exception
22
+ {
23
+ _testNullHandling (5 );
24
+ _testNullHandling (6 );
25
+ }
26
+
27
+ public void testNullHandling3Quads () throws Exception
28
+ {
29
+ _testNullHandling (9 );
30
+ _testNullHandling (10 );
31
+ }
32
+
33
+ public void testNullHandlingNQuads () throws Exception
34
+ {
35
+ _testNullHandling (13 );
36
+ _testNullHandling (14 );
37
+ _testNullHandling (17 );
38
+ _testNullHandling (18 );
39
+ _testNullHandling (21 );
40
+ }
41
+
42
+ public void _testNullHandling (int minNulls ) throws Exception
43
+ {
44
+ final String FIELD1 = _nulls (minNulls );
45
+ final String FIELD2 = _nulls (minNulls +1 );
46
+ final String FIELD3 = _nulls (minNulls +2 );
47
+ final String FIELD4 = _nulls (minNulls +3 );
48
+ final String FIELD5 = _nulls (minNulls +4 );
20
49
21
- final String SRC = a2q (String .format ("{'%s':'a','%s':'b','%s':'c'}" ,
22
- QUOTED_NULL , QUOTED_NULL +QUOTED_NULL , QUOTED_NULL +QUOTED_NULL +QUOTED_NULL ));
50
+ final String SRC = a2q (String .format ("{'%s':'a','%s':'b','%s':'c','%s':'d','%s':'e'}" ,
51
+ _quotedNulls (minNulls ),
52
+ _quotedNulls (minNulls +1 ),
53
+ _quotedNulls (minNulls +2 ),
54
+ _quotedNulls (minNulls +3 ),
55
+ _quotedNulls (minNulls +4 )));
23
56
byte [] DOC = cborDoc (SRC );
24
57
25
58
try (JsonParser p = MAPPER .createParser (DOC )) {
@@ -40,13 +73,35 @@ public void testNullHandling() throws Exception
40
73
assertToken (JsonToken .VALUE_STRING , p .nextToken ());
41
74
assertEquals ("c" , p .getText ());
42
75
76
+ assertToken (JsonToken .FIELD_NAME , p .nextToken ());
77
+ _assertNullStrings (FIELD4 , p .currentName ());
78
+ assertToken (JsonToken .VALUE_STRING , p .nextToken ());
79
+ assertEquals ("d" , p .getText ());
80
+
81
+ assertToken (JsonToken .FIELD_NAME , p .nextToken ());
82
+ _assertNullStrings (FIELD5 , p .currentName ());
83
+ assertToken (JsonToken .VALUE_STRING , p .nextToken ());
84
+ assertEquals ("e" , p .getText ());
85
+
43
86
assertToken (JsonToken .END_OBJECT , p .nextToken ());
44
87
}
45
88
}
46
89
90
+ private String _nulls (int len ) {
91
+ return new String (new byte [len ], StandardCharsets .US_ASCII );
92
+ }
93
+
94
+ private String _quotedNulls (int len ) {
95
+ StringBuilder sb = new StringBuilder ();
96
+ while (--len >= 0 ) {
97
+ sb .append ("\\ u0000" );
98
+ }
99
+ return sb .toString ();
100
+ }
101
+
47
102
private void _assertNullStrings (String exp , String actual ) {
48
103
if (exp .length () != actual .length ()) {
49
- fail ("Expected " +exp .length ()+" nulls , got " +actual .length ());
104
+ fail ("Expected name with " +exp .length ()+" null chars , got " +actual .length ());
50
105
}
51
106
assertEquals (exp , actual );
52
107
}
0 commit comments