Skip to content

Commit

Permalink
test if ManualResetEvent works
Browse files Browse the repository at this point in the history
  • Loading branch information
joekolodz committed Sep 28, 2021
1 parent 54f942e commit a07a249
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions tests/HOTASQueueTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Threading;
using Castle.Core.Smtp;
using NSubstitute;
using SharpDX.DirectInput;
Expand Down Expand Up @@ -195,7 +196,7 @@ public void keystroke_up_sent()
Assert.False(isEventCalled);
joystick.TestData[0] = new JoystickUpdate() { RawOffset = (int)JoystickOffset.Button1, Sequence = 0, Timestamp = 0, Value = (int)JoystickOffsetValues.ButtonState.ButtonPressed };
joystick.TestData[1] = new JoystickUpdate() { RawOffset = (int)JoystickOffset.Button1, Sequence = 0, Timestamp = 0, Value = (int)JoystickOffsetValues.ButtonState.ButtonReleased };

while (!isEventCalled && --timeOut > 0)
{
System.Threading.Thread.Sleep(5);
Expand Down Expand Up @@ -277,32 +278,24 @@ public void macro_cancelled()
public void button_pressed()
{
var isEventCalled = false;
var timeOut = 80;

var joystick = new TestJoystick_BasicQueue(dataBufferSize: 1);
var map = CreateTestHotasTestMapWithButton();

var queue = new HOTASQueue(Substitute.For<IKeyboard>());
queue.Listen(joystick, map);

queue.ButtonPressed += (sender, e) => { isEventCalled = true; };
var mre = new ManualResetEventSlim();
queue.ButtonPressed += (sender, e) => { isEventCalled = true; mre.Set(); };
Assert.False(isEventCalled);

var sw = Stopwatch.StartNew();
var x = new long[80];


joystick.TestData[0] = new JoystickUpdate() { RawOffset = (int)JoystickOffset.Button1, Sequence = 0, Timestamp = 0, Value = (int)JoystickOffsetValues.ButtonState.ButtonPressed };
while (!isEventCalled && --timeOut > 0)
{
System.Threading.Thread.Sleep(10);
x[timeOut] = sw.ElapsedMilliseconds;
}
mre.Wait(5000);

sw.Stop();
_output.WriteLine($"wait times: {sw.ElapsedMilliseconds}");

foreach (var i in x)
{
_output.WriteLine($"wait times: {i}");
}
Assert.True(isEventCalled);
}

Expand Down Expand Up @@ -475,10 +468,10 @@ public void force_button_press()
var queue = new HOTASQueue(Substitute.For<IKeyboard>());
queue.Listen(joystick, map);
Assert.False(isEventCalled);

queue.ButtonPressed += (sender, e) => { isEventCalled = true; };
queue.ForceButtonPress(JoystickOffset.Button1, true);

Assert.True(isEventCalled);
}

Expand Down

0 comments on commit a07a249

Please sign in to comment.