1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-17 04:42:55 +08:00
osu-lazer/osu.Game.Tests/Editing/Checks/CheckSongFormatTest.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

113 lines
3.8 KiB
C#
Raw Normal View History

2024-04-16 17:15:21 +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.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 partial class CheckSongFormatTest
{
private CheckSongFormat check = null!;
private IBeatmap beatmap = null!;
[SetUp]
public void Setup()
{
check = new CheckSongFormat();
beatmap = new Beatmap<HitObject>
{
BeatmapInfo = new BeatmapInfo
{
BeatmapSet = new BeatmapSetInfo
{
Files = { CheckTestHelpers.CreateMockFile("mp3") }
}
}
};
// 0 = No output device. This still allows decoding.
if (!Bass.Init(0) && Bass.LastError != Errors.Already)
throw new AudioException("Could not initialize Bass.");
}
[Test]
2024-04-17 19:22:05 +08:00
public void TestMp3Audio()
2024-04-16 17:15:21 +08:00
{
using (var resourceStream = TestResources.OpenResource("Samples/test-sample-cut.mp3"))
{
beatmap.Metadata.AudioFile = "abc123.mp3";
var issues = check.Run(getContext(resourceStream)).ToList();
Assert.That(issues, Has.Count.EqualTo(0));
}
}
[Test]
2024-04-17 19:22:05 +08:00
public void TestOggAudio()
2024-04-16 17:15:21 +08:00
{
using (var resourceStream = TestResources.OpenResource("Samples/test-sample.ogg"))
{
beatmap.Metadata.AudioFile = "abc123.mp3";
var issues = check.Run(getContext(resourceStream)).ToList();
Assert.That(issues, Has.Count.EqualTo(0));
}
}
[Test]
2024-04-17 19:22:05 +08:00
public void TestWavAudio()
2024-04-16 17:15:21 +08:00
{
using (var resourceStream = TestResources.OpenResource("Samples/hitsound-delay.wav"))
{
beatmap.Metadata.AudioFile = "abc123.mp3";
var issues = check.Run(getContext(resourceStream)).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckSongFormat.IssueTemplateIncorrectFormat);
}
}
[Test]
2024-04-17 19:22:05 +08:00
public void TestWebmAudio()
2024-04-16 17:15:21 +08:00
{
using (var resourceStream = TestResources.OpenResource("Samples/test-sample.webm"))
{
beatmap.Metadata.AudioFile = "abc123.mp3";
var issues = check.Run(getContext(resourceStream)).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckSongFormat.IssueTemplateFormatUnsupported);
}
}
[Test]
public void TestCorruptAudio()
{
using (var resourceStream = TestResources.OpenResource("Samples/corrupt.wav"))
{
beatmap.Metadata.AudioFile = "abc123.mp3";
var issues = check.Run(getContext(resourceStream)).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckSongFormat.IssueTemplateFormatUnsupported);
}
}
2024-04-16 17:15:21 +08:00
private BeatmapVerifierContext getContext(Stream? resourceStream)
{
var mockWorkingBeatmap = new Mock<TestWorkingBeatmap>(beatmap, null, null);
mockWorkingBeatmap.Setup(w => w.GetStream(It.IsAny<string>())).Returns(resourceStream);
return new BeatmapVerifierContext(beatmap, mockWorkingBeatmap.Object);
}
}
}