[WebRTC][Non-ACR] Wait IceGathering completed 73/282973/1
authorHaesu Gwon <haesu.gwon@samsung.com>
Fri, 14 Oct 2022 04:58:25 +0000 (13:58 +0900)
committerHaesu Gwon <haesu.gwon@samsung.com>
Fri, 14 Oct 2022 04:58:36 +0000 (13:58 +0900)
Change-Id: I3c23e5fd99f0f6b612a6e9125b75d91b4cb98956

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

index b11c3fb..26382cb 100755 (executable)
@@ -517,26 +517,39 @@ namespace Tizen.Multimedia.Remoting.Tests {
         [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
         public async Task AddIceCandidate_NO_EXCEPTION()
         {
+            var tcsIceGatheringStateChanged = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
             _webRtc.AddSource(new MediaTestSource(MediaType.Video));
             await _webRtc.StartAsync();
             var offer = await _webRtc.CreateOfferAsync();
 
-            using (var eventWaiter = EventAwaiter<WebRTCIceCandidateEventArgs>.Create())
+            using (var eventWaiterIceCandidate = EventAwaiter<WebRTCIceCandidateEventArgs>.Create())
             {
-                _webRtc.IceCandidate += eventWaiter;
+                _webRtc.IceCandidate += eventWaiterIceCandidate;
+                _webRtc.IceGatheringStateChanged += IceGatheringStateChanged;
 
                 try
                 {
                     _webRtc.SetLocalDescription(offer);
 
-                    var result = await eventWaiter.GetResultAsync();
+                    var result = await eventWaiterIceCandidate.GetResultAsync();
 
                     Assert.That(() => _webRtc.AddIceCandidate(result.ICECandidate), Throws.Nothing,
                         "Should not throw exception");
+
+                    await tcsIceGatheringStateChanged.Task;
                 }
                 finally
                 {
-                    _webRtc.IceCandidate -= eventWaiter;
+                    _webRtc.IceCandidate -= eventWaiterIceCandidate;
+                    _webRtc.IceGatheringStateChanged -= IceGatheringStateChanged;
+                }
+            }
+
+            void IceGatheringStateChanged(object s, WebRTCIceGatheringStateChangedEventArgs e)
+            {
+                if (e.State == WebRTCIceGatheringState.Completed)
+                {
+                    tcsIceGatheringStateChanged.TrySetResult(true);
                 }
             }
         }
@@ -613,6 +626,7 @@ namespace Tizen.Multimedia.Remoting.Tests {
         [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
         public async Task AddIceCandidates_NO_EXCEPTION()
         {
+            var tcsIceGatheringStateChanged = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
             _webRtc.AddSource(new MediaTestSource(MediaType.Video));
             await _webRtc.StartAsync();
             var offer = await _webRtc.CreateOfferAsync();
@@ -622,6 +636,7 @@ namespace Tizen.Multimedia.Remoting.Tests {
                 try
                 {
                     _webRtc.IceCandidate += eventWaiter;
+                    _webRtc.IceGatheringStateChanged += IceGatheringStateChanged;
 
                     _webRtc.SetLocalDescription(offer);
 
@@ -629,10 +644,21 @@ namespace Tizen.Multimedia.Remoting.Tests {
 
                     Assert.That(() => _webRtc.AddIceCandidates(new List<string>{ result.ICECandidate }), Throws.Nothing,
                         "Should not throw exception");
+
+                    await tcsIceGatheringStateChanged.Task;
                 }
                 finally
                 {
                     _webRtc.IceCandidate -= eventWaiter;
+                    _webRtc.IceGatheringStateChanged -= IceGatheringStateChanged;
+                }
+            }
+
+            void IceGatheringStateChanged(object s, WebRTCIceGatheringStateChangedEventArgs e)
+            {
+                if (e.State == WebRTCIceGatheringState.Completed)
+                {
+                    tcsIceGatheringStateChanged.TrySetResult(true);
                 }
             }
         }