From ce81fc9dad6f4c916aaed507ef0c80e5067cffd4 Mon Sep 17 00:00:00 2001 From: Haesu Gwon Date: Thu, 4 Oct 2018 11:43:47 +0900 Subject: [PATCH] [Multimedia][Non-ACR][Add CancellationTokenSource to cancel useless job] Change-Id: I0e21e4a2b01dd6984bd7c03f6bd20747087503d3 --- .../testcase/AudioManager/TSAudioDevice.cs | 23 +++++++++++++++------- .../testcase/AudioManager/TSAudioManager.cs | 5 ++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/tct-suite-vs/Tizen.Multimedia.Tests/testcase/AudioManager/TSAudioDevice.cs b/tct-suite-vs/Tizen.Multimedia.Tests/testcase/AudioManager/TSAudioDevice.cs index 711a0d1..42a4644 100644 --- a/tct-suite-vs/Tizen.Multimedia.Tests/testcase/AudioManager/TSAudioDevice.cs +++ b/tct-suite-vs/Tizen.Multimedia.Tests/testcase/AudioManager/TSAudioDevice.cs @@ -1,5 +1,6 @@ using NUnit.Framework; using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace Tizen.Multimedia.Tests @@ -107,16 +108,24 @@ namespace Tizen.Multimedia.Tests public async Task IsRunning_GET_RUNNING_STATE() { var audioStreamPolicy = new AudioStreamPolicy(AudioStreamType.Media); + var cts = new CancellationTokenSource(); - // We need to play anything in BACKGROUND for checking whether IsRunning returns true or not. - Task.Run(() => TonePlayer.StartAsync(ToneType.Default, audioStreamPolicy, 500)); + try + { + // We need to play anything in BACKGROUND for checking whether IsRunning returns true or not. + Task.Run(() => TonePlayer.StartAsync(ToneType.Default, audioStreamPolicy, 1000, cts.Token)); - // Wait until tone is played. - await Task.Delay(300); + // Wait until tone is played. + await Task.Delay(300); - // We need to check IsRunning property while audioDevice is running. - Assert.IsTrue(AudioManager.GetConnectedDevices().FirstOrDefault( - device => device.Type == AudioDeviceType.BuiltinSpeaker).IsRunning); + // We need to check IsRunning property while audioDevice is running. + Assert.IsTrue(AudioManager.GetConnectedDevices().FirstOrDefault( + device => device.Type == AudioDeviceType.BuiltinSpeaker).IsRunning); + } + finally + { + cts.Cancel(); + } } } } diff --git a/tct-suite-vs/Tizen.Multimedia.Tests/testcase/AudioManager/TSAudioManager.cs b/tct-suite-vs/Tizen.Multimedia.Tests/testcase/AudioManager/TSAudioManager.cs index 8da4ea4..e692646 100644 --- a/tct-suite-vs/Tizen.Multimedia.Tests/testcase/AudioManager/TSAudioManager.cs +++ b/tct-suite-vs/Tizen.Multimedia.Tests/testcase/AudioManager/TSAudioManager.cs @@ -1,5 +1,6 @@ using NUnit.Framework; using System; +using System.Threading; using System.Threading.Tasks; namespace Tizen.Multimedia.Tests @@ -42,6 +43,7 @@ namespace Tizen.Multimedia.Tests public async Task DeviceRunningChanged_CHECK_EVENT() { var tcs = new TaskCompletionSource(); + var cts = new CancellationTokenSource(); var audioStreamPolicy = new AudioStreamPolicy(AudioStreamType.Media); EventHandler eventHandler = (s, e) => @@ -57,12 +59,13 @@ namespace Tizen.Multimedia.Tests AudioManager.DeviceRunningChanged += eventHandler; // We need to play anything in BACKGROUND for checking whether IsRunning returns true or not. - Task.Run(() => TonePlayer.StartAsync(ToneType.Default, audioStreamPolicy, 500)); + Task.Run(() => TonePlayer.StartAsync(ToneType.Default, audioStreamPolicy, 1000, cts.Token)); Assert.That(await tcs.Task); } finally { + cts.Cancel(); AudioManager.DeviceRunningChanged -= eventHandler; } } -- 2.7.4