Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
72dd7bf
[CBOR] Implement support for dateTime types
eiriktsarpalis Apr 9, 2020
d02f2a6
fix test errors
eiriktsarpalis Apr 9, 2020
484feef
refine RFC3339 dateTime formatting logic
eiriktsarpalis Apr 9, 2020
d686a8c
add invalid date string tests
eiriktsarpalis Apr 9, 2020
5251fc6
Implement BigInteger support
eiriktsarpalis Apr 9, 2020
9943b72
initial decimal support implementation
eiriktsarpalis Apr 10, 2020
8ad65f2
use stack allocated buffers instead of thread local buffers
eiriktsarpalis Apr 14, 2020
2ed35e8
add test cases for negative unix time dates
eiriktsarpalis Apr 14, 2020
c915828
add WriteNegativeIntegerEncoding tests
eiriktsarpalis Apr 14, 2020
5672f1d
implement checkpointing logic and apply to SkipValue() method
eiriktsarpalis Apr 14, 2020
e51fddd
implement checkpointing for tagged type readers
eiriktsarpalis Apr 15, 2020
0d7105b
store reader checkpoints in the stack
eiriktsarpalis Apr 15, 2020
d1a582c
add tests for rollback logic in tagged type readers
eiriktsarpalis Apr 15, 2020
0c13c32
add tested that utilizes nested reader state rollbacks
eiriktsarpalis Apr 15, 2020
261ff0b
use culture invariant decimal parsing in tests
eiriktsarpalis Apr 16, 2020
134224b
add WriteUnixTimeSeconds(double) method
eiriktsarpalis Apr 16, 2020
9033e1c
split unix time and string time readers into separate methods
eiriktsarpalis Apr 16, 2020
3275cfa
add WriteUnixTestSeconds invalid input test
eiriktsarpalis Apr 16, 2020
2558310
add support and tests for indefinite-length buffers in tagged types
eiriktsarpalis Apr 16, 2020
1f6d5f4
add PeekTag() tests
eiriktsarpalis Apr 17, 2020
db18459
add Read/WriteInt32() convenience methods
eiriktsarpalis Apr 17, 2020
485a859
add pervasive buffer postcondition checks on negative reader tests; f…
eiriktsarpalis Apr 17, 2020
d550b2a
add comment on DateTime parsing
eiriktsarpalis Apr 17, 2020
8b9f7a7
Rename CborReader.Peek() to CborReader.PeekState()
eiriktsarpalis Apr 17, 2020
37cf2bd
Use correct overload for int32 handling
eiriktsarpalis Apr 17, 2020
69741a8
add caching to CborReader.PeekState()
eiriktsarpalis Apr 17, 2020
26d8198
Use "simple" instead of "special" for cbor major type
eiriktsarpalis Apr 20, 2020
1533f80
add Write/ReadUInt32() convenience methods
eiriktsarpalis Apr 20, 2020
d33f054
add uint32 negative tests
eiriktsarpalis Apr 20, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static void ReadArray_SimpleValues_HappyPath(object[] expectedValues, str
byte[] encoding = hexEncoding.HexToByteArray();
var reader = new CborReader(encoding);
Helpers.VerifyArray(reader, expectedValues);
Assert.Equal(CborReaderState.Finished, reader.Peek());
Assert.Equal(CborReaderState.Finished, reader.PeekState());
}

[Theory]
Expand All @@ -39,7 +39,7 @@ public static void ReadArray_NestedValues_HappyPath(object[] expectedValues, str
byte[] encoding = hexEncoding.HexToByteArray();
var reader = new CborReader(encoding);
Helpers.VerifyArray(reader, expectedValues);
Assert.Equal(CborReaderState.Finished, reader.Peek());
Assert.Equal(CborReaderState.Finished, reader.PeekState());
}

[Theory]
Expand All @@ -55,7 +55,7 @@ public static void ReadArray_IndefiniteLength_HappyPath(object[] expectedValues,
byte[] encoding = hexEncoding.HexToByteArray();
var reader = new CborReader(encoding);
Helpers.VerifyArray(reader, expectedValues, expectDefiniteLengthCollections: false);
Assert.Equal(CborReaderState.Finished, reader.Peek());
Assert.Equal(CborReaderState.Finished, reader.PeekState());
}

[Theory]
Expand All @@ -75,7 +75,9 @@ public static void ReadArray_DefiniteLengthExceeded_ShouldThrowInvalidOperationE
reader.ReadInt64();
}

int bytesRemaining = reader.BytesRemaining;
Assert.Throws<InvalidOperationException>(() => reader.ReadInt64());
Assert.Equal(bytesRemaining, reader.BytesRemaining);
}

[Theory]
Expand Down Expand Up @@ -109,12 +111,12 @@ public static void ReadArray_IndefiniteLength_MissingBreakByte_ShouldReportEndOf
byte[] encoding = hexEncoding.HexToByteArray();
var reader = new CborReader(encoding);
reader.ReadStartArray();
while (reader.Peek() == CborReaderState.UnsignedInteger)
while (reader.PeekState() == CborReaderState.UnsignedInteger)
{
reader.ReadInt64();
}

