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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « components/tracing/test/fake_scattered_buffer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/tracing/test/fake_scattered_buffer.h"
6
7 #include <string.h>
8
9 #include "base/strings/string_number_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace tracing {
13 namespace v2 {
14
15 FakeScatteredBuffer::FakeScatteredBuffer(size_t chunk_size)
16 : chunk_size_(chunk_size) {}
17
18 FakeScatteredBuffer::~FakeScatteredBuffer() {}
19
20 ContiguousMemoryRange FakeScatteredBuffer::GetNewBuffer() {
21 std::unique_ptr<uint8_t[]> chunk(new uint8_t[chunk_size_]);
22 uint8_t* begin = chunk.get();
23 memset(begin, 0, chunk_size_);
24 chunks_.push_back(std::move(chunk));
25 return {begin, begin + chunk_size_};
26 }
27
28 std::string FakeScatteredBuffer::GetChunkAsString(int chunk_index) {
29 return base::HexEncode(chunks_[chunk_index].get(), chunk_size_);
30 }
31
32 std::string FakeScatteredBuffer::GetBytesAsString(size_t start, size_t length) {
33 std::string hexstr;
34 EXPECT_LE(start + length, chunks_.size() * chunk_size_);
35 for (size_t pos = start; pos < start + length; ++pos) {
36 const size_t chunk_idx = pos / chunk_size_;
37 const size_t chunk_off = pos % chunk_size_;
38 if (chunk_idx >= chunks_.size()) {
39 hexstr += " <OUT OF BOUND @ pos=" + base::SizeTToString(pos) + ">";
40 return hexstr;
41 }
42 hexstr += base::HexEncode(&chunks_[chunk_idx].get()[chunk_off], 1);
43 }
44 return hexstr;
45 }
46
47 } // namespace v2
48 } // namespace tracing
OLDNEW
« 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