| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/quic/core/quic_bandwidth.h" | 5 #include "net/quic/core/quic_bandwidth.h" |
| 6 #include "net/quic/core/quic_time.h" | 6 #include "net/quic/core/quic_time.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 namespace net { | 9 namespace net { |
| 10 namespace test { | 10 namespace test { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 QuicBandwidth::FromKBytesPerSecond(1000) * 1.25f); | 66 QuicBandwidth::FromKBytesPerSecond(1000) * 1.25f); |
| 67 | 67 |
| 68 // Ensure we are rounding correctly within a 1bps level of precision. | 68 // Ensure we are rounding correctly within a 1bps level of precision. |
| 69 EXPECT_EQ(QuicBandwidth::FromBitsPerSecond(5), | 69 EXPECT_EQ(QuicBandwidth::FromBitsPerSecond(5), |
| 70 QuicBandwidth::FromBitsPerSecond(9) * 0.5f); | 70 QuicBandwidth::FromBitsPerSecond(9) * 0.5f); |
| 71 EXPECT_EQ(QuicBandwidth::FromBitsPerSecond(2), | 71 EXPECT_EQ(QuicBandwidth::FromBitsPerSecond(2), |
| 72 QuicBandwidth::FromBitsPerSecond(12) * 0.2f); | 72 QuicBandwidth::FromBitsPerSecond(12) * 0.2f); |
| 73 } | 73 } |
| 74 | 74 |
| 75 TEST_F(QuicBandwidthTest, BytesPerPeriod) { | 75 TEST_F(QuicBandwidthTest, BytesPerPeriod) { |
| 76 EXPECT_EQ(2000u, | 76 EXPECT_EQ(2000u, QuicBandwidth::FromKBytesPerSecond(2000).ToBytesPerPeriod( |
| 77 QuicBandwidth::FromKBytesPerSecond(2000).ToBytesPerPeriod( | 77 QuicTime::Delta::FromMilliseconds(1))); |
| 78 QuicTime::Delta::FromMilliseconds(1))); | 78 EXPECT_EQ(2u, QuicBandwidth::FromKBytesPerSecond(2000).ToKBytesPerPeriod( |
| 79 EXPECT_EQ(2u, | 79 QuicTime::Delta::FromMilliseconds(1))); |
| 80 QuicBandwidth::FromKBytesPerSecond(2000).ToKBytesPerPeriod( | 80 EXPECT_EQ(200000u, QuicBandwidth::FromKBytesPerSecond(2000).ToBytesPerPeriod( |
| 81 QuicTime::Delta::FromMilliseconds(1))); | 81 QuicTime::Delta::FromMilliseconds(100))); |
| 82 EXPECT_EQ(200000u, | 82 EXPECT_EQ(200u, QuicBandwidth::FromKBytesPerSecond(2000).ToKBytesPerPeriod( |
| 83 QuicBandwidth::FromKBytesPerSecond(2000).ToBytesPerPeriod( | 83 QuicTime::Delta::FromMilliseconds(100))); |
| 84 QuicTime::Delta::FromMilliseconds(100))); | |
| 85 EXPECT_EQ(200u, | |
| 86 QuicBandwidth::FromKBytesPerSecond(2000).ToKBytesPerPeriod( | |
| 87 QuicTime::Delta::FromMilliseconds(100))); | |
| 88 } | 84 } |
| 89 | 85 |
| 90 TEST_F(QuicBandwidthTest, TransferTime) { | 86 TEST_F(QuicBandwidthTest, TransferTime) { |
| 91 EXPECT_EQ(QuicTime::Delta::FromSeconds(1), | 87 EXPECT_EQ(QuicTime::Delta::FromSeconds(1), |
| 92 QuicBandwidth::FromKBytesPerSecond(1).TransferTime(1000)); | 88 QuicBandwidth::FromKBytesPerSecond(1).TransferTime(1000)); |
| 93 EXPECT_EQ(QuicTime::Delta::Zero(), QuicBandwidth::Zero().TransferTime(1000)); | 89 EXPECT_EQ(QuicTime::Delta::Zero(), QuicBandwidth::Zero().TransferTime(1000)); |
| 94 } | 90 } |
| 95 | 91 |
| 96 TEST_F(QuicBandwidthTest, RelOps) { | 92 TEST_F(QuicBandwidthTest, RelOps) { |
| 97 const QuicBandwidth b1 = QuicBandwidth::FromKBitsPerSecond(1); | 93 const QuicBandwidth b1 = QuicBandwidth::FromKBitsPerSecond(1); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 117 | 113 |
| 118 bandwidth = bandwidth * 1000; | 114 bandwidth = bandwidth * 1000; |
| 119 EXPECT_EQ("400.00 Mbits/s (50.00 Mbytes/s)", bandwidth.ToDebugValue()); | 115 EXPECT_EQ("400.00 Mbits/s (50.00 Mbytes/s)", bandwidth.ToDebugValue()); |
| 120 | 116 |
| 121 bandwidth = bandwidth * 1000; | 117 bandwidth = bandwidth * 1000; |
| 122 EXPECT_EQ("400.00 Gbits/s (50.00 Gbytes/s)", bandwidth.ToDebugValue()); | 118 EXPECT_EQ("400.00 Gbits/s (50.00 Gbytes/s)", bandwidth.ToDebugValue()); |
| 123 } | 119 } |
| 124 | 120 |
| 125 } // namespace test | 121 } // namespace test |
| 126 } // namespace net | 122 } // namespace net |
| OLD | NEW |