public void Decode_WithMaximumLengthInput_Works() { var fullChunkLength = CobsZpeZreEncoder.MAX_CHUNK_LENGTH - 1; var fullChunksCount = CobsZpeZreEncoder.MAX_PACKET_SIZE / fullChunkLength; var totalBytesInFullChunks = fullChunksCount * fullChunkLength; var bytesInLastChunk = CobsZpeZreEncoder.MAX_PACKET_SIZE - totalBytesInFullChunks; var input = GenerateInput( Enumerable .Repeat((byte)fullChunkLength, fullChunksCount) .Append((byte)bytesInLastChunk) .ToArray(), 0x04 ); var decoder = new CobsZpeZreDecoder(); byte[] output = null; foreach (var b in input) { output = decoder.NextByte(b); } Assert.NotNull(output); Assert.Equal(CobsEncoder.MAX_PACKET_SIZE, output.Length); Assert.Equal(CobsEncoder.MAX_PACKET_SIZE, output.Count(a => a == 0x04)); }
public void Decode_TooLongInput_Fails() { var fullChunkLength = CobsZpeZreEncoder.MAX_CHUNK_LENGTH - 1; var fullChunksCount = CobsZpeZreEncoder.MAX_PACKET_SIZE / fullChunkLength; var totalBytesInFullChunks = fullChunksCount * fullChunkLength; var bytesInLastChunk = CobsZpeZreEncoder.MAX_PACKET_SIZE - totalBytesInFullChunks; fullChunksCount++; var input = GenerateInput( Enumerable .Repeat((byte)fullChunkLength, fullChunksCount) .Append((byte)bytesInLastChunk) .ToArray(), 0x05 ); var decoder = new CobsZpeZreDecoder(); byte[] output = null; foreach (var b in input) { output = decoder.NextByte(b); Assert.Null(output); } }
public void Decoder_ShortRegularPacket_Works() { var decoder = new CobsZpeZreDecoder(); var input = new byte[] { 0x03, 0x01, 0x02, 0x00 }; byte[] output = null; foreach (var b in input) { output = decoder.NextByte(b); } Assert.NotNull(output); Assert.NotNull(output); Assert.Equal(new byte[] { 0x01, 0x02 }, output); }
public void Decoder_ZeroEndEncoded_Works() { var decoder = new CobsZpeZreDecoder(); var input = new byte[] { 0xE5, 0x01, 0x02, 0x03, 0x04, 0x00 }; byte[] output = null; foreach (var b in input) { output = decoder.NextByte(b); } Assert.NotNull(output); Assert.Equal(6, output.Length); Assert.Equal(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x00, 0x00 }, output); }
public void Decoder_ZeroRunEncoded_Works() { var decoder = new CobsZpeZreDecoder(); var input = new byte[] { 0xD7, 0x00 }; byte[] output = null; foreach (var b in input) { output = decoder.NextByte(b); } Assert.NotNull(output); Assert.Equal(7, output.Length); Assert.True(output.All(b => b == 0x00)); }
public void Decoder_LongRegularPacket_Works() { var decoder = new CobsZpeZreDecoder(); var input = new byte[0xD5]; input[0] = 0xD0; Array.Fill <byte>(input, 0x01, 1, 0xD0 - 1); input[0xD0] = 4; Array.Fill <byte>(input, 0x01, 0xD0 + 1, 3); input[0xD4] = 0x00; byte[] output = null; foreach (var b in input) { output = decoder.NextByte(b); } Assert.NotNull(output); Assert.Equal(0xD0 - 1 + 3, output.Length); Assert.Equal(0xD0 - 1 + 3, output.Count(b => b == 0x01)); }