mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Add unit tests for Parallels images created by QEMU.
This commit is contained in:
5
.idea/.idea.Aaru/.idea/indexLayout.xml
generated
5
.idea/.idea.Aaru/.idea/indexLayout.xml
generated
@@ -5,4 +5,9 @@
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
<component name="WorkspaceUserModelUpdater">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
||||
8
.idea/.idea.Aaru/.idea/modules.xml
generated
8
.idea/.idea.Aaru/.idea/modules.xml
generated
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/.idea.Aaru/.idea/riderModule.iml" filepath="$PROJECT_DIR$/.idea/.idea.Aaru/.idea/riderModule.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
12
.idea/.idea.Aaru/.idea/riderModule.iml
generated
12
.idea/.idea.Aaru/.idea/riderModule.iml
generated
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="RIDER_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$USER_HOME$/.nuget/packages/microsoft.net.test.sdk/16.4.0/build/netcoreapp2.1" />
|
||||
<content url="file://$USER_HOME$/.nuget/packages/nunit3testadapter/3.15.1/build/netcoreapp2.0/NUnit3.TestAdapter.dll" />
|
||||
<content url="file://$USER_HOME$/.nuget/packages/nunit3testadapter/3.15.1/build/netcoreapp2.0/NUnit3.TestAdapter.pdb" />
|
||||
<content url="file://$USER_HOME$/.nuget/packages/nunit3testadapter/3.15.1/build/netcoreapp2.0/nunit.engine.api.dll" />
|
||||
<content url="file://$USER_HOME$/.nuget/packages/nunit3testadapter/3.15.1/build/netcoreapp2.0/nunit.engine.dll" />
|
||||
<content url="file://$MODULE_DIR$/../.." />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
12
.idea/.idea.Aaru/riderModule.iml
generated
12
.idea/.idea.Aaru/riderModule.iml
generated
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="RIDER_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$USER_HOME$/.nuget/packages/microsoft.net.test.sdk/16.4.0/build/netcoreapp2.1" />
|
||||
<content url="file://$USER_HOME$/.nuget/packages/nunit3testadapter/3.15.1/build/netcoreapp2.0/NUnit3.TestAdapter.dll" />
|
||||
<content url="file://$USER_HOME$/.nuget/packages/nunit3testadapter/3.15.1/build/netcoreapp2.0/NUnit3.TestAdapter.pdb" />
|
||||
<content url="file://$USER_HOME$/.nuget/packages/nunit3testadapter/3.15.1/build/netcoreapp2.0/nunit.engine.api.dll" />
|
||||
<content url="file://$USER_HOME$/.nuget/packages/nunit3testadapter/3.15.1/build/netcoreapp2.0/nunit.engine.dll" />
|
||||
<content url="file://$MODULE_DIR$/../.." />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
155
Aaru.Tests/Images/QEMU/Parallels.cs
Normal file
155
Aaru.Tests/Images/QEMU/Parallels.cs
Normal file
@@ -0,0 +1,155 @@
|
||||
// /***************************************************************************
|
||||
// Aaru Data Preservation Suite
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Parallels.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : Aaru unit testing.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2021 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using Aaru.Checksums;
|
||||
using Aaru.CommonTypes;
|
||||
using Aaru.Filters;
|
||||
using FluentAssertions.Execution;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Aaru.Tests.Images.QEMU
|
||||
{
|
||||
[TestFixture]
|
||||
public class Parallels
|
||||
{
|
||||
readonly string[] _testFiles =
|
||||
{
|
||||
"parallels.hdd.lz"
|
||||
};
|
||||
|
||||
readonly ulong[] _sectors =
|
||||
{
|
||||
// parallels.hdd.lz
|
||||
251904
|
||||
};
|
||||
|
||||
readonly uint[] _sectorSize =
|
||||
{
|
||||
// parallels.hdd.lz
|
||||
512
|
||||
};
|
||||
|
||||
readonly MediaType[] _mediaTypes =
|
||||
{
|
||||
// parallels.hdd.lz
|
||||
MediaType.GENERIC_HDD
|
||||
};
|
||||
|
||||
readonly string[] _md5S =
|
||||
{
|
||||
// parallels.hdd.lz
|
||||
"4bfc9e9e2dd86aa52ef709e77d2617ed"
|
||||
};
|
||||
|
||||
readonly string _dataFolder = Path.Combine(Consts.TEST_FILES_ROOT, "Media image formats", "QEMU", "Parallels");
|
||||
|
||||
[Test]
|
||||
public void Info()
|
||||
{
|
||||
Environment.CurrentDirectory = _dataFolder;
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
for(int i = 0; i < _testFiles.Length; i++)
|
||||
{
|
||||
var filter = new LZip();
|
||||
filter.Open(_testFiles[i]);
|
||||
|
||||
var image = new DiscImages.Parallels();
|
||||
bool opened = image.Open(filter);
|
||||
|
||||
Assert.AreEqual(true, opened, $"Open: {_testFiles[i]}");
|
||||
|
||||
if(!opened)
|
||||
continue;
|
||||
|
||||
using(new AssertionScope())
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(_sectors[i], image.Info.Sectors, $"Sectors: {_testFiles[i]}");
|
||||
Assert.AreEqual(_sectorSize[i], image.Info.SectorSize, $"Sector size: {_testFiles[i]}");
|
||||
Assert.AreEqual(_mediaTypes[i], image.Info.MediaType, $"Media type: {_testFiles[i]}");
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// How many sectors to read at once
|
||||
const uint _sectorsToRead = 256;
|
||||
|
||||
[Test]
|
||||
public void Hashes()
|
||||
{
|
||||
Environment.CurrentDirectory = _dataFolder;
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
for(int i = 0; i < _testFiles.Length; i++)
|
||||
{
|
||||
var filter = new LZip();
|
||||
filter.Open(_testFiles[i]);
|
||||
|
||||
var image = new DiscImages.Parallels();
|
||||
bool opened = image.Open(filter);
|
||||
ulong doneSectors = 0;
|
||||
|
||||
Assert.AreEqual(true, opened, $"Open: {_testFiles[i]}");
|
||||
|
||||
if(!opened)
|
||||
continue;
|
||||
|
||||
var ctx = new Md5Context();
|
||||
|
||||
while(doneSectors < image.Info.Sectors)
|
||||
{
|
||||
byte[] sector;
|
||||
|
||||
if(image.Info.Sectors - doneSectors >= _sectorsToRead)
|
||||
{
|
||||
sector = image.ReadSectors(doneSectors, _sectorsToRead);
|
||||
doneSectors += _sectorsToRead;
|
||||
}
|
||||
else
|
||||
{
|
||||
sector = image.ReadSectors(doneSectors, (uint)(image.Info.Sectors - doneSectors));
|
||||
doneSectors += image.Info.Sectors - doneSectors;
|
||||
}
|
||||
|
||||
ctx.Update(sector);
|
||||
}
|
||||
|
||||
Assert.AreEqual(_md5S[i], ctx.End(), $"Hash: {_testFiles[i]}");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user