|
| 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