Skip to content

Commit

Permalink
Improved some tests that checked recording duration by removing cold …
Browse files Browse the repository at this point in the history
…start time factor. This should make them more accurate on slower hardware.
  • Loading branch information
sskodje committed Feb 15, 2023
1 parent 951a076 commit a968ae0
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion Tests/ScreenRecorderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ public void FixedFramerate()
bool isComplete = false;
ManualResetEvent finalizeResetEvent = new ManualResetEvent(false);
ManualResetEvent recordingResetEvent = new ManualResetEvent(false);
ManualResetEvent recordingStartedEvent = new ManualResetEvent(false);
rec.OnRecordingComplete += (s, args) =>
{
isComplete = true;
Expand All @@ -723,8 +724,21 @@ public void FixedFramerate()
finalizeResetEvent.Set();
recordingResetEvent.Set();
};
rec.OnStatusChanged += (s, args) =>
{
switch (args.Status)
{
case RecorderStatus.Recording:
{
recordingStartedEvent.Set();
break;
}
default: break;
}
};
int durationMillis = 5000;
rec.Record(outStream);
recordingStartedEvent.WaitOne(3000);
recordingResetEvent.WaitOne(durationMillis);
rec.Stop();
finalizeResetEvent.WaitOne(5000);
Expand Down Expand Up @@ -979,6 +993,7 @@ public void Slideshow()
bool isComplete = false;
ManualResetEvent finalizeResetEvent = new ManualResetEvent(false);
ManualResetEvent recordingResetEvent = new ManualResetEvent(false);
ManualResetEvent recordingStartedEvent = new ManualResetEvent(false);
rec.OnRecordingComplete += (s, args) =>
{
isComplete = true;
Expand All @@ -991,8 +1006,20 @@ public void Slideshow()
finalizeResetEvent.Set();
recordingResetEvent.Set();
};

rec.OnStatusChanged += (s, args) =>
{
switch (args.Status)
{
case RecorderStatus.Recording:
{
recordingStartedEvent.Set();
break;
}
default: break;
}
};
rec.Record(directoryPath);
recordingStartedEvent.WaitOne(1000);
recordingResetEvent.WaitOne(recordingLengthMillis);
rec.Stop();
finalizeResetEvent.WaitOne(5000);
Expand Down Expand Up @@ -1149,6 +1176,7 @@ public void DefaultRecording30SecondsToFile()
bool isComplete = false;
ManualResetEvent finalizingResetEvent = new ManualResetEvent(false);
ManualResetEvent recordingResetEvent = new ManualResetEvent(false);
ManualResetEvent recordingStartedEvent = new ManualResetEvent(false);
rec.OnRecordingComplete += (s, args) =>
{
isComplete = true;
Expand All @@ -1161,9 +1189,22 @@ public void DefaultRecording30SecondsToFile()
finalizingResetEvent.Set();
recordingResetEvent.Set();
};
rec.OnStatusChanged += (s, args) =>
{
switch (args.Status)
{
case RecorderStatus.Recording:
{
recordingStartedEvent.Set();
break;
}
default: break;
}
};
int recordingTimeMillis = 30 * 1000;
Stopwatch sw = Stopwatch.StartNew();
rec.Record(filePath);
recordingStartedEvent.WaitOne(1000);
recordingResetEvent.WaitOne(recordingTimeMillis);
rec.Stop();
finalizingResetEvent.WaitOne(5000);
Expand Down

0 comments on commit a968ae0

Please sign in to comment.