|
| 1 | +// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. |
| 2 | +// See the LICENCE file in the repository root for full licence text. |
| 3 | + |
| 4 | +using System.Linq; |
| 5 | +using NUnit.Framework; |
| 6 | +using osu.Game.Beatmaps; |
| 7 | +using osu.Game.Models; |
| 8 | +using osu.Game.Rulesets.Edit; |
| 9 | +using osu.Game.Rulesets.Edit.Checks; |
| 10 | +using osu.Game.Rulesets.Objects; |
| 11 | +using osu.Game.Tests.Beatmaps; |
| 12 | + |
| 13 | +namespace osu.Game.Tests.Editing.Checks |
| 14 | +{ |
| 15 | + [TestFixture] |
| 16 | + public class CheckInconsistentAudioTest |
| 17 | + { |
| 18 | + private CheckInconsistentAudio check = null!; |
| 19 | + |
| 20 | + [SetUp] |
| 21 | + public void Setup() |
| 22 | + { |
| 23 | + check = new CheckInconsistentAudio(); |
| 24 | + } |
| 25 | + |
| 26 | + [Test] |
| 27 | + public void TestConsistentAudio() |
| 28 | + { |
| 29 | + var beatmaps = createBeatmapSetWithAudio("audio.mp3", "audio.mp3"); |
| 30 | + var context = createContextWithMultipleDifficulties(beatmaps.First(), beatmaps); |
| 31 | + |
| 32 | + Assert.That(check.Run(context), Is.Empty); |
| 33 | + } |
| 34 | + |
| 35 | + [Test] |
| 36 | + public void TestInconsistentAudio() |
| 37 | + { |
| 38 | + var beatmaps = createBeatmapSetWithAudio("audio1.mp3", "audio2.mp3"); |
| 39 | + var context = createContextWithMultipleDifficulties(beatmaps.First(), beatmaps); |
| 40 | + |
| 41 | + var issues = check.Run(context).ToList(); |
| 42 | + |
| 43 | + Assert.That(issues, Has.Count.EqualTo(1)); |
| 44 | + Assert.That(issues.Single().Template is CheckInconsistentAudio.IssueTemplateInconsistentAudio); |
| 45 | + Assert.That(issues.Single().ToString(), Contains.Substring("audio1.mp3")); |
| 46 | + Assert.That(issues.Single().ToString(), Contains.Substring("audio2.mp3")); |
| 47 | + } |
| 48 | + |
| 49 | + [Test] |
| 50 | + public void TestInconsistentAudioWithNull() |
| 51 | + { |
| 52 | + var beatmaps = createBeatmapSetWithAudio("audio.mp3", null); |
| 53 | + var context = createContextWithMultipleDifficulties(beatmaps.First(), beatmaps); |
| 54 | + |
| 55 | + var issues = check.Run(context).ToList(); |
| 56 | + |
| 57 | + Assert.That(issues, Has.Count.EqualTo(1)); |
| 58 | + Assert.That(issues.Single().Template is CheckInconsistentAudio.IssueTemplateInconsistentAudio); |
| 59 | + Assert.That(issues.Single().ToString(), Contains.Substring("audio.mp3")); |
| 60 | + Assert.That(issues.Single().ToString(), Contains.Substring("not set")); |
| 61 | + } |
| 62 | + |
| 63 | + [Test] |
| 64 | + public void TestInconsistentAudioWithEmptyString() |
| 65 | + { |
| 66 | + var beatmaps = createBeatmapSetWithAudio("audio.mp3", ""); |
| 67 | + var context = createContextWithMultipleDifficulties(beatmaps.First(), beatmaps); |
| 68 | + |
| 69 | + var issues = check.Run(context).ToList(); |
| 70 | + |
| 71 | + Assert.That(issues, Has.Count.EqualTo(1)); |
| 72 | + Assert.That(issues.Single().Template is CheckInconsistentAudio.IssueTemplateInconsistentAudio); |
| 73 | + Assert.That(issues.Single().ToString(), Contains.Substring("audio.mp3")); |
| 74 | + Assert.That(issues.Single().ToString(), Contains.Substring("not set")); |
| 75 | + } |
| 76 | + |
| 77 | + [Test] |
| 78 | + public void TestBothAudioNotSet() |
| 79 | + { |
| 80 | + var beatmaps = createBeatmapSetWithAudio("", ""); |
| 81 | + var context = createContextWithMultipleDifficulties(beatmaps.First(), beatmaps); |
| 82 | + |
| 83 | + Assert.That(check.Run(context), Is.Empty); |
| 84 | + } |
| 85 | + |
| 86 | + [Test] |
| 87 | + public void TestMultipleInconsistencies() |
| 88 | + { |
| 89 | + var beatmaps = createBeatmapSetWithAudio("audio1.mp3", "audio2.mp3", "audio3.mp3"); |
| 90 | + var context = createContextWithMultipleDifficulties(beatmaps.First(), beatmaps); |
| 91 | + |
| 92 | + var issues = check.Run(context).ToList(); |
| 93 | + |
| 94 | + Assert.That(issues, Has.Count.EqualTo(2)); |
| 95 | + Assert.That(issues.All(issue => issue.Template is CheckInconsistentAudio.IssueTemplateInconsistentAudio)); |
| 96 | + } |
| 97 | + |
| 98 | + [Test] |
| 99 | + public void TestSingleDifficulty() |
| 100 | + { |
| 101 | + var beatmaps = createBeatmapSetWithAudio("audio.mp3"); |
| 102 | + var context = createContextWithMultipleDifficulties(beatmaps.First(), beatmaps); |
| 103 | + |
| 104 | + Assert.That(check.Run(context), Is.Empty); |
| 105 | + } |
| 106 | + |
| 107 | + private IBeatmap createBeatmapWithAudio(string audioFile, RealmNamedFileUsage? file) |
| 108 | + { |
| 109 | + var beatmap = new Beatmap<HitObject> |
| 110 | + { |
| 111 | + BeatmapInfo = new BeatmapInfo |
| 112 | + { |
| 113 | + Metadata = new BeatmapMetadata { AudioFile = audioFile }, |
| 114 | + BeatmapSet = new BeatmapSetInfo() |
| 115 | + } |
| 116 | + }; |
| 117 | + |
| 118 | + if (file != null) |
| 119 | + beatmap.BeatmapInfo.BeatmapSet!.Files.Add(file); |
| 120 | + |
| 121 | + return beatmap; |
| 122 | + } |
| 123 | + |
| 124 | + private IBeatmap[] createBeatmapSetWithAudio(params string?[] audioFiles) |
| 125 | + { |
| 126 | + var beatmapSet = new BeatmapSetInfo(); |
| 127 | + var beatmaps = new IBeatmap[audioFiles.Length]; |
| 128 | + |
| 129 | + for (int i = 0; i < audioFiles.Length; i++) |
| 130 | + { |
| 131 | + string? audioFile = audioFiles[i]; |
| 132 | + var file = !string.IsNullOrEmpty(audioFile) ? CheckTestHelpers.CreateMockFile("mp3") : null; |
| 133 | + |
| 134 | + beatmaps[i] = createBeatmapWithAudio(audioFile ?? "", file); |
| 135 | + beatmaps[i].BeatmapInfo.BeatmapSet = beatmapSet; |
| 136 | + beatmaps[i].BeatmapInfo.DifficultyName = $"Difficulty {i + 1}"; |
| 137 | + beatmapSet.Beatmaps.Add(beatmaps[i].BeatmapInfo); |
| 138 | + } |
| 139 | + |
| 140 | + return beatmaps; |
| 141 | + } |
| 142 | + |
| 143 | + private BeatmapVerifierContext createContextWithMultipleDifficulties(IBeatmap currentBeatmap, IBeatmap[] allDifficulties) |
| 144 | + { |
| 145 | + var verifiedCurrentBeatmap = new BeatmapVerifierContext.VerifiedBeatmap(new TestWorkingBeatmap(currentBeatmap), currentBeatmap); |
| 146 | + var verifiedOtherBeatmaps = allDifficulties.Select(b => new BeatmapVerifierContext.VerifiedBeatmap(new TestWorkingBeatmap(b), b)).ToList(); |
| 147 | + |
| 148 | + return new BeatmapVerifierContext(verifiedCurrentBeatmap, verifiedOtherBeatmaps, DifficultyRating.ExpertPlus); |
| 149 | + } |
| 150 | + } |
| 151 | +} |
0 commit comments