[longomatch] Add more units tests and fix related bugs
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Add more units tests and fix related bugs
- Date: Tue, 31 Mar 2015 17:34:04 +0000 (UTC)
commit ed6a68283c3c6650afba84a8a9625ccc53879807
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Wed Mar 25 15:13:57 2015 +0100
Add more units tests and fix related bugs
LongoMatch.Services/Services/PlayerController.cs | 40 +++++-
Tests/Services/TestPlayerController.cs | 161 ++++++++++++++++++++--
2 files changed, 182 insertions(+), 19 deletions(-)
---
diff --git a/LongoMatch.Services/Services/PlayerController.cs
b/LongoMatch.Services/Services/PlayerController.cs
index edb5ba8..2d8f239 100644
--- a/LongoMatch.Services/Services/PlayerController.cs
+++ b/LongoMatch.Services/Services/PlayerController.cs
@@ -54,7 +54,7 @@ namespace LongoMatch.Services
double rate;
Seeker seeker;
Segment loadedSegment;
- object[] pendingSeek;
+ PendingSeek pendingSeek;
Timer timer;
struct Segment
@@ -63,6 +63,16 @@ namespace LongoMatch.Services
public Time Stop;
}
+ class PendingSeek
+ {
+ public Time time;
+ public float rate;
+ public bool playing;
+ public bool accurate;
+ public bool syncrhonous;
+ public bool throttled;
+ }
+
#region Constructors
public PlayerController ()
@@ -272,7 +282,13 @@ namespace LongoMatch.Services
}
} else {
Log.Debug ("Delaying seek until player is ready");
- pendingSeek = new object[3] { time, 1.0f, false };
+ pendingSeek = new PendingSeek {
+ time = time,
+ rate = 1.0f,
+ accurate = accurate,
+ syncrhonous = synchronous,
+ throttled = throtlled
+ };
}
}
return true;
@@ -303,7 +319,6 @@ namespace LongoMatch.Services
throthled = false;
}
Seek (seekPos, accurate, false, throthled);
- EmitTimeChanged (timePos, duration);
}
public bool SeekToNextFrame ()
@@ -623,6 +638,7 @@ namespace LongoMatch.Services
try {
Log.Debug ("Opening new file set " + fileSet);
player.Open (fileSet);
+ FileSet = fileSet;
EmitTimeChanged (new Time (0), player.StreamLength);
} catch (Exception ex) {
Log.Exception (ex);
@@ -692,7 +708,12 @@ namespace LongoMatch.Services
}
} else {
Log.Debug ("Delaying seek until player is ready");
- pendingSeek = new object[3] { seekTime, rate, playing };
+ pendingSeek = new PendingSeek {
+ time = seekTime,
+ rate = 1.0f,
+ playing = playing,
+ accurate = true,
+ };
}
}
@@ -731,8 +752,11 @@ namespace LongoMatch.Services
void PerformStep (Time step)
{
Time pos = CurrentTime + step;
- if (pos.MSeconds < 0)
+ if (pos.MSeconds < 0) {
pos.MSeconds = 0;
+ } else if (pos >= StreamLength) {
+ pos = StreamLength;
+ }
Log.Debug (String.Format ("Stepping {0} seconds from {1} to {2}",
step, CurrentTime, pos));
EmitLoadDrawings (null);
@@ -840,9 +864,9 @@ namespace LongoMatch.Services
readyToSeek = true;
streamLenght = player.StreamLength;
if (pendingSeek != null) {
- SetRate ((float)pendingSeek [1]);
- player.Seek ((Time)pendingSeek [0], true);
- if ((bool)pendingSeek [2]) {
+ SetRate (pendingSeek.rate);
+ player.Seek (pendingSeek.time, pendingSeek.accurate,
pendingSeek.syncrhonous);
+ if (pendingSeek.playing) {
Play ();
}
pendingSeek = null;
diff --git a/Tests/Services/TestPlayerController.cs b/Tests/Services/TestPlayerController.cs
index da2b247..550d73e 100644
--- a/Tests/Services/TestPlayerController.cs
+++ b/Tests/Services/TestPlayerController.cs
@@ -33,6 +33,7 @@ namespace Tests.Services
public class TestPlayerController
{
Mock<IPlayer> playerMock;
+ MediaFileSet mfs;
PlayerController player;
Time currentTime, streamLength;
TimelineEvent evt;
@@ -40,8 +41,8 @@ namespace Tests.Services
Playlist playlist;
double rate;
- [SetUp ()]
- public void Setup ()
+ [TestFixtureSetUp ()]
+ public void FixtureSetup ()
{
playerMock = new Mock<IPlayer> ();
playerMock.SetupAllProperties ();
@@ -60,7 +61,10 @@ namespace Tests.Services
Config.EventsBroker = new EventsBroker ();
- player = new PlayerController ();
+ mfs = new MediaFileSet ();
+ mfs.Add (new MediaFile { FilePath = "test1", VideoWidth = 320, VideoHeight = 240, Par
= 1 });
+ mfs.Add (new MediaFile { FilePath = "test2", VideoWidth = 320, VideoHeight = 240, Par
= 1 });
+
evt = new TimelineEvent { Start = new Time (100), Stop = new Time (200) };
plImage = new PlaylistImage (Utils.LoadImageFromFile (), new Time (5));
playlist = new Playlist ();
@@ -68,6 +72,22 @@ namespace Tests.Services
playlist.Elements.Add (plImage);
}
+ [SetUp ()]
+ public void Setup ()
+ {
+ playerMock.ResetCalls ();
+ player = new PlayerController ();
+ }
+
+ void PreparePlayer ()
+ {
+ player.CamerasVisible = new List<int> { 0, 1 };
+ player.WindowHandles = new List<IntPtr> { IntPtr.Zero, IntPtr.Zero };
+ player.Ready ();
+ player.Open (mfs);
+ playerMock.Raise (p => p.ReadyToSeek += null);
+ }
+
[Test ()]
public void TestPropertiesProxy ()
{
@@ -132,9 +152,6 @@ namespace Tests.Services
int parCount = 0, timeCount = 0;
bool multimediaError = false;
Time curTime = null, duration = null;
- MediaFileSet mfs = new MediaFileSet ();
- mfs.Add (new MediaFile { FilePath = "test1", VideoWidth = 320, VideoHeight = 240, Par
= 1 });
- mfs.Add (new MediaFile { FilePath = "test2", VideoWidth = 320, VideoHeight = 240, Par
= 1 });
player.PARChangedEvent += (w, p) => {
par = p;
@@ -165,15 +182,13 @@ namespace Tests.Services
/* Open with the view ready */
streamLength = new Time { TotalSeconds = 5000 };
- player.CamerasVisible = new List<int> { 0, 1 };
- player.WindowHandles = new List<IntPtr> { IntPtr.Zero, IntPtr.Zero };
- player.Ready ();
- player.Open (mfs);
+ currentTime = new Time (0);
+ PreparePlayer ();
playerMock.Verify (p => p.Open (mfs), Times.Once ());
playerMock.Verify (p => p.Play (), Times.Never ());
playerMock.Verify (p => p.Seek (new Time (0), true, false), Times.Never ());
Assert.AreEqual (2, parCount);
- Assert.AreEqual (1, timeCount);
+ Assert.AreEqual (2, timeCount);
Assert.AreEqual ((float)320 / 240, par);
Assert.AreEqual (streamLength, duration);
Assert.AreEqual (new Time (0), curTime);
@@ -236,6 +251,130 @@ namespace Tests.Services
player.TogglePlay ();
Assert.IsFalse (player.Playing);
}
+
+ [Test ()]
+ public void TestSeek ()
+ {
+ int drawingsCount = 0;
+ int timeChanged = 0;
+ Time curTime = new Time (0);
+ Time strLenght = new Time (0);
+
+ player.TimeChangedEvent += (c, d, s) => {
+ timeChanged++;
+ curTime = c;
+ strLenght = d;
+ };
+ player.LoadDrawingsEvent += (f) => drawingsCount++;
+ player.Ready ();
+ player.Open (mfs);
+ Assert.AreEqual (0, timeChanged);
+
+ /* Not ready, seek queued */
+ currentTime = new Time (2000);
+ player.Seek (currentTime, false, false, false);
+ playerMock.Verify (p => p.Seek (It.IsAny<Time> (), It.IsAny<bool> (), It.IsAny<bool>
()), Times.Never ());
+ Assert.AreEqual (1, drawingsCount);
+ Assert.AreEqual (0, timeChanged);
+ playerMock.ResetCalls ();
+
+ /* Once ready the seek kicks in */
+ currentTime = new Time (2000);
+ playerMock.Raise (p => p.ReadyToSeek += null);
+ /* ReadyToSeek emits TimeChanged */
+ Assert.AreEqual (1, timeChanged);
+ playerMock.Verify (p => p.Seek (currentTime, false, false), Times.Once ());
+ Assert.AreEqual (1, drawingsCount);
+ Assert.AreEqual (currentTime, curTime);
+ Assert.AreEqual (strLenght, streamLength);
+ playerMock.ResetCalls ();
+
+ /* Seek when player ready to seek */
+ currentTime = new Time (4000);
+ player.Seek (currentTime, true, true, false);
+ playerMock.Verify (p => p.Seek (currentTime, true, true), Times.Once ());
+ Assert.AreEqual (2, drawingsCount);
+ Assert.AreEqual (2, timeChanged);
+ Assert.AreEqual (currentTime, curTime);
+ Assert.AreEqual (strLenght, streamLength);
+ playerMock.ResetCalls ();
+
+ currentTime = new Time (5000);
+ player.LoadPlaylistEvent (playlist, plImage);
+ player.Seek (currentTime, true, true, false);
+ playerMock.Verify (p => p.Seek (It.IsAny<Time> (), It.IsAny<bool> (), It.IsAny<bool>
()), Times.Never ());
+ Assert.AreEqual (2, drawingsCount);
+ playerMock.ResetCalls ();
+ }
+
+ [Test ()]
+ public void TestSeekProportional ()
+ {
+ int seekPos;
+ int timeChanged = 0;
+ Time curTime = new Time (0);
+ Time strLenght = new Time (0);
+
+ streamLength = new Time { TotalSeconds = 5000 };
+ player.TimeChangedEvent += (c, d, s) => {
+ timeChanged++;
+ curTime = c;
+ strLenght = d;
+ };
+ PreparePlayer ();
+
+ /* Seek without any segment loaded */
+ seekPos = (int)(streamLength.MSeconds * 0.1);
+ currentTime = new Time (seekPos);
+ player.Seek (0.1f);
+ playerMock.Verify (p => p.Seek (new Time (seekPos), false, false), Times.Once ());
+ Assert.IsTrue (timeChanged != 0);
+ Assert.AreEqual (seekPos, curTime.MSeconds);
+ Assert.AreEqual (strLenght.MSeconds, streamLength.MSeconds);
+
+ /* Seek with a segment loaded */
+ timeChanged = 0;
+ seekPos = (int)(evt.Start.MSeconds + evt.Duration.MSeconds * 0.5);
+ currentTime = new Time (seekPos);
+ player.LoadEvent (mfs, evt, evt.Start, true);
+ playerMock.ResetCalls ();
+ player.Seek (0.5f);
+ playerMock.Verify (p => p.Seek (new Time (seekPos), true, false), Times.Once ());
+ Assert.IsTrue (timeChanged != 0);
+ /* current time is now relative to the loaded segment's duration */
+ Assert.AreEqual (evt.Duration * 0.5, curTime);
+ Assert.AreEqual (evt.Duration, strLenght);
+ }
+
+ [Test ()]
+ public void TestStepping ()
+ {
+ int timeChanged = 0;
+ Time curTime = new Time (0);
+ Time strLenght = new Time (0);
+
+ currentTime = new Time { TotalSeconds = 2000 };
+ streamLength = new Time { TotalSeconds = 5000 };
+ PreparePlayer ();
+ player.TimeChangedEvent += (c, d, s) => {
+ timeChanged++;
+ curTime = c;
+ strLenght = d;
+ };
+
+ player.SeekToNextFrame ();
+ playerMock.Verify (p => p.SeekToNextFrame (), Times.Once ());
+ Assert.AreEqual (1, timeChanged);
+ Assert.AreEqual (currentTime, curTime);
+ Assert.AreEqual (streamLength, strLenght);
+
+ player.SeekToPreviousFrame ();
+ playerMock.Verify (p => p.SeekToPreviousFrame (), Times.Once ());
+ Assert.AreEqual (2, timeChanged);
+ Assert.AreEqual (currentTime, curTime);
+ Assert.AreEqual (streamLength, strLenght);
+ }
+
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]