public override void TestFixtureSetup() { base.TestFixtureSetup(); File.Delete(DataFileNameCopy); // Make a copy FileInfo fileInfo = new FileInfo(DataFileName); fileInfo.CopyTo(DataFileNameCopy); // Create fragmented data packet and bytes _dataPacket = TestFramework.CreateDataPacket(InputFile, 10, 113); // < 123 _dataPacket = _dataPacket.Append(TestFramework.CreateDataPacket(InputFile, 151, 89)); // < 240 _dataPacket = _dataPacket.Append(TestFramework.CreateDataPacket(InputFile, 255, 17)); // < 272 _dataPacket = _dataPacket.Append(TestFramework.CreateDataPacket(InputFile, 289, 1)); // < 290 _dataPacket = _dataPacket.Append(TestFramework.CreateDataPacket(InputFile, 393, 44)); // < 437 _dataPacket = _dataPacket.Append(TestFramework.CreateDataPacket(InputFile, 0, 5)); // < 5 _dataPacket = _dataPacket.Append(TestFramework.CreateDataPacket(InputFile, 511, 22)); // < 533 _dataPacket = _dataPacket.Append(TestFramework.CreateDataPacket(InputFile, 140, 40)); // overlap! _fragmentedData = new byte[113 + 89 + 17 + 1 + 44 + 5 + 22 + 40]; Array.Copy(base.DataReaderData, 10, _fragmentedData, 0, 113); Array.Copy(base.DataReaderData, 151, _fragmentedData, 113, 89); Array.Copy(base.DataReaderData, 255, _fragmentedData, 113 + 89, 17); Array.Copy(base.DataReaderData, 289, _fragmentedData, 113 + 89 + 17, 1); Array.Copy(base.DataReaderData, 393, _fragmentedData, 113 + 89 + 17 + 1, 44); Array.Copy(base.DataReaderData, 0, _fragmentedData, 113 + 89 + 17 + 1 + 44, 5); Array.Copy(base.DataReaderData, 511, _fragmentedData, 113 + 89 + 17 + 1 + 44 + 5, 22); Array.Copy(base.DataReaderData, 140, _fragmentedData, 113 + 89 + 17 + 1 + 44 + 5 + 22, 40); }
public void TestGetDataPacketFragmented() { IDataPacket dataPacket = _dataReader.GetDataPacket(70, 70); Assert.IsTrue(dataPacket.GetFragment(0).Equals(TestFramework.CreateDataPacket(InputFile, 80, 43)), "GetDataPacket() for fragmented packet (a)"); Assert.IsTrue(dataPacket.GetFragment(43).Equals(TestFramework.CreateDataPacket(InputFile, 151, 27)), "GetDataPacket() for fragmented packet (b)"); }
public void TestFixtureSetup() { // Create temporary directory Uri codeBaseUri = new Uri(Assembly.GetExecutingAssembly().CodeBase); DirectoryInfo debugDirectory = (new FileInfo(codeBaseUri.LocalPath)).Directory; const string TestFrameworkFiles = "TestFrameworkFiles"; if (Directory.Exists(debugDirectory + "\\" + TestFrameworkFiles)) { Directory.Delete(debugDirectory + "\\" + TestFrameworkFiles, true); } _testFilesDirectory = debugDirectory.CreateSubdirectory(TestFrameworkFiles); FileInfo testFile = new FileInfo(_testFilesDirectory.FullName + "/allfiles.dat"); FileInfo testProjectFile = new FileInfo(_testFilesDirectory.FullName + "/allfiles.dpr"); // Create input file and project _testProject = TestFramework.ProjectManager.CreateProject(testProjectFile.FullName, "S. Holmes", DateTime.Now, "Scan all files"); // Locate detectors TestFramework.DetectorFactory.Initialize("."); IDetector[] containerDetectors = new IDetector[] { Util.FindDetector(TestFramework.DetectorFactory.ContainerDetectors, "MPEG-1/2 Systems"), Util.FindDetector(TestFramework.DetectorFactory.ContainerDetectors, "3GPP/QT/MP4") }; IDetector[] codecDetectors = new IDetector[] { Util.FindDetector(TestFramework.DetectorFactory.CodecDetectors, Mpeg2VideoDetector.DetectorName), Util.FindDetector(TestFramework.DetectorFactory.CodecDetectors, "MPEG-4") }; // Append test files, create desired data blocks DirectoryInfo testDataDirectory = new DirectoryInfo(Util.TestdataPath); using (FileStream testFileStream = testFile.OpenWrite()) { long offset = 0; DesiredDataBlocks = new List <IDataBlock>(); for (int i = 0; i < TestFileNames.GetLength(0); i++) { // Copy file byte[] b = File.ReadAllBytes(testDataDirectory.FullName + "/" + TestFileNames[i, 1]); testFileStream.Write(b, 0, b.Length); if (TestFileNames[i, 0] != null) { IDetector detector = Util.FindDetector(TestFramework.DetectorFactory.Detectors, TestFileNames[i, 0]); IDataBlock dataBlock = TestFramework.CreateDataBlock(detector, TestFramework.CreateDataPacket(_testFile, offset, b.Length), true, null); DesiredDataBlocks.Add(dataBlock); } else if (i == 3) { // Partial detection: File is split in 2 blocks IDetector detector = Util.FindDetector(TestFramework.DetectorFactory.Detectors, "MPEG-1/2 Systems"); DesiredDataBlocks.Add(TestFramework.CreateDataBlock(detector, TestFramework.CreateDataPacket(_testFile, offset, 30), false, null)); DesiredDataBlocks.Add(TestFramework.CreateDataBlock(detector, TestFramework.CreateDataPacket(_testFile, offset + b.Length - 16, 16), false, null)); } offset += b.Length; // Add zero padding testFileStream.Write(new byte[256], 0, 256); offset += 256; } } bool isFullFile = DesiredDataBlocks[0].IsFullFile; DesiredDataBlocks[0] = TestFramework.CreateDataBlock(DesiredDataBlocks[0].Detectors.First(), TestFramework.CreateDataPacket(DesiredDataBlocks[0].InputFile, DesiredDataBlocks[0].StartOffset, DesiredDataBlocks[0].Length - 20), isFullFile, null); _testFile = TestFramework.DetectData(containerDetectors, codecDetectors, _testProject, testFile.FullName); }
public override void SetUp() { base.SetUp(); _dataReader = new FileDataReader(TestFramework.CreateDataPacket(InputFile, 0, DataFileSize)); }
public void TestConstructorNonExistingFile() { using (new FileDataReader(TestFramework.CreateDataPacket(TestFramework.CreateInputFile("banaan.aap"), 0, 1))) { } }
public void SerializeProject() { IProject project = TestFramework.ProjectManager.CreateProject(ProjectPath, ProjectInvestigator, DateTime.Now, ProjectDescription); IDetector systemDetector = TestFramework.DetectorFactory.ContainerDetectors.Single(x => x.Name == "MPEG-1/2 Systems"); IDetector videoDetector = TestFramework.DetectorFactory.CodecDetectors.Single(x => x.Name == Mpeg2VideoDetector.DetectorName); IInputFile inputFile1 = project.AddFile(FileName1, new[] { systemDetector, videoDetector }); IInputFile inputFile2 = project.AddFile(FileName2, new[] { videoDetector }); IDataBlockBuilder dataBlockBuilder1 = TestFramework.CreateDataBlockBuilder(); dataBlockBuilder1.DataFormat = CodecID.Mpeg2System; dataBlockBuilder1.Detectors = new[] { systemDetector }; dataBlockBuilder1.InputFile = inputFile1; dataBlockBuilder1.StartOffset = 0L; dataBlockBuilder1.EndOffset = 20480L; dataBlockBuilder1.IsFullFile = true; ICodecStreamBuilder codecStreamBuilder = dataBlockBuilder1.AddCodecStream(); codecStreamBuilder.Name = "Video Stream #1"; codecStreamBuilder.DataFormat = CodecID.Mpeg2Video; codecStreamBuilder.Detector = videoDetector; codecStreamBuilder.Data = TestFramework.CreateDataPacket(inputFile1, 0L, 3033L); IDataBlock dataBlock1 = dataBlockBuilder1.Build(); IDataBlockBuilder dataBlockBuilder2 = TestFramework.CreateDataBlockBuilder(); dataBlockBuilder2.DataFormat = CodecID.Mpeg2Video; dataBlockBuilder2.Detectors = new[] { videoDetector }; dataBlockBuilder2.InputFile = inputFile1; dataBlockBuilder2.StartOffset = 130303L; dataBlockBuilder2.EndOffset = 130327L; dataBlockBuilder2.IsFullFile = false; IDataBlock dataBlock2 = dataBlockBuilder2.Build(); IDataBlockBuilder dataBlockBuilder3 = TestFramework.CreateDataBlockBuilder(); dataBlockBuilder3.DataFormat = CodecID.Mpeg2Video; dataBlockBuilder3.Detectors = new[] { videoDetector }; dataBlockBuilder3.InputFile = inputFile2; dataBlockBuilder3.StartOffset = 0L; dataBlockBuilder3.EndOffset = FileLength2; dataBlockBuilder3.IsFullFile = true; IDataBlock dataBlock3 = dataBlockBuilder3.Build(); project.AddDataBlock(dataBlock1); project.AddDataBlock(dataBlock2); project.AddDataBlock(dataBlock3); project.SetMetadata(_fullMetadata); // project.SetVisibleColumns(systemDetector, TwoColumns); IProject deserializedProject; using (FileStream fileStream = new FileStream(_project.FileName, FileMode.Create)) { TestFramework.CreateXmlObjectSerializer().WriteObject(fileStream, project); } using (FileStream fileStream = new FileStream(ProjectPath, FileMode.Open)) { deserializedProject = TestFramework.CreateXmlObjectSerializer().ReadObject(fileStream) as IProject; } IList <IInputFile> inputFiles = deserializedProject.GetInputFiles(); Assert.AreEqual(2, inputFiles.Count, "Serialization, input files (2 files)"); AreEqual(inputFile1, inputFiles[0], "1"); AreEqual(inputFile2, inputFiles[1], "2"); IList <IDataBlock> dataBlocks = deserializedProject.GetDataBlocks(inputFiles[0]); Assert.AreEqual(2, dataBlocks.Count, "Serialization, data blocks (file 1, 2 blocks)"); AreEqual(dataBlock1, dataBlocks[0], "1", "1"); AreEqual(dataBlock2, dataBlocks[1], "1", "2"); dataBlocks = deserializedProject.GetDataBlocks(inputFiles[1]); Assert.AreEqual(1, dataBlocks.Count, "Serialization, data blocks (file 2, 1 block)"); AreEqual(dataBlock3, dataBlocks[0], "2", "1"); IDictionary <ProjectMetadataKey, string> metadata = deserializedProject.GetMetadata(); Assert.AreEqual(5, metadata.Count, "Serialization, metadata (5 entries)"); Assert.IsTrue(metadata.ContainsKey(ProjectMetadataKey.FileVersion), "Serialization, metadata (FileVersion)"); Assert.AreEqual("1.0.0.4", metadata[ProjectMetadataKey.FileVersion], "Serialization, metadata (FileVersion)"); Assert.IsTrue(metadata.ContainsKey(ProjectMetadataKey.ProjectDescription), "Serialization, metadata (ProjectDescription)"); Assert.AreEqual(ProjectDescription, metadata[ProjectMetadataKey.ProjectDescription], "Serialization, metadata (ProjectDescription)"); Assert.IsTrue(metadata.ContainsKey(ProjectMetadataKey.InvestigatorName), "Serialization, metadata (InvestigatorName)"); Assert.AreEqual(ProjectInvestigator, metadata[ProjectMetadataKey.InvestigatorName], "Serialization, metadata (InvestigatorName)"); Assert.IsTrue(metadata.ContainsKey(ProjectMetadataKey.DateCreated), "Serialization, metadata (DateCreated)"); Assert.AreEqual(ProjectCreationDate, metadata[ProjectMetadataKey.DateCreated], "Serialization, metadata (DateCreated)"); Assert.IsTrue(metadata.ContainsKey(ProjectMetadataKey.DateLastModified), "Serialization, metadata (DateLastModified)"); Assert.AreEqual(ProjectModificationDate, metadata[ProjectMetadataKey.DateLastModified], "Serialization, metadata (DateLastModified)"); //IList<IColumnInfo> visibleColumns = deserializedProject.GetVisibleColumns(systemDetector); //Assert.AreEqual(2, visibleColumns.Count, "Serialization, visible columns (2 columns)"); //Assert.IsTrue(visibleColumns.Contains(_columnInfo1), "Serialization, visible columns (column 1)"); //Assert.IsTrue(visibleColumns.Contains(_columnInfo2), "Serialization, visible columns (column 2)"); TestFramework.ProjectManager.CloseProject(project); }
public void TestGetDataPacketRandom() { IDataPacket dataPacket = _dataReader.GetDataPacket(30, 20); Assert.IsTrue(dataPacket.Equals(TestFramework.CreateDataPacket(InputFile, 40, 20)), "GetDataPacket() for random, unfragmented packet"); }
public void TestConstructorInvalidDataReader() { using (new FragmentedDataReader(TestFramework.CreateDataPacket(InputFile, 0, 100), _dataReaderPoolMock)) { } }
public void TestConstructorInputFileMismatch() { using (new FragmentedDataReader(TestFramework.CreateDataPacket(TestFramework.CreateInputFile(DataFileNameCopy), 0, 100), _dataReaderPoolMock)) { } }
public void TestReaderGetResultsDataBlockUnknown() { IDataPacket data = TestFramework.CreateDataPacket(TestFramework.CreateInputFile("ja"), 31337, 1); IDataBlock dataBlock = TestFramework.CreateDataBlock(TestFramework.DetectorFactory.Detectors[0], data, false, null); IResultNode results = TestFramework.GetResults(dataBlock); // TODO: _project?? }