2021-04-20 07:36:15 +08: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.Linq;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Audio.Track;
|
|
|
|
using osu.Game.Beatmaps;
|
2021-05-12 08:29:18 +08:00
|
|
|
using osu.Game.Rulesets.Edit;
|
2021-04-20 07:36:15 +08:00
|
|
|
using osu.Game.Rulesets.Edit.Checks;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Editing.Checks
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class CheckAudioQualityTest
|
|
|
|
{
|
|
|
|
private CheckAudioQuality check;
|
|
|
|
private IBeatmap beatmap;
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
|
|
|
check = new CheckAudioQuality();
|
|
|
|
beatmap = new Beatmap<HitObject>
|
|
|
|
{
|
|
|
|
BeatmapInfo = new BeatmapInfo
|
|
|
|
{
|
|
|
|
Metadata = new BeatmapMetadata { AudioFile = "abc123.jpg" }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMissing()
|
|
|
|
{
|
|
|
|
// While this is a problem, it is out of scope for this check and is caught by a different one.
|
|
|
|
beatmap.Metadata.AudioFile = null;
|
|
|
|
|
|
|
|
var mock = new Mock<IWorkingBeatmap>();
|
2021-04-20 19:29:14 +08:00
|
|
|
mock.SetupGet(w => w.Beatmap).Returns(beatmap);
|
|
|
|
mock.SetupGet(w => w.Track).Returns((Track)null);
|
2021-04-20 07:36:15 +08:00
|
|
|
|
2021-05-12 08:29:18 +08:00
|
|
|
Assert.That(check.Run(beatmap, new BeatmapVerifierContext(mock.Object)), Is.Empty);
|
2021-04-20 07:36:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAcceptable()
|
|
|
|
{
|
2021-05-12 08:29:18 +08:00
|
|
|
var context = getContext(192);
|
2021-04-20 07:36:15 +08:00
|
|
|
|
2021-05-12 08:29:18 +08:00
|
|
|
Assert.That(check.Run(beatmap, context), Is.Empty);
|
2021-04-20 07:36:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestNullBitrate()
|
|
|
|
{
|
2021-05-12 08:29:18 +08:00
|
|
|
var context = getContext(null);
|
2021-04-20 07:36:15 +08:00
|
|
|
|
2021-05-12 08:29:18 +08:00
|
|
|
var issues = check.Run(beatmap, context).ToList();
|
2021-04-20 07:36:15 +08:00
|
|
|
|
|
|
|
Assert.That(issues, Has.Count.EqualTo(1));
|
|
|
|
Assert.That(issues.Single().Template is CheckAudioQuality.IssueTemplateNoBitrate);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestZeroBitrate()
|
|
|
|
{
|
2021-05-12 08:29:18 +08:00
|
|
|
var context = getContext(0);
|
2021-04-20 07:36:15 +08:00
|
|
|
|
2021-05-12 08:29:18 +08:00
|
|
|
var issues = check.Run(beatmap, context).ToList();
|
2021-04-20 07:36:15 +08:00
|
|
|
|
|
|
|
Assert.That(issues, Has.Count.EqualTo(1));
|
|
|
|
Assert.That(issues.Single().Template is CheckAudioQuality.IssueTemplateNoBitrate);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestTooHighBitrate()
|
|
|
|
{
|
2021-05-12 08:29:18 +08:00
|
|
|
var context = getContext(320);
|
2021-04-20 07:36:15 +08:00
|
|
|
|
2021-05-12 08:29:18 +08:00
|
|
|
var issues = check.Run(beatmap, context).ToList();
|
2021-04-20 07:36:15 +08:00
|
|
|
|
|
|
|
Assert.That(issues, Has.Count.EqualTo(1));
|
|
|
|
Assert.That(issues.Single().Template is CheckAudioQuality.IssueTemplateTooHighBitrate);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestTooLowBitrate()
|
|
|
|
{
|
2021-05-12 08:29:18 +08:00
|
|
|
var context = getContext(64);
|
2021-04-20 07:36:15 +08:00
|
|
|
|
2021-05-12 08:29:18 +08:00
|
|
|
var issues = check.Run(beatmap, context).ToList();
|
2021-04-20 07:36:15 +08:00
|
|
|
|
|
|
|
Assert.That(issues, Has.Count.EqualTo(1));
|
|
|
|
Assert.That(issues.Single().Template is CheckAudioQuality.IssueTemplateTooLowBitrate);
|
|
|
|
}
|
|
|
|
|
2021-05-12 08:29:18 +08:00
|
|
|
private BeatmapVerifierContext getContext(int? audioBitrate)
|
|
|
|
{
|
|
|
|
return new BeatmapVerifierContext(getMockWorkingBeatmap(audioBitrate).Object);
|
|
|
|
}
|
|
|
|
|
2021-04-20 07:36:15 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Returns the mock of the working beatmap with the given audio properties.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="audioBitrate">The bitrate of the audio file the beatmap uses.</param>
|
|
|
|
private Mock<IWorkingBeatmap> getMockWorkingBeatmap(int? audioBitrate)
|
|
|
|
{
|
|
|
|
var mockTrack = new Mock<Track>();
|
2021-04-20 19:29:14 +08:00
|
|
|
mockTrack.SetupGet(t => t.Bitrate).Returns(audioBitrate);
|
2021-04-20 07:36:15 +08:00
|
|
|
|
|
|
|
var mockWorkingBeatmap = new Mock<IWorkingBeatmap>();
|
2021-04-20 19:29:14 +08:00
|
|
|
mockWorkingBeatmap.SetupGet(w => w.Beatmap).Returns(beatmap);
|
|
|
|
mockWorkingBeatmap.SetupGet(w => w.Track).Returns(mockTrack.Object);
|
2021-04-20 07:36:15 +08:00
|
|
|
|
|
|
|
return mockWorkingBeatmap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|