1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 17:07:38 +08:00
osu-lazer/osu.Game.Tests/Editing/Checks/CheckAudioInVideoTest.cs

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

99 lines
3.2 KiB
C#
Raw Normal View History

2021-07-13 10:17:41 +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 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.Storyboards;
using osu.Game.Tests.Beatmaps;
using osu.Game.Tests.Resources;
namespace osu.Game.Tests.Editing.Checks
{
[TestFixture]
public class CheckAudioInVideoTest
{
private CheckAudioInVideo check = null!;
private IBeatmap beatmap = null!;
2021-07-13 10:17:41 +08:00
[SetUp]
public void Setup()
{
check = new CheckAudioInVideo();
beatmap = new Beatmap<HitObject>
{
BeatmapInfo = new BeatmapInfo
{
BeatmapSet = new BeatmapSetInfo
{
Files =
2021-07-13 10:17:41 +08:00
{
CheckTestHelpers.CreateMockFile("mp4"),
}
2021-07-13 10:17:41 +08:00
}
}
};
}
[Test]
public void TestRegularVideoFile()
{
2021-10-12 09:57:54 +08:00
using (var resourceStream = TestResources.OpenResource("Videos/test-video.mp4"))
Assert.IsEmpty(check.Run(getContext(resourceStream)));
2021-07-13 10:17:41 +08:00
}
[Test]
public void TestVideoFileWithAudio()
{
2021-10-12 09:57:54 +08:00
using (var resourceStream = TestResources.OpenResource("Videos/test-video-with-audio.mp4"))
{
var issues = check.Run(getContext(resourceStream)).ToList();
2021-07-13 10:17:41 +08:00
2021-10-12 09:57:54 +08:00
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckAudioInVideo.IssueTemplateHasAudioTrack);
}
2021-07-13 10:17:41 +08:00
}
[Test]
public void TestVideoFileWithTrackButNoAudio()
{
2021-10-12 09:57:54 +08:00
using (var resourceStream = TestResources.OpenResource("Videos/test-video-with-track-but-no-audio.mp4"))
{
var issues = check.Run(getContext(resourceStream)).ToList();
2021-07-13 10:17:41 +08:00
2021-10-12 09:57:54 +08:00
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckAudioInVideo.IssueTemplateHasAudioTrack);
}
2021-07-13 10:17:41 +08:00
}
[Test]
public void TestMissingFile()
{
2021-11-22 13:24:17 +08:00
beatmap.BeatmapInfo.BeatmapSet?.Files.Clear();
2021-07-13 10:17:41 +08:00
2021-10-12 09:57:54 +08:00
var issues = check.Run(getContext(null)).ToList();
2021-07-13 10:17:41 +08:00
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckAudioInVideo.IssueTemplateMissingFile);
}
2022-10-30 16:58:16 +08:00
private BeatmapVerifierContext getContext(Stream? resourceStream)
2021-07-13 10:17:41 +08:00
{
var storyboard = new Storyboard();
var layer = storyboard.GetLayer("Video");
layer.Add(new StoryboardVideo("abc123.mp4", 0));
var mockWorkingBeatmap = new Mock<TestWorkingBeatmap>(beatmap, null, null);
mockWorkingBeatmap.Setup(w => w.GetStream(It.IsAny<string>())).Returns(resourceStream);
mockWorkingBeatmap.As<IWorkingBeatmap>().SetupGet(w => w.Storyboard).Returns(storyboard);
return new BeatmapVerifierContext(beatmap, mockWorkingBeatmap.Object);
}
}
}