2021-07-13 01:46:45 +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.
|
|
|
|
|
2021-11-22 05:24:17 +00:00
|
|
|
using System.Diagnostics;
|
2021-07-13 01:46:45 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using ManagedBass;
|
|
|
|
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;
|
|
|
|
using osu.Game.Tests.Beatmaps;
|
|
|
|
using osu.Game.Tests.Resources;
|
|
|
|
using osuTK.Audio;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Editing.Checks
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class CheckTooShortAudioFilesTest
|
|
|
|
{
|
|
|
|
private CheckTooShortAudioFiles check;
|
|
|
|
private IBeatmap beatmap;
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
|
|
|
check = new CheckTooShortAudioFiles();
|
|
|
|
beatmap = new Beatmap<HitObject>
|
|
|
|
{
|
|
|
|
BeatmapInfo = new BeatmapInfo
|
|
|
|
{
|
|
|
|
BeatmapSet = new BeatmapSetInfo
|
|
|
|
{
|
2021-11-24 05:22:41 +00:00
|
|
|
Files = { CheckTestHelpers.CreateMockFile("wav") }
|
2021-07-13 01:46:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// 0 = No output device. This still allows decoding.
|
|
|
|
if (!Bass.Init(0) && Bass.LastError != Errors.Already)
|
|
|
|
throw new AudioException("Could not initialize Bass.");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestDifferentExtension()
|
|
|
|
{
|
2021-11-22 05:24:17 +00:00
|
|
|
Debug.Assert(beatmap.BeatmapInfo.BeatmapSet != null);
|
|
|
|
|
2021-07-13 01:46:45 +00:00
|
|
|
beatmap.BeatmapInfo.BeatmapSet.Files.Clear();
|
2021-11-24 05:22:41 +00:00
|
|
|
beatmap.BeatmapInfo.BeatmapSet.Files.Add(CheckTestHelpers.CreateMockFile("jpg"));
|
2021-07-13 01:46:45 +00:00
|
|
|
|
|
|
|
// Should fail to load, but not produce an error due to the extension not being expected to load.
|
|
|
|
Assert.IsEmpty(check.Run(getContext(null, allowMissing: true)));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestRegularAudioFile()
|
|
|
|
{
|
2021-10-12 01:57:54 +00:00
|
|
|
using (var resourceStream = TestResources.OpenResource("Samples/test-sample.mp3"))
|
|
|
|
{
|
|
|
|
Assert.IsEmpty(check.Run(getContext(resourceStream)));
|
|
|
|
}
|
2021-07-13 01:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestBlankAudioFile()
|
|
|
|
{
|
2021-10-12 01:57:54 +00:00
|
|
|
using (var resourceStream = TestResources.OpenResource("Samples/blank.wav"))
|
|
|
|
{
|
|
|
|
// This is a 0 ms duration audio file, commonly used to silence sliderslides/ticks, and so should be fine.
|
|
|
|
Assert.IsEmpty(check.Run(getContext(resourceStream)));
|
|
|
|
}
|
2021-07-13 01:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestTooShortAudioFile()
|
|
|
|
{
|
2021-10-12 01:57:54 +00:00
|
|
|
using (var resourceStream = TestResources.OpenResource("Samples/test-sample-cut.mp3"))
|
|
|
|
{
|
|
|
|
var issues = check.Run(getContext(resourceStream)).ToList();
|
2021-07-13 01:46:45 +00:00
|
|
|
|
2021-10-12 01:57:54 +00:00
|
|
|
Assert.That(issues, Has.Count.EqualTo(1));
|
|
|
|
Assert.That(issues.Single().Template is CheckTooShortAudioFiles.IssueTemplateTooShort);
|
|
|
|
}
|
2021-07-13 01:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMissingAudioFile()
|
|
|
|
{
|
2021-10-12 01:57:54 +00:00
|
|
|
using (var resourceStream = TestResources.OpenResource("Samples/missing.mp3"))
|
|
|
|
{
|
|
|
|
Assert.IsEmpty(check.Run(getContext(resourceStream, allowMissing: true)));
|
|
|
|
}
|
2021-07-13 01:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestCorruptAudioFile()
|
|
|
|
{
|
2021-10-12 01:57:54 +00:00
|
|
|
using (var resourceStream = TestResources.OpenResource("Samples/corrupt.wav"))
|
|
|
|
{
|
|
|
|
var issues = check.Run(getContext(resourceStream)).ToList();
|
2021-07-13 01:46:45 +00:00
|
|
|
|
2021-10-12 01:57:54 +00:00
|
|
|
Assert.That(issues, Has.Count.EqualTo(1));
|
|
|
|
Assert.That(issues.Single().Template is CheckTooShortAudioFiles.IssueTemplateBadFormat);
|
|
|
|
}
|
2021-07-13 01:46:45 +00:00
|
|
|
}
|
|
|
|
|
2021-10-12 01:57:54 +00:00
|
|
|
private BeatmapVerifierContext getContext(Stream resourceStream, bool allowMissing = false)
|
2021-07-13 01:46:45 +00:00
|
|
|
{
|
|
|
|
var mockWorkingBeatmap = new Mock<TestWorkingBeatmap>(beatmap, null, null);
|
|
|
|
mockWorkingBeatmap.Setup(w => w.GetStream(It.IsAny<string>())).Returns(resourceStream);
|
|
|
|
|
|
|
|
return new BeatmapVerifierContext(beatmap, mockWorkingBeatmap.Object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|