osu/osu.Game.Tests/Visual/TestCasePlaySongSelect.cs

136 lines
5.1 KiB
C#
Raw Normal View History

2017-09-18 13:32:49 +00:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
2017-09-18 13:32:49 +00:00
using System.Collections.Generic;
2017-10-25 13:25:28 +00:00
using System.IO;
2017-10-04 19:52:12 +00:00
using System.Linq;
2017-10-25 13:25:28 +00:00
using System.Text;
using osu.Framework.Allocation;
2017-10-25 13:25:28 +00:00
using osu.Framework.Extensions;
2017-09-18 13:32:49 +00:00
using osu.Framework.MathUtils;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Rulesets;
using osu.Game.Screens.Select;
2017-12-13 10:56:16 +00:00
using osu.Game.Screens.Select.Carousel;
2017-09-18 13:32:49 +00:00
using osu.Game.Screens.Select.Filter;
using osu.Game.Tests.Platform;
namespace osu.Game.Tests.Visual
{
internal class TestCasePlaySongSelect : OsuTestCase
{
private BeatmapManager manager;
2017-09-18 13:32:49 +00:00
private RulesetStore rulesets;
2017-09-18 13:32:49 +00:00
private DependencyContainer dependencies;
2017-12-12 08:48:38 +00:00
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(SongSelect),
2017-12-13 10:56:16 +00:00
typeof(BeatmapCarousel),
typeof(CarouselItem),
typeof(CarouselGroup),
typeof(CarouselGroupEagerSelect),
typeof(CarouselBeatmap),
typeof(CarouselBeatmapSet),
typeof(DrawableCarouselItem),
typeof(CarouselItemState),
typeof(DrawableCarouselBeatmap),
typeof(DrawableCarouselBeatmapSet),
2017-12-12 08:48:38 +00:00
};
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) => dependencies = new DependencyContainer(parent);
[BackgroundDependencyLoader]
2017-12-14 11:45:59 +00:00
private void load(BeatmapManager baseManager)
2017-09-18 13:32:49 +00:00
{
PlaySongSelect songSelect;
if (manager == null)
{
var storage = new TestStorage(@"TestCasePlaySongSelect");
2017-10-17 07:02:13 +00:00
// this is by no means clean. should be replacing inside of OsuGameBase somehow.
var context = new OsuDbContext();
2017-09-18 13:32:49 +00:00
2017-10-17 07:02:13 +00:00
Func<OsuDbContext> contextFactory = () => context;
dependencies.Cache(rulesets = new RulesetStore(contextFactory));
2017-12-12 08:48:38 +00:00
dependencies.Cache(manager = new BeatmapManager(storage, contextFactory, rulesets, null)
{
2017-12-14 11:45:59 +00:00
DefaultBeatmap = baseManager.GetWorkingBeatmap(null)
2017-12-12 08:48:38 +00:00
});
2017-09-18 13:32:49 +00:00
for (int i = 0; i < 100; i += 10)
manager.Import(createTestBeatmapSet(i));
}
Add(songSelect = new PlaySongSelect());
AddStep(@"Sort by Artist", delegate { songSelect.FilterControl.Sort = SortMode.Artist; });
AddStep(@"Sort by Title", delegate { songSelect.FilterControl.Sort = SortMode.Title; });
AddStep(@"Sort by Author", delegate { songSelect.FilterControl.Sort = SortMode.Author; });
AddStep(@"Sort by Difficulty", delegate { songSelect.FilterControl.Sort = SortMode.Difficulty; });
}
private BeatmapSetInfo createTestBeatmapSet(int i)
{
return new BeatmapSetInfo
{
2017-10-14 05:28:25 +00:00
OnlineBeatmapSetID = 1234 + i,
2017-10-25 13:25:28 +00:00
Hash = new MemoryStream(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())).ComputeMD5Hash(),
2017-10-05 21:23:26 +00:00
Metadata = new BeatmapMetadata
2017-09-18 13:32:49 +00:00
{
2017-10-14 05:28:25 +00:00
OnlineBeatmapSetID = 1234 + i,
2017-09-18 13:32:49 +00:00
// Create random metadata, then we can check if sorting works based on these
Artist = "MONACA " + RNG.Next(0, 9),
Title = "Black Song " + RNG.Next(0, 9),
AuthorString = "Some Guy " + RNG.Next(0, 9),
2017-09-18 13:32:49 +00:00
},
Beatmaps = new List<BeatmapInfo>(new[]
{
new BeatmapInfo
{
2017-10-14 05:28:25 +00:00
OnlineBeatmapID = 1234 + i,
2017-10-16 08:02:31 +00:00
Ruleset = rulesets.AvailableRulesets.First(),
2017-09-18 13:32:49 +00:00
Path = "normal.osu",
Version = "Normal",
2017-10-19 05:05:11 +00:00
BaseDifficulty = new BeatmapDifficulty
2017-09-18 13:32:49 +00:00
{
OverallDifficulty = 3.5f,
}
},
new BeatmapInfo
{
2017-10-14 05:28:25 +00:00
OnlineBeatmapID = 1235 + i,
2017-10-16 08:02:31 +00:00
Ruleset = rulesets.AvailableRulesets.First(),
2017-09-18 13:32:49 +00:00
Path = "hard.osu",
Version = "Hard",
2017-10-19 05:05:11 +00:00
BaseDifficulty = new BeatmapDifficulty
2017-09-18 13:32:49 +00:00
{
OverallDifficulty = 5,
}
},
new BeatmapInfo
{
2017-10-14 05:28:25 +00:00
OnlineBeatmapID = 1236 + i,
2017-10-16 08:02:31 +00:00
Ruleset = rulesets.AvailableRulesets.First(),
2017-09-18 13:32:49 +00:00
Path = "insane.osu",
Version = "Insane",
2017-10-19 05:05:11 +00:00
BaseDifficulty = new BeatmapDifficulty
2017-09-18 13:32:49 +00:00
{
OverallDifficulty = 7,
}
},
}),
};
}
}
}