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 // Common utilities for Quic tests | 5 // Common utilities for Quic tests |
6 | 6 |
7 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 7 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
8 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 8 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
9 | 9 |
10 #include <stddef.h> | 10 #include <stddef.h> |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 // packet could not be created. | 208 // packet could not be created. |
209 QuicPacket* BuildUnsizedDataPacket(QuicFramer* framer, | 209 QuicPacket* BuildUnsizedDataPacket(QuicFramer* framer, |
210 const QuicPacketHeader& header, | 210 const QuicPacketHeader& header, |
211 const QuicFrames& frames); | 211 const QuicFrames& frames); |
212 // Returns a QuicPacket that is owned by the caller, and of size |packet_size|. | 212 // Returns a QuicPacket that is owned by the caller, and of size |packet_size|. |
213 QuicPacket* BuildUnsizedDataPacket(QuicFramer* framer, | 213 QuicPacket* BuildUnsizedDataPacket(QuicFramer* framer, |
214 const QuicPacketHeader& header, | 214 const QuicPacketHeader& header, |
215 const QuicFrames& frames, | 215 const QuicFrames& frames, |
216 size_t packet_size); | 216 size_t packet_size); |
217 | 217 |
218 template <typename SaveType> | 218 // When constructed, checks that all QUIC flags have their correct default |
219 class ValueRestore { | 219 // values and when destructed, restores those values. |
| 220 class QuicFlagSaver { |
220 public: | 221 public: |
221 ValueRestore(SaveType* name, SaveType value) : name_(name), value_(*name) { | 222 QuicFlagSaver(); |
222 *name_ = value; | 223 ~QuicFlagSaver(); |
223 } | |
224 ~ValueRestore() { *name_ = value_; } | |
225 | |
226 private: | |
227 SaveType* name_; | |
228 SaveType value_; | |
229 | |
230 DISALLOW_COPY_AND_ASSIGN(ValueRestore); | |
231 }; | 224 }; |
232 | 225 |
233 // Simple random number generator used to compute random numbers suitable | 226 // Simple random number generator used to compute random numbers suitable |
234 // for pseudo-randomly dropping packets in tests. It works by computing | 227 // for pseudo-randomly dropping packets in tests. It works by computing |
235 // the sha1 hash of the current seed, and using the first 64 bits as | 228 // the sha1 hash of the current seed, and using the first 64 bits as |
236 // the next random number, and the next seed. | 229 // the next random number, and the next seed. |
237 class SimpleRandom { | 230 class SimpleRandom { |
238 public: | 231 public: |
239 SimpleRandom() : seed_(0) {} | 232 SimpleRandom() : seed_(0) {} |
240 | 233 |
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 TestQuicSpdyServerSession** server_session); | 1024 TestQuicSpdyServerSession** server_session); |
1032 | 1025 |
1033 // Helper to generate client side stream ids, generalizes | 1026 // Helper to generate client side stream ids, generalizes |
1034 // kClientDataStreamId1 etc. above. | 1027 // kClientDataStreamId1 etc. above. |
1035 QuicStreamId QuicClientDataStreamId(int i); | 1028 QuicStreamId QuicClientDataStreamId(int i); |
1036 | 1029 |
1037 } // namespace test | 1030 } // namespace test |
1038 } // namespace net | 1031 } // namespace net |
1039 | 1032 |
1040 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 1033 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
OLD | NEW |