Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: webrtc/video/receive_statistics_proxy_unittest.cc

Issue 2450363003: Add unit tests to ReceiveStatisticsProxy class. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/video/receive_statistics_proxy.h" 11 #include "webrtc/video/receive_statistics_proxy.h"
12 12
13 #include <memory> 13 #include <memory>
14 14
15 #include "webrtc/system_wrappers/include/metrics_default.h"
15 #include "webrtc/test/gtest.h" 16 #include "webrtc/test/gtest.h"
16 17
17 namespace webrtc { 18 namespace webrtc {
19 namespace {
20 const uint32_t kLocalSsrc = 123;
21 const uint32_t kRemoteSsrc = 456;
22 const int kMinRequiredSamples = 200;
23 } // namespace
18 24
19 // TODO(sakal): ReceiveStatisticsProxy is lacking unittesting. 25 // TODO(sakal): ReceiveStatisticsProxy is lacking unittesting.
20 class ReceiveStatisticsProxyTest : public ::testing::Test { 26 class ReceiveStatisticsProxyTest : public ::testing::Test {
21 public: 27 public:
22 ReceiveStatisticsProxyTest() : fake_clock_(1234), config_(GetTestConfig()) {} 28 ReceiveStatisticsProxyTest() : fake_clock_(1234), config_(GetTestConfig()) {}
23 virtual ~ReceiveStatisticsProxyTest() {} 29 virtual ~ReceiveStatisticsProxyTest() {}
24 30
25 protected: 31 protected:
26 virtual void SetUp() { 32 virtual void SetUp() {
33 metrics::Reset();
27 statistics_proxy_.reset(new ReceiveStatisticsProxy(&config_, &fake_clock_)); 34 statistics_proxy_.reset(new ReceiveStatisticsProxy(&config_, &fake_clock_));
28 } 35 }
29 36
30 VideoReceiveStream::Config GetTestConfig() { 37 VideoReceiveStream::Config GetTestConfig() {
31 VideoReceiveStream::Config config(nullptr); 38 VideoReceiveStream::Config config(nullptr);
39 config.rtp.local_ssrc = kLocalSsrc;
40 config.rtp.remote_ssrc = kRemoteSsrc;
32 return config; 41 return config;
33 } 42 }
34 43
35 SimulatedClock fake_clock_; 44 SimulatedClock fake_clock_;
45 const VideoReceiveStream::Config config_;
36 std::unique_ptr<ReceiveStatisticsProxy> statistics_proxy_; 46 std::unique_ptr<ReceiveStatisticsProxy> statistics_proxy_;
37 VideoReceiveStream::Config config_;
38 }; 47 };
39 48
40 TEST_F(ReceiveStatisticsProxyTest, OnDecodedFrameIncreasesFramesDecoded) { 49 TEST_F(ReceiveStatisticsProxyTest, OnDecodedFrameIncreasesFramesDecoded) {
41 EXPECT_EQ(0u, statistics_proxy_->GetStats().frames_decoded); 50 EXPECT_EQ(0u, statistics_proxy_->GetStats().frames_decoded);
42 for (uint32_t i = 1; i <= 3; ++i) { 51 for (uint32_t i = 1; i <= 3; ++i) {
43 statistics_proxy_->OnDecodedFrame(); 52 statistics_proxy_->OnDecodedFrame();
44 EXPECT_EQ(i, statistics_proxy_->GetStats().frames_decoded); 53 EXPECT_EQ(i, statistics_proxy_->GetStats().frames_decoded);
45 } 54 }
46 } 55 }
47 56
57 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsSsrc) {
58 EXPECT_EQ(kRemoteSsrc, statistics_proxy_->GetStats().ssrc);
59 }
60
61 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsIncomingPayloadType) {
62 const int kPayloadType = 111;
63 statistics_proxy_->OnIncomingPayloadType(kPayloadType);
64 EXPECT_EQ(kPayloadType, statistics_proxy_->GetStats().current_payload_type);
65 }
66
67 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsIncomingRate) {
68 const int kFramerate = 28;
69 const int kBitrateBps = 311000;
70 statistics_proxy_->OnIncomingRate(kFramerate, kBitrateBps);
71 EXPECT_EQ(kFramerate, statistics_proxy_->GetStats().network_frame_rate);
72 EXPECT_EQ(kBitrateBps, statistics_proxy_->GetStats().total_bitrate_bps);
73 }
74
75 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsDecodeTimingStats) {
76 const int kDecodeMs = 1;
77 const int kMaxDecodeMs = 2;
78 const int kCurrentDelayMs = 3;
79 const int kTargetDelayMs = 4;
80 const int kJitterBufferMs = 5;
81 const int kMinPlayoutDelayMs = 6;
82 const int kRenderDelayMs = 7;
83 const int64_t kRttMs = 8;
84 statistics_proxy_->OnDecoderTiming(
85 kDecodeMs, kMaxDecodeMs, kCurrentDelayMs, kTargetDelayMs, kJitterBufferMs,
86 kMinPlayoutDelayMs, kRenderDelayMs, kRttMs);
87 VideoReceiveStream::Stats stats = statistics_proxy_->GetStats();
88 EXPECT_EQ(kDecodeMs, stats.decode_ms);
89 EXPECT_EQ(kMaxDecodeMs, stats.max_decode_ms);
90 EXPECT_EQ(kCurrentDelayMs, stats.current_delay_ms);
91 EXPECT_EQ(kTargetDelayMs, stats.target_delay_ms);
92 EXPECT_EQ(kJitterBufferMs, stats.jitter_buffer_ms);
93 EXPECT_EQ(kMinPlayoutDelayMs, stats.min_playout_delay_ms);
94 EXPECT_EQ(kRenderDelayMs, stats.render_delay_ms);
95 }
96
97 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsDiscardedPackets) {
98 const int kDiscardedPackets = 12;
99 statistics_proxy_->OnDiscardedPacketsUpdated(kDiscardedPackets);
100 EXPECT_EQ(kDiscardedPackets, statistics_proxy_->GetStats().discarded_packets);
101 }
102
103 TEST_F(ReceiveStatisticsProxyTest, LifetimeHistogramIsUpdated) {
104 const int64_t kTimeSec = 3;
105 fake_clock_.AdvanceTimeMilliseconds(kTimeSec * 1000);
106 statistics_proxy_.reset();
stefan-webrtc 2016/10/31 09:45:42 Why reset here? Maybe comment on that.
åsapersson 2016/10/31 10:20:24 Done.
107 EXPECT_EQ(1,
108 metrics::NumSamples("WebRTC.Video.ReceiveStreamLifetimeInSeconds"));
109 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.ReceiveStreamLifetimeInSeconds",
110 kTimeSec));
111 }
112
113 TEST_F(ReceiveStatisticsProxyTest, AvSyncOffsetHistogramIsUpdated) {
114 const int64_t kSyncOffsetMs = 22;
115 for (int i = 0; i < kMinRequiredSamples; ++i)
116 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs);
117
118 statistics_proxy_.reset();
119 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.AVSyncOffsetInMs"));
120 EXPECT_EQ(1,
121 metrics::NumEvents("WebRTC.Video.AVSyncOffsetInMs", kSyncOffsetMs));
122 }
123
48 } // namespace webrtc 124 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698