OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 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 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 TEST_F(StatsCounterTest, TestRegisterObserver) { | 65 TEST_F(StatsCounterTest, TestRegisterObserver) { |
66 StatsCounterObserverImpl* observer = new StatsCounterObserverImpl(); | 66 StatsCounterObserverImpl* observer = new StatsCounterObserverImpl(); |
67 const int kSample = 22; | 67 const int kSample = 22; |
68 AvgCounter counter(&clock_, observer); | 68 AvgCounter counter(&clock_, observer); |
69 AddSampleAndAdvance(kSample, kProcessIntervalMs, &counter); | 69 AddSampleAndAdvance(kSample, kProcessIntervalMs, &counter); |
70 // Trigger process (sample included in next interval). | 70 // Trigger process (sample included in next interval). |
71 counter.Add(111); | 71 counter.Add(111); |
72 EXPECT_EQ(1, observer->num_calls_); | 72 EXPECT_EQ(1, observer->num_calls_); |
73 } | 73 } |
74 | 74 |
| 75 TEST_F(StatsCounterTest, HasSample) { |
| 76 AvgCounter counter(&clock_, nullptr); |
| 77 EXPECT_FALSE(counter.HasSample()); |
| 78 counter.Add(1); |
| 79 EXPECT_TRUE(counter.HasSample()); |
| 80 } |
| 81 |
75 TEST_F(StatsCounterTest, VerifyProcessInterval) { | 82 TEST_F(StatsCounterTest, VerifyProcessInterval) { |
76 StatsCounterObserverImpl* observer = new StatsCounterObserverImpl(); | 83 StatsCounterObserverImpl* observer = new StatsCounterObserverImpl(); |
77 AvgCounter counter(&clock_, observer); | 84 AvgCounter counter(&clock_, observer); |
78 counter.Add(4); | 85 counter.Add(4); |
79 clock_.AdvanceTimeMilliseconds(kProcessIntervalMs - 1); | 86 clock_.AdvanceTimeMilliseconds(kProcessIntervalMs - 1); |
80 // Try trigger process (interval has not passed). | 87 // Try trigger process (interval has not passed). |
81 counter.Add(8); | 88 counter.Add(8); |
82 EXPECT_EQ(0, observer->num_calls_); | 89 EXPECT_EQ(0, observer->num_calls_); |
83 VerifyStatsIsNotSet(counter.GetStats()); | 90 VerifyStatsIsNotSet(counter.GetStats()); |
84 // Make process interval pass. | 91 // Make process interval pass. |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 EXPECT_EQ(3, observer->num_calls_); | 345 EXPECT_EQ(3, observer->num_calls_); |
339 EXPECT_EQ(10, observer->last_sample_); | 346 EXPECT_EQ(10, observer->last_sample_); |
340 // Aggregated stats. | 347 // Aggregated stats. |
341 AggregatedStats stats = counter.GetStats(); | 348 AggregatedStats stats = counter.GetStats(); |
342 EXPECT_EQ(3, stats.num_samples); | 349 EXPECT_EQ(3, stats.num_samples); |
343 EXPECT_EQ(0, stats.min); | 350 EXPECT_EQ(0, stats.min); |
344 EXPECT_EQ(25, stats.max); | 351 EXPECT_EQ(25, stats.max); |
345 } | 352 } |
346 | 353 |
347 } // namespace webrtc | 354 } // namespace webrtc |
OLD | NEW |