2024-03-17 00:20:12 +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.
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
2024-03-18 19:08:41 +00:00
|
|
|
using osu.Framework.Graphics;
|
2024-03-17 00:20:12 +00:00
|
|
|
using osu.Framework.Timing;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Rulesets.Edit;
|
|
|
|
using osu.Game.Rulesets.Edit.Checks;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
2024-03-18 19:08:41 +00:00
|
|
|
using osu.Game.Storyboards;
|
|
|
|
using osuTK;
|
2024-03-17 00:20:12 +00:00
|
|
|
using static osu.Game.Tests.Visual.OsuTestScene.ClockBackedTestWorkingBeatmap;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Editing.Checks
|
|
|
|
{
|
2024-03-17 02:30:59 +00:00
|
|
|
public class CheckUnusedAudioAtEndTest
|
2024-03-17 00:20:12 +00:00
|
|
|
{
|
|
|
|
private CheckUnusedAudioAtEnd check = null!;
|
|
|
|
|
|
|
|
private IBeatmap beatmapNotFullyMapped = null!;
|
|
|
|
|
|
|
|
private IBeatmap beatmapFullyMapped = null!;
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
|
|
|
check = new CheckUnusedAudioAtEnd();
|
|
|
|
beatmapNotFullyMapped = new Beatmap<HitObject>
|
|
|
|
{
|
|
|
|
HitObjects =
|
|
|
|
{
|
|
|
|
new HitCircle { StartTime = 0 },
|
|
|
|
new HitCircle { StartTime = 1_298 },
|
|
|
|
},
|
|
|
|
BeatmapInfo = new BeatmapInfo
|
|
|
|
{
|
|
|
|
Metadata = new BeatmapMetadata { AudioFile = "abc123.jpg" }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
beatmapFullyMapped = new Beatmap<HitObject>
|
|
|
|
{
|
|
|
|
HitObjects =
|
|
|
|
{
|
|
|
|
new HitCircle { StartTime = 0 },
|
|
|
|
new HitCircle { StartTime = 9000 },
|
|
|
|
},
|
|
|
|
BeatmapInfo = new BeatmapInfo
|
|
|
|
{
|
2024-03-18 19:08:41 +00:00
|
|
|
Metadata = new BeatmapMetadata { AudioFile = "abc123.jpg" },
|
2024-03-17 00:20:12 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-03-19 18:16:33 +00:00
|
|
|
[Test]
|
|
|
|
public void TestEmptyBeatmap()
|
|
|
|
{
|
|
|
|
var context = getContext(new Beatmap<HitObject>());
|
|
|
|
var issues = check.Run(context).ToList();
|
|
|
|
|
|
|
|
Assert.That(issues, Has.Count.EqualTo(1));
|
|
|
|
Assert.That(issues.Single().Template is CheckUnusedAudioAtEnd.IssueTemplateUnusedAudioAtEnd);
|
|
|
|
}
|
|
|
|
|
2024-03-17 00:20:12 +00:00
|
|
|
[Test]
|
|
|
|
public void TestAudioNotFullyUsed()
|
|
|
|
{
|
|
|
|
var context = getContext(beatmapNotFullyMapped);
|
|
|
|
var issues = check.Run(context).ToList();
|
|
|
|
|
|
|
|
Assert.That(issues, Has.Count.EqualTo(1));
|
|
|
|
Assert.That(issues.Single().Template is CheckUnusedAudioAtEnd.IssueTemplateUnusedAudioAtEnd);
|
|
|
|
}
|
|
|
|
|
2024-03-18 19:08:41 +00:00
|
|
|
[Test]
|
|
|
|
public void TestAudioNotFullyUsedWithVideo()
|
|
|
|
{
|
|
|
|
var storyboard = new Storyboard();
|
|
|
|
|
|
|
|
var video = new StoryboardVideo("abc123.mp4", 0);
|
|
|
|
|
|
|
|
storyboard.GetLayer("Video").Add(video);
|
|
|
|
|
|
|
|
var mockWorkingBeatmap = getMockWorkingBeatmap(beatmapNotFullyMapped, storyboard);
|
|
|
|
|
|
|
|
var context = getContext(beatmapNotFullyMapped, mockWorkingBeatmap);
|
|
|
|
var issues = check.Run(context).ToList();
|
|
|
|
|
|
|
|
Assert.That(issues, Has.Count.EqualTo(1));
|
|
|
|
Assert.That(issues.Single().Template is CheckUnusedAudioAtEnd.IssueTemplateUnusedAudioAtEndStoryboardOrVideo);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAudioNotFullyUsedWithStoryboardElement()
|
|
|
|
{
|
|
|
|
var storyboard = new Storyboard();
|
|
|
|
|
|
|
|
var sprite = new StoryboardSprite("unknown", Anchor.TopLeft, Vector2.Zero);
|
|
|
|
|
|
|
|
storyboard.GetLayer("Background").Add(sprite);
|
|
|
|
|
|
|
|
var mockWorkingBeatmap = getMockWorkingBeatmap(beatmapNotFullyMapped, storyboard);
|
|
|
|
|
|
|
|
var context = getContext(beatmapNotFullyMapped, mockWorkingBeatmap);
|
|
|
|
var issues = check.Run(context).ToList();
|
|
|
|
|
|
|
|
Assert.That(issues, Has.Count.EqualTo(1));
|
|
|
|
Assert.That(issues.Single().Template is CheckUnusedAudioAtEnd.IssueTemplateUnusedAudioAtEndStoryboardOrVideo);
|
|
|
|
}
|
|
|
|
|
2024-03-17 00:20:12 +00:00
|
|
|
[Test]
|
|
|
|
public void TestAudioFullyUsed()
|
|
|
|
{
|
|
|
|
var context = getContext(beatmapFullyMapped);
|
|
|
|
var issues = check.Run(context).ToList();
|
|
|
|
|
|
|
|
Assert.That(issues, Has.Count.EqualTo(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
private BeatmapVerifierContext getContext(IBeatmap beatmap)
|
|
|
|
{
|
2024-03-18 19:08:41 +00:00
|
|
|
return new BeatmapVerifierContext(beatmap, getMockWorkingBeatmap(beatmap, new Storyboard()).Object);
|
|
|
|
}
|
|
|
|
|
|
|
|
private BeatmapVerifierContext getContext(IBeatmap beatmap, Mock<IWorkingBeatmap> workingBeatmap)
|
|
|
|
{
|
|
|
|
return new BeatmapVerifierContext(beatmap, workingBeatmap.Object);
|
2024-03-17 00:20:12 +00:00
|
|
|
}
|
|
|
|
|
2024-03-18 19:08:41 +00:00
|
|
|
private Mock<IWorkingBeatmap> getMockWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard)
|
2024-03-17 00:20:12 +00:00
|
|
|
{
|
|
|
|
var mockTrack = new TrackVirtualStore(new FramedClock()).GetVirtual(10000, "virtual");
|
|
|
|
|
|
|
|
var mockWorkingBeatmap = new Mock<IWorkingBeatmap>();
|
|
|
|
mockWorkingBeatmap.SetupGet(w => w.Beatmap).Returns(beatmap);
|
|
|
|
mockWorkingBeatmap.SetupGet(w => w.Track).Returns(mockTrack);
|
2024-03-18 19:08:41 +00:00
|
|
|
mockWorkingBeatmap.SetupGet(w => w.Storyboard).Returns(storyboard);
|
2024-03-17 00:20:12 +00:00
|
|
|
|
|
|
|
return mockWorkingBeatmap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|