From 7f203f1893454d6134b01d608b23da3feb2a0e16 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 25 Feb 2022 17:23:17 -0800 Subject: [PATCH] Add failing tests for #312 (cbor, smile) --- .../cbor/failing/SymbolTable312Test.java | 53 +++++++++++++++++++ .../smile/failing/SymbolTable312Test.java | 53 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/failing/SymbolTable312Test.java create mode 100644 smile/src/test/java/com/fasterxml/jackson/dataformat/smile/failing/SymbolTable312Test.java diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/failing/SymbolTable312Test.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/failing/SymbolTable312Test.java new file mode 100644 index 000000000..607a151b3 --- /dev/null +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/failing/SymbolTable312Test.java @@ -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); + } +} diff --git a/smile/src/test/java/com/fasterxml/jackson/dataformat/smile/failing/SymbolTable312Test.java b/smile/src/test/java/com/fasterxml/jackson/dataformat/smile/failing/SymbolTable312Test.java new file mode 100644 index 000000000..a237763e0 --- /dev/null +++ b/smile/src/test/java/com/fasterxml/jackson/dataformat/smile/failing/SymbolTable312Test.java @@ -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); + } +}