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

Unified Diff: components/tracing/test/fake_scattered_buffer.cc

Issue 2138903002: tracing v2: refactor fake_scattered_buffer class for tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: petr review 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/tracing/test/fake_scattered_buffer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/tracing/test/fake_scattered_buffer.cc
diff --git a/components/tracing/test/fake_scattered_buffer.cc b/components/tracing/test/fake_scattered_buffer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..18e16e73f9cc8dccddcb3244404bed036630e096
--- /dev/null
+++ b/components/tracing/test/fake_scattered_buffer.cc
@@ -0,0 +1,48 @@
+// 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 "components/tracing/test/fake_scattered_buffer.h"
+
+#include <string.h>
+
+#include "base/strings/string_number_conversions.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace tracing {
+namespace v2 {
+
+FakeScatteredBuffer::FakeScatteredBuffer(size_t chunk_size)
+ : chunk_size_(chunk_size) {}
+
+FakeScatteredBuffer::~FakeScatteredBuffer() {}
+
+ContiguousMemoryRange FakeScatteredBuffer::GetNewBuffer() {
+ std::unique_ptr<uint8_t[]> chunk(new uint8_t[chunk_size_]);
+ uint8_t* begin = chunk.get();
+ memset(begin, 0, chunk_size_);
+ chunks_.push_back(std::move(chunk));
+ return {begin, begin + chunk_size_};
+}
+
+std::string FakeScatteredBuffer::GetChunkAsString(int chunk_index) {
+ return base::HexEncode(chunks_[chunk_index].get(), chunk_size_);
+}
+
+std::string FakeScatteredBuffer::GetBytesAsString(size_t start, size_t length) {
+ std::string hexstr;
+ EXPECT_LE(start + length, chunks_.size() * chunk_size_);
+ for (size_t pos = start; pos < start + length; ++pos) {
+ const size_t chunk_idx = pos / chunk_size_;
+ const size_t chunk_off = pos % chunk_size_;
+ if (chunk_idx >= chunks_.size()) {
+ hexstr += " <OUT OF BOUND @ pos=" + base::SizeTToString(pos) + ">";
+ return hexstr;
+ }
+ hexstr += base::HexEncode(&chunks_[chunk_idx].get()[chunk_off], 1);
+ }
+ return hexstr;
+}
+
+} // namespace v2
+} // namespace tracing
« no previous file with comments | « components/tracing/test/fake_scattered_buffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698