mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-31 02:08:03 +01:00
Merge pull request #678 from tig/scenariotests2
tweaked scenario tests; minor bug fixes
This commit is contained in:
@@ -478,7 +478,7 @@ namespace Terminal.Gui {
|
||||
/// Building block API: completes the execution of a <see cref="Toplevel"/> that was started with <see cref="Begin(Toplevel)"/> .
|
||||
/// </summary>
|
||||
/// <param name="runState">The runstate returned by the <see cref="Begin(Toplevel)"/> method.</param>
|
||||
/// <param name="closeDriver"><c>true</c>Closes the application.<c>false</c>Closes the toplevels only.</param>
|
||||
/// <param name="closeDriver">If <c>true</c>, closes the application. If <c>false</c> closes the toplevels only.</param>
|
||||
public static void End (RunState runState, bool closeDriver = true)
|
||||
{
|
||||
if (runState == null)
|
||||
@@ -491,7 +491,7 @@ namespace Terminal.Gui {
|
||||
/// <summary>
|
||||
/// Shutdown an application initialized with <see cref="Init(ConsoleDriver, IMainLoopDriver)"/>
|
||||
/// </summary>
|
||||
/// /// <param name="closeDriver"><c>true</c>Closes the application.<c>false</c>Closes toplevels only.</param>
|
||||
/// <param name="closeDriver"><c>true</c>Closes the application.<c>false</c>Closes toplevels only.</param>
|
||||
public static void Shutdown (bool closeDriver = true)
|
||||
{
|
||||
// Shutdown is the bookend for Init. As such it needs to clean up all resources
|
||||
@@ -651,6 +651,8 @@ namespace Terminal.Gui {
|
||||
/// then return control immediately.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <param name="view">The <see cref="Toplevel"/> tu run modally.</param>
|
||||
/// <param name="closeDriver">Set to <true/> to cause the MainLoop to end when <see cref="End(RunState, bool)"/> is called, clsing the toplevels only.</param>
|
||||
public static void Run (Toplevel view, bool closeDriver = true)
|
||||
{
|
||||
var runToken = Begin (view);
|
||||
|
||||
@@ -154,10 +154,10 @@ namespace Terminal.Gui {
|
||||
}
|
||||
}
|
||||
|
||||
Rune _leftBracket = new Rune (Driver.LeftBracket);
|
||||
Rune _rightBracket = new Rune (Driver.RightBracket);
|
||||
Rune _leftDefault = new Rune (Driver.LeftDefaultIndicator);
|
||||
Rune _rightDefault = new Rune (Driver.RightDefaultIndicator);
|
||||
Rune _leftBracket = new Rune (Driver != null ? Driver.LeftBracket : '[');
|
||||
Rune _rightBracket = new Rune (Driver != null ? Driver.RightBracket : ']');
|
||||
Rune _leftDefault = new Rune (Driver != null ? Driver.LeftDefaultIndicator : '<');
|
||||
Rune _rightDefault = new Rune (Driver != null ? Driver.RightDefaultIndicator : '>');
|
||||
|
||||
internal void Update ()
|
||||
{
|
||||
|
||||
@@ -148,7 +148,8 @@ namespace Terminal.Gui {
|
||||
};
|
||||
}
|
||||
|
||||
Application.Run (d);
|
||||
// Rin the modal; do not shutdown the mainloop driver when done
|
||||
Application.Run (d, false);
|
||||
return clicked;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace UICatalog {
|
||||
private void Open ()
|
||||
{
|
||||
var d = new OpenDialog ("Open", "Open a file") { AllowsMultipleSelection = false };
|
||||
Application.Run (d);
|
||||
Application.Run (d, false);
|
||||
|
||||
if (!d.Canceled) {
|
||||
_fileName = d.FilePaths [0];
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace UICatalog {
|
||||
}
|
||||
};
|
||||
|
||||
Application.Run (_top, false);
|
||||
Application.Run (_top, true);
|
||||
Application.Shutdown ();
|
||||
return _runningScenario;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ namespace Terminal.Gui {
|
||||
foreach (var scenarioClass in scenarioClasses) {
|
||||
// Setup some fake kepresses
|
||||
// Passing empty string will cause just a ctrl-q to be fired
|
||||
Console.MockKeyPresses.Clear ();
|
||||
int stackSize = CreateInput ("");
|
||||
int iterations = 0;
|
||||
Application.Iteration = () => {
|
||||
@@ -49,6 +50,15 @@ namespace Terminal.Gui {
|
||||
};
|
||||
Application.Init (new FakeDriver (), new NetMainLoop (() => FakeConsole.ReadKey (true)));
|
||||
|
||||
var ms = 1000;
|
||||
var abortCount = 0;
|
||||
Func<MainLoop, bool> abortCallback = (MainLoop loop) => {
|
||||
abortCount++;
|
||||
Application.RequestStop ();
|
||||
return false;
|
||||
};
|
||||
var token = Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (ms), abortCallback);
|
||||
|
||||
var scenario = (Scenario)Activator.CreateInstance (scenarioClass);
|
||||
scenario.Init (Application.Top, Colors.Base);
|
||||
scenario.Setup ();
|
||||
@@ -56,10 +66,59 @@ namespace Terminal.Gui {
|
||||
|
||||
Application.Shutdown ();
|
||||
|
||||
Assert.Equal (0, abortCount);
|
||||
// # of key up events should match # of iterations
|
||||
Assert.Equal (1, iterations);
|
||||
Assert.Equal (stackSize, iterations);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Run_Generic ()
|
||||
{
|
||||
List<Type> scenarioClasses = Scenario.GetDerivedClasses<Scenario> ();
|
||||
Assert.NotEmpty (scenarioClasses);
|
||||
|
||||
var item = scenarioClasses.FindIndex (t => Scenario.ScenarioMetadata.GetName (t).Equals ("Generic", StringComparison.OrdinalIgnoreCase));
|
||||
var scenarioClass = scenarioClasses[item];
|
||||
// Setup some fake kepresses
|
||||
// Passing empty string will cause just a ctrl-q to be fired
|
||||
int stackSize = CreateInput ("");
|
||||
|
||||
int iterations = 0;
|
||||
Application.Iteration = () => {
|
||||
iterations++;
|
||||
// Stop if we run out of control...
|
||||
if (iterations == 10) {
|
||||
Application.RequestStop ();
|
||||
}
|
||||
};
|
||||
Application.Init (new FakeDriver (), new NetMainLoop (() => FakeConsole.ReadKey (true)));
|
||||
|
||||
var ms = 1000;
|
||||
var abortCount = 0;
|
||||
Func<MainLoop, bool> abortCallback = (MainLoop loop) => {
|
||||
abortCount++;
|
||||
Application.RequestStop ();
|
||||
return false;
|
||||
};
|
||||
var token = Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (ms), abortCallback);
|
||||
|
||||
Application.Top.KeyPress += (View.KeyEventEventArgs args) => {
|
||||
Assert.Equal (Key.ControlQ, args.KeyEvent.Key);
|
||||
};
|
||||
|
||||
var scenario = (Scenario)Activator.CreateInstance (scenarioClass);
|
||||
scenario.Init (Application.Top, Colors.Base);
|
||||
scenario.Setup ();
|
||||
scenario.Run ();
|
||||
|
||||
Application.Shutdown ();
|
||||
|
||||
Assert.Equal (0, abortCount);
|
||||
// # of key up events should match # of iterations
|
||||
//Assert.Equal (1, iterations);
|
||||
Assert.Equal (stackSize, iterations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user