OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
| 8 #include "base/macros.h" |
5 #include "remoting/base/rate_counter.h" | 9 #include "remoting/base/rate_counter.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
7 | 11 |
8 namespace remoting { | 12 namespace remoting { |
9 | 13 |
10 static const int64 kTestValues[] = { 10, 20, 30, 10, 25, 16, 15 }; | 14 static const int64_t kTestValues[] = { 10, 20, 30, 10, 25, 16, 15 }; |
11 | 15 |
12 // One second window and one sample per second, so rate equals each sample. | 16 // One second window and one sample per second, so rate equals each sample. |
13 TEST(RateCounterTest, OneSecondWindow) { | 17 TEST(RateCounterTest, OneSecondWindow) { |
14 RateCounter rate_counter(base::TimeDelta::FromSeconds(1)); | 18 RateCounter rate_counter(base::TimeDelta::FromSeconds(1)); |
15 EXPECT_EQ(0, rate_counter.Rate()); | 19 EXPECT_EQ(0, rate_counter.Rate()); |
16 | 20 |
17 base::Time now = base::Time::Now(); | 21 base::Time now = base::Time::Now(); |
18 for (size_t i = 0; i < arraysize(kTestValues); ++i) { | 22 for (size_t i = 0; i < arraysize(kTestValues); ++i) { |
19 now += base::TimeDelta::FromSeconds(1); | 23 now += base::TimeDelta::FromSeconds(1); |
20 rate_counter.SetCurrentTimeForTest(now); | 24 rate_counter.SetCurrentTimeForTest(now); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 rate_counter.Record(kTestValues[i]); | 79 rate_counter.Record(kTestValues[i]); |
76 if (i != 0) | 80 if (i != 0) |
77 expected += kTestValues[i]; | 81 expected += kTestValues[i]; |
78 } | 82 } |
79 expected /= kWindowSeconds; | 83 expected /= kWindowSeconds; |
80 | 84 |
81 EXPECT_EQ(expected, rate_counter.Rate()); | 85 EXPECT_EQ(expected, rate_counter.Rate()); |
82 } | 86 } |
83 | 87 |
84 } // namespace remoting | 88 } // namespace remoting |
OLD | NEW |