2019-03-18 07:39:34 +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;
|
|
|
|
using osu.Framework.Lists;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Screens.Play;
|
2019-11-21 09:50:54 +00:00
|
|
|
using osu.Game.Storyboards;
|
2019-03-18 07:39:34 +00:00
|
|
|
|
2019-03-24 16:02:36 +00:00
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
2019-03-18 07:39:34 +00:00
|
|
|
{
|
2020-01-31 04:54:26 +00:00
|
|
|
public class TestScenePlayerReferenceLeaking : TestSceneAllRulesetPlayers
|
2019-03-18 07:39:34 +00:00
|
|
|
{
|
|
|
|
private readonly WeakList<WorkingBeatmap> workingWeakReferences = new WeakList<WorkingBeatmap>();
|
|
|
|
|
|
|
|
private readonly WeakList<Player> playerWeakReferences = new WeakList<Player>();
|
|
|
|
|
|
|
|
protected override void AddCheckSteps()
|
|
|
|
{
|
2019-03-19 11:33:39 +00:00
|
|
|
AddUntilStep("no leaked beatmaps", () =>
|
2019-03-18 07:39:34 +00:00
|
|
|
{
|
|
|
|
GC.Collect();
|
|
|
|
GC.WaitForPendingFinalizers();
|
|
|
|
int count = 0;
|
|
|
|
|
2019-05-17 13:35:23 +00:00
|
|
|
foreach (var unused in workingWeakReferences)
|
|
|
|
count++;
|
|
|
|
|
2019-03-18 07:39:34 +00:00
|
|
|
return count == 1;
|
2019-03-19 11:33:39 +00:00
|
|
|
});
|
2019-03-18 07:39:34 +00:00
|
|
|
|
2019-03-19 11:33:39 +00:00
|
|
|
AddUntilStep("no leaked players", () =>
|
2019-03-18 07:39:34 +00:00
|
|
|
{
|
|
|
|
GC.Collect();
|
|
|
|
GC.WaitForPendingFinalizers();
|
|
|
|
int count = 0;
|
|
|
|
|
2019-05-17 13:35:23 +00:00
|
|
|
foreach (var unused in playerWeakReferences)
|
|
|
|
count++;
|
|
|
|
|
2019-03-18 07:39:34 +00:00
|
|
|
return count == 1;
|
2019-03-19 11:33:39 +00:00
|
|
|
});
|
2019-03-18 07:39:34 +00:00
|
|
|
}
|
|
|
|
|
2019-11-21 09:50:54 +00:00
|
|
|
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null)
|
2019-03-18 07:39:34 +00:00
|
|
|
{
|
2019-11-21 09:50:54 +00:00
|
|
|
var working = base.CreateWorkingBeatmap(beatmap, storyboard);
|
2019-03-18 07:39:34 +00:00
|
|
|
workingWeakReferences.Add(working);
|
|
|
|
return working;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override Player CreatePlayer(Ruleset ruleset)
|
|
|
|
{
|
|
|
|
var player = base.CreatePlayer(ruleset);
|
|
|
|
playerWeakReferences.Add(player);
|
|
|
|
return player;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|