public void TestLoadCompressedFileHeaders() { var loader = new ContainerFileLoader(); AnnoRDA.FileSystem fileSystem; using (var context = new ContainerFileLoader.Context("dummy.rda", TestData.GetStream("FileHeaders/2.2_multiple_file_headers_compressed.bin"), false, new PassThroughFileHeaderTransformer())) { var block = new AnnoRDA.FileEntities.BlockHeader() { Offset = context.Reader.StreamLength, IsCompressed = true, NumFiles = 2, CompressedFileHeadersSize = context.Reader.StreamLength, UncompressedFileHeadersSize = 1120, }; loader.LoadFileHeaders(context, block); fileSystem = context.FileSystem; } Assert.ContainsFile(fileSystem, new Assert.FileSpec("path", "to", "file1.txt") { DataOffset = 11111111, CompressedFileSize = 36960, UncompressedFileSize = 36960, ModificationDate = new DateTime(2015, 11, 24, 21, 1, 21, DateTimeKind.Utc), }); Assert.ContainsFile(fileSystem, new Assert.FileSpec("path", "to", "file2.txt") { DataOffset = 11148071, CompressedFileSize = 36960, UncompressedFileSize = 36960, ModificationDate = new DateTime(2015, 11, 24, 21, 1, 22, DateTimeKind.Utc), }); }
public void TestVerifyInvalidBlockHeader() { var block = new AnnoRDA.FileEntities.BlockHeader() { Offset = 17, IsCompressed = true, NumFiles = 66, CompressedFileHeadersSize = 8888, UncompressedFileHeadersSize = 55555, NextBlockOffset = 11111111, }; System.Exception exception = Assert.Throws<AnnoRDA.FileFormatException>(() => { this.verifier.VerifyBlockHeader(block); }); Assert.Equal(new AnnoRDA.FileFormatException(AnnoRDA.FileFormatException.EntityType.BlockHeader, AnnoRDA.FileFormatException.Error.InvalidValue, 17, "The file headers size does not match the number of files."), exception); block = new AnnoRDA.FileEntities.BlockHeader() { Offset = 17, IsCompressed = false, NumFiles = 66, CompressedFileHeadersSize = 8888, UncompressedFileHeadersSize = 36960, NextBlockOffset = 11111111, }; exception = Assert.Throws<AnnoRDA.FileFormatException>(() => { this.verifier.VerifyBlockHeader(block); }); Assert.Equal(new AnnoRDA.FileFormatException(AnnoRDA.FileFormatException.EntityType.BlockHeader, AnnoRDA.FileFormatException.Error.InvalidValue, 17, "The compressed file headers size should match the uncompressed size when compression is disabled."), exception); }
public void TestReadBlockHeader() { AnnoRDA.FileEntities.BlockHeader actual; var data = new byte[] { 0xFF, 0xFF, 0xFF, // gibberish data before the block, will be skipped when reading 0x01, 0x00, 0x00, 0x00, // flags 0x42, 0x00, 0x00, 0x00, // number of files 0xB8, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // compressed file headers size 0x60, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // uncompressed file headers size 0xC7, 0x8A, 0xA9, 0x00, 0x00, 0x00, 0x00, 0x00, // next block offset }; using (var reader = new ContainerFileLoaderReader(TestData.GetStream(data), false)) { actual = reader.ReadBlockHeader(3); } var expected = new AnnoRDA.FileEntities.BlockHeader() { Offset = 3, Flags = 1, NumFiles = 66, CompressedFileHeadersSize = 8888, UncompressedFileHeadersSize = 36960, NextBlockOffset = 11111111, }; Assert.Equal(expected, actual); }
public void TestVerifyValidBlockHeader() { var block = new AnnoRDA.FileEntities.BlockHeader() { Offset = 36960 + 792, IsCompressed = false, NumFiles = 66, CompressedFileHeadersSize = 36960, UncompressedFileHeadersSize = 36960, NextBlockOffset = 11111111, }; this.verifier.VerifyBlockHeader(block); var blockWithCompression = new AnnoRDA.FileEntities.BlockHeader() { Offset = 8888 + 792, IsCompressed = true, NumFiles = 66, CompressedFileHeadersSize = 8888, UncompressedFileHeadersSize = 36960, NextBlockOffset = 11111111, }; this.verifier.VerifyBlockHeader(blockWithCompression); }