2018-04-13 17:19:50 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2018-08-16 08:59:03 +08:00
|
|
|
|
using JetBrains.Annotations;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Rulesets;
|
2018-05-07 10:36:51 +08:00
|
|
|
|
using osu.Game.Rulesets.Catch;
|
|
|
|
|
using osu.Game.Rulesets.Mania;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2018-05-07 10:33:40 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Rulesets.Osu;
|
2018-05-07 10:36:51 +08:00
|
|
|
|
using osu.Game.Rulesets.Taiko;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Screens.Select;
|
|
|
|
|
using osu.Game.Tests.Beatmaps;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class TestCaseBeatmapInfoWedge : OsuTestCase
|
|
|
|
|
{
|
|
|
|
|
private RulesetStore rulesets;
|
|
|
|
|
private TestBeatmapInfoWedge infoWedge;
|
2018-04-19 19:44:38 +08:00
|
|
|
|
private readonly List<IBeatmap> beatmaps = new List<IBeatmap>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2018-05-23 16:37:39 +08:00
|
|
|
|
private void load(RulesetStore rulesets)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
this.rulesets = rulesets;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
Add(infoWedge = new TestBeatmapInfoWedge
|
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(0.5f, 245),
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Margin = new MarginPadding { Top = 20 }
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddStep("show", () =>
|
|
|
|
|
{
|
|
|
|
|
infoWedge.State = Visibility.Visible;
|
2018-06-06 17:26:51 +08:00
|
|
|
|
infoWedge.Beatmap = Beatmap;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
});
|
|
|
|
|
|
2018-04-23 23:51:33 +08:00
|
|
|
|
// select part is redundant, but wait for load isn't
|
2018-05-23 16:37:39 +08:00
|
|
|
|
selectBeatmap(Beatmap.Value.Beatmap);
|
2018-04-23 23:51:33 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
AddWaitStep(3);
|
|
|
|
|
|
|
|
|
|
AddStep("hide", () => { infoWedge.State = Visibility.Hidden; });
|
|
|
|
|
|
|
|
|
|
AddWaitStep(3);
|
|
|
|
|
|
|
|
|
|
AddStep("show", () => { infoWedge.State = Visibility.Visible; });
|
|
|
|
|
|
|
|
|
|
foreach (var rulesetInfo in rulesets.AvailableRulesets)
|
|
|
|
|
{
|
2018-06-26 17:59:13 +08:00
|
|
|
|
var instance = rulesetInfo.CreateInstance();
|
2018-04-24 01:07:16 +08:00
|
|
|
|
var testBeatmap = createTestBeatmap(rulesetInfo);
|
2018-04-23 23:51:33 +08:00
|
|
|
|
|
2018-04-24 01:07:16 +08:00
|
|
|
|
beatmaps.Add(testBeatmap);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-26 17:59:13 +08:00
|
|
|
|
AddStep("set ruleset", () => Ruleset.Value = rulesetInfo);
|
|
|
|
|
|
2018-04-24 01:07:16 +08:00
|
|
|
|
selectBeatmap(testBeatmap);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-26 17:59:13 +08:00
|
|
|
|
testBeatmapLabels(instance);
|
2018-05-07 10:36:51 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
// TODO: adjust cases once more info is shown for other gamemodes
|
2018-06-26 17:59:13 +08:00
|
|
|
|
switch (instance)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-05-07 10:36:51 +08:00
|
|
|
|
case OsuRuleset _:
|
|
|
|
|
testInfoLabels(5);
|
|
|
|
|
break;
|
|
|
|
|
case TaikoRuleset _:
|
2018-04-13 17:19:50 +08:00
|
|
|
|
testInfoLabels(5);
|
|
|
|
|
break;
|
2018-05-07 10:36:51 +08:00
|
|
|
|
case CatchRuleset _:
|
|
|
|
|
testInfoLabels(5);
|
|
|
|
|
break;
|
|
|
|
|
case ManiaRuleset _:
|
|
|
|
|
testInfoLabels(4);
|
|
|
|
|
break;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
default:
|
|
|
|
|
testInfoLabels(2);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
testNullBeatmap();
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-07 10:36:51 +08:00
|
|
|
|
private void testBeatmapLabels(Ruleset ruleset)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
AddAssert("check version", () => infoWedge.Info.VersionLabel.Text == $"{ruleset.ShortName}Version");
|
|
|
|
|
AddAssert("check title", () => infoWedge.Info.TitleLabel.Text == $"{ruleset.ShortName}Source — {ruleset.ShortName}Title");
|
|
|
|
|
AddAssert("check artist", () => infoWedge.Info.ArtistLabel.Text == $"{ruleset.ShortName}Artist");
|
|
|
|
|
AddAssert("check author", () => infoWedge.Info.MapperContainer.Children.OfType<OsuSpriteText>().Any(s => s.Text == $"{ruleset.ShortName}Author"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void testInfoLabels(int expectedCount)
|
|
|
|
|
{
|
2018-07-05 10:32:09 +08:00
|
|
|
|
AddAssert("check info labels exists", () => infoWedge.Info.InfoLabelContainer.Children.Any());
|
|
|
|
|
AddAssert("check info labels count", () => infoWedge.Info.InfoLabelContainer.Children.Count == expectedCount);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void testNullBeatmap()
|
|
|
|
|
{
|
2018-08-16 08:59:03 +08:00
|
|
|
|
selectBeatmap(null);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
AddAssert("check empty version", () => string.IsNullOrEmpty(infoWedge.Info.VersionLabel.Text));
|
2018-05-23 16:37:39 +08:00
|
|
|
|
AddAssert("check default title", () => infoWedge.Info.TitleLabel.Text == Beatmap.Default.BeatmapInfo.Metadata.Title);
|
|
|
|
|
AddAssert("check default artist", () => infoWedge.Info.ArtistLabel.Text == Beatmap.Default.BeatmapInfo.Metadata.Artist);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
AddAssert("check empty author", () => !infoWedge.Info.MapperContainer.Children.Any());
|
2018-07-05 10:32:09 +08:00
|
|
|
|
AddAssert("check no info labels", () => !infoWedge.Info.InfoLabelContainer.Children.Any());
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-16 08:59:03 +08:00
|
|
|
|
private void selectBeatmap([CanBeNull] IBeatmap b)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-04-23 19:50:16 +08:00
|
|
|
|
BeatmapInfoWedge.BufferedWedgeInfo infoBefore = null;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-08-16 08:59:03 +08:00
|
|
|
|
AddStep($"select {b?.Metadata.Title ?? "null"} beatmap", () =>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-04-23 19:50:16 +08:00
|
|
|
|
infoBefore = infoWedge.Info;
|
2018-08-16 08:59:03 +08:00
|
|
|
|
infoWedge.Beatmap = Beatmap.Value = b == null ? Beatmap.Default : new TestWorkingBeatmap(b);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddUntilStep(() => infoWedge.Info != infoBefore, "wait for async load");
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-19 19:44:38 +08:00
|
|
|
|
private IBeatmap createTestBeatmap(RulesetInfo ruleset)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
List<HitObject> objects = new List<HitObject>();
|
|
|
|
|
for (double i = 0; i < 50000; i += 1000)
|
2018-05-07 10:33:40 +08:00
|
|
|
|
objects.Add(new TestHitObject { StartTime = i });
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
return new Beatmap
|
|
|
|
|
{
|
|
|
|
|
BeatmapInfo = new BeatmapInfo
|
|
|
|
|
{
|
|
|
|
|
Metadata = new BeatmapMetadata
|
|
|
|
|
{
|
|
|
|
|
AuthorString = $"{ruleset.ShortName}Author",
|
|
|
|
|
Artist = $"{ruleset.ShortName}Artist",
|
|
|
|
|
Source = $"{ruleset.ShortName}Source",
|
|
|
|
|
Title = $"{ruleset.ShortName}Title"
|
|
|
|
|
},
|
|
|
|
|
Ruleset = ruleset,
|
|
|
|
|
StarDifficulty = 6,
|
2018-05-07 10:33:40 +08:00
|
|
|
|
Version = $"{ruleset.ShortName}Version",
|
|
|
|
|
BaseDifficulty = new BeatmapDifficulty()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
HitObjects = objects
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class TestBeatmapInfoWedge : BeatmapInfoWedge
|
|
|
|
|
{
|
|
|
|
|
public new BufferedWedgeInfo Info => base.Info;
|
|
|
|
|
}
|
2018-05-07 10:33:40 +08:00
|
|
|
|
|
|
|
|
|
private class TestHitObject : HitObject, IHasPosition
|
|
|
|
|
{
|
|
|
|
|
public float X { get; } = 0;
|
|
|
|
|
public float Y { get; } = 0;
|
|
|
|
|
public Vector2 Position { get; } = Vector2.Zero;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|