mirror of
https://github.com/ppy/osu.git
synced 2025-02-28 20:13:00 +08:00
Add proper stream disposal to tests
This commit is contained in:
parent
82f7f99f37
commit
7f95400f46
@ -49,25 +49,32 @@ namespace osu.Game.Tests.Editing.Checks
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestRegularVideoFile()
|
public void TestRegularVideoFile()
|
||||||
{
|
{
|
||||||
Assert.IsEmpty(check.Run(getContext("Videos/test-video.mp4")));
|
using (var resourceStream = TestResources.OpenResource("Videos/test-video.mp4"))
|
||||||
|
Assert.IsEmpty(check.Run(getContext(resourceStream)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestVideoFileWithAudio()
|
public void TestVideoFileWithAudio()
|
||||||
{
|
{
|
||||||
var issues = check.Run(getContext("Videos/test-video-with-audio.mp4")).ToList();
|
using (var resourceStream = TestResources.OpenResource("Videos/test-video-with-audio.mp4"))
|
||||||
|
{
|
||||||
|
var issues = check.Run(getContext(resourceStream)).ToList();
|
||||||
|
|
||||||
Assert.That(issues, Has.Count.EqualTo(1));
|
Assert.That(issues, Has.Count.EqualTo(1));
|
||||||
Assert.That(issues.Single().Template is CheckAudioInVideo.IssueTemplateHasAudioTrack);
|
Assert.That(issues.Single().Template is CheckAudioInVideo.IssueTemplateHasAudioTrack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestVideoFileWithTrackButNoAudio()
|
public void TestVideoFileWithTrackButNoAudio()
|
||||||
{
|
{
|
||||||
var issues = check.Run(getContext("Videos/test-video-with-track-but-no-audio.mp4")).ToList();
|
using (var resourceStream = TestResources.OpenResource("Videos/test-video-with-track-but-no-audio.mp4"))
|
||||||
|
{
|
||||||
|
var issues = check.Run(getContext(resourceStream)).ToList();
|
||||||
|
|
||||||
Assert.That(issues, Has.Count.EqualTo(1));
|
Assert.That(issues, Has.Count.EqualTo(1));
|
||||||
Assert.That(issues.Single().Template is CheckAudioInVideo.IssueTemplateHasAudioTrack);
|
Assert.That(issues.Single().Template is CheckAudioInVideo.IssueTemplateHasAudioTrack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -75,18 +82,14 @@ namespace osu.Game.Tests.Editing.Checks
|
|||||||
{
|
{
|
||||||
beatmap.BeatmapInfo.BeatmapSet.Files.Clear();
|
beatmap.BeatmapInfo.BeatmapSet.Files.Clear();
|
||||||
|
|
||||||
var issues = check.Run(getContext("Videos/missing.mp4", allowMissing: true)).ToList();
|
var issues = check.Run(getContext(null)).ToList();
|
||||||
|
|
||||||
Assert.That(issues, Has.Count.EqualTo(1));
|
Assert.That(issues, Has.Count.EqualTo(1));
|
||||||
Assert.That(issues.Single().Template is CheckAudioInVideo.IssueTemplateMissingFile);
|
Assert.That(issues.Single().Template is CheckAudioInVideo.IssueTemplateMissingFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BeatmapVerifierContext getContext(string resourceName, bool allowMissing = false)
|
private BeatmapVerifierContext getContext(Stream resourceStream)
|
||||||
{
|
{
|
||||||
Stream resourceStream = string.IsNullOrEmpty(resourceName) ? null : TestResources.OpenResource(resourceName);
|
|
||||||
if (!allowMissing && resourceStream == null)
|
|
||||||
throw new FileNotFoundException($"The requested test resource \"{resourceName}\" does not exist.");
|
|
||||||
|
|
||||||
var storyboard = new Storyboard();
|
var storyboard = new Storyboard();
|
||||||
var layer = storyboard.GetLayer("Video");
|
var layer = storyboard.GetLayer("Video");
|
||||||
layer.Add(new StoryboardVideo("abc123.mp4", 0));
|
layer.Add(new StoryboardVideo("abc123.mp4", 0));
|
||||||
|
@ -68,46 +68,57 @@ namespace osu.Game.Tests.Editing.Checks
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestRegularAudioFile()
|
public void TestRegularAudioFile()
|
||||||
{
|
{
|
||||||
Assert.IsEmpty(check.Run(getContext("Samples/test-sample.mp3")));
|
using (var resourceStream = TestResources.OpenResource("Samples/test-sample.mp3"))
|
||||||
|
{
|
||||||
|
Assert.IsEmpty(check.Run(getContext(resourceStream)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestBlankAudioFile()
|
public void TestBlankAudioFile()
|
||||||
{
|
{
|
||||||
// This is a 0 ms duration audio file, commonly used to silence sliderslides/ticks, and so should be fine.
|
using (var resourceStream = TestResources.OpenResource("Samples/blank.wav"))
|
||||||
Assert.IsEmpty(check.Run(getContext("Samples/blank.wav")));
|
{
|
||||||
|
// This is a 0 ms duration audio file, commonly used to silence sliderslides/ticks, and so should be fine.
|
||||||
|
Assert.IsEmpty(check.Run(getContext(resourceStream)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestTooShortAudioFile()
|
public void TestTooShortAudioFile()
|
||||||
{
|
{
|
||||||
var issues = check.Run(getContext("Samples/test-sample-cut.mp3")).ToList();
|
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, Has.Count.EqualTo(1));
|
||||||
Assert.That(issues.Single().Template is CheckTooShortAudioFiles.IssueTemplateTooShort);
|
Assert.That(issues.Single().Template is CheckTooShortAudioFiles.IssueTemplateTooShort);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestMissingAudioFile()
|
public void TestMissingAudioFile()
|
||||||
{
|
{
|
||||||
Assert.IsEmpty(check.Run(getContext("Samples/missing.mp3", allowMissing: true)));
|
using (var resourceStream = TestResources.OpenResource("Samples/missing.mp3"))
|
||||||
|
{
|
||||||
|
Assert.IsEmpty(check.Run(getContext(resourceStream, allowMissing: true)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestCorruptAudioFile()
|
public void TestCorruptAudioFile()
|
||||||
{
|
{
|
||||||
var issues = check.Run(getContext("Samples/corrupt.wav")).ToList();
|
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, Has.Count.EqualTo(1));
|
||||||
Assert.That(issues.Single().Template is CheckTooShortAudioFiles.IssueTemplateBadFormat);
|
Assert.That(issues.Single().Template is CheckTooShortAudioFiles.IssueTemplateBadFormat);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private BeatmapVerifierContext getContext(string resourceName, bool allowMissing = false)
|
private BeatmapVerifierContext getContext(Stream resourceStream, bool allowMissing = false)
|
||||||
{
|
{
|
||||||
Stream resourceStream = string.IsNullOrEmpty(resourceName) ? null : TestResources.OpenResource(resourceName);
|
|
||||||
if (!allowMissing && resourceStream == null)
|
|
||||||
throw new FileNotFoundException($"The requested test resource \"{resourceName}\" does not exist.");
|
|
||||||
|
|
||||||
var mockWorkingBeatmap = new Mock<TestWorkingBeatmap>(beatmap, null, null);
|
var mockWorkingBeatmap = new Mock<TestWorkingBeatmap>(beatmap, null, null);
|
||||||
mockWorkingBeatmap.Setup(w => w.GetStream(It.IsAny<string>())).Returns(resourceStream);
|
mockWorkingBeatmap.Setup(w => w.GetStream(It.IsAny<string>())).Returns(resourceStream);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user