Assert.Equal(CborReaderState.EndOfData, reader.Peek());
Assert.Equal(CborReaderState.EndOfData, reader.PeekState());
}

[Theory]
Expand All @@ -131,7 +133,9 @@ public static void ReadArray_IndefiniteLength_PrematureEndArrayCall_ShouldThrowI
reader.ReadInt64();
}

int bytesRemaining = reader.BytesRemaining;
Assert.Throws<InvalidOperationException>(() => reader.ReadEndArray());
Assert.Equal(bytesRemaining, reader.BytesRemaining);
}

[Theory]
Expand All @@ -150,7 +154,9 @@ public static void EndReadArray_DefiniteLengthNotMet_ShouldThrowInvalidOperation
reader.ReadInt64();
}

int bytesRemaining = reader.BytesRemaining;
Assert.Throws<InvalidOperationException>(() => reader.ReadEndArray());
Assert.Equal(bytesRemaining, reader.BytesRemaining);
}

[Theory]
Expand All @@ -172,7 +178,9 @@ public static void EndReadArray_DefiniteLengthNotMet_WithNestedData_ShouldThrowI
reader.ReadEndArray();
}

int bytesRemaining = reader.BytesRemaining;
Assert.Throws<InvalidOperationException>(() => reader.ReadEndArray());
Assert.Equal(bytesRemaining, reader.BytesRemaining);
}

[Fact]
Expand All @@ -199,7 +207,9 @@ public static void ReadArray_IncorrectDefiniteLength_ShouldThrowFormatException(
reader.ReadInt64();
}

int bytesRemaining = reader.BytesRemaining;
Assert.Throws<FormatException>(() => reader.ReadInt64());
Assert.Equal(bytesRemaining, reader.BytesRemaining);
}

[Theory]
Expand All @@ -221,7 +231,9 @@ public static void ReadArray_IncorrectDefiniteLength_NestedValues_ShouldThrowFor
reader.ReadEndArray();
}

int bytesRemaining = reader.BytesRemaining;
Assert.Throws<FormatException>(() => reader.ReadInt64());
Assert.Equal(bytesRemaining, reader.BytesRemaining);
}

[Fact]
Expand All @@ -231,6 +243,7 @@ public static void ReadStartArray_EmptyBuffer_ShouldThrowFormatException()
var reader = new CborReader(encoding);

Assert.Throws<FormatException>(() => reader.ReadStartArray());
Assert.Equal(encoding.Length, reader.BytesRemaining);
}

[Theory]
Expand All @@ -244,9 +257,11 @@ public static void ReadStartArray_EmptyBuffer_ShouldThrowFormatException()
[InlineData("fb3ff199999999999a")] // 1.1
public static void ReadStartArray_InvalidType_ShouldThrowInvalidOperationException(string hexEncoding)
{
byte[] data = hexEncoding.HexToByteArray();
var reader = new CborReader(data);
byte[] encoding = hexEncoding.HexToByteArray();
var reader = new CborReader(encoding);

Assert.Throws<InvalidOperationException>(() => reader.ReadStartArray());
Assert.Equal(encoding.Length, reader.BytesRemaining);
}

[Theory]
Expand All @@ -261,22 +276,24 @@ public static void ReadStartArray_InvalidType_ShouldThrowInvalidOperationExcepti
[InlineData("9b00000000000000")]
public static void ReadStartArray_InvalidData_ShouldThrowFormatException(string hexEncoding)
{
byte[] data = hexEncoding.HexToByteArray();
var reader = new CborReader(data);
byte[] encoding = hexEncoding.HexToByteArray();
var reader = new CborReader(encoding);

Assert.Throws<FormatException>(() => reader.ReadStartArray());
Assert.Equal(encoding.Length, reader.BytesRemaining);
}

