2019-01-24 17:43:03 +09: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.
2018-04-13 18:19:50 +09:00
2022-06-17 16:37:17 +09:00
#nullable disable
2017-11-08 13:52:44 +09:00
using System ;
using System.Collections.Generic ;
2018-03-02 15:34:31 +09:00
using NUnit.Framework ;
2019-02-26 18:02:24 +09:00
using osu.Framework.Allocation ;
2019-05-14 11:05:53 +09:00
using osu.Framework.Bindables ;
2021-10-01 00:34:09 +09:00
using osu.Framework.Configuration ;
2019-05-14 11:05:53 +09:00
using osu.Framework.Graphics.Textures ;
2021-08-20 19:45:52 +09:00
using osu.Framework.Platform ;
2019-05-14 11:05:53 +09:00
using osu.Game.Audio ;
using osu.Game.Beatmaps ;
using osu.Game.Configuration ;
using osu.Game.Graphics ;
using osu.Game.Input ;
using osu.Game.Input.Bindings ;
using osu.Game.Online.API ;
using osu.Game.Online.Chat ;
using osu.Game.Overlays ;
using osu.Game.Rulesets ;
2019-05-15 13:00:11 +09:00
using osu.Game.Rulesets.Mods ;
2019-05-14 11:05:53 +09:00
using osu.Game.Scoring ;
2017-11-08 13:52:44 +09:00
using osu.Game.Screens.Menu ;
2019-05-14 11:05:53 +09:00
using osu.Game.Skinning ;
2022-10-15 00:18:56 +03:00
using osuTK.Input ;
2018-04-13 18:19:50 +09:00
2021-08-11 16:24:47 +09:00
namespace osu.Game.Tests.Visual.Navigation
2017-11-08 13:52:44 +09:00
{
2018-03-02 15:34:31 +09:00
[TestFixture]
2021-10-07 16:18:47 +09:00
public partial class TestSceneOsuGame : OsuGameTestScene
2017-11-08 13:52:44 +09:00
{
2019-05-14 11:05:53 +09:00
private IReadOnlyList < Type > requiredGameDependencies = > new [ ]
{
typeof ( OsuGame ) ,
typeof ( OsuLogo ) ,
typeof ( IdleTracker ) ,
typeof ( OnScreenDisplay ) ,
2022-04-18 19:59:57 +09:00
typeof ( INotificationOverlay ) ,
2020-04-21 16:03:18 +09:00
typeof ( BeatmapListingOverlay ) ,
2020-04-16 12:05:51 +03:00
typeof ( DashboardOverlay ) ,
2020-07-16 14:48:40 +03:00
typeof ( NewsOverlay ) ,
2019-05-14 11:05:53 +09:00
typeof ( ChannelManager ) ,
2022-05-30 17:54:09 +09:00
typeof ( ChatOverlay ) ,
2019-05-14 11:05:53 +09:00
typeof ( SettingsOverlay ) ,
typeof ( UserProfileOverlay ) ,
typeof ( BeatmapSetOverlay ) ,
typeof ( LoginOverlay ) ,
typeof ( MusicController ) ,
typeof ( AccountCreationOverlay ) ,
2022-04-18 18:09:14 +09:00
typeof ( IDialogOverlay ) ,
2019-05-15 13:00:11 +09:00
typeof ( ScreenshotManager )
2019-05-14 11:05:53 +09:00
} ;
private IReadOnlyList < Type > requiredGameBaseDependencies = > new [ ]
{
typeof ( OsuGameBase ) ,
2019-05-15 13:00:11 +09:00
typeof ( Bindable < RulesetInfo > ) ,
typeof ( IBindable < RulesetInfo > ) ,
typeof ( Bindable < IReadOnlyList < Mod > > ) ,
typeof ( IBindable < IReadOnlyList < Mod > > ) ,
2019-05-14 11:05:53 +09:00
typeof ( LargeTextureStore ) ,
typeof ( OsuConfigManager ) ,
typeof ( SkinManager ) ,
typeof ( ISkinSource ) ,
typeof ( IAPIProvider ) ,
typeof ( RulesetStore ) ,
typeof ( ScoreManager ) ,
typeof ( BeatmapManager ) ,
2021-12-23 19:02:10 +01:00
typeof ( IRulesetConfigCache ) ,
2019-05-14 11:05:53 +09:00
typeof ( OsuColour ) ,
typeof ( IBindable < WorkingBeatmap > ) ,
typeof ( Bindable < WorkingBeatmap > ) ,
typeof ( GlobalActionContainer ) ,
typeof ( PreviewTrackManager ) ,
} ;
2021-07-26 16:33:56 +09:00
[Resolved]
private OsuGameBase gameBase { get ; set ; }
2022-10-15 00:18:56 +03:00
[Test]
public void TestCursorHidesWhenIdle ( )
{
AddStep ( "click mouse" , ( ) = > InputManager . Click ( MouseButton . Left ) ) ;
AddUntilStep ( "wait until idle" , ( ) = > Game . IsIdle . Value ) ;
AddUntilStep ( "menu cursor hidden" , ( ) = > Game . GlobalCursorDisplay . MenuCursor . ActiveCursor . Alpha = = 0 ) ;
AddStep ( "click mouse" , ( ) = > InputManager . Click ( MouseButton . Left ) ) ;
AddUntilStep ( "menu cursor shown" , ( ) = > Game . GlobalCursorDisplay . MenuCursor . ActiveCursor . Alpha = = 1 ) ;
}
2021-07-26 16:33:56 +09:00
[Test]
public void TestNullRulesetHandled ( )
{
RulesetInfo ruleset = null ;
2019-05-14 11:05:53 +09:00
2021-07-26 16:33:56 +09:00
AddStep ( "store current ruleset" , ( ) = > ruleset = Ruleset . Value ) ;
AddStep ( "set global ruleset to null value" , ( ) = > Ruleset . Value = null ) ;
AddAssert ( "ruleset still valid" , ( ) = > Ruleset . Value . Available ) ;
AddAssert ( "ruleset unchanged" , ( ) = > ReferenceEquals ( Ruleset . Value , ruleset ) ) ;
}
2021-10-01 00:34:09 +09:00
[Test]
public void TestSwitchThreadExecutionMode ( )
{
2021-10-07 16:18:47 +09:00
AddStep ( "Change thread mode to multi threaded" , ( ) = > { Game . Dependencies . Get < FrameworkConfigManager > ( ) . SetValue ( FrameworkSetting . ExecutionMode , ExecutionMode . MultiThreaded ) ; } ) ;
AddStep ( "Change thread mode to single thread" , ( ) = > { Game . Dependencies . Get < FrameworkConfigManager > ( ) . SetValue ( FrameworkSetting . ExecutionMode , ExecutionMode . SingleThread ) ; } ) ;
2021-10-01 00:34:09 +09:00
}
2021-07-26 16:33:56 +09:00
[Test]
public void TestUnavailableRulesetHandled ( )
{
RulesetInfo ruleset = null ;
AddStep ( "store current ruleset" , ( ) = > ruleset = Ruleset . Value ) ;
AddStep ( "set global ruleset to invalid value" , ( ) = > Ruleset . Value = new RulesetInfo
{
Name = "unavailable" ,
Available = false ,
} ) ;
AddAssert ( "ruleset still valid" , ( ) = > Ruleset . Value . Available ) ;
AddAssert ( "ruleset unchanged" , ( ) = > ReferenceEquals ( Ruleset . Value , ruleset ) ) ;
}
[Test]
public void TestAvailableDependencies ( )
{
2019-05-15 13:00:11 +09:00
AddAssert ( "check OsuGame DI members" , ( ) = >
{
foreach ( var type in requiredGameDependencies )
2019-11-11 19:53:22 +08:00
{
2021-10-07 16:18:47 +09:00
if ( Game . Dependencies . Get ( type ) = = null )
2019-11-28 21:52:05 +08:00
throw new InvalidOperationException ( $"{type} has not been cached" ) ;
2019-11-11 19:53:22 +08:00
}
2019-05-15 13:00:11 +09:00
return true ;
} ) ;
2021-07-26 16:33:56 +09:00
2019-05-15 13:00:11 +09:00
AddAssert ( "check OsuGameBase DI members" , ( ) = >
{
foreach ( var type in requiredGameBaseDependencies )
2019-11-11 19:53:22 +08:00
{
2019-05-15 13:00:11 +09:00
if ( gameBase . Dependencies . Get ( type ) = = null )
2019-11-28 21:52:05 +08:00
throw new InvalidOperationException ( $"{type} has not been cached" ) ;
2019-11-11 19:53:22 +08:00
}
2019-05-15 13:00:11 +09:00
return true ;
} ) ;
2017-11-08 13:52:44 +09:00
}
}
}