-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add failing tests for #312 (cbor, smile)
- Loading branch information
1 parent
42d4c44
commit 7f203f1
Showing
2 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/failing/SymbolTable312Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.fasterxml.jackson.dataformat.cbor.failing; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonToken; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; | ||
|
||
public class SymbolTable312Test extends CBORTestBase | ||
{ | ||
private final ObjectMapper MAPPER = cborMapper(); | ||
|
||
// [dataformats-binary#312]: null handling | ||
public void testNullHandling() throws Exception | ||
{ | ||
final String FIELD1 = "\u0000"; | ||
final String FIELD2 = FIELD1 + FIELD1; | ||
final String FIELD3 = FIELD2 + FIELD1; | ||
|
||
final String QUOTED_NULL = "\\u0000"; | ||
|
||
final String SRC = a2q(String.format("{'%s':'a','%s':'b','%s':'c'}", | ||
QUOTED_NULL, QUOTED_NULL+QUOTED_NULL, QUOTED_NULL+QUOTED_NULL+QUOTED_NULL)); | ||
byte[] DOC = cborDoc(SRC); | ||
|
||
try (JsonParser p = MAPPER.createParser(DOC)) { | ||
assertToken(JsonToken.START_OBJECT, p.nextToken()); | ||
|
||
assertToken(JsonToken.FIELD_NAME, p.nextToken()); | ||
_assertNullStrings(FIELD1, p.currentName()); | ||
assertToken(JsonToken.VALUE_STRING, p.nextToken()); | ||
assertEquals("a", p.getText()); | ||
|
||
assertToken(JsonToken.FIELD_NAME, p.nextToken()); | ||
_assertNullStrings(FIELD2, p.currentName()); | ||
assertToken(JsonToken.VALUE_STRING, p.nextToken()); | ||
assertEquals("b", p.getText()); | ||
|
||
assertToken(JsonToken.FIELD_NAME, p.nextToken()); | ||
_assertNullStrings(FIELD3, p.currentName()); | ||
assertToken(JsonToken.VALUE_STRING, p.nextToken()); | ||
assertEquals("c", p.getText()); | ||
|
||
assertToken(JsonToken.END_OBJECT, p.nextToken()); | ||
} | ||
} | ||
|
||
private void _assertNullStrings(String exp, String actual) { | ||
if (exp.length() != actual.length()) { | ||
fail("Expected "+exp.length()+" nulls, got "+actual.length()); | ||
} | ||
assertEquals(exp, actual); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
smile/src/test/java/com/fasterxml/jackson/dataformat/smile/failing/SymbolTable312Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.fasterxml.jackson.dataformat.smile.failing; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonToken; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.smile.BaseTestForSmile; | ||
|
||
public class SymbolTable312Test extends BaseTestForSmile | ||
{ | ||
private final ObjectMapper MAPPER = smileMapper(); | ||
|
||
// [dataformats-binary#312]: null handling | ||
public void testNullHandling() throws Exception | ||
{ | ||
final String FIELD1 = "\u0000"; | ||
final String FIELD2 = FIELD1 + FIELD1; | ||
final String FIELD3 = FIELD2 + FIELD1; | ||
|
||
final String QUOTED_NULL = "\\u0000"; | ||
|
||
final String SRC = a2q(String.format("{'%s':'a','%s':'b','%s':'c'}", | ||
QUOTED_NULL, QUOTED_NULL+QUOTED_NULL, QUOTED_NULL+QUOTED_NULL+QUOTED_NULL)); | ||
byte[] DOC = _smileDoc(SRC); | ||
|
||
try (JsonParser p = MAPPER.createParser(DOC)) { | ||
assertToken(JsonToken.START_OBJECT, p.nextToken()); | ||
|
||
assertToken(JsonToken.FIELD_NAME, p.nextToken()); | ||
_assertNullStrings(FIELD1, p.currentName()); | ||
assertToken(JsonToken.VALUE_STRING, p.nextToken()); | ||
assertEquals("a", p.getText()); | ||
|
||
assertToken(JsonToken.FIELD_NAME, p.nextToken()); | ||
_assertNullStrings(FIELD2, p.currentName()); | ||
assertToken(JsonToken.VALUE_STRING, p.nextToken()); | ||
assertEquals("b", p.getText()); | ||
|
||
assertToken(JsonToken.FIELD_NAME, p.nextToken()); | ||
_assertNullStrings(FIELD3, p.currentName()); | ||
assertToken(JsonToken.VALUE_STRING, p.nextToken()); | ||
assertEquals("c", p.getText()); | ||
|
||
assertToken(JsonToken.END_OBJECT, p.nextToken()); | ||
} | ||
} | ||
|
||
private void _assertNullStrings(String exp, String actual) { | ||
if (exp.length() != actual.length()) { | ||
fail("Expected "+exp.length()+" nulls, got "+actual.length()); | ||
} | ||
assertEquals(exp, actual); | ||
} | ||
} |