Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Alias Console to MockConsole so we don't accidentally use Console
using Console = Terminal.Gui.FakeConsole;

namespace Terminal.Gui.Core {
namespace Terminal.Gui.ApplicationTests {
public class ApplicationTests {
public ApplicationTests ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Alias Console to MockConsole so we don't accidentally use Console
using Console = Terminal.Gui.FakeConsole;

namespace Terminal.Gui.Core {
namespace Terminal.Gui.ApplicationTests {
/// <summary>
/// Tests MainLoop using the FakeMainLoop.
/// </summary>
Expand Down Expand Up @@ -171,19 +171,15 @@ public void False_Idle_Stops_It_Being_Called_Again ()
var functionCalled = 0;
Func<bool> fn1 = () => {
functionCalled++;
if (functionCalled == 10) {
return false;
}
if (functionCalled == 10) return false;
return true;
};

// Force stop if 20 iterations
var stopCount = 0;
Func<bool> fnStop = () => {
stopCount++;
if (stopCount == 20) {
ml.Stop ();
}
if (stopCount == 20) ml.Stop ();
return true;
};

Expand Down Expand Up @@ -212,9 +208,7 @@ public void AddIdle_Twice_Returns_False_Called_Twice ()
var stopCount = 0;
Func<bool> fnStop = () => {
stopCount++;
if (stopCount == 10) {
ml.Stop ();
}
if (stopCount == 10) ml.Stop ();
return true;
};

Expand All @@ -237,9 +231,7 @@ public void Run_Runs_Idle_Stop_Stops_Idle ()
var functionCalled = 0;
Func<bool> fn = () => {
functionCalled++;
if (functionCalled == 10) {
ml.Stop ();
}
if (functionCalled == 10) ml.Stop ();
return true;
};

Expand All @@ -258,7 +250,7 @@ public void AddTimer_Adds_Removes_NoFaults ()
var ms = 100;

var callbackCount = 0;
Func<MainLoop, bool> callback = (MainLoop loop) => {
Func<MainLoop, bool> callback = (loop) => {
callbackCount++;
return true;
};
Expand All @@ -279,7 +271,7 @@ public void AddTimer_Run_Called ()
var ms = 100;

var callbackCount = 0;
Func<MainLoop, bool> callback = (MainLoop loop) => {
Func<MainLoop, bool> callback = (loop) => {
callbackCount++;
ml.Stop ();
return true;
Expand All @@ -300,11 +292,9 @@ public async Task AddTimer_Duplicate_Keys_Not_Allowed ()
object token1 = null, token2 = null;

var callbackCount = 0;
Func<MainLoop, bool> callback = (MainLoop loop) => {
Func<MainLoop, bool> callback = (loop) => {
callbackCount++;
if (callbackCount == 2) {
ml.Stop ();
}
if (callbackCount == 2) ml.Stop ();
return true;
};

Expand Down Expand Up @@ -332,11 +322,9 @@ public void AddTimer_In_Parallel_Wont_Throw ()
object token1 = null, token2 = null;

var callbackCount = 0;
Func<MainLoop, bool> callback = (MainLoop loop) => {
Func<MainLoop, bool> callback = (loop) => {
callbackCount++;
if (callbackCount == 2) {
ml.Stop ();
}
if (callbackCount == 2) ml.Stop ();
return true;
};

Expand Down Expand Up @@ -369,7 +357,7 @@ public void AddTimer_Run_CalledAtApproximatelyRightTime ()
var watch = new System.Diagnostics.Stopwatch ();

var callbackCount = 0;
Func<MainLoop, bool> callback = (MainLoop loop) => {
Func<MainLoop, bool> callback = (loop) => {
watch.Stop ();
callbackCount++;
ml.Stop ();
Expand All @@ -381,7 +369,7 @@ public void AddTimer_Run_CalledAtApproximatelyRightTime ()
ml.Run ();
// +/- 100ms should be good enuf
// https://github.com/xunit/assert.xunit/pull/25
Assert.Equal<TimeSpan> (ms * callbackCount, watch.Elapsed, new MillisecondTolerance (100));
Assert.Equal (ms * callbackCount, watch.Elapsed, new MillisecondTolerance (100));

Assert.True (ml.RemoveTimeout (token));
Assert.Equal (1, callbackCount);
Expand All @@ -395,7 +383,7 @@ public void AddTimer_Run_CalledTwiceApproximatelyRightTime ()
var watch = new System.Diagnostics.Stopwatch ();

var callbackCount = 0;
Func<MainLoop, bool> callback = (MainLoop loop) => {
Func<MainLoop, bool> callback = (loop) => {
callbackCount++;
if (callbackCount == 2) {
watch.Stop ();
Expand All @@ -409,7 +397,7 @@ public void AddTimer_Run_CalledTwiceApproximatelyRightTime ()
ml.Run ();
// +/- 100ms should be good enuf
// https://github.com/xunit/assert.xunit/pull/25
Assert.Equal<TimeSpan> (ms * callbackCount, watch.Elapsed, new MillisecondTolerance (100));
Assert.Equal (ms * callbackCount, watch.Elapsed, new MillisecondTolerance (100));

Assert.True (ml.RemoveTimeout (token));
Assert.Equal (2, callbackCount);
Expand All @@ -425,15 +413,13 @@ public void AddTimer_Remove_NotCalled ()
var stopCount = 0;
Func<bool> fnStop = () => {
stopCount++;
if (stopCount == 10) {
ml.Stop ();
}
if (stopCount == 10) ml.Stop ();
return true;
};
ml.AddIdle (fnStop);

var callbackCount = 0;
Func<MainLoop, bool> callback = (MainLoop loop) => {
Func<MainLoop, bool> callback = (loop) => {
callbackCount++;
return true;
};
Expand All @@ -455,15 +441,13 @@ public void AddTimer_ReturnFalse_StopsBeingCalled ()
Func<bool> fnStop = () => {
Thread.Sleep (10); // Sleep to enable timer to fire
stopCount++;
if (stopCount == 10) {
ml.Stop ();
}
if (stopCount == 10) ml.Stop ();
return true;
};
ml.AddIdle (fnStop);

var callbackCount = 0;
Func<MainLoop, bool> callback = (MainLoop loop) => {
Func<MainLoop, bool> callback = (loop) => {
callbackCount++;
return false;
};
Expand Down Expand Up @@ -541,10 +525,8 @@ private static void Launch (Random r, TextField tf, int target)
Application.MainLoop.Invoke (() => {
tf.Text = $"index{r.Next ()}";
Interlocked.Increment (ref tbCounter);
if (target == tbCounter) {
// On last increment wake up the check
if (target == tbCounter) // On last increment wake up the check
_wakeUp.Set ();
}
});
});
}
Expand All @@ -554,9 +536,7 @@ private static void RunTest (Random r, TextField tf, int numPasses, int numIncre
for (int j = 0; j < numPasses; j++) {

_wakeUp.Reset ();
for (var i = 0; i < numIncrements; i++) {
Launch (r, tf, (j + 1) * numIncrements);
}
for (var i = 0; i < numIncrements; i++) Launch (r, tf, (j + 1) * numIncrements);


while (tbCounter != (j + 1) * numIncrements) // Wait for tbCounter to reach expected value
Expand Down Expand Up @@ -594,7 +574,7 @@ public async Task InvokeLeakTest ()

await task; // Propagate exception if any occurred

Assert.Equal ((numIncrements * numPasses), tbCounter);
Assert.Equal (numIncrements * numPasses, tbCounter);
}

private static int total;
Expand Down Expand Up @@ -652,9 +632,7 @@ public void Mainloop_Invoke_Or_AddIdle_Can_Be_Used_For_Events_Or_Actions (Action
Assert.True (btn.ProcessKey (new KeyEvent (Key.Enter, null)));
Assert.Equal (cancel, btn.Text);
Assert.Equal (one, total);
} else if (taskCompleted) {
Application.RequestStop ();
}
} else if (taskCompleted) Application.RequestStop ();
};

Application.Run ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Terminal.Gui;
using Xunit;

// Alias Console to MockConsole so we don't accidentally use Console
using Console = Terminal.Gui.FakeConsole;

namespace Terminal.Gui.Core {
namespace Terminal.Gui.ApplicationTests {
/// <summary>
/// These tests focus on Application.RunState and the various ways it can be changed.
/// </summary>
Expand All @@ -26,7 +27,7 @@ public void New_Creates_RunState ()
{
var rs = new Application.RunState (null);
Assert.Null (rs.Toplevel);

var top = new Toplevel ();
rs = new Application.RunState (top);
Assert.Equal (top, rs.Toplevel);
Expand Down Expand Up @@ -72,9 +73,7 @@ void Shutdown ()
Application.Shutdown ();
#if DEBUG_IDISPOSABLE
// Validate there are no outstanding RunState-based instances left
foreach (var inst in Application.RunState.Instances) {
Assert.True (inst.WasDisposed);
}
foreach (var inst in Application.RunState.Instances) Assert.True (inst.WasDisposed);
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using Xunit;

namespace Terminal.Gui.Core {
namespace Terminal.Gui.ApplicationTests {
public class StackExtensionsTests {
[Fact]
public void Stack_Toplevels_CreateToplevels ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Alias Console to MockConsole so we don't accidentally use Console
using Console = Terminal.Gui.FakeConsole;

namespace Terminal.Gui.Core {
namespace Terminal.Gui.ApplicationTests {
public class SyncrhonizationContextTests {

[Fact, AutoInitShutdown]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Xunit;
using Rune = System.Rune;

namespace Terminal.Gui.Core {
namespace Terminal.Gui.CoreTests {
public class BorderTests {
[Fact]
[AutoInitShutdown]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Terminal.Gui;
using Xunit;
using static Terminal.Gui.Core.ViewTests;

// Alias Console to MockConsole so we don't accidentally use Console
using Console = Terminal.Gui.FakeConsole;

namespace Terminal.Gui.Core {
namespace Terminal.Gui.CoreTests {
public class ResponderTests {
[Fact]
public void New_Initializes ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Alias Console to MockConsole so we don't accidentally use Console
using Console = Terminal.Gui.FakeConsole;

namespace Terminal.Gui.ConsoleDrivers {
namespace Terminal.Gui.DriverTests {
public class AttributeTests {
[Fact]
public void Constuctors_Constuct ()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Terminal.Gui;
using Xunit;
using Xunit.Abstractions;
using static AutoInitShutdownAttribute;

namespace Terminal.Gui.ConsoleDrivers {
namespace Terminal.Gui.DriverTests {
public class ClipboardTests {
readonly ITestOutputHelper output;

Expand Down Expand Up @@ -101,11 +102,8 @@ public void Contents_Fake_Gets_Sets_When_IsSupportedFalse ()
[Fact, AutoInitShutdown (useFakeClipboard: false)]
public void IsSupported_Get ()
{
if (Clipboard.IsSupported) {
Assert.True (Clipboard.IsSupported);
} else {
Assert.False (Clipboard.IsSupported);
}
if (Clipboard.IsSupported) Assert.True (Clipboard.IsSupported);
else Assert.False (Clipboard.IsSupported);
}

[Fact, AutoInitShutdown (useFakeClipboard: false)]
Expand All @@ -131,21 +129,15 @@ public void TryGetClipboardData_Gets_From_OS_Clipboard ()
public void TrySetClipboardData_Sets_The_OS_Clipboard ()
{
var clipText = "The TrySetClipboardData_Sets_The_OS_Clipboard unit test pasted this to the OS clipboard.";
if (Clipboard.IsSupported) {
Assert.True (Clipboard.TrySetClipboardData (clipText));
} else {
Assert.False (Clipboard.TrySetClipboardData (clipText));
}
if (Clipboard.IsSupported) Assert.True (Clipboard.TrySetClipboardData (clipText));
else Assert.False (Clipboard.TrySetClipboardData (clipText));

Application.Iteration += () => Application.RequestStop ();

Application.Run ();

if (Clipboard.IsSupported) {
Assert.Equal (clipText, Clipboard.Contents);
} else {
Assert.NotEqual (clipText, Clipboard.Contents);
}
if (Clipboard.IsSupported) Assert.Equal (clipText, Clipboard.Contents);
else Assert.NotEqual (clipText, Clipboard.Contents);
}


Expand Down Expand Up @@ -217,9 +209,7 @@ public void Contents_Copies_From_OS_Clipboard ()

Application.Run ();

if (!failed) {
Assert.Equal (clipText, getClipText);
}
if (!failed) Assert.Equal (clipText, getClipText);
}

[Fact, AutoInitShutdown (useFakeClipboard: false)]
Expand Down Expand Up @@ -275,9 +265,7 @@ public void Contents_Pastes_To_OS_Clipboard ()

Application.Run ();

if (!failed) {
Assert.Equal (clipText, clipReadText.TrimEnd ());
}
if (!failed) Assert.Equal (clipText, clipReadText.TrimEnd ());

}

Expand All @@ -292,7 +280,7 @@ bool xclipExists ()
try {
var (_, result) = ClipboardProcessRunner.Process ("bash", $"-c \"which xclip\"");
return result.TrimEnd () != "";
} catch (System.Exception) {
} catch (Exception) {
return false;
}
}
Expand Down
Loading