1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-26 00:42:53 +08:00
osu-lazer/osu.Game.Tests/Visual/Gameplay/TestScenePlayerReferenceLeaking.cs

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

63 lines
1.8 KiB
C#
Raw Normal View History

// 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.
2022-06-17 15:37:17 +08:00
#nullable disable
using System;
using osu.Framework.Lists;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
using osu.Game.Screens.Play;
2019-11-21 17:50:54 +08:00
using osu.Game.Storyboards;
2019-03-25 00:02:36 +08:00
namespace osu.Game.Tests.Visual.Gameplay
{
public class TestScenePlayerReferenceLeaking : TestSceneAllRulesetPlayers
{
private readonly WeakList<IWorkingBeatmap> workingWeakReferences = new WeakList<IWorkingBeatmap>();
private readonly WeakList<Player> playerWeakReferences = new WeakList<Player>();
protected override void AddCheckSteps()
{
AddUntilStep("no leaked beatmaps", () =>
{
GC.Collect();
GC.WaitForPendingFinalizers();
int count = 0;
2019-05-17 21:35:23 +08:00
foreach (var unused in workingWeakReferences)
count++;
return count == 1;
});
AddUntilStep("no leaked players", () =>
{
GC.Collect();
GC.WaitForPendingFinalizers();
int count = 0;
2019-05-17 21:35:23 +08:00
foreach (var unused in playerWeakReferences)
count++;
return count == 1;
});
}
2019-11-21 17:50:54 +08:00
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null)
{
2019-11-21 17:50:54 +08:00
var working = base.CreateWorkingBeatmap(beatmap, storyboard);
workingWeakReferences.Add(working);
return working;
}
protected override Player CreatePlayer(Ruleset ruleset)
{
var player = base.CreatePlayer(ruleset);
playerWeakReferences.Add(player);
return player;
}
}
}