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

Unified Diff: net/http2/tools/http2_random.cc

Issue 2293613002: Add new HTTP/2 and HPACK decoder in net/http2/. (Closed)
Patch Set: Replace LOG(INFO) by VLOG(2) in DecodeBufferTest.SlowDecodeTestStruct so that trybots do not fail. Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http2/tools/http2_random.h ('k') | net/http2/tools/random_decoder_test.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http2/tools/http2_random.cc
diff --git a/net/http2/tools/http2_random.cc b/net/http2/tools/http2_random.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8732d6a857d38fe51f40979d9e4504738358dae7
--- /dev/null
+++ b/net/http2/tools/http2_random.cc
@@ -0,0 +1,59 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/http2/tools/http2_random.h"
+
+#include <limits>
+#include <memory>
+
+#include "base/rand_util.h"
+
+namespace net {
+namespace test {
+
+bool Http2Random::OneIn(int n) {
+ return base::RandGenerator(n) == 0;
+}
+
+int32_t Http2Random::Uniform(int32_t n) {
+ return base::RandGenerator(n);
+}
+
+uint8_t Http2Random::Rand8() {
+ return base::RandGenerator(
+ static_cast<uint64_t>(std::numeric_limits<uint8_t>::max()) + 1);
+}
+
+uint16_t Http2Random::Rand16() {
+ return base::RandGenerator(
+ static_cast<uint64_t>(std::numeric_limits<uint16_t>::max()) + 1);
+}
+
+uint32_t Http2Random::Rand32() {
+ return base::RandGenerator(
+ static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()) + 1);
+}
+
+uint64_t Http2Random::Rand64() {
+ return base::RandUint64();
+}
+
+int32_t Http2Random::Next() {
+ return Rand32();
+}
+
+int32_t Http2Random::Skewed(int max_log) {
+ const uint32_t base = Rand32() % (max_log + 1);
+ const uint32_t mask = ((base < 32) ? (1u << base) : 0u) - 1u;
+ return Rand32() & mask;
+}
+
+std::string Http2Random::RandString(int length) {
+ std::unique_ptr<char[]> buffer(new char[length]);
+ base::RandBytes(buffer.get(), length);
+ return std::string(buffer.get(), length);
+}
+
+} // namespace test
+} // namespace net
« no previous file with comments | « net/http2/tools/http2_random.h ('k') | net/http2/tools/random_decoder_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698