[WebRTC][NON-ACR] Call DataChannel Send method after DataChannel is established 25/278325/1
authorHaesu Gwon <haesu.gwon@samsung.com>
Tue, 19 Jul 2022 05:25:44 +0000 (14:25 +0900)
committerHaesu Gwon <haesu.gwon@samsung.com>
Tue, 19 Jul 2022 05:25:44 +0000 (14:25 +0900)
Change-Id: Ia3b1ed2a15102052f2490413359464b9e562fd2f

tct-suite-vs/Tizen.WebRTC.Tests/testcase/TSWebRTCDataChannel.cs

index 5e06a3b..ef878c6 100755 (executable)
  */
 using NUnit.Framework;
 using System;
+using System.Threading.Tasks;
 
 namespace Tizen.Multimedia.Remoting.Tests {
 
     [TestFixture]
     [Description("Tizen.Multimedia.Remoting.WebRTCDataChannel Tests")]
-    public class WebRTCDataChannelTests
+    public class WebRTCDataChannelTests : TestBase
     {
         private WebRTC _webRtc;
 
@@ -117,11 +118,32 @@ namespace Tizen.Multimedia.Remoting.Tests {
         [Property("CRITERIA", "MR")]
         [Property("COVPARAM", "string")]
         [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
-        public void Send_CHECK_RETURN()
+        public async Task Send_CHECK_RETURN()
         {
-            var webRtcDataChannel = new WebRTCDataChannel(_webRtc, "test");
-            Assert.That(() => webRtcDataChannel.Send("test"), Throws.Nothing,
-                "Should not throw exception");
+            using (var offerClient = new WebRTC())
+            using (var answerClient = new WebRTC())
+            {
+                var tcsAnswerTrackAdded =
+                    new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
+                var tcsOfferDataChannel =
+                    new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
+
+                answerClient.TrackAdded += (s, e) => tcsAnswerTrackAdded.TrySetResult(true);
+                answerClient.DataChannel += (s, e) => tcsOfferDataChannel.TrySetResult(true);
+
+                offerClient.AddSource(new MediaTestSource(MediaType.Video));
+                var offerDataChannel = new WebRTCDataChannel(offerClient, "offerDataChannel");
+
+                await offerClient.StartAsync();
+                await answerClient.StartAsync();
+
+                await ConnectPeerAsync(offerClient, answerClient);
+
+                await Task.WhenAll(tcsOfferDataChannel.Task, tcsAnswerTrackAdded.Task);
+
+                Assert.That(() => offerDataChannel.Send("test"), Throws.Nothing,
+                    "Should not throw exception");
+            }
         }
 
         [Test]
@@ -149,13 +171,33 @@ namespace Tizen.Multimedia.Remoting.Tests {
         [Property("CRITERIA", "MR")]
         [Property("COVPARAM", "byte[]")]
         [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
-        public void Send_WITH_BYTE_CHECK_RETURN()
+        public async Task Send_WITH_BYTE_CHECK_RETURN()
         {
-            var webRtcDataChannel = new WebRTCDataChannel(_webRtc, "test");
-            var data = new byte[10];
+            using (var offerClient = new WebRTC())
+            using (var answerClient = new WebRTC())
+            {
+                var tcsAnswerTrackAdded =
+                    new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
+                var tcsOfferDataChannel =
+                    new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
+
+                answerClient.TrackAdded += (s, e) => tcsAnswerTrackAdded.TrySetResult(true);
+                answerClient.DataChannel += (s, e) => tcsOfferDataChannel.TrySetResult(true);
+
+                offerClient.AddSource(new MediaTestSource(MediaType.Video));
+                var offerDataChannel = new WebRTCDataChannel(offerClient, "offerDataChannel");
 
-            Assert.That(() => webRtcDataChannel.Send(data), Throws.Nothing,
-                "Should not throw exception");
+                await offerClient.StartAsync();
+                await answerClient.StartAsync();
+
+                await ConnectPeerAsync(offerClient, answerClient);
+
+                await Task.WhenAll(tcsOfferDataChannel.Task, tcsAnswerTrackAdded.Task);
+
+                var data = new byte[10];
+                Assert.That(() => offerDataChannel.Send(data), Throws.Nothing,
+                    "Should not throw exception");
+            }
         }
 
         [Test]