andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 1 | /* |
| 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.org | d5d709e | 2013-05-27 12:41:33 +0000 | [diff] [blame] | 11 | #include "testing/gtest/include/gtest/gtest.h" |
solenberg@webrtc.org | e5117e7 | 2013-04-18 12:25:32 +0000 | [diff] [blame] | 12 | #include "webrtc/modules/remote_bitrate_estimator/bitrate_estimator.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 13 | |
| 14 | namespace { |
| 15 | |
| 16 | using webrtc::BitRateStats; |
| 17 | |
solenberg@webrtc.org | e5117e7 | 2013-04-18 12:25:32 +0000 | [diff] [blame] | 18 | class BitRateStatsTest : public ::testing::Test { |
| 19 | protected: |
| 20 | BitRateStatsTest() {}; |
| 21 | BitRateStats stats_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 22 | }; |
| 23 | |
solenberg@webrtc.org | e5117e7 | 2013-04-18 12:25:32 +0000 | [diff] [blame] | 24 | TEST_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.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 37 | } |
solenberg@webrtc.org | e5117e7 | 2013-04-18 12:25:32 +0000 | [diff] [blame] | 38 | // 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.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 49 | } |
solenberg@webrtc.org | e5117e7 | 2013-04-18 12:25:32 +0000 | [diff] [blame] | 50 | } // namespace |