2021-07-13 01:45:21 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Rulesets.Edit;
|
|
|
|
using osu.Game.Rulesets.Edit.Checks;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Editing.Checks
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class CheckZeroByteFilesTest
|
|
|
|
{
|
2022-10-30 08:36:22 +00:00
|
|
|
private CheckZeroByteFiles check = null!;
|
|
|
|
private IBeatmap beatmap = null!;
|
2021-07-13 01:45:21 +00:00
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
|
|
|
check = new CheckZeroByteFiles();
|
|
|
|
beatmap = new Beatmap<HitObject>
|
|
|
|
{
|
|
|
|
BeatmapInfo = new BeatmapInfo
|
|
|
|
{
|
|
|
|
BeatmapSet = new BeatmapSetInfo
|
|
|
|
{
|
2021-11-24 04:49:38 +00:00
|
|
|
Files =
|
2021-07-13 01:45:21 +00:00
|
|
|
{
|
2021-11-24 05:22:41 +00:00
|
|
|
CheckTestHelpers.CreateMockFile("jpg"),
|
2021-11-24 04:49:38 +00:00
|
|
|
}
|
2021-07-13 01:45:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestNonZeroBytes()
|
|
|
|
{
|
|
|
|
Assert.IsEmpty(check.Run(getContext(byteLength: 44)));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestZeroBytes()
|
|
|
|
{
|
|
|
|
var issues = check.Run(getContext(byteLength: 0)).ToList();
|
|
|
|
|
|
|
|
Assert.That(issues, Has.Count.EqualTo(1));
|
|
|
|
Assert.That(issues.Single().Template is CheckZeroByteFiles.IssueTemplateZeroBytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMissing()
|
|
|
|
{
|
|
|
|
Assert.IsEmpty(check.Run(getContextMissing()));
|
|
|
|
}
|
|
|
|
|
|
|
|
private BeatmapVerifierContext getContext(long byteLength)
|
|
|
|
{
|
|
|
|
var mockStream = new Mock<Stream>();
|
|
|
|
mockStream.Setup(s => s.Length).Returns(byteLength);
|
|
|
|
|
|
|
|
var mockWorkingBeatmap = new Mock<IWorkingBeatmap>();
|
|
|
|
mockWorkingBeatmap.Setup(w => w.GetStream(It.IsAny<string>())).Returns(mockStream.Object);
|
|
|
|
|
|
|
|
return new BeatmapVerifierContext(beatmap, mockWorkingBeatmap.Object);
|
|
|
|
}
|
|
|
|
|
|
|
|
private BeatmapVerifierContext getContextMissing()
|
|
|
|
{
|
|
|
|
var mockWorkingBeatmap = new Mock<IWorkingBeatmap>();
|
2022-11-05 12:13:50 +00:00
|
|
|
mockWorkingBeatmap.Setup(w => w.GetStream(It.IsAny<string>())).Returns((Stream)null!);
|
2021-07-13 01:45:21 +00:00
|
|
|
|
|
|
|
return new BeatmapVerifierContext(beatmap, mockWorkingBeatmap.Object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|