| 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/test_tools/simulator/simulator.h" | 5 #include "net/quic/test_tools/simulator/simulator.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "net/quic/platform/api/quic_logging.h" |
| 8 #include "net/quic/test_tools/quic_test_utils.h" | 9 #include "net/quic/test_tools/quic_test_utils.h" |
| 9 #include "net/quic/test_tools/simulator/alarm_factory.h" | 10 #include "net/quic/test_tools/simulator/alarm_factory.h" |
| 10 #include "net/quic/test_tools/simulator/link.h" | 11 #include "net/quic/test_tools/simulator/link.h" |
| 11 #include "net/quic/test_tools/simulator/packet_filter.h" | 12 #include "net/quic/test_tools/simulator/packet_filter.h" |
| 12 #include "net/quic/test_tools/simulator/queue.h" | 13 #include "net/quic/test_tools/simulator/queue.h" |
| 13 #include "net/quic/test_tools/simulator/switch.h" | 14 #include "net/quic/test_tools/simulator/switch.h" |
| 14 #include "net/quic/test_tools/simulator/traffic_policer.h" | 15 #include "net/quic/test_tools/simulator/traffic_policer.h" |
| 15 | |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 using std::string; | 19 using std::string; |
| 20 using testing::_; | 20 using testing::_; |
| 21 using testing::Return; | 21 using testing::Return; |
| 22 using testing::StrictMock; | 22 using testing::StrictMock; |
| 23 | 23 |
| 24 namespace net { | 24 namespace net { |
| 25 namespace simulator { | 25 namespace simulator { |
| 26 | 26 |
| 27 // A simple counter that increments its value by 1 every specified period. | 27 // A simple counter that increments its value by 1 every specified period. |
| 28 class Counter : public Actor { | 28 class Counter : public Actor { |
| 29 public: | 29 public: |
| 30 Counter(Simulator* simulator, string name, QuicTime::Delta period) | 30 Counter(Simulator* simulator, string name, QuicTime::Delta period) |
| 31 : Actor(simulator, name), value_(-1), period_(period) { | 31 : Actor(simulator, name), value_(-1), period_(period) { |
| 32 Schedule(clock_->Now()); | 32 Schedule(clock_->Now()); |
| 33 } | 33 } |
| 34 ~Counter() override {} | 34 ~Counter() override {} |
| 35 | 35 |
| 36 inline int get_value() const { return value_; } | 36 inline int get_value() const { return value_; } |
| 37 | 37 |
| 38 void Act() override { | 38 void Act() override { |
| 39 ++value_; | 39 ++value_; |
| 40 DVLOG(1) << name_ << " has value " << value_ << " at time " | 40 QUIC_DVLOG(1) << name_ << " has value " << value_ << " at time " |
| 41 << clock_->Now().ToDebuggingValue(); | 41 << clock_->Now().ToDebuggingValue(); |
| 42 Schedule(clock_->Now() + period_); | 42 Schedule(clock_->Now() + period_); |
| 43 } | 43 } |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 int value_; | 46 int value_; |
| 47 QuicTime::Delta period_; | 47 QuicTime::Delta period_; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 // Test that the basic event handling works. | 50 // Test that the basic event handling works. |
| 51 TEST(SimulatorTest, Counters) { | 51 TEST(SimulatorTest, Counters) { |
| (...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 | 724 |
| 725 // Expect subsequent traffic to be policed. | 725 // Expect subsequent traffic to be policed. |
| 726 saturator1.Resume(); | 726 saturator1.Resume(); |
| 727 simulator.RunFor(QuicTime::Delta::FromSeconds(10)); | 727 simulator.RunFor(QuicTime::Delta::FromSeconds(10)); |
| 728 test::ExpectApproxEq(saturator1.bytes_transmitted() / 4, | 728 test::ExpectApproxEq(saturator1.bytes_transmitted() / 4, |
| 729 saturator2.counter()->bytes(), 0.1f); | 729 saturator2.counter()->bytes(), 0.1f); |
| 730 } | 730 } |
| 731 | 731 |
| 732 } // namespace simulator | 732 } // namespace simulator |
| 733 } // namespace net | 733 } // namespace net |
| OLD | NEW |