[longomatch] Add more unit tests for the PlayerController
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Add more unit tests for the PlayerController
- Date: Tue, 31 Mar 2015 17:33:49 +0000 (UTC)
commit 0acbc0196a70dd55eebbbab9e72775f5f1782090
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Tue Mar 24 19:32:12 2015 +0100
Add more unit tests for the PlayerController
Tests/Services/TestPlayerController.cs | 83 ++++++++++++++++++++++++++++++++
1 files changed, 83 insertions(+), 0 deletions(-)
---
diff --git a/Tests/Services/TestPlayerController.cs b/Tests/Services/TestPlayerController.cs
index 68252b6..da2b247 100644
--- a/Tests/Services/TestPlayerController.cs
+++ b/Tests/Services/TestPlayerController.cs
@@ -24,6 +24,8 @@ using LongoMatch;
using LongoMatch.Core.Store;
using LongoMatch.Core.Common;
using System.Collections.Generic;
+using LongoMatch.Core.Interfaces.GUI;
+using LongoMatch.Core.Store.Playlists;
namespace Tests.Services
{
@@ -33,6 +35,9 @@ namespace Tests.Services
Mock<IPlayer> playerMock;
PlayerController player;
Time currentTime, streamLength;
+ TimelineEvent evt;
+ PlaylistImage plImage;
+ Playlist playlist;
double rate;
[SetUp ()]
@@ -43,13 +48,24 @@ namespace Tests.Services
/* Mock properties without setter */
playerMock.Setup (p => p.CurrentTime).Returns (() => currentTime);
playerMock.Setup (p => p.StreamLength).Returns (() => streamLength);
+ playerMock.Setup (p => p.Play ()).Raises (p => p.StateChange += null, true);
+ playerMock.Setup (p => p.Pause ()).Raises (p => p.StateChange += null, false);
var mtk = Mock.Of<IMultimediaToolkit> (m => m.GetPlayer () == playerMock.Object);
Config.MultimediaToolkit = mtk;
+ var ftk = new Mock<IGUIToolkit> ();
+ ftk.Setup (m => m.Invoke (It.IsAny<EventHandler> ())).Callback<EventHandler> (e => e
(null, null));
+ Config.GUIToolkit = ftk.Object;
+
Config.EventsBroker = new EventsBroker ();
player = new PlayerController ();
+ evt = new TimelineEvent { Start = new Time (100), Stop = new Time (200) };
+ plImage = new PlaylistImage (Utils.LoadImageFromFile (), new Time (5));
+ playlist = new Playlist ();
+ playlist.Elements.Add (new PlaylistPlayElement (evt));
+ playlist.Elements.Add (plImage);
}
[Test ()]
@@ -101,6 +117,15 @@ namespace Tests.Services
}
[Test ()]
+ public void Dispose ()
+ {
+ player.Dispose ();
+ playerMock.Verify (p => p.Dispose (), Times.Once ());
+ Assert.IsTrue (player.IgnoreTicks);
+ Assert.IsNull (player.FileSet);
+ }
+
+ [Test ()]
public void Open ()
{
float par = 0;
@@ -153,6 +178,64 @@ namespace Tests.Services
Assert.AreEqual (streamLength, duration);
Assert.AreEqual (new Time (0), curTime);
}
+
+ [Test ()]
+ public void TestPlayPause ()
+ {
+ bool loadSent = false;
+ bool playing = false;
+ FrameDrawing drawing = null;
+
+
+ player.PlaybackStateChangedEvent += (p) => {
+ playing = p;
+ };
+ player.LoadDrawingsEvent += (f) => {
+ loadSent = true;
+ drawing = f;
+ };
+
+ /* Start playing */
+ player.Play ();
+ Assert.IsTrue (loadSent);
+ Assert.IsNull (drawing);
+ playerMock.Verify (p => p.Play (), Times.Once ());
+ Assert.IsTrue (player.Playing);
+ Assert.IsTrue (playing);
+
+ /* Go to pause */
+ loadSent = false;
+ player.Pause ();
+ Assert.IsFalse (loadSent);
+ Assert.IsNull (drawing);
+ playerMock.Verify (p => p.Pause (), Times.Once ());
+ Assert.IsFalse (player.Playing);
+ Assert.IsFalse (playing);
+
+ /* Check now with a still image loaded */
+ playerMock.ResetCalls ();
+ player.LoadPlaylistEvent (playlist, plImage);
+ player.Play ();
+ playerMock.Verify (p => p.Play (), Times.Never ());
+ playerMock.Verify (p => p.Pause (), Times.Once ());
+ Assert.IsTrue (player.Playing);
+
+ /* Go to pause */
+ playerMock.ResetCalls ();
+ player.Pause ();
+ playerMock.Verify (p => p.Play (), Times.Never ());
+ playerMock.Verify (p => p.Pause (), Times.Never ());
+ Assert.IsFalse (player.Playing);
+ }
+
+ [Test ()]
+ public void TestTogglePlay ()
+ {
+ player.TogglePlay ();
+ Assert.IsTrue (player.Playing);
+ player.TogglePlay ();
+ Assert.IsFalse (player.Playing);
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]