OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef NET_HTTP2_TOOLS_HTTP2_RANDOM_H_ | 5 #ifndef NET_HTTP2_TOOLS_HTTP2_RANDOM_H_ |
6 #define NET_HTTP2_TOOLS_HTTP2_RANDOM_H_ | 6 #define NET_HTTP2_TOOLS_HTTP2_RANDOM_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <limits> | |
10 #include <string> | 11 #include <string> |
11 | 12 |
12 namespace net { | 13 namespace net { |
13 namespace test { | 14 namespace test { |
14 | 15 |
15 class RandomBase { | 16 class RandomBase { |
16 public: | 17 public: |
17 virtual ~RandomBase() {} | 18 virtual ~RandomBase() {} |
18 virtual bool OneIn(int n) = 0; | 19 virtual bool OneIn(int n) = 0; |
19 virtual int32_t Uniform(int32_t n) = 0; | 20 virtual int32_t Uniform(int32_t n) = 0; |
20 virtual uint8_t Rand8() = 0; | 21 virtual uint8_t Rand8() = 0; |
21 virtual uint16_t Rand16() = 0; | 22 virtual uint16_t Rand16() = 0; |
22 virtual uint32_t Rand32() = 0; | 23 virtual uint32_t Rand32() = 0; |
23 virtual uint64_t Rand64() = 0; | 24 virtual uint64_t Rand64() = 0; |
24 virtual int32_t Next() = 0; | 25 virtual int32_t Next() = 0; |
25 virtual int32_t Skewed(int max_log) = 0; | 26 virtual int32_t Skewed(int max_log) = 0; |
26 virtual std::string RandString(int length) = 0; | 27 virtual std::string RandString(int length) = 0; |
28 | |
29 // STL UniformRandomNumberGenerator implementation. | |
30 typedef uint32_t result_type; | |
31 static constexpr result_type min() { return 0; } | |
32 static constexpr result_type max() { | |
33 return std::numeric_limits<uint32_t>::max(); | |
34 } | |
35 result_type operator()() { return Rand32(); } | |
27 }; | 36 }; |
28 | 37 |
29 class Http2Random : public RandomBase { | 38 class Http2Random : public RandomBase { |
James Synge
2017/01/03 19:11:29
Seems like there should be a comment indicating th
Bence
2017/01/04 16:15:20
Done.
| |
30 public: | 39 public: |
31 ~Http2Random() override {} | 40 ~Http2Random() override {} |
32 bool OneIn(int n) override; | 41 bool OneIn(int n) override; |
33 int32_t Uniform(int32_t n) override; | 42 int32_t Uniform(int32_t n) override; |
34 uint8_t Rand8() override; | 43 uint8_t Rand8() override; |
35 uint16_t Rand16() override; | 44 uint16_t Rand16() override; |
36 uint32_t Rand32() override; | 45 uint32_t Rand32() override; |
37 uint64_t Rand64() override; | 46 uint64_t Rand64() override; |
38 int32_t Next() override; | 47 int32_t Next() override; |
39 int32_t Skewed(int max_log) override; | 48 int32_t Skewed(int max_log) override; |
40 std::string RandString(int length) override; | 49 std::string RandString(int length) override; |
41 }; | 50 }; |
42 | 51 |
43 } // namespace test | 52 } // namespace test |
44 } // namespace net | 53 } // namespace net |
45 | 54 |
46 #endif // NET_HTTP2_TOOLS_HTTP2_RANDOM_H_ | 55 #endif // NET_HTTP2_TOOLS_HTTP2_RANDOM_H_ |
OLD | NEW |