mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Fixed Scenario tests
This commit is contained in:
@@ -42,7 +42,7 @@ PowerShellHostName = 'ConsoleHost'
|
||||
# PowerShellHostVersion = ''
|
||||
|
||||
# Processor architecture (None, X86, Amd64) required by this module
|
||||
ProcessorArchitecture = 'Amd64'
|
||||
ProcessorArchitecture = ''
|
||||
|
||||
# Modules that must be imported into the global environment prior to importing this module
|
||||
RequiredModules = @('Microsoft.PowerShell.Management','Microsoft.PowerShell.Utility','./Terminal.Gui.PowerShell.Core.psd1')
|
||||
|
||||
@@ -36,7 +36,7 @@ PowerShellHostVersion = '7.4.0'
|
||||
# Processor architecture (None, MSIL, X86, IA64, Amd64, Arm, or an empty string) required by this module. One value only.
|
||||
# Set to AMD64 here because development on Terminal.Gui isn't really supported on anything else.
|
||||
# Has nothing to do with runtime use of Terminal.Gui.
|
||||
ProcessorArchitecture = 'Amd64'
|
||||
ProcessorArchitecture = ''
|
||||
|
||||
# Modules that must be imported into the global environment prior to importing this module
|
||||
RequiredModules = @(
|
||||
|
||||
@@ -44,7 +44,7 @@ PowerShellHostVersion = '7.4.0'
|
||||
# Processor architecture (None, MSIL, X86, IA64, Amd64, Arm, or an empty string) required by this module. One value only.
|
||||
# Set to AMD64 here because development on Terminal.Gui isn't really supported on anything else.
|
||||
# Has nothing to do with runtime use of Terminal.Gui.
|
||||
ProcessorArchitecture = 'Amd64'
|
||||
ProcessorArchitecture = ''
|
||||
|
||||
# Modules that must be imported into the global environment prior to importing this module
|
||||
RequiredModules = @(
|
||||
|
||||
@@ -44,7 +44,7 @@ PowerShellHostVersion = '7.4.0'
|
||||
# Processor architecture (None, MSIL, X86, IA64, Amd64, Arm, or an empty string) required by this module. One value only.
|
||||
# Set to AMD64 here because development on Terminal.Gui isn't really supported on anything else.
|
||||
# Has nothing to do with runtime use of Terminal.Gui.
|
||||
ProcessorArchitecture = 'AMD64'
|
||||
ProcessorArchitecture = ''
|
||||
|
||||
# Modules that must be imported into the global environment prior to importing this module
|
||||
RequiredModules = @(
|
||||
|
||||
@@ -49,7 +49,7 @@ PowerShellHostVersion = '7.4.0'
|
||||
# Processor architecture (None, MSIL, X86, IA64, Amd64, Arm, or an empty string) required by this module. One value only.
|
||||
# Set to AMD64 here because development on Terminal.Gui isn't really supported on anything else.
|
||||
# Has nothing to do with runtime use of Terminal.Gui.
|
||||
ProcessorArchitecture = 'Amd64'
|
||||
ProcessorArchitecture = ''
|
||||
|
||||
# Modules that must be imported into the global environment prior to importing this module
|
||||
RequiredModules = @(
|
||||
|
||||
@@ -620,9 +620,9 @@ public class MainLoopTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public async Task InvokeLeakTest ()
|
||||
{
|
||||
Application.Init ();
|
||||
Random r = new ();
|
||||
TextField tf = new ();
|
||||
var top = new Toplevel ();
|
||||
@@ -641,10 +641,10 @@ public class MainLoopTests
|
||||
|
||||
Assert.Equal (numIncrements * numPasses, tbCounter);
|
||||
top.Dispose ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[AutoInitShutdown]
|
||||
[MemberData (nameof (TestAddIdle))]
|
||||
public void Mainloop_Invoke_Or_AddIdle_Can_Be_Used_For_Events_Or_Actions (
|
||||
Action action,
|
||||
@@ -658,6 +658,8 @@ public class MainLoopTests
|
||||
int pfour
|
||||
)
|
||||
{
|
||||
Application.Init ();
|
||||
|
||||
total = 0;
|
||||
btn = null;
|
||||
clickMe = pclickMe;
|
||||
@@ -720,6 +722,8 @@ public class MainLoopTests
|
||||
Assert.True (taskCompleted);
|
||||
Assert.Equal (clickMe, btn.Text);
|
||||
Assert.Equal (four, total);
|
||||
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -5,9 +5,9 @@ namespace Terminal.Gui.ApplicationTests;
|
||||
public class SyncrhonizationContextTests
|
||||
{
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void SynchronizationContext_CreateCopy ()
|
||||
{
|
||||
Application.Init ();
|
||||
SynchronizationContext context = SynchronizationContext.Current;
|
||||
Assert.NotNull (context);
|
||||
|
||||
@@ -15,12 +15,13 @@ public class SyncrhonizationContextTests
|
||||
Assert.NotNull (contextCopy);
|
||||
|
||||
Assert.NotEqual (context, contextCopy);
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void SynchronizationContext_Post ()
|
||||
{
|
||||
Application.Init ();
|
||||
SynchronizationContext context = SynchronizationContext.Current;
|
||||
|
||||
var success = false;
|
||||
@@ -48,12 +49,14 @@ public class SyncrhonizationContextTests
|
||||
// blocks here until the RequestStop is processed at the end of the test
|
||||
Application.Run ().Dispose ();
|
||||
Assert.True (success);
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void SynchronizationContext_Send ()
|
||||
{
|
||||
Application.Init ();
|
||||
SynchronizationContext context = SynchronizationContext.Current;
|
||||
|
||||
var success = false;
|
||||
@@ -81,5 +84,6 @@ public class SyncrhonizationContextTests
|
||||
// blocks here until the RequestStop is processed at the end of the test
|
||||
Application.Run ().Dispose ();
|
||||
Assert.True (success);
|
||||
Application.Shutdown ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public class ScenarioTests : TestsAllViews
|
||||
.Where (type => type.IsClass && !type.IsAbstract && type.IsSubclassOf (typeof (Scenario)))
|
||||
.Select (type => new object [] { type });
|
||||
|
||||
private readonly object _timeoutLock = new object ();
|
||||
|
||||
/// <summary>
|
||||
/// <para>This runs through all Scenarios defined in UI Catalog, calling Init, Setup, and Run.</para>
|
||||
@@ -32,61 +33,72 @@ public class ScenarioTests : TestsAllViews
|
||||
[MemberData (nameof (AllScenarioTypes))]
|
||||
public void All_Scenarios_Quit_And_Init_Shutdown_Properly (Type scenarioType)
|
||||
{
|
||||
// If a previous test failed, this will ensure that the Application is in a clean state
|
||||
Application.ResetState (true);
|
||||
|
||||
_output.WriteLine ($"Running Scenario '{scenarioType}'");
|
||||
|
||||
Scenario scenario = (Scenario)Activator.CreateInstance (scenarioType);
|
||||
|
||||
uint abortTime = 500;
|
||||
|
||||
bool initialized = false;
|
||||
bool shutdown = false;
|
||||
|
||||
object timeout = null;
|
||||
|
||||
Application.InitializedChanged += (s, a) =>
|
||||
{
|
||||
if (a.NewValue)
|
||||
{
|
||||
//output.WriteLine ($" Add timeout to force quit after {abortTime}ms");
|
||||
timeout = Application.AddTimeout (TimeSpan.FromMilliseconds (abortTime), ForceCloseCallback);
|
||||
void OnApplicationOnInitializedChanged (object s, StateEventArgs<bool> a)
|
||||
{
|
||||
if (a.NewValue)
|
||||
{
|
||||
lock (_timeoutLock)
|
||||
{
|
||||
timeout = Application.AddTimeout (TimeSpan.FromMilliseconds (abortTime), ForceCloseCallback);
|
||||
}
|
||||
|
||||
Application.Iteration += OnApplicationOnIteration;
|
||||
initialized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (timeout is { })
|
||||
{
|
||||
Application.RemoveTimeout (timeout);
|
||||
timeout = null;
|
||||
}
|
||||
Application.Iteration -= OnApplicationOnIteration;
|
||||
shutdown = true;
|
||||
}
|
||||
};
|
||||
Application.Iteration += OnApplicationOnIteration;
|
||||
initialized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Application.Iteration -= OnApplicationOnIteration;
|
||||
shutdown = true;
|
||||
}
|
||||
}
|
||||
|
||||
Application.InitializedChanged += OnApplicationOnInitializedChanged;
|
||||
|
||||
scenario.Main ();
|
||||
scenario.Dispose ();
|
||||
scenario = null;
|
||||
|
||||
Application.InitializedChanged -= OnApplicationOnInitializedChanged;
|
||||
|
||||
lock (_timeoutLock)
|
||||
{
|
||||
if (timeout is { })
|
||||
{
|
||||
Application.RemoveTimeout (timeout);
|
||||
timeout = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Assert.True (initialized);
|
||||
Assert.True (shutdown);
|
||||
|
||||
#if DEBUG_IDISPOSABLE
|
||||
Assert.Empty (Responder.Instances);
|
||||
#endif
|
||||
Application.Shutdown ();
|
||||
return;
|
||||
|
||||
// If the scenario doesn't close within 500ms, this will force it to quit
|
||||
bool ForceCloseCallback ()
|
||||
{
|
||||
if (timeout is { })
|
||||
lock (_timeoutLock)
|
||||
{
|
||||
Application.RemoveTimeout (timeout);
|
||||
timeout = null;
|
||||
if (timeout is { })
|
||||
{
|
||||
Application.RemoveTimeout (timeout);
|
||||
timeout = null;
|
||||
}
|
||||
}
|
||||
Application.ResetState (true);
|
||||
Assert.Fail (
|
||||
@@ -97,7 +109,7 @@ public class ScenarioTests : TestsAllViews
|
||||
|
||||
void OnApplicationOnIteration (object s, IterationEventArgs a)
|
||||
{
|
||||
if (scenario is { })
|
||||
if (Application._initialized)
|
||||
{
|
||||
// Press QuitKey
|
||||
Application.OnKeyDown (Application.QuitKey);
|
||||
|
||||
Reference in New Issue
Block a user