public void ParseFileTest1() { IReadOnlyList <Bit> data = BitListHelper.CreateBuilder() .AddInt(0x10) .AddChar('f') .AddChar('i') .AddChar('l') .AddChar('e') .AddChar('.') .AddChar('b') .AddChar('i') .AddChar('n') .AddLong(0x0).BitList; FileSegment segment = streamParser.ParseFile(new TestIDecodingInputStream(data), new WeightsTable()); Assert.IsNotNull(segment); Assert.AreEqual("file.bin", segment.Name); Assert.IsNull(segment.Path); IFileDecoder decoder = segment.FileDecoder; Assert.IsNotNull(decoder); TestIDecodingOutputStream outputStream = new TestIDecodingOutputStream(); decoder.Decode(outputStream, CancellationToken.None, null); CollectionAssert.IsEmpty(outputStream.ByteList); }
public void ParseFileTest2() { IReadOnlyList <Bit> data = BitListHelper.CreateBuilder() .AddInt(0x10) .AddChar('d') .AddChar('a') .AddChar('t') .AddChar('a') .AddChar('.') .AddChar('b') .AddChar('i') .AddChar('n') .AddLong(0x19) .AddByte(0x20) .AddByte(0x55) .AddByte(0xFF) .AddByte(0x01).BitList; WeightsTable weightsTable = new WeightsTable(); weightsTable.TrackSymbol(1, 1); weightsTable.TrackSymbol(2, 2); weightsTable.TrackSymbol(3, 4); weightsTable.TrackSymbol(4, 8); FileSegment segment = streamParser.ParseFile(new TestIDecodingInputStream(data), weightsTable); Assert.IsNotNull(segment); Assert.AreEqual("data.bin", segment.Name); Assert.IsNull(segment.Path); IFileDecoder decoder = segment.FileDecoder; Assert.IsNotNull(decoder); TestIDecodingOutputStream outputStream = new TestIDecodingOutputStream(); decoder.Decode(outputStream, CancellationToken.None, null); byte[] expectedData = { 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4 }; Assert.AreEqual(expectedData, outputStream.ByteList); }