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

Side by Side Diff: minidump/minidump_memory_writer_test_util.cc

Issue 639513002: Pull test utilities from MinidumpMemoryWriter’s test out into their own file (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 2 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 | « minidump/minidump_memory_writer_test_util.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 2014 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "minidump/minidump_memory_writer_test_util.h"
16
17 #include "gtest/gtest.h"
18
19 namespace crashpad {
20 namespace test {
21
22 TestMinidumpMemoryWriter::TestMinidumpMemoryWriter(uint64_t base_address,
23 size_t size,
24 uint8_t value)
25 : MinidumpMemoryWriter(),
26 base_address_(base_address),
27 expected_offset_(-1),
28 size_(size),
29 value_(value) {
30 }
31
32 TestMinidumpMemoryWriter::~TestMinidumpMemoryWriter() {
33 }
34
35 uint64_t TestMinidumpMemoryWriter::MemoryRangeBaseAddress() const {
36 EXPECT_EQ(state(), kStateFrozen);
37 return base_address_;
38 }
39
40 size_t TestMinidumpMemoryWriter::MemoryRangeSize() const {
41 EXPECT_GE(state(), kStateFrozen);
42 return size_;
43 }
44
45 bool TestMinidumpMemoryWriter::WillWriteAtOffsetImpl(off_t offset) {
46 EXPECT_EQ(state(), kStateFrozen);
47 expected_offset_ = offset;
48 bool rv = MinidumpMemoryWriter::WillWriteAtOffsetImpl(offset);
49 EXPECT_TRUE(rv);
50 return rv;
51 }
52
53 bool TestMinidumpMemoryWriter::WriteObject(FileWriterInterface* file_writer) {
54 EXPECT_EQ(state(), kStateWritable);
55 EXPECT_EQ(expected_offset_, file_writer->Seek(0, SEEK_CUR));
56
57 bool rv = true;
58 if (size_ > 0) {
59 std::string data(size_, value_);
60 rv = file_writer->Write(&data[0], size_);
61 EXPECT_TRUE(rv);
62 }
63
64 return rv;
65 }
66
67 void ExpectMinidumpMemoryDescriptorAndContents(
68 const MINIDUMP_MEMORY_DESCRIPTOR* expected,
69 const MINIDUMP_MEMORY_DESCRIPTOR* observed,
70 const std::string& file_contents,
71 uint8_t value,
72 bool at_eof) {
73 EXPECT_EQ(expected->StartOfMemoryRange, observed->StartOfMemoryRange);
74 EXPECT_EQ(expected->Memory.DataSize, observed->Memory.DataSize);
75 if (expected->Memory.Rva != 0) {
Mark Mentovai 2014/10/07 19:01:56 This new conditional is the only change to the cod
76 const uint32_t kMemoryAlignment = 16;
77 EXPECT_EQ(
78 (expected->Memory.Rva + kMemoryAlignment - 1) & ~(kMemoryAlignment - 1),
79 observed->Memory.Rva);
80 }
81 if (at_eof) {
82 EXPECT_EQ(file_contents.size(),
83 observed->Memory.Rva + observed->Memory.DataSize);
84 } else {
85 EXPECT_GE(file_contents.size(),
86 observed->Memory.Rva + observed->Memory.DataSize);
87 }
88
89 std::string expected_data(expected->Memory.DataSize, value);
90 std::string observed_data(&file_contents[observed->Memory.Rva],
91 observed->Memory.DataSize);
92 EXPECT_EQ(expected_data, observed_data);
93 }
94
95 } // namespace test
96 } // namespace crashpad
OLDNEW
« no previous file with comments | « minidump/minidump_memory_writer_test_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698