2019-06-11 14:28:52 +09:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 17:43:03 +09:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2018-08-16 09:59:03 +09:00
|
|
|
|
using JetBrains.Annotations;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
2021-05-05 18:50:49 +02:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-02-25 23:36:02 +09:00
|
|
|
|
using osu.Framework.Testing;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Rulesets;
|
2018-05-07 11:36:51 +09:00
|
|
|
|
using osu.Game.Rulesets.Catch;
|
|
|
|
|
using osu.Game.Rulesets.Mania;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2020-02-25 19:07:15 +09:00
|
|
|
|
using osu.Game.Rulesets.Objects.Legacy;
|
2018-05-07 11:33:40 +09:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using osu.Game.Rulesets.Osu;
|
2018-05-07 11:36:51 +09:00
|
|
|
|
using osu.Game.Rulesets.Taiko;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using osu.Game.Screens.Select;
|
2019-03-25 01:02:36 +09:00
|
|
|
|
using osuTK;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2019-03-25 01:02:36 +09:00
|
|
|
|
namespace osu.Game.Tests.Visual.SongSelect
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2019-05-14 22:37:25 +03:00
|
|
|
|
public class TestSceneBeatmapInfoWedge : OsuTestScene
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
|
|
|
|
private RulesetStore rulesets;
|
|
|
|
|
private TestBeatmapInfoWedge infoWedge;
|
2018-04-19 20:44:38 +09:00
|
|
|
|
private readonly List<IBeatmap> beatmaps = new List<IBeatmap>();
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2018-05-23 17:37:39 +09:00
|
|
|
|
private void load(RulesetStore rulesets)
|
2018-04-13 18:19:50 +09: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", () =>
|
|
|
|
|
{
|
2019-06-11 14:28:52 +09:00
|
|
|
|
infoWedge.Show();
|
2019-02-21 18:56:34 +09:00
|
|
|
|
infoWedge.Beatmap = Beatmap.Value;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
});
|
|
|
|
|
|
2018-04-24 00:51:33 +09:00
|
|
|
|
// select part is redundant, but wait for load isn't
|
2018-05-23 17:37:39 +09:00
|
|
|
|
selectBeatmap(Beatmap.Value.Beatmap);
|
2018-04-24 00:51:33 +09:00
|
|
|
|
|
2019-03-19 17:24:26 +09:00
|
|
|
|
AddWaitStep("wait for select", 3);
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2019-06-11 14:28:52 +09:00
|
|
|
|
AddStep("hide", () => { infoWedge.Hide(); });
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2019-03-19 17:24:26 +09:00
|
|
|
|
AddWaitStep("wait for hide", 3);
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2019-06-11 14:28:52 +09:00
|
|
|
|
AddStep("show", () => { infoWedge.Show(); });
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
|
|
|
|
foreach (var rulesetInfo in rulesets.AvailableRulesets)
|
|
|
|
|
{
|
2018-06-26 18:59:13 +09:00
|
|
|
|
var instance = rulesetInfo.CreateInstance();
|
2018-04-24 02:07:16 +09:00
|
|
|
|
var testBeatmap = createTestBeatmap(rulesetInfo);
|
2018-04-24 00:51:33 +09:00
|
|
|
|
|
2018-04-24 02:07:16 +09:00
|
|
|
|
beatmaps.Add(testBeatmap);
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2018-06-26 18:59:13 +09:00
|
|
|
|
AddStep("set ruleset", () => Ruleset.Value = rulesetInfo);
|
|
|
|
|
|
2018-04-24 02:07:16 +09:00
|
|
|
|
selectBeatmap(testBeatmap);
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2018-06-26 18:59:13 +09:00
|
|
|
|
testBeatmapLabels(instance);
|
2018-05-07 11:36:51 +09:00
|
|
|
|
|
2018-06-26 18:59:13 +09:00
|
|
|
|
switch (instance)
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2018-05-07 11:36:51 +09:00
|
|
|
|
case OsuRuleset _:
|
|
|
|
|
testInfoLabels(5);
|
|
|
|
|
break;
|
2019-04-01 12:44:46 +09:00
|
|
|
|
|
2018-05-07 11:36:51 +09:00
|
|
|
|
case TaikoRuleset _:
|
2018-04-13 18:19:50 +09:00
|
|
|
|
testInfoLabels(5);
|
|
|
|
|
break;
|
2019-04-01 12:44:46 +09:00
|
|
|
|
|
2018-05-07 11:36:51 +09:00
|
|
|
|
case CatchRuleset _:
|
|
|
|
|
testInfoLabels(5);
|
|
|
|
|
break;
|
2019-04-01 12:44:46 +09:00
|
|
|
|
|
2018-05-07 11:36:51 +09:00
|
|
|
|
case ManiaRuleset _:
|
|
|
|
|
testInfoLabels(4);
|
|
|
|
|
break;
|
2019-04-01 12:44:46 +09:00
|
|
|
|
|
2018-04-13 18:19:50 +09:00
|
|
|
|
default:
|
|
|
|
|
testInfoLabels(2);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-07 11:36:51 +09:00
|
|
|
|
private void testBeatmapLabels(Ruleset ruleset)
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2021-02-25 17:46:35 +09:00
|
|
|
|
AddAssert("check version", () => infoWedge.Info.VersionLabel.Current.Value == $"{ruleset.ShortName}Version");
|
|
|
|
|
AddAssert("check title", () => infoWedge.Info.TitleLabel.Current.Value == $"{ruleset.ShortName}Source — {ruleset.ShortName}Title");
|
|
|
|
|
AddAssert("check artist", () => infoWedge.Info.ArtistLabel.Current.Value == $"{ruleset.ShortName}Artist");
|
2021-04-19 19:24:58 +02:00
|
|
|
|
AddAssert("check author", () => infoWedge.Info.MapperContainer.ChildrenOfType<OsuSpriteText>().Any(s => s.Current.Value == $"{ruleset.ShortName}Author"));
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void testInfoLabels(int expectedCount)
|
|
|
|
|
{
|
2021-04-19 23:41:51 +02:00
|
|
|
|
AddAssert("check info labels exists", () => infoWedge.Info.ChildrenOfType<BeatmapInfoWedge.WedgeInfoText.InfoLabel>().Any());
|
|
|
|
|
AddAssert("check info labels count", () => infoWedge.Info.ChildrenOfType<BeatmapInfoWedge.WedgeInfoText.InfoLabel>().Count() == expectedCount);
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-24 16:23:36 -07:00
|
|
|
|
[Test]
|
2019-09-24 16:48:22 -07:00
|
|
|
|
public void TestNullBeatmap()
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2018-08-16 09:59:03 +09:00
|
|
|
|
selectBeatmap(null);
|
2021-02-25 17:46:35 +09:00
|
|
|
|
AddAssert("check empty version", () => string.IsNullOrEmpty(infoWedge.Info.VersionLabel.Current.Value));
|
|
|
|
|
AddAssert("check default title", () => infoWedge.Info.TitleLabel.Current.Value == Beatmap.Default.BeatmapInfo.Metadata.Title);
|
|
|
|
|
AddAssert("check default artist", () => infoWedge.Info.ArtistLabel.Current.Value == Beatmap.Default.BeatmapInfo.Metadata.Artist);
|
2021-04-19 19:24:58 +02:00
|
|
|
|
AddAssert("check empty author", () => !infoWedge.Info.MapperContainer.ChildrenOfType<OsuSpriteText>().Any());
|
2021-04-19 23:41:51 +02:00
|
|
|
|
AddAssert("check no info labels", () => !infoWedge.Info.ChildrenOfType<BeatmapInfoWedge.WedgeInfoText.InfoLabel>().Any());
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-24 16:21:08 -07:00
|
|
|
|
[Test]
|
2019-09-24 16:48:22 -07:00
|
|
|
|
public void TestTruncation()
|
2019-09-24 16:21:08 -07:00
|
|
|
|
{
|
|
|
|
|
selectBeatmap(createLongMetadata());
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-16 09:59:03 +09:00
|
|
|
|
private void selectBeatmap([CanBeNull] IBeatmap b)
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2021-05-05 18:50:49 +02:00
|
|
|
|
Container containerBefore = null;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2018-08-16 09:59:03 +09:00
|
|
|
|
AddStep($"select {b?.Metadata.Title ?? "null"} beatmap", () =>
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2021-05-06 02:14:04 +09:00
|
|
|
|
containerBefore = infoWedge.DisplayedContent;
|
2019-05-31 14:40:53 +09:00
|
|
|
|
infoWedge.Beatmap = Beatmap.Value = b == null ? Beatmap.Default : CreateWorkingBeatmap(b);
|
2018-04-13 18:19:50 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-05-06 02:14:04 +09:00
|
|
|
|
AddUntilStep("wait for async load", () => infoWedge.DisplayedContent != containerBefore);
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-19 20:44:38 +09:00
|
|
|
|
private IBeatmap createTestBeatmap(RulesetInfo ruleset)
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
|
|
|
|
List<HitObject> objects = new List<HitObject>();
|
|
|
|
|
for (double i = 0; i < 50000; i += 1000)
|
2018-05-07 11:33:40 +09:00
|
|
|
|
objects.Add(new TestHitObject { StartTime = i });
|
2018-04-13 18:19:50 +09: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 11:33:40 +09:00
|
|
|
|
Version = $"{ruleset.ShortName}Version",
|
|
|
|
|
BaseDifficulty = new BeatmapDifficulty()
|
2018-04-13 18:19:50 +09:00
|
|
|
|
},
|
|
|
|
|
HitObjects = objects
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-24 16:21:08 -07:00
|
|
|
|
private IBeatmap createLongMetadata()
|
|
|
|
|
{
|
|
|
|
|
return new Beatmap
|
|
|
|
|
{
|
|
|
|
|
BeatmapInfo = new BeatmapInfo
|
|
|
|
|
{
|
|
|
|
|
Metadata = new BeatmapMetadata
|
|
|
|
|
{
|
2019-09-24 16:48:22 -07:00
|
|
|
|
AuthorString = "WWWWWWWWWWWWWWW",
|
|
|
|
|
Artist = "Verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long Artist",
|
|
|
|
|
Source = "Verrrrry long Source",
|
|
|
|
|
Title = "Verrrrry long Title"
|
2019-09-24 16:21:08 -07:00
|
|
|
|
},
|
2019-09-24 16:48:22 -07:00
|
|
|
|
Version = "Verrrrrrrrrrrrrrrrrrrrrrrrrrrrry long Version",
|
2019-09-24 16:21:08 -07:00
|
|
|
|
Status = BeatmapSetOnlineStatus.Graveyard,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 18:19:50 +09:00
|
|
|
|
private class TestBeatmapInfoWedge : BeatmapInfoWedge
|
|
|
|
|
{
|
2021-05-06 02:14:04 +09:00
|
|
|
|
public new Container DisplayedContent => base.DisplayedContent;
|
2021-05-05 21:07:49 +09:00
|
|
|
|
|
2021-05-05 18:50:49 +02:00
|
|
|
|
public new WedgeInfoText Info => base.Info;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|
2018-05-07 11:33:40 +09:00
|
|
|
|
|
2020-02-23 13:01:30 +09:00
|
|
|
|
private class TestHitObject : ConvertHitObject, IHasPosition
|
2018-05-07 11:33:40 +09:00
|
|
|
|
{
|
2020-11-01 20:51:23 +01:00
|
|
|
|
public float X => 0;
|
|
|
|
|
public float Y => 0;
|
2018-05-07 11:33:40 +09:00
|
|
|
|
public Vector2 Position { get; } = Vector2.Zero;
|
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|
|
|
|
|
}
|