mirror of
https://github.com/ppy/osu.git
synced 2024-11-15 01:57:51 +08:00
Fix failing tests due to pooling safety changes
This commit is contained in:
parent
a69fd8198d
commit
18d16018d3
@ -1,10 +1,8 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Game.Rulesets.Mania.Beatmaps;
|
using osu.Game.Rulesets.Mania.Beatmaps;
|
||||||
using osu.Game.Rulesets.Mania.Objects;
|
using osu.Game.Rulesets.Mania.Objects;
|
||||||
using osu.Game.Rulesets.Mania.UI;
|
using osu.Game.Rulesets.Mania.UI;
|
||||||
@ -16,37 +14,35 @@ namespace osu.Game.Rulesets.Mania.Tests.Skinning
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestMinor()
|
public void TestMinor()
|
||||||
{
|
{
|
||||||
AddStep("Create barlines", () => recreate());
|
AddStep("Create barlines", recreate);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void recreate(Func<IEnumerable<BarLine>>? createBarLines = null)
|
private void recreate()
|
||||||
{
|
{
|
||||||
var stageDefinitions = new List<StageDefinition>
|
var stageDefinitions = new List<StageDefinition>
|
||||||
{
|
{
|
||||||
new StageDefinition(4),
|
new StageDefinition(4),
|
||||||
};
|
};
|
||||||
|
|
||||||
SetContents(_ => new ManiaPlayfield(stageDefinitions).With(s =>
|
SetContents(_ =>
|
||||||
{
|
{
|
||||||
if (createBarLines != null)
|
var maniaPlayfield = new ManiaPlayfield(stageDefinitions);
|
||||||
|
|
||||||
|
// Must be scheduled so the pool is loaded before we try and retrieve from it.
|
||||||
|
Schedule(() =>
|
||||||
{
|
{
|
||||||
var barLines = createBarLines();
|
|
||||||
|
|
||||||
foreach (var b in barLines)
|
|
||||||
s.Add(b);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < 64; i++)
|
for (int i = 0; i < 64; i++)
|
||||||
{
|
{
|
||||||
s.Add(new BarLine
|
maniaPlayfield.Add(new BarLine
|
||||||
{
|
{
|
||||||
StartTime = Time.Current + i * 500,
|
StartTime = Time.Current + i * 500,
|
||||||
Major = i % 4 == 0,
|
Major = i % 4 == 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
|
|
||||||
|
return maniaPlayfield;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,16 +25,16 @@ namespace osu.Game.Rulesets.Osu.Tests
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuConfigManager config { get; set; } = null!;
|
private OsuConfigManager config { get; set; } = null!;
|
||||||
|
|
||||||
private readonly List<DrawablePool<TestDrawableOsuJudgement>> pools;
|
private readonly List<DrawablePool<TestDrawableOsuJudgement>> pools = new List<DrawablePool<TestDrawableOsuJudgement>>();
|
||||||
|
|
||||||
public TestSceneDrawableJudgement()
|
[TestCaseSource(nameof(validResults))]
|
||||||
|
public void Test(HitResult result)
|
||||||
{
|
{
|
||||||
pools = new List<DrawablePool<TestDrawableOsuJudgement>>();
|
|
||||||
|
|
||||||
foreach (HitResult result in Enum.GetValues(typeof(HitResult)).OfType<HitResult>().Skip(1))
|
|
||||||
showResult(result);
|
showResult(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<HitResult> validResults => Enum.GetValues<HitResult>().Skip(1);
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestHitLightingDisabled()
|
public void TestHitLightingDisabled()
|
||||||
{
|
{
|
||||||
@ -72,19 +72,21 @@ namespace osu.Game.Rulesets.Osu.Tests
|
|||||||
pools.Add(pool = new DrawablePool<TestDrawableOsuJudgement>(1));
|
pools.Add(pool = new DrawablePool<TestDrawableOsuJudgement>(1));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pool = pools[poolIndex];
|
|
||||||
|
|
||||||
// We need to make sure neither the pool nor the judgement get disposed when new content is set, and they both share the same parent.
|
// We need to make sure neither the pool nor the judgement get disposed when new content is set, and they both share the same parent.
|
||||||
|
pool = pools[poolIndex];
|
||||||
((Container)pool.Parent!).Clear(false);
|
((Container)pool.Parent!).Clear(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
var container = new Container
|
var container = new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Children = new Drawable[]
|
Child = pool,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Must be scheduled so the pool is loaded before we try and retrieve from it.
|
||||||
|
Schedule(() =>
|
||||||
{
|
{
|
||||||
pool,
|
container.Add(pool.Get(j => j.Apply(new JudgementResult(new HitObject
|
||||||
pool.Get(j => j.Apply(new JudgementResult(new HitObject
|
|
||||||
{
|
{
|
||||||
StartTime = Time.Current
|
StartTime = Time.Current
|
||||||
}, new Judgement())
|
}, new Judgement())
|
||||||
@ -94,9 +96,8 @@ namespace osu.Game.Rulesets.Osu.Tests
|
|||||||
{
|
{
|
||||||
j.Anchor = Anchor.Centre;
|
j.Anchor = Anchor.Centre;
|
||||||
j.Origin = Anchor.Centre;
|
j.Origin = Anchor.Centre;
|
||||||
})
|
}));
|
||||||
}
|
});
|
||||||
};
|
|
||||||
|
|
||||||
poolIndex++;
|
poolIndex++;
|
||||||
return container;
|
return container;
|
||||||
|
Loading…
Reference in New Issue
Block a user