mirror of
https://github.com/ppy/osu.git
synced 2026-05-13 19:54:15 +08:00
a996261304
It's been a while. Notes: - `SharpCompress` usages changed a bit. Manually adjusted these, mostly just renames or adjusted parameters. - nUnit 3 -> 4 migrated using https://gist.github.com/peppy/07994386d793a117350cb5f24b156585. there's a mode in this script to update to the newer `Assert.That` syntax but it requires fixes and couldn't really be bothered. - DeepEqual nuked as the only usage was on a disabled test. The reason it's disabled has been merged upstream, but it's failing for other (realm) reasons which I don't think is worthwhile to investigate for now. - This bumps Moq. I think the author is back in a sensible headspace and the new version has the stupid shit removed, so probably okay? Nice to be on a level playing field with packages for once in a long time. - Automapper is silly, but we've discussed this elsewhere. - `TestRealmKeyBindingStore` failures are a wildcard, but fixed by using a more standardised testing method. Dunno why, don't care. --------- Co-authored-by: Bartłomiej Dach <dach.bartlomiej@gmail.com>
175 lines
6.2 KiB
C#
175 lines
6.2 KiB
C#
// 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 class CheckHitsoundsFormatTest
|
|
{
|
|
private CheckHitsoundsFormat check = null!;
|
|
|
|
private IBeatmap beatmap = null!;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
check = new CheckHitsoundsFormat();
|
|
beatmap = new Beatmap<HitObject>
|
|
{
|
|
BeatmapInfo = new BeatmapInfo
|
|
{
|
|
BeatmapSet = new BeatmapSetInfo
|
|
{
|
|
Files = { CheckTestHelpers.CreateMockFile("wav") }
|
|
}
|
|
}
|
|
};
|
|
|
|
// 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 TestMp3Audio()
|
|
{
|
|
using (var resourceStream = TestResources.OpenResource("Samples/test-sample-cut.mp3"))
|
|
{
|
|
var issues = check.Run(getContext(resourceStream)).ToList();
|
|
Assert.That(issues, Has.Count.EqualTo(1));
|
|
Assert.That(issues.Single().Template is CheckHitsoundsFormat.IssueTemplateIncorrectFormat);
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void TestOggAudio()
|
|
{
|
|
using (var resourceStream = TestResources.OpenResource("Samples/test-sample.ogg"))
|
|
{
|
|
var issues = check.Run(getContext(resourceStream)).ToList();
|
|
Assert.That(issues, Has.Count.EqualTo(0));
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void TestWavAudio()
|
|
{
|
|
using (var resourceStream = TestResources.OpenResource("Samples/hitsound-delay.wav"))
|
|
{
|
|
var issues = check.Run(getContext(resourceStream)).ToList();
|
|
Assert.That(issues, Has.Count.EqualTo(0));
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void TestWebmAudio()
|
|
{
|
|
using (var resourceStream = TestResources.OpenResource("Samples/test-sample.webm"))
|
|
{
|
|
var issues = check.Run(getContext(resourceStream)).ToList();
|
|
Assert.That(issues, Has.Count.EqualTo(1));
|
|
Assert.That(issues.Single().Template is CheckHitsoundsFormat.IssueTemplateFormatUnsupported);
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void TestNotAnAudioFile()
|
|
{
|
|
beatmap = new Beatmap<HitObject>
|
|
{
|
|
BeatmapInfo = new BeatmapInfo
|
|
{
|
|
BeatmapSet = new BeatmapSetInfo
|
|
{
|
|
Files = { CheckTestHelpers.CreateMockFile("png") }
|
|
}
|
|
}
|
|
};
|
|
|
|
using (var resourceStream = TestResources.OpenResource("Textures/test-image.png"))
|
|
{
|
|
var issues = check.Run(getContext(resourceStream)).ToList();
|
|
Assert.That(issues, Has.Count.EqualTo(0));
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void TestCorruptAudio()
|
|
{
|
|
using (var resourceStream = TestResources.OpenResource("Samples/corrupt.wav"))
|
|
{
|
|
var issues = check.Run(getContext(resourceStream)).ToList();
|
|
Assert.That(issues, Has.Count.EqualTo(1));
|
|
Assert.That(issues.Single().Template is CheckHitsoundsFormat.IssueTemplateFormatUnsupported);
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void TestBeatmapAudioTracksExemptedFromCheck()
|
|
{
|
|
using (var resourceStream = TestResources.OpenResource("Samples/corrupt.wav"))
|
|
{
|
|
var beatmapSet = new BeatmapSetInfo
|
|
{
|
|
Files =
|
|
{
|
|
CheckTestHelpers.CreateMockFile("wav"),
|
|
CheckTestHelpers.CreateMockFile("mp3")
|
|
}
|
|
};
|
|
|
|
var firstPlayable = new Beatmap<HitObject>
|
|
{
|
|
BeatmapInfo = new BeatmapInfo
|
|
{
|
|
BeatmapSet = beatmapSet,
|
|
Metadata = new BeatmapMetadata { AudioFile = beatmapSet.Files[0].Filename }
|
|
}
|
|
};
|
|
var firstWorking = new Mock<TestWorkingBeatmap>(firstPlayable, null!, null!);
|
|
firstWorking.Setup(w => w.GetStream(It.IsAny<string>())).Returns(resourceStream);
|
|
|
|
var secondPlayable = new Beatmap<HitObject>
|
|
{
|
|
BeatmapInfo = new BeatmapInfo
|
|
{
|
|
BeatmapSet = beatmapSet,
|
|
Metadata = new BeatmapMetadata { AudioFile = beatmapSet.Files[1].Filename }
|
|
}
|
|
};
|
|
var secondWorking = new Mock<TestWorkingBeatmap>(secondPlayable, null!, null!);
|
|
secondWorking.Setup(w => w.GetStream(It.IsAny<string>())).Returns(resourceStream);
|
|
|
|
var context = new BeatmapVerifierContext(
|
|
new BeatmapVerifierContext.VerifiedBeatmap(firstWorking.Object, firstPlayable),
|
|
[new BeatmapVerifierContext.VerifiedBeatmap(secondWorking.Object, secondPlayable)],
|
|
DifficultyRating.ExpertPlus);
|
|
|
|
var issues = check.Run(context).ToList();
|
|
Assert.That(issues, Is.Empty);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|