OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 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/base/gunit.h" | 11 #include "webrtc/base/gunit.h" |
12 #include "webrtc/base/ratetracker.h" | 12 #include "webrtc/base/ratetracker.h" |
13 | 13 |
14 namespace rtc { | 14 namespace rtc { |
| 15 namespace { |
| 16 const uint32_t kBucketIntervalMs = 100; |
| 17 } // namespace |
15 | 18 |
16 class RateTrackerForTest : public RateTracker { | 19 class RateTrackerForTest : public RateTracker { |
17 public: | 20 public: |
18 RateTrackerForTest() : RateTracker(100u, 10u), time_(0) {} | 21 RateTrackerForTest() : RateTracker(kBucketIntervalMs, 10u), time_(0) {} |
19 virtual uint32_t Time() const { return time_; } | 22 virtual uint32_t Time() const { return time_; } |
20 void AdvanceTime(uint32_t delta) { time_ += delta; } | 23 void AdvanceTime(uint32_t delta) { time_ += delta; } |
21 | 24 |
22 private: | 25 private: |
23 uint32_t time_; | 26 uint32_t time_; |
24 }; | 27 }; |
25 | 28 |
26 TEST(RateTrackerTest, Test30FPS) { | 29 TEST(RateTrackerTest, Test30FPS) { |
27 RateTrackerForTest tracker; | 30 RateTrackerForTest tracker; |
28 | 31 |
(...skipping 19 matching lines...) Expand all Loading... |
48 } | 51 } |
49 EXPECT_DOUBLE_EQ(60.0, tracker.ComputeRateForInterval(1000u)); | 52 EXPECT_DOUBLE_EQ(60.0, tracker.ComputeRateForInterval(1000u)); |
50 } | 53 } |
51 | 54 |
52 TEST(RateTrackerTest, TestRateTrackerBasics) { | 55 TEST(RateTrackerTest, TestRateTrackerBasics) { |
53 RateTrackerForTest tracker; | 56 RateTrackerForTest tracker; |
54 EXPECT_DOUBLE_EQ(0.0, tracker.ComputeRateForInterval(1000u)); | 57 EXPECT_DOUBLE_EQ(0.0, tracker.ComputeRateForInterval(1000u)); |
55 | 58 |
56 // Add a sample. | 59 // Add a sample. |
57 tracker.AddSamples(1234); | 60 tracker.AddSamples(1234); |
58 // Advance the clock by 100 ms. | 61 // Advance the clock by less than one bucket interval (no rate returned). |
59 tracker.AdvanceTime(100); | 62 tracker.AdvanceTime(kBucketIntervalMs - 1); |
| 63 EXPECT_DOUBLE_EQ(0.0, tracker.ComputeRate()); |
| 64 // Advance the clock by 100 ms (one bucket interval). |
| 65 tracker.AdvanceTime(1); |
60 EXPECT_DOUBLE_EQ(12340.0, tracker.ComputeRateForInterval(1000u)); | 66 EXPECT_DOUBLE_EQ(12340.0, tracker.ComputeRateForInterval(1000u)); |
61 EXPECT_DOUBLE_EQ(12340.0, tracker.ComputeRate()); | 67 EXPECT_DOUBLE_EQ(12340.0, tracker.ComputeRate()); |
62 EXPECT_EQ(1234U, tracker.TotalSampleCount()); | 68 EXPECT_EQ(1234U, tracker.TotalSampleCount()); |
63 EXPECT_DOUBLE_EQ(12340.0, tracker.ComputeTotalRate()); | 69 EXPECT_DOUBLE_EQ(12340.0, tracker.ComputeTotalRate()); |
64 | 70 |
65 // Repeat. | 71 // Repeat. |
66 tracker.AddSamples(1234); | 72 tracker.AddSamples(1234); |
67 tracker.AdvanceTime(100); | 73 tracker.AdvanceTime(100); |
68 EXPECT_DOUBLE_EQ(12340.0, tracker.ComputeRateForInterval(1000u)); | 74 EXPECT_DOUBLE_EQ(12340.0, tracker.ComputeRateForInterval(1000u)); |
69 EXPECT_DOUBLE_EQ(12340.0, tracker.ComputeRate()); | 75 EXPECT_DOUBLE_EQ(12340.0, tracker.ComputeRate()); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 159 } |
154 | 160 |
155 TEST(RateTrackerTest, TestGetUnitSecondsAfterInitialValue) { | 161 TEST(RateTrackerTest, TestGetUnitSecondsAfterInitialValue) { |
156 RateTrackerForTest tracker; | 162 RateTrackerForTest tracker; |
157 tracker.AddSamples(1234); | 163 tracker.AddSamples(1234); |
158 tracker.AdvanceTime(1000); | 164 tracker.AdvanceTime(1000); |
159 EXPECT_DOUBLE_EQ(1234.0, tracker.ComputeRateForInterval(1000u)); | 165 EXPECT_DOUBLE_EQ(1234.0, tracker.ComputeRateForInterval(1000u)); |
160 } | 166 } |
161 | 167 |
162 } // namespace rtc | 168 } // namespace rtc |
OLD | NEW |