Esempio n. 1
0
        public void LuigiScrambleKeyBlock_Truncated_ThrowsEndOfStreamException()
        {
            var truncatedDataBlock = new byte[] { 0x00, 0x00, 0x01, 0x34, 0xCC, 0x44, 0xCC, 0x00, 0xDE, 0xAD, 0xBE, 0xEF };

            using (var truncatedLuigiBlockStream = new MemoryStream(truncatedDataBlock))
            {
                Assert.Throws <EndOfStreamException>(() => LuigiDataBlock.Inflate(truncatedLuigiBlockStream));
            }
        }
Esempio n. 2
0
        public void LuigiDataBlock_DeserializeTruncatedPayloadBlock_ThrowsEndOfStreamException()
        {
            var truncatedDataBlock = new byte[] { (byte)LuigiTestDataBlock.BlockType, 0x01, 0x00, 0x77, 0x22, 0x33, 0x44, 0x55 };

            using (var truncatedLuigiBlockStream = new MemoryStream(truncatedDataBlock))
            {
                Assert.Throws <System.IO.EndOfStreamException>(() => LuigiDataBlock.Inflate(truncatedLuigiBlockStream));
            }
        }
Esempio n. 3
0
        public void LuigiDataBlock_DeserializeTruncatedPayloadCrcBlock_ThrowsEndOfStreamException()
        {
            var truncatedDataBlock = new byte[] { 0x00, 0x01, 0x00, 0xe5, 0x22 };

            using (var truncatedLuigiBlockStream = new MemoryStream(truncatedDataBlock))
            {
                Assert.Throws <System.IO.EndOfStreamException>(() => LuigiDataBlock.Inflate(truncatedLuigiBlockStream));
            }
        }
Esempio n. 4
0
        public void LuigiDataBlock_DeserializeEmptyBlock_ThrowsEndOfStreamException()
        {
            var truncatedDataBlock = new byte[0];

            using (var truncatedLuigiBlockStream = new MemoryStream(truncatedDataBlock))
            {
                Assert.Throws <System.IO.EndOfStreamException>(() => LuigiDataBlock.Inflate(truncatedLuigiBlockStream));
            }
        }
Esempio n. 5
0
        public void LuigiDataBlock_DeserializeEmptyUnknownBlockType_ReturnsCorrectNumberOfBytes()
        {
            using (var fakeLuigiBlockData = new MemoryStream())
            {
                fakeLuigiBlockData.WriteByte((byte)LuigiTestDataBlock.BlockType); // bogus block type
                fakeLuigiBlockData.WriteByte(0);
                fakeLuigiBlockData.WriteByte(0);                                  // zero payload length
                var crc = Crc8.OfBlock(fakeLuigiBlockData.ToArray());
                fakeLuigiBlockData.WriteByte(crc);
                fakeLuigiBlockData.Seek(0, SeekOrigin.Begin);

                var luigiDataBlock = LuigiDataBlock.Inflate(fakeLuigiBlockData);

                Assert.Equal(LuigiTestDataBlock.BlockType, luigiDataBlock.Type);
                Assert.Equal(crc, luigiDataBlock.HeaderCrc);
                Assert.Equal(0u, luigiDataBlock.PayloadCrc);
            }
        }
Esempio n. 6
0
        public void LuigiDataBlock_DeserializePayloadWithCorruptedPayloadCrc_ThrowsInvalidDataException()
        {
            var truncatedDataBlock = new byte[] { (byte)LuigiTestDataBlock.BlockType, 0x01, 0x00, 0x77, 0x44, 0x33, 0x22, 0x11, 0xee };

            using (var truncatedLuigiBlockStream = new MemoryStream(truncatedDataBlock))
            {
                var exception       = Assert.Throws <System.IO.InvalidDataException>(() => LuigiDataBlock.Inflate(truncatedLuigiBlockStream));
                var expectedMessage = string.Format(CultureInfo.CurrentCulture, Resources.Strings.InvalidDataBlockChecksumFormat, 0x4F48173D, 0x11223344);
                Assert.Equal(expectedMessage, exception.Message);
            }
        }