Skip to content

Commit badcf4b

Browse files
committed
DiskAccessLibraryTests: Added FileRecordTests class
1 parent b753bc5 commit badcf4b

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

DiskAccessLibraryTests/DiskAccessLibraryTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<Compile Include="Tests\NTFSLogTests.cs" />
4141
<Compile Include="Tests\NTFSVolumeTests.cs" />
4242
<Compile Include="Tests\RawDiskImageTests.cs" />
43+
<Compile Include="UnitTests\FileRecordTests.cs" />
4344
</ItemGroup>
4445
<ItemGroup>
4546
<ProjectReference Include="..\DiskAccessLibrary\DiskAccessLibrary.csproj">

DiskAccessLibraryTests/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ private static void Main(string[] args)
2929
}
3030
}
3131

32+
FileRecordTests.Tests();
3233
long size = 100 * 1024 * 1024;
3334
RawDiskImageTests.Test(path, size);
3435
if (!VHDMountHelper.IsVHDMountInstalled())
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using DiskAccessLibrary.FileSystems.NTFS;
4+
using Utilities;
5+
6+
namespace DiskAccessLibraryTests
7+
{
8+
public class FileRecordTests
9+
{
10+
public static void Tests()
11+
{
12+
AttributeCloneTest();
13+
}
14+
15+
/// <summary>
16+
/// This test checks that attributes are deep cloned when assembled from FileRecordSegment list and sliced into FileRecordSegment list.
17+
/// </summary>
18+
public static void AttributeCloneTest()
19+
{
20+
byte minorNTFSVersion = 1;
21+
int bytesPerFileRecordSegment = 1024;
22+
FileRecordSegment baseSegment = new FileRecordSegment(30, 1);
23+
FileRecordSegment segment2 = new FileRecordSegment(31, 1, baseSegment.SegmentReference);
24+
FileNameRecord fileNameRecord = new FileNameRecord(NTFSVolume.RootDirSegmentReference, "john.txt", false, DateTime.Now);
25+
FileNameAttributeRecord fileNameAttribute = new FileNameAttributeRecord(String.Empty);
26+
fileNameAttribute.Record = fileNameRecord;
27+
NonResidentAttributeRecord dataRecord = new NonResidentAttributeRecord(AttributeType.Data, String.Empty);
28+
baseSegment.ImmediateAttributes.Add(fileNameAttribute);
29+
baseSegment.ImmediateAttributes.Add(dataRecord);
30+
dataRecord.DataRunSequence.Add(new DataRun(5, 0));
31+
byte[] segmentBytesBefore = baseSegment.GetBytes(bytesPerFileRecordSegment, minorNTFSVersion, false);
32+
33+
List<FileRecordSegment> segments = new List<FileRecordSegment>();
34+
segments.Add(baseSegment);
35+
segments.Add(segment2);
36+
FileRecord fileRecord = new FileRecord(segments);
37+
((NonResidentAttributeRecord)fileRecord.DataRecord).DataRunSequence[0].RunLength = 8;
38+
fileRecord.FileNameRecord.ParentDirectory = new MftSegmentReference(8, 8);
39+
fileRecord.FileNameRecord.FileName = "d";
40+
byte[] segmentBytesAfter = baseSegment.GetBytes(bytesPerFileRecordSegment, minorNTFSVersion, false);
41+
if (!ByteUtils.AreByteArraysEqual(segmentBytesBefore, segmentBytesAfter))
42+
{
43+
throw new Exception("Test failed");
44+
}
45+
46+
fileRecord.UpdateSegments(1024, 1);
47+
byte[] segmentBytesBefore2 = fileRecord.Segments[0].GetBytes(bytesPerFileRecordSegment, minorNTFSVersion, false);
48+
((NonResidentAttributeRecord)fileRecord.DataRecord).DataRunSequence[0].RunLength = 10;
49+
fileRecord.FileNameRecord.FileName = "x";
50+
byte[] segmentBytesAfter2 = fileRecord.Segments[0].GetBytes(bytesPerFileRecordSegment, minorNTFSVersion, false);
51+
if (!ByteUtils.AreByteArraysEqual(segmentBytesBefore2, segmentBytesAfter2))
52+
{
53+
throw new Exception("Test failed");
54+
}
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)