2017-09-28 15:44:21 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Filename : 2MG.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2017-09-28 15:44:21 +01:00
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : DiscImageChef unit testing.
|
2017-09-28 15:44:21 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2017-09-28 15:44:21 +01:00
|
|
|
|
// ****************************************************************************/
|
2017-12-19 03:50:57 +00:00
|
|
|
|
|
2017-09-28 15:44:21 +01:00
|
|
|
|
using System.IO;
|
2017-12-19 19:33:46 +00:00
|
|
|
|
using DiscImageChef.Checksums;
|
2017-09-28 15:44:21 +01:00
|
|
|
|
using DiscImageChef.CommonTypes;
|
2018-06-25 19:08:16 +01:00
|
|
|
|
using DiscImageChef.CommonTypes.Interfaces;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using DiscImageChef.Filters;
|
2017-09-28 15:44:21 +01:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Tests.Images
|
|
|
|
|
|
{
|
|
|
|
|
|
[TestFixture]
|
2017-12-22 22:18:21 +00:00
|
|
|
|
public class Apple2Mg
|
2017-09-28 15:44:21 +01:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
readonly string[] testfiles =
|
|
|
|
|
|
{
|
|
|
|
|
|
"blank140.2mg.lz", "dos32.2mg.lz", "dos33-do.2mg.lz", "dos33-nib.2mg.lz", "dos33-po.2mg.lz",
|
2017-12-21 02:52:12 +00:00
|
|
|
|
"prodos1440.2mg.lz"
|
2017-09-28 15:44:21 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
2017-12-21 02:52:12 +00:00
|
|
|
|
readonly ulong[] sectors = {560, 415, 560, 560, 560, 2880};
|
2017-09-28 15:44:21 +01:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
readonly uint[] sectorsize = {256, 256, 256, 256, 256, 512};
|
2017-09-28 15:44:21 +01:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
readonly MediaType[] mediatypes =
|
|
|
|
|
|
{
|
|
|
|
|
|
MediaType.Apple33SS, MediaType.Apple32SS, MediaType.Apple33SS, MediaType.Apple33SS, MediaType.Apple33SS,
|
2017-12-21 02:52:12 +00:00
|
|
|
|
MediaType.DOS_35_HD
|
2017-09-28 15:44:21 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
2017-12-22 22:18:21 +00:00
|
|
|
|
readonly string[] md5S =
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
"7db5d585270ab858043d50e60068d45f", "c62ee4dac8835f9acc999e7531d3b5f8", "86bc7879bb477917aab3976057a6a7b2",
|
2017-12-21 02:52:12 +00:00
|
|
|
|
"32b8f8163238d4f3ea2a3db95ad1a812", "a5acba4cbaddd9c53ea0e8210f4aba55", "eb9b60c78b30d2b6541ed0781944b6da"
|
2017-09-28 15:44:21 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Test()
|
|
|
|
|
|
{
|
|
|
|
|
|
for(int i = 0; i < testfiles.Length; i++)
|
|
|
|
|
|
{
|
2018-02-03 17:39:49 +00:00
|
|
|
|
string location = Path.Combine(Consts.TestFilesRoot, "images", "2mg", testfiles[i]);
|
|
|
|
|
|
IFilter filter = new LZip();
|
2017-09-28 15:44:21 +01:00
|
|
|
|
filter.Open(location);
|
2017-12-26 06:05:12 +00:00
|
|
|
|
IMediaImage image = new DiscImages.Apple2Mg();
|
2018-02-03 17:39:49 +00:00
|
|
|
|
Assert.AreEqual(true, image.Open(filter), testfiles[i]);
|
|
|
|
|
|
Assert.AreEqual(sectors[i], image.Info.Sectors, testfiles[i]);
|
2017-12-26 06:05:12 +00:00
|
|
|
|
Assert.AreEqual(sectorsize[i], image.Info.SectorSize, testfiles[i]);
|
2018-02-03 17:39:49 +00:00
|
|
|
|
Assert.AreEqual(mediatypes[i], image.Info.MediaType, testfiles[i]);
|
2017-09-28 15:44:21 +01:00
|
|
|
|
|
|
|
|
|
|
// How many sectors to read at once
|
2017-12-22 22:18:21 +00:00
|
|
|
|
const uint SECTORS_TO_READ = 256;
|
2018-02-03 17:39:49 +00:00
|
|
|
|
ulong doneSectors = 0;
|
2017-09-28 15:44:21 +01:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
Md5Context ctx = new Md5Context();
|
2017-09-28 15:44:21 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
while(doneSectors < image.Info.Sectors)
|
2017-09-28 15:44:21 +01:00
|
|
|
|
{
|
|
|
|
|
|
byte[] sector;
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(image.Info.Sectors - doneSectors >= SECTORS_TO_READ)
|
2017-09-28 15:44:21 +01:00
|
|
|
|
{
|
2018-02-03 17:39:49 +00:00
|
|
|
|
sector = image.ReadSectors(doneSectors, SECTORS_TO_READ);
|
2017-12-22 22:18:21 +00:00
|
|
|
|
doneSectors += SECTORS_TO_READ;
|
2017-09-28 15:44:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-02-03 17:39:49 +00:00
|
|
|
|
sector = image.ReadSectors(doneSectors, (uint)(image.Info.Sectors - doneSectors));
|
2018-06-22 08:08:38 +01:00
|
|
|
|
doneSectors += image.Info.Sectors - doneSectors;
|
2017-09-28 15:44:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Update(sector);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-22 22:18:21 +00:00
|
|
|
|
Assert.AreEqual(md5S[i], ctx.End(), testfiles[i]);
|
2017-09-28 15:44:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|