mirror of
https://github.com/ppy/osu.git
synced 2025-02-27 00:52:57 +08:00
Merge pull request #15552 from Naxesss/dispose-background-after-check
Use disposal in `CheckBackgroundQuality`
This commit is contained in:
commit
9404eac227
@ -54,7 +54,7 @@ namespace osu.Game.Tests.Editing.Checks
|
|||||||
{
|
{
|
||||||
// While this is a problem, it is out of scope for this check and is caught by a different one.
|
// While this is a problem, it is out of scope for this check and is caught by a different one.
|
||||||
beatmap.Metadata.BackgroundFile = string.Empty;
|
beatmap.Metadata.BackgroundFile = string.Empty;
|
||||||
var context = getContext(null, System.Array.Empty<byte>());
|
var context = getContext(null, new MemoryStream(System.Array.Empty<byte>()));
|
||||||
|
|
||||||
Assert.That(check.Run(context), Is.Empty);
|
Assert.That(check.Run(context), Is.Empty);
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ namespace osu.Game.Tests.Editing.Checks
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestTooUncompressed()
|
public void TestTooUncompressed()
|
||||||
{
|
{
|
||||||
var context = getContext(new Texture(1920, 1080), new byte[1024 * 1024 * 3]);
|
var context = getContext(new Texture(1920, 1080), new MemoryStream(new byte[1024 * 1024 * 3]));
|
||||||
|
|
||||||
var issues = check.Run(context).ToList();
|
var issues = check.Run(context).ToList();
|
||||||
|
|
||||||
@ -111,19 +111,32 @@ namespace osu.Game.Tests.Editing.Checks
|
|||||||
Assert.That(issues.Single().Template is CheckBackgroundQuality.IssueTemplateTooUncompressed);
|
Assert.That(issues.Single().Template is CheckBackgroundQuality.IssueTemplateTooUncompressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BeatmapVerifierContext getContext(Texture background, [CanBeNull] byte[] fileBytes = null)
|
[Test]
|
||||||
|
public void TestStreamClosed()
|
||||||
{
|
{
|
||||||
return new BeatmapVerifierContext(beatmap, getMockWorkingBeatmap(background, fileBytes).Object);
|
var background = new Texture(1920, 1080);
|
||||||
|
var stream = new Mock<MemoryStream>(new byte[1024 * 1024]);
|
||||||
|
|
||||||
|
var context = getContext(background, stream.Object);
|
||||||
|
|
||||||
|
Assert.That(check.Run(context), Is.Empty);
|
||||||
|
|
||||||
|
stream.Verify(x => x.Close(), Times.Once());
|
||||||
|
}
|
||||||
|
|
||||||
|
private BeatmapVerifierContext getContext(Texture background, [CanBeNull] Stream stream = null)
|
||||||
|
{
|
||||||
|
return new BeatmapVerifierContext(beatmap, getMockWorkingBeatmap(background, stream).Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the mock of the working beatmap with the given background and filesize.
|
/// Returns the mock of the working beatmap with the given background and its file stream.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="background">The texture of the background.</param>
|
/// <param name="background">The texture of the background.</param>
|
||||||
/// <param name="fileBytes">The bytes that represent the background file.</param>
|
/// <param name="stream">The stream representing the background file.</param>
|
||||||
private Mock<IWorkingBeatmap> getMockWorkingBeatmap(Texture background, [CanBeNull] byte[] fileBytes = null)
|
private Mock<IWorkingBeatmap> getMockWorkingBeatmap(Texture background, [CanBeNull] Stream stream = null)
|
||||||
{
|
{
|
||||||
var stream = new MemoryStream(fileBytes ?? new byte[1024 * 1024]);
|
stream ??= new MemoryStream(new byte[1024 * 1024]);
|
||||||
|
|
||||||
var mock = new Mock<IWorkingBeatmap>();
|
var mock = new Mock<IWorkingBeatmap>();
|
||||||
mock.SetupGet(w => w.Beatmap).Returns(beatmap);
|
mock.SetupGet(w => w.Beatmap).Returns(beatmap);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using osu.Game.Rulesets.Edit.Checks.Components;
|
using osu.Game.Rulesets.Edit.Checks.Components;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Edit.Checks
|
namespace osu.Game.Rulesets.Edit.Checks
|
||||||
@ -48,11 +49,15 @@ namespace osu.Game.Rulesets.Edit.Checks
|
|||||||
yield return new IssueTemplateLowResolution(this).Create(texture.Width, texture.Height);
|
yield return new IssueTemplateLowResolution(this).Create(texture.Width, texture.Height);
|
||||||
|
|
||||||
string storagePath = context.Beatmap.BeatmapInfo.BeatmapSet.GetPathForFile(backgroundFile);
|
string storagePath = context.Beatmap.BeatmapInfo.BeatmapSet.GetPathForFile(backgroundFile);
|
||||||
double filesizeMb = context.WorkingBeatmap.GetStream(storagePath).Length / (1024d * 1024d);
|
|
||||||
|
using (Stream stream = context.WorkingBeatmap.GetStream(storagePath))
|
||||||
|
{
|
||||||
|
double filesizeMb = stream.Length / (1024d * 1024d);
|
||||||
|
|
||||||
if (filesizeMb > max_filesize_mb)
|
if (filesizeMb > max_filesize_mb)
|
||||||
yield return new IssueTemplateTooUncompressed(this).Create(filesizeMb);
|
yield return new IssueTemplateTooUncompressed(this).Create(filesizeMb);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class IssueTemplateTooHighResolution : IssueTemplate
|
public class IssueTemplateTooHighResolution : IssueTemplate
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user