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 #include "components/tracing/test/fake_scattered_buffer.h" | 5 #include "components/tracing/test/fake_scattered_buffer.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 uint8_t* begin = chunk.get(); | 22 uint8_t* begin = chunk.get(); |
23 memset(begin, 0, chunk_size_); | 23 memset(begin, 0, chunk_size_); |
24 chunks_.push_back(std::move(chunk)); | 24 chunks_.push_back(std::move(chunk)); |
25 return {begin, begin + chunk_size_}; | 25 return {begin, begin + chunk_size_}; |
26 } | 26 } |
27 | 27 |
28 std::string FakeScatteredBuffer::GetChunkAsString(int chunk_index) { | 28 std::string FakeScatteredBuffer::GetChunkAsString(int chunk_index) { |
29 return base::HexEncode(chunks_[chunk_index].get(), chunk_size_); | 29 return base::HexEncode(chunks_[chunk_index].get(), chunk_size_); |
30 } | 30 } |
31 | 31 |
32 void FakeScatteredBuffer::GetBytes(size_t start, size_t length, uint8_t* buf) { | |
33 ASSERT_LE(start + length, chunks_.size() * chunk_size_); | |
34 for (size_t pos = 0; pos < length; ++pos) { | |
35 size_t chunk_index = (start + pos) / chunk_size_; | |
36 size_t chunk_offset = (start + pos) % chunk_size_; | |
37 if (chunk_index >= chunks_.size()) { | |
alph
2016/08/22 22:48:35
nit: looks redundant provided the ASSERT above.
kraynov
2016/08/23 12:43:49
Done.
| |
38 FAIL(); | |
39 } | |
40 buf[pos] = chunks_[chunk_index].get()[chunk_offset]; | |
41 } | |
42 } | |
43 | |
32 std::string FakeScatteredBuffer::GetBytesAsString(size_t start, size_t length) { | 44 std::string FakeScatteredBuffer::GetBytesAsString(size_t start, size_t length) { |
33 std::string hexstr; | 45 std::string hexstr; |
34 EXPECT_LE(start + length, chunks_.size() * chunk_size_); | 46 EXPECT_LE(start + length, chunks_.size() * chunk_size_); |
35 for (size_t pos = start; pos < start + length; ++pos) { | 47 for (size_t pos = start; pos < start + length; ++pos) { |
36 const size_t chunk_idx = pos / chunk_size_; | 48 const size_t chunk_idx = pos / chunk_size_; |
37 const size_t chunk_off = pos % chunk_size_; | 49 const size_t chunk_off = pos % chunk_size_; |
38 if (chunk_idx >= chunks_.size()) { | 50 if (chunk_idx >= chunks_.size()) { |
39 hexstr += " <OUT OF BOUND @ pos=" + base::SizeTToString(pos) + ">"; | 51 hexstr += " <OUT OF BOUND @ pos=" + base::SizeTToString(pos) + ">"; |
40 return hexstr; | 52 return hexstr; |
41 } | 53 } |
42 hexstr += base::HexEncode(&chunks_[chunk_idx].get()[chunk_off], 1); | 54 hexstr += base::HexEncode(&chunks_[chunk_idx].get()[chunk_off], 1); |
43 } | 55 } |
44 return hexstr; | 56 return hexstr; |
45 } | 57 } |
46 | 58 |
47 } // namespace v2 | 59 } // namespace v2 |
48 } // namespace tracing | 60 } // namespace tracing |
OLD | NEW |