From c85c4fb2fc86b3b74f255e2452d6945ba8ed8b8e Mon Sep 17 00:00:00 2001 From: ruble Date: Wed, 31 Jul 2019 16:19:26 +0900 Subject: [PATCH] [MediaPlayer][TCSACR-253] add TCs to cancel the player while it's getting ready Change-Id: I684b345f75964ef8f7e95910ef9fa91bc2435aa7 --- .../testcase/TSPlayer.cs | 145 ++++++++++++++++++ 1 file changed, 145 insertions(+) diff --git a/tct-suite-vs/Tizen.MediaPlayer.Tests/testcase/TSPlayer.cs b/tct-suite-vs/Tizen.MediaPlayer.Tests/testcase/TSPlayer.cs index 6327fe9cc..53a9d2aa9 100755 --- a/tct-suite-vs/Tizen.MediaPlayer.Tests/testcase/TSPlayer.cs +++ b/tct-suite-vs/Tizen.MediaPlayer.Tests/testcase/TSPlayer.cs @@ -1,6 +1,7 @@ using NUnit.Framework; using System; using System.IO; +using System.Threading; using System.Threading.Tasks; using Tizen.System; @@ -121,6 +122,148 @@ namespace Tizen.Multimedia.Tests Assert.That(() => player.PrepareAsync(), Throws.InvalidOperationException); } + [Test] + [Category("P1")] + [Description("Check whether PrepareAsync changes player state to ready")] + [Property("SPEC", "Tizen.Multimedia.Player.PrepareAsync M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MCST")] + [Property("COVPARAM", "CancellationToken")] + [Property("AUTHOR", "Jeongyoon Nam, just.nam@samsung.com")] + public async Task PrepareAsync_WITH_TOCKEN_CHECK() + { + TestPlayer.SetSource(Constants.VideoFileSource); + Assert.That(TestPlayer.State, Is.EqualTo(PlayerState.Idle)); + + using (var tokenSource = new CancellationTokenSource()) + { + var prepareTask = TestPlayer.PrepareAsync(tokenSource.Token); + Assert.That(TestPlayer.State, Is.EqualTo(PlayerState.Preparing)); + + await prepareTask; + Assert.That(TestPlayer.State, Is.EqualTo(PlayerState.Ready)); + + tokenSource.Dispose(); + } + } + + [Test] + [Category("P1")] + [Description("Check cancel operation of PrepareAsync when the state is preparing")] + [Property("SPEC", "Tizen.Multimedia.Player.PrepareAsync M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MCST")] + [Property("COVPARAM", "CancellationToken")] + [Property("AUTHOR", "Jeongyoon Nam, just.nam@samsung.com")] + public void PrepareAsync_WITH_TOCKEN_CANCEL() + { + TestPlayer.SetSource(_streamingSource); + Assert.That(TestPlayer.State, Is.EqualTo(PlayerState.Idle)); + + using (var tokenSource = new CancellationTokenSource()) + { + var prepareTask = TestPlayer.PrepareAsync(tokenSource.Token); + Assert.That(TestPlayer.State, Is.EqualTo(PlayerState.Preparing)); + + tokenSource.Cancel(); + Assert.That(TestPlayer.State, Is.EqualTo(PlayerState.Idle)); + + tokenSource.Dispose(); + } + } + + + [Test] + [Category("P2")] + [Description("Check cancel operation of PrepareAsync when the state is invalid")] + [Property("SPEC", "Tizen.Multimedia.Player.PrepareAsync M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MEX")] + [Property("COVPARAM", "CancellationToken")] + [Property("AUTHOR", "Jeongyoon Nam, just.nam@samsung.com")] + public async Task PrepareAsync_WITH_TOCKEN_THROWS_IF_NOT_VALID_STATE() + { + TestPlayer.SetSource(Constants.VideoFileSource); + Assert.That(TestPlayer.State, Is.EqualTo(PlayerState.Idle)); + + using (var tokenSource = new CancellationTokenSource()) + { + await TestPlayer.PrepareAsync(tokenSource.Token); + Assert.That(TestPlayer.State, Is.EqualTo(PlayerState.Ready)); + + try + { + tokenSource.Cancel(); + } + catch (AggregateException ae) + { + foreach (var e in ae.InnerExceptions) + { + if (e is InvalidOperationException) + { + Assert.Pass("Proper exception occured."); + } + + Assert.Fail("Expected exception didn't occur."); + } + } + finally + { + tokenSource.Dispose(); + } + } + } + + [Test] + [Category("P2")] + [Description("PrepareAsync throws if source is not set")] + [Property("SPEC", "Tizen.Multimedia.Player.PrepareAsync M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MEX")] + [Property("COVPARAM", "CancellationToken")] + [Property("AUTHOR", "Jeongyoon Nam, just.nam@samsung.com")] + public void PrepareAsync_WITH_TOCKEN_THROWS_IF_NO_SOURCE_SET() + { + Assert.That(() => TestPlayer.PrepareAsync(CancellationToken.None), Throws.InvalidOperationException); + } + + [Test] + [Category("P2")] + [Description("PrepareAsync throws if the player is not in the idle state")] + [Property("SPEC", "Tizen.Multimedia.Player.PrepareAsync M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MEX")] + [Property("COVPARAM", "CancellationToken")] + [Property("AUTHOR", "Jeongyoon Nam, just.nam@samsung.com")] + public async Task PrepareAsync_WITH_TOCKEN_THROWS_IF_NOT_IDLE() + { + var player = await GetPreparedPlayer(); + + Assert.That(() => player.PrepareAsync(CancellationToken.None), Throws.InvalidOperationException); + + player.Start(); + Assert.That(() => player.PrepareAsync(CancellationToken.None), Throws.InvalidOperationException); + + player.Pause(); + Assert.That(() => player.PrepareAsync(CancellationToken.None), Throws.InvalidOperationException); + } + + [Test] + [Category("P2")] + [Description("Any attempt to access the PrepareAsync if the player has been disposed of")] + [Property("SPEC", "Tizen.Multimedia.Player.PrepareAsync M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MEX")] + [Property("COVPARAM", "CancellationToken")] + [Property("AUTHOR", "Jeongyoon Nam, just.nam@samsung.com")] + public void PrepareAsync_WITH_TOCKEN_DISPOSED() + { + GetIdlePlayer().Dispose(); + + Assert.That(() => TestPlayer.PrepareAsync(CancellationToken.None), + Throws.TypeOf()); + } + [Test] [Category("P1")] [Description("Start normal test")] @@ -1785,6 +1928,7 @@ namespace Tizen.Multimedia.Tests Assert.That(() => player.SetVideoRoi(sr), Throws.Nothing); Assert.That(player.GetVideoRoi(), Is.EqualTo(sr), "Invalid value."); + player.Dispose(); } [Test] @@ -1820,6 +1964,7 @@ namespace Tizen.Multimedia.Tests Assert.That(() => player.SetVideoRoi(new ScaleRectangle(0.99, -0.1, 1, 1)), Throws.TypeOf()); Assert.That(() => player.SetVideoRoi(new ScaleRectangle(0.1, 0.1, 1.1, 1)), Throws.TypeOf()); Assert.That(() => player.SetVideoRoi(new ScaleRectangle(-3, 0.1, 1, 1)), Throws.TypeOf()); + player.Dispose(); } [Test] -- 2.34.1