Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Side by Side Diff: net/quic/quic_alarm_test.cc

Issue 2125303002: Use overloaded operators with QuicTime for addition, subtraction and scalar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@126402784
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_alarm.cc ('k') | net/quic/quic_buffered_packet_store.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "net/quic/quic_alarm.h" 5 #include "net/quic/quic_alarm.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 void SetImpl() override {} 73 void SetImpl() override {}
74 74
75 void CancelImpl() override {} 75 void CancelImpl() override {}
76 }; 76 };
77 77
78 class QuicAlarmTest : public ::testing::Test { 78 class QuicAlarmTest : public ::testing::Test {
79 public: 79 public:
80 QuicAlarmTest() 80 QuicAlarmTest()
81 : delegate_(new MockDelegate()), 81 : delegate_(new MockDelegate()),
82 alarm_(delegate_), 82 alarm_(delegate_),
83 deadline_(QuicTime::Zero().Add(QuicTime::Delta::FromSeconds(7))), 83 deadline_(QuicTime::Zero() + QuicTime::Delta::FromSeconds(7)),
84 deadline2_(QuicTime::Zero().Add(QuicTime::Delta::FromSeconds(14))), 84 deadline2_(QuicTime::Zero() + QuicTime::Delta::FromSeconds(14)),
85 new_deadline_(QuicTime::Zero()) {} 85 new_deadline_(QuicTime::Zero()) {}
86 86
87 void ResetAlarm() { alarm_.Set(new_deadline_); } 87 void ResetAlarm() { alarm_.Set(new_deadline_); }
88 88
89 MockDelegate* delegate_; // not owned 89 MockDelegate* delegate_; // not owned
90 TestAlarm alarm_; 90 TestAlarm alarm_;
91 QuicTime deadline_; 91 QuicTime deadline_;
92 QuicTime deadline2_; 92 QuicTime deadline2_;
93 QuicTime new_deadline_; 93 QuicTime new_deadline_;
94 }; 94 };
95 95
96 TEST_F(QuicAlarmTest, IsSet) { 96 TEST_F(QuicAlarmTest, IsSet) {
97 EXPECT_FALSE(alarm_.IsSet()); 97 EXPECT_FALSE(alarm_.IsSet());
98 } 98 }
99 99
100 TEST_F(QuicAlarmTest, Set) { 100 TEST_F(QuicAlarmTest, Set) {
101 QuicTime deadline = QuicTime::Zero().Add(QuicTime::Delta::FromSeconds(7)); 101 QuicTime deadline = QuicTime::Zero() + QuicTime::Delta::FromSeconds(7);
102 alarm_.Set(deadline); 102 alarm_.Set(deadline);
103 EXPECT_TRUE(alarm_.IsSet()); 103 EXPECT_TRUE(alarm_.IsSet());
104 EXPECT_TRUE(alarm_.scheduled()); 104 EXPECT_TRUE(alarm_.scheduled());
105 EXPECT_EQ(deadline, alarm_.deadline()); 105 EXPECT_EQ(deadline, alarm_.deadline());
106 } 106 }
107 107
108 TEST_F(QuicAlarmTest, Cancel) { 108 TEST_F(QuicAlarmTest, Cancel) {
109 QuicTime deadline = QuicTime::Zero().Add(QuicTime::Delta::FromSeconds(7)); 109 QuicTime deadline = QuicTime::Zero() + QuicTime::Delta::FromSeconds(7);
110 alarm_.Set(deadline); 110 alarm_.Set(deadline);
111 alarm_.Cancel(); 111 alarm_.Cancel();
112 EXPECT_FALSE(alarm_.IsSet()); 112 EXPECT_FALSE(alarm_.IsSet());
113 EXPECT_FALSE(alarm_.scheduled()); 113 EXPECT_FALSE(alarm_.scheduled());
114 EXPECT_EQ(QuicTime::Zero(), alarm_.deadline()); 114 EXPECT_EQ(QuicTime::Zero(), alarm_.deadline());
115 } 115 }
116 116
117 TEST_F(QuicAlarmTest, Update) { 117 TEST_F(QuicAlarmTest, Update) {
118 QuicTime deadline = QuicTime::Zero().Add(QuicTime::Delta::FromSeconds(7)); 118 QuicTime deadline = QuicTime::Zero() + QuicTime::Delta::FromSeconds(7);
119 alarm_.Set(deadline); 119 alarm_.Set(deadline);
120 QuicTime new_deadline = QuicTime::Zero().Add(QuicTime::Delta::FromSeconds(8)); 120 QuicTime new_deadline = QuicTime::Zero() + QuicTime::Delta::FromSeconds(8);
121 alarm_.Update(new_deadline, QuicTime::Delta::Zero()); 121 alarm_.Update(new_deadline, QuicTime::Delta::Zero());
122 EXPECT_TRUE(alarm_.IsSet()); 122 EXPECT_TRUE(alarm_.IsSet());
123 EXPECT_TRUE(alarm_.scheduled()); 123 EXPECT_TRUE(alarm_.scheduled());
124 EXPECT_EQ(new_deadline, alarm_.deadline()); 124 EXPECT_EQ(new_deadline, alarm_.deadline());
125 } 125 }
126 126
127 TEST_F(QuicAlarmTest, UpdateWithZero) { 127 TEST_F(QuicAlarmTest, UpdateWithZero) {
128 QuicTime deadline = QuicTime::Zero().Add(QuicTime::Delta::FromSeconds(7)); 128 QuicTime deadline = QuicTime::Zero() + QuicTime::Delta::FromSeconds(7);
129 alarm_.Set(deadline); 129 alarm_.Set(deadline);
130 alarm_.Update(QuicTime::Zero(), QuicTime::Delta::Zero()); 130 alarm_.Update(QuicTime::Zero(), QuicTime::Delta::Zero());
131 EXPECT_FALSE(alarm_.IsSet()); 131 EXPECT_FALSE(alarm_.IsSet());
132 EXPECT_FALSE(alarm_.scheduled()); 132 EXPECT_FALSE(alarm_.scheduled());
133 EXPECT_EQ(QuicTime::Zero(), alarm_.deadline()); 133 EXPECT_EQ(QuicTime::Zero(), alarm_.deadline());
134 } 134 }
135 135
136 TEST_F(QuicAlarmTest, Fire) { 136 TEST_F(QuicAlarmTest, Fire) {
137 QuicTime deadline = QuicTime::Zero().Add(QuicTime::Delta::FromSeconds(7)); 137 QuicTime deadline = QuicTime::Zero() + QuicTime::Delta::FromSeconds(7);
138 alarm_.Set(deadline); 138 alarm_.Set(deadline);
139 alarm_.FireAlarm(); 139 alarm_.FireAlarm();
140 EXPECT_FALSE(alarm_.IsSet()); 140 EXPECT_FALSE(alarm_.IsSet());
141 EXPECT_FALSE(alarm_.scheduled()); 141 EXPECT_FALSE(alarm_.scheduled());
142 EXPECT_EQ(QuicTime::Zero(), alarm_.deadline()); 142 EXPECT_EQ(QuicTime::Zero(), alarm_.deadline());
143 } 143 }
144 144
145 TEST_F(QuicAlarmTest, FireAndResetViaSet) { 145 TEST_F(QuicAlarmTest, FireAndResetViaSet) {
146 alarm_.Set(deadline_); 146 alarm_.Set(deadline_);
147 new_deadline_ = deadline2_; 147 new_deadline_ = deadline2_;
148 EXPECT_CALL(*delegate_, OnAlarm()) 148 EXPECT_CALL(*delegate_, OnAlarm())
149 .WillOnce(Invoke(this, &QuicAlarmTest::ResetAlarm)); 149 .WillOnce(Invoke(this, &QuicAlarmTest::ResetAlarm));
150 alarm_.FireAlarm(); 150 alarm_.FireAlarm();
151 EXPECT_TRUE(alarm_.IsSet()); 151 EXPECT_TRUE(alarm_.IsSet());
152 EXPECT_TRUE(alarm_.scheduled()); 152 EXPECT_TRUE(alarm_.scheduled());
153 EXPECT_EQ(deadline2_, alarm_.deadline()); 153 EXPECT_EQ(deadline2_, alarm_.deadline());
154 } 154 }
155 155
156 TEST_F(QuicAlarmTest, FireDestroysAlarm) { 156 TEST_F(QuicAlarmTest, FireDestroysAlarm) {
157 DestructiveDelegate* delegate(new DestructiveDelegate); 157 DestructiveDelegate* delegate(new DestructiveDelegate);
158 DestructiveAlarm* alarm = new DestructiveAlarm(delegate); 158 DestructiveAlarm* alarm = new DestructiveAlarm(delegate);
159 delegate->set_alarm(alarm); 159 delegate->set_alarm(alarm);
160 QuicTime deadline = QuicTime::Zero().Add(QuicTime::Delta::FromSeconds(7)); 160 QuicTime deadline = QuicTime::Zero() + QuicTime::Delta::FromSeconds(7);
161 alarm->Set(deadline); 161 alarm->Set(deadline);
162 // This should not crash, even though it will destroy alarm. 162 // This should not crash, even though it will destroy alarm.
163 alarm->FireAlarm(); 163 alarm->FireAlarm();
164 } 164 }
165 165
166 } // namespace 166 } // namespace
167 } // namespace test 167 } // namespace test
168 } // namespace net 168 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_alarm.cc ('k') | net/quic/quic_buffered_packet_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698