public async void ReadHeaderPart1Async_ExtraBytesAtEnd_ExtraBytesIgnored() { byte[] bytes = { // 5 bytes offset 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // Entry 1 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x11, 0x12, 0x13, 0x14, 0x21, 0x22, 0x23, 0x24, 0x31, 0x32, 0x33, 0x34, // Extra bytes 0xFF, 0xFF, }; var stream = new MemoryStream(bytes); var reader = new NefsReader(this.fileSystem); var size = NefsHeaderPart1Entry.Size + 2; var offset = (uint)5; // Test var part1 = await reader.ReadHeaderPart1Async(stream, offset, size, this.p); // Verify Assert.Single(part1.EntriesByIndex); var e1 = part1.EntriesByIndex[0]; Assert.Equal((ulong)0x0807060504030201, e1.OffsetToData); Assert.Equal((uint)0x14131211, e1.IndexPart2); Assert.Equal((uint)0x24232221, e1.IndexPart4); Assert.Equal((uint)0x34333231, e1.Id.Value); }
public async void ReadHeaderPart1Async_SizeOutOfBounds_NoEntries() { var bytes = new byte[10]; var stream = new MemoryStream(bytes); var reader = new NefsReader(this.fileSystem); // Test var part1 = await reader.ReadHeaderPart1Async(stream, 0, 20, this.p); // Verify Assert.Empty(part1.EntriesByIndex); }
public async void ReadHeaderPart1Async_ValidData_DataRead() { byte[] bytes = { // 5 bytes offset 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // Entry 1 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x11, 0x12, 0x13, 0x14, 0x21, 0x22, 0x23, 0x24, 0x31, 0x32, 0x33, 0x34, // Entry 2 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x51, 0x52, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x71, 0x72, 0x73, 0x74, }; var stream = new MemoryStream(bytes); var reader = new NefsReader(this.fileSystem); var size = 2 * NefsHeaderPart1Entry.Size; var offset = (uint)5; // Test var part1 = await reader.ReadHeaderPart1Async(stream, offset, size, this.p); // Verify Assert.Equal(2, part1.EntriesById.Count); // Entries are keyed by id var e1 = part1.EntriesById[new NefsItemId(0x34333231)]; Assert.Equal((ulong)0x0807060504030201, e1.OffsetToData); Assert.Equal((uint)0x14131211, e1.MetadataIndex); Assert.Equal((uint)0x24232221, e1.IndexIntoPart4); Assert.Equal((uint)0x34333231, e1.Id.Value); var e2 = part1.EntriesById[new NefsItemId(0x74737271)]; Assert.Equal((ulong)0x4847464544434241, e2.OffsetToData); Assert.Equal((uint)0x54535251, e2.MetadataIndex); Assert.Equal((uint)0x64636261, e2.IndexIntoPart4); Assert.Equal((uint)0x74737271, e2.Id.Value); }
public async void ReadHeaderPart6Async_ValidData_DataRead() { var reader = new NefsReader(this.fileSystem); NefsHeaderPart1 part1; Nefs20HeaderPart6 part6; var part1Offset = (uint)5; var part1Size = 2 * NefsHeaderPart1Entry.Size; var part6Offset = (uint)5; // NOTE: Part 6 is ordered in the same way part 1 is byte[] part1Bytes = { // 5 bytes offset 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // Entry 1 0x11, 0x12, 0x13, 0x14, // Offset to data 0x15, 0x14, 0x17, 0x18, // Offset to data (cont) 0x19, 0x1A, 0x1B, 0x1C, // Index part 2 0x1D, 0x1E, 0x1F, 0x20, // Index part 4 0x21, 0x22, 0x23, 0x24, // Item id // Entry 2 0x01, 0x02, 0x03, 0x04, // Offset to data 0x05, 0x04, 0x07, 0x08, // Offset to data (cont) 0x09, 0x0A, 0x0B, 0x0C, // Index part 2 0x0D, 0x0E, 0x0F, 0x10, // Index part 4 0x11, 0x12, 0x13, 0x14, // Item id }; using (var part1Stream = new MemoryStream(part1Bytes)) { part1 = await reader.ReadHeaderPart1Async(part1Stream, part1Offset, part1Size, this.p); } // Part 6 data byte[] bytes = { // 5 bytes offset 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // Entry 1 0x11, 0x12, 0x13, 0x14, // Entry 2 0x21, 0x22, 0x23, 0x24, }; // Test using (var part6Stream = new MemoryStream(bytes)) { part6 = await reader.Read20HeaderPart6Async(part6Stream, part6Offset, part1, this.p); } // Verify Assert.Equal(2, part6.EntriesByIndex.Count); var e1 = part6.EntriesByIndex[0]; Assert.Equal(0x1211, e1.Volume); Assert.Equal(0x13, (byte)e1.Flags); Assert.Equal(0x14, e1.Unknown0x3); Assert.Same(e1, part6.EntriesByGuid[part1.EntriesByIndex[0].Guid]); var e2 = part6.EntriesByIndex[1]; Assert.Equal(0x2221, e2.Volume); Assert.Equal(0x23, (byte)e2.Flags); Assert.Equal(0x24, e2.Unknown0x3); Assert.Same(e2, part6.EntriesByGuid[part1.EntriesByIndex[1].Guid]); }