-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a1866e
commit 7d26d7b
Showing
3 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
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
64 changes: 64 additions & 0 deletions
64
cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/UndefinedValueTest.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,64 @@ | ||
package com.fasterxml.jackson.dataformat.cbor.parse; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonToken; | ||
import com.fasterxml.jackson.dataformat.cbor.CBORConstants; | ||
import com.fasterxml.jackson.dataformat.cbor.CBORFactory; | ||
import com.fasterxml.jackson.dataformat.cbor.CBORGenerator; | ||
import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; | ||
|
||
// for [dataformat-binary#93] | ||
public class UndefinedValueTest extends CBORTestBase | ||
{ | ||
private final static byte BYTE_UNDEFINED = (byte) 0xF7; | ||
|
||
private final CBORFactory CBOR_F = cborFactory(); | ||
|
||
public void testUndefinedLiteralStreaming() throws Exception | ||
{ | ||
JsonParser p = cborParser(CBOR_F, new byte[] { BYTE_UNDEFINED }); | ||
assertEquals(JsonToken.VALUE_NULL, p.nextToken()); | ||
assertNull(p.nextToken()); | ||
p.close(); | ||
} | ||
|
||
public void testUndefinedInArray() throws Exception | ||
{ | ||
ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
out.write(CBORConstants.BYTE_ARRAY_INDEFINITE); | ||
out.write(BYTE_UNDEFINED); | ||
out.write(CBORConstants.BYTE_BREAK); | ||
JsonParser p = cborParser(CBOR_F, out.toByteArray()); | ||
assertEquals(JsonToken.START_ARRAY, p.nextToken()); | ||
assertEquals(JsonToken.VALUE_NULL, p.nextToken()); | ||
assertEquals(JsonToken.END_ARRAY, p.nextToken()); | ||
assertNull(p.nextToken()); | ||
p.close(); | ||
} | ||
|
||
public void testUndefinedInObject() throws Exception | ||
{ | ||
ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
CBORGenerator g = cborGenerator(out); | ||
g.writeStartObject(); | ||
g.writeFieldName("bar"); | ||
g.writeBoolean(true); | ||
g.writeEndObject(); | ||
g.close(); | ||
|
||
byte[] doc = out.toByteArray(); | ||
// assume we use end marker for Object, so | ||
doc[doc.length-2] = BYTE_UNDEFINED; | ||
|
||
JsonParser p = cborParser(CBOR_F, doc); | ||
assertEquals(JsonToken.START_OBJECT, p.nextToken()); | ||
assertEquals(JsonToken.FIELD_NAME, p.nextToken()); | ||
assertEquals("bar", p.currentName()); | ||
assertEquals(JsonToken.VALUE_NULL, p.nextToken()); | ||
assertEquals(JsonToken.END_OBJECT, p.nextToken()); | ||
assertNull(p.nextToken()); | ||
p.close(); | ||
} | ||
} |
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