[Theory]
[InlineData("81")]
[InlineData("830102")]
[InlineData("82")]
[InlineData("870102")]
[InlineData("9b7fffffffffffffff")] // long.MaxValue
public static void ReadStartArray_BufferTooSmall_ShouldThrowFormatException(string hexEncoding)
{
byte[] data = hexEncoding.HexToByteArray();
var reader = new CborReader(data);
byte[] encoding = hexEncoding.HexToByteArray();
var reader = new CborReader(encoding);

Assert.Throws<FormatException>(() => reader.ReadStartArray());
Assert.Equal(encoding.Length, reader.BytesRemaining);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ public static void VerifyValue(CborReader reader, object expectedValue, bool exp
switch (expectedValue)
{
case null:
Assert.Equal(CborReaderState.Null, reader.Peek());
Assert.Equal(CborReaderState.Null, reader.PeekState());
reader.ReadNull();
break;
case bool expected:
Assert.Equal(CborReaderState.Boolean, reader.Peek());
Assert.Equal(CborReaderState.Boolean, reader.PeekState());
bool b = reader.ReadBoolean();
Assert.Equal(expected, b);
break;
case int expected:
VerifyPeekInteger(reader, isUnsignedInteger: expected >= 0);
long i = reader.ReadInt64();
Assert.Equal(expected, (int)i);
int i = reader.ReadInt32();
Assert.Equal(expected, i);
break;
case long expected:
VerifyPeekInteger(reader, isUnsignedInteger: expected >= 0);
Expand All @@ -42,47 +42,47 @@ public static void VerifyValue(CborReader reader, object expectedValue, bool exp
Assert.Equal(expected, u);
break;
case float expected:
Assert.Equal(CborReaderState.SinglePrecisionFloat, reader.Peek());
Assert.Equal(CborReaderState.SinglePrecisionFloat, reader.PeekState());
float f = reader.ReadSingle();
Assert.Equal(expected, f);
break;
case double expected:
Assert.Equal(CborReaderState.DoublePrecisionFloat, reader.Peek());
Assert.Equal(CborReaderState.DoublePrecisionFloat, reader.PeekState());
double d = reader.ReadDouble();
Assert.Equal(expected, d);
break;
case string expected:
Assert.Equal(CborReaderState.TextString, reader.Peek());
Assert.Equal(CborReaderState.TextString, reader.PeekState());
string s = reader.ReadTextString();
Assert.Equal(expected, s);
break;
case byte[] expected:
Assert.Equal(CborReaderState.ByteString, reader.Peek());
Assert.Equal(CborReaderState.ByteString, reader.PeekState());
byte[] bytes = reader.ReadByteString();
Assert.Equal(expected.ByteArrayToHex(), bytes.ByteArrayToHex());
break;
case string[] expectedChunks:
Assert.Equal(CborReaderState.StartTextString, reader.Peek());
Assert.Equal(CborReaderState.StartTextString, reader.PeekState());
reader.ReadStartTextStringIndefiniteLength();
foreach(string expectedChunk in expectedChunks)
{
Assert.Equal(CborReaderState.TextString, reader.Peek());
Assert.Equal(CborReaderState.TextString, reader.PeekState());
string chunk = reader.ReadTextString();
Assert.Equal(expectedChunk, chunk);
}
Assert.Equal(CborReaderState.EndTextString, reader.Peek());
Assert.Equal(CborReaderState.EndTextString, reader.PeekState());
reader.ReadEndTextStringIndefiniteLength();
break;
case byte[][] expectedChunks:
Assert.Equal(CborReaderState.StartByteString, reader.Peek());
Assert.Equal(CborReaderState.StartByteString, reader.PeekState());
reader.ReadStartByteStringIndefiniteLength();
foreach (byte[] expectedChunk in expectedChunks)
{
Assert.Equal(CborReaderState.ByteString, reader.Peek());
Assert.Equal(CborReaderState.ByteString, reader.PeekState());
byte[] chunk = reader.ReadByteString();
Assert.Equal(expectedChunk.ByteArrayToHex(), chunk.ByteArrayToHex());
}
Assert.Equal(CborReaderState.EndByteString, reader.Peek());
Assert.Equal(CborReaderState.EndByteString, reader.PeekState());
reader.ReadEndByteStringIndefiniteLength();
break;

Expand All @@ -99,13 +99,13 @@ public static void VerifyValue(CborReader reader, object expectedValue, bool exp
static void VerifyPeekInteger(CborReader reader, bool isUnsignedInteger)
{
CborReaderState expectedState = isUnsignedInteger ? CborReaderState.UnsignedInteger : CborReaderState.NegativeInteger;
Assert.Equal(expectedState, reader.Peek());
Assert.Equal(expectedState, reader.PeekState());
}
}

public static void VerifyArray(CborReader reader, object[] expectedValues, bool expectDefiniteLengthCollections = true)
{
Assert.Equal(CborReaderState.StartArray, reader.Peek());
Assert.Equal(CborReaderState.StartArray, reader.PeekState());

ulong? length = reader.ReadStartArray();

Expand All @@ -124,7 +124,7 @@ public static void VerifyArray(CborReader reader, object[] expectedValues, bool
VerifyValue(reader, value);
}

Assert.Equal(CborReaderState.EndArray, reader.Peek());
Assert.Equal(CborReaderState.EndArray, reader.PeekState());
reader.ReadEndArray();
}

Expand All @@ -135,7 +135,7 @@ public static void VerifyMap(CborReader reader, object[] expectedValues, bool ex
throw new ArgumentException($"cbor map expected values missing '{CborWriterTests.Helpers.MapPrefixIdentifier}' prefix.");
}

Assert.Equal(CborReaderState.StartMap, reader.Peek());
Assert.Equal(CborReaderState.StartMap, reader.PeekState());

ulong? length = reader.ReadStartMap();

Expand All @@ -154,7 +154,7 @@ public static void VerifyMap(CborReader reader, object[] expectedValues, bool ex
VerifyValue(reader, value);
}

Assert.Equal(CborReaderState.EndMap, reader.Peek());
Assert.Equal(CborReaderState.EndMap, reader.PeekState());
reader.ReadEndMap();
}
}
Expand Down
Loading