blob: ca9da99c010ce37de45ea5bb327121af80b591f6 [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
pbos@webrtc.orgd5d709e2013-05-27 12:41:33 +000011#include "testing/gtest/include/gtest/gtest.h"
solenberg@webrtc.orge5117e72013-04-18 12:25:32 +000012#include "webrtc/modules/remote_bitrate_estimator/bitrate_estimator.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000013
14namespace {
15
16using webrtc::BitRateStats;
17
solenberg@webrtc.orge5117e72013-04-18 12:25:32 +000018class BitRateStatsTest : public ::testing::Test {
19 protected:
20 BitRateStatsTest() {};
21 BitRateStats stats_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000022};
23
solenberg@webrtc.orge5117e72013-04-18 12:25:32 +000024TEST_F(BitRateStatsTest, TestStrictMode) {
25 int64_t now_ms = 0;
26 // Should be initialized to 0.
27 EXPECT_EQ(0u, stats_.BitRate(now_ms));
28 stats_.Update(1500, now_ms);
29 // Expecting 24 kbps given a 500 ms window with one 1500 bytes packet.
30 EXPECT_EQ(24000u, stats_.BitRate(now_ms));
31 stats_.Init();
32 // Expecting 0 after init.
33 EXPECT_EQ(0u, stats_.BitRate(now_ms));
34 for (int i = 0; i < 100000; ++i) {
35 if (now_ms % 10 == 0) {
36 stats_.Update(1500, now_ms);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000037 }
solenberg@webrtc.orge5117e72013-04-18 12:25:32 +000038 // Approximately 1200 kbps expected. Not exact since when packets
39 // are removed we will jump 10 ms to the next packet.
40 if (now_ms > 0 && now_ms % 500 == 0) {
41 EXPECT_NEAR(1200000u, stats_.BitRate(now_ms), 24000u);
42 }
43 now_ms += 1;
44 }
45 now_ms += 500;
46 // The window is 2 seconds. If nothing has been received for that time
47 // the estimate should be 0.
48 EXPECT_EQ(0u, stats_.BitRate(now_ms));
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000049}
solenberg@webrtc.orge5117e72013-04-18 12:25:32 +000050} // namespace