From 8fd5c7afd90ff34f2ffa4f2dabfd1f819272c1c1 Mon Sep 17 00:00:00 2001 From: Haesu Gwon Date: Wed, 14 Sep 2022 17:59:44 +0900 Subject: [PATCH] [TCSACR-501][WebRTC] Add new APIs for WebRTC statistics Change-Id: I05d7f666b0bbe9e94784f53e868e84b2ed9e7ba3 --- .../testcase/TSWebRTC.statistics.cs | 263 +++++++++++++++++++++ 1 file changed, 263 insertions(+) create mode 100755 tct-suite-vs/Tizen.WebRTC.Tests/testcase/TSWebRTC.statistics.cs diff --git a/tct-suite-vs/Tizen.WebRTC.Tests/testcase/TSWebRTC.statistics.cs b/tct-suite-vs/Tizen.WebRTC.Tests/testcase/TSWebRTC.statistics.cs new file mode 100755 index 0000000..a6d8c0b --- /dev/null +++ b/tct-suite-vs/Tizen.WebRTC.Tests/testcase/TSWebRTC.statistics.cs @@ -0,0 +1,263 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Tizen.Multimedia.Remoting.Tests { + + [TestFixture] + [Description("Tizen.Multimedia.Remoting.WebRTCStatistics Tests")] + public class WebRTCStatisticsTests : TestBase + { + private WebRTC _webRtc; + + private readonly string _turnServer = "turn://turnserver.address"; + + [SetUp] + public void Init() + { + _webRtc = new WebRTC(); + } + + [TearDown] + public void Destroy() + { + _webRtc?.Dispose(); + } + + [Test] + [Category("P1")] + [Description("Test GetStatistics whether throws exception or not.")] + [Property("SPEC", "Tizen.Multimedia.Remoting.WebRTC.GetStatistics M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")] + public async Task GetStatistics_NO_EXCEPTION() + { + using (var offerClient = new WebRTC()) + using (var answerClient = new WebRTC()) + { + offerClient.AddSource(new MediaTestSource(MediaType.Video)); + + await offerClient.StartAsync(); + await answerClient.StartAsync(); + + await ConnectPeerAsync(offerClient, answerClient); + + foreach (WebRTCStatisticsCategory category in Enum.GetValues(typeof(WebRTCStatisticsCategory))) + { + Assert.That(() => offerClient.GetStatistics(category), Throws.Nothing); + } + } + } + + [Test] + [Category("P2")] + [Description("Check whether GetStatistics throws exception when it's already disposed.")] + [Property("SPEC", "Tizen.Multimedia.Remoting.WebRTC.GetStatistics M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MEX")] + [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")] + public async Task GetStatistics_THROWS_IF_ALREADY_DISPOSED() + { + using (var offerClient = new WebRTC()) + using (var answerClient = new WebRTC()) + { + offerClient.AddSource(new MediaTestSource(MediaType.Video)); + + await offerClient.StartAsync(); + await answerClient.StartAsync(); + + await ConnectPeerAsync(offerClient, answerClient); + + offerClient.Dispose(); + + Assert.That(() => offerClient.GetStatistics(WebRTCStatisticsCategory.Codec), Throws.TypeOf(), + "Should throw ObjectDisposedException"); + } + } + + [Test] + [Category("P2")] + [Description("Check whether GetStatistics throws exception when WebRTC is in invalid state.")] + [Property("SPEC", "Tizen.Multimedia.Remoting.WebRTC.GetStatistics M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MEX")] + [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")] + public async Task GetStatistics_THROWS_IF_INVALID_STATE() + { + _webRtc.AddSource(new MediaTestSource(MediaType.Video)); + + await _webRtc.StartAsync(); + + Assert.That(() => _webRtc.GetStatistics(WebRTCStatisticsCategory.Codec), Throws.InvalidOperationException, + "Should throw InvalidOperationException"); + } + + [Test] + [Category("P1")] + [Description("Test Category whether throws exception or not.")] + [Property("SPEC", "Tizen.Multimedia.Remoting.WebRTC.WebRTCStatistics.Category A")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRO")] + [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")] + public async Task Category_READ_ONLY() + { + using (var offerClient = new WebRTC()) + using (var answerClient = new WebRTC()) + { + offerClient.AddSource(new MediaTestSource(MediaType.Video)); + + await offerClient.StartAsync(); + await answerClient.StartAsync(); + + await ConnectPeerAsync(offerClient, answerClient); + + foreach (WebRTCStatisticsCategory category in Enum.GetValues(typeof(WebRTCStatisticsCategory))) + { + var stats = offerClient.GetStatistics(category); + foreach (var stat in stats) + { + if (category == WebRTCStatisticsCategory.All) + { + Assert.That(Enum.IsDefined(typeof(WebRTCStatisticsCategory), stat.Category), + "Should be one of WebRTCStatisticsCategory"); + } + else + { + Assert.That(stat.Category == category, "Should be same value"); + } + } + } + } + } + + [Test] + [Category("P1")] + [Description("Test Name whether throws exception or not.")] + [Property("SPEC", "Tizen.Multimedia.Remoting.WebRTC.WebRTCStatistics.Name A")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRO")] + [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")] + public async Task Name_READ_ONLY() + { + using (var offerClient = new WebRTC()) + using (var answerClient = new WebRTC()) + { + offerClient.AddSource(new MediaTestSource(MediaType.Video)); + + await offerClient.StartAsync(); + await answerClient.StartAsync(); + + await ConnectPeerAsync(offerClient, answerClient); + + var stats = offerClient.GetStatistics(WebRTCStatisticsCategory.Codec); + foreach (var stat in stats) + { + Assert.That(stat.Name != null, "Should not be null"); + } + } + } + + [Test] + [Category("P1")] + [Description("Test Property whether throws exception or not.")] + [Property("SPEC", "Tizen.Multimedia.Remoting.WebRTC.WebRTCStatistics.Property A")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRO")] + [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")] + public async Task Property_READ_ONLY() + { + using (var offerClient = new WebRTC()) + using (var answerClient = new WebRTC()) + { + offerClient.AddSource(new MediaTestSource(MediaType.Video)); + + await offerClient.StartAsync(); + await answerClient.StartAsync(); + + await ConnectPeerAsync(offerClient, answerClient); + + var stats = offerClient.GetStatistics(WebRTCStatisticsCategory.Codec); + foreach (var stat in stats) + { + Assert.That(Enum.IsDefined(typeof(WebRTCStatisticsProperty), stat.Property), + "Enum type should be matched"); + } + } + } + + [Test] + [Category("P1")] + [Description("Test Value whether throws exception or not.")] + [Property("SPEC", "Tizen.Multimedia.Remoting.WebRTC.WebRTCStatistics.Value A")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRO")] + [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")] + public async Task Value_READ_ONLY() + { + using (var offerClient = new WebRTC()) + using (var answerClient = new WebRTC()) + { + offerClient.AddSource(new MediaTestSource(MediaType.Video)); + + await offerClient.StartAsync(); + await answerClient.StartAsync(); + + await ConnectPeerAsync(offerClient, answerClient); + + var stats = offerClient.GetStatistics(WebRTCStatisticsCategory.Codec); + foreach (var stat in stats) + { + Assert.That(stat.Value != null, "Should not be null"); + } + } + } + + [Test] + [Category("P1")] + [Description("Check whether ToString returns expected value or not.")] + [Property("SPEC", "Tizen.Multimedia.Remoting.WebRTC.WebRTCStatistics.ToString M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")] + public async Task ToString_CHECK_VALUE() + { + using (var offerClient = new WebRTC()) + using (var answerClient = new WebRTC()) + { + offerClient.AddSource(new MediaTestSource(MediaType.Video)); + + await offerClient.StartAsync(); + await answerClient.StartAsync(); + + await ConnectPeerAsync(offerClient, answerClient); + + var stats = offerClient.GetStatistics(WebRTCStatisticsCategory.Codec); + foreach (var stat in stats) + { + var toString = + $"Category={stat.Category}, Name={stat.Name}, Property={stat.Property}, Value={stat.Value}, Type={stat.Value.GetType()}"; + + Assert.AreEqual(toString, stat.ToString(), "Should return same value"); + } + } + } + } +} -- 2.7.4