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

Side by Side Diff: minidump/minidump_context_writer_test.cc

Issue 936153002: Add FileReaderInterface. Move StringFileWriter to StringFile and (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Remove unused #include Created 5 years, 10 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 | « no previous file | minidump/minidump_crashpad_info_writer_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with 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 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "minidump/minidump_context_writer.h" 15 #include "minidump/minidump_context_writer.h"
16 16
17 #include <stdint.h> 17 #include <stdint.h>
18 18
19 #include "gtest/gtest.h" 19 #include "gtest/gtest.h"
20 #include "minidump/minidump_context.h" 20 #include "minidump/minidump_context.h"
21 #include "minidump/test/minidump_context_test_util.h" 21 #include "minidump/test/minidump_context_test_util.h"
22 #include "minidump/test/minidump_writable_test_util.h" 22 #include "minidump/test/minidump_writable_test_util.h"
23 #include "snapshot/cpu_context.h" 23 #include "snapshot/cpu_context.h"
24 #include "snapshot/test/test_cpu_context.h" 24 #include "snapshot/test/test_cpu_context.h"
25 #include "util/file/string_file_writer.h" 25 #include "util/file/string_file.h"
26 26
27 namespace crashpad { 27 namespace crashpad {
28 namespace test { 28 namespace test {
29 namespace { 29 namespace {
30 30
31 TEST(MinidumpContextWriter, MinidumpContextX86Writer) { 31 TEST(MinidumpContextWriter, MinidumpContextX86Writer) {
32 StringFileWriter file_writer; 32 StringFile string_file;
33 33
34 { 34 {
35 // Make sure that a context writer that’s untouched writes a zeroed-out 35 // Make sure that a context writer that’s untouched writes a zeroed-out
36 // context. 36 // context.
37 SCOPED_TRACE("zero"); 37 SCOPED_TRACE("zero");
38 38
39 MinidumpContextX86Writer context_writer; 39 MinidumpContextX86Writer context_writer;
40 40
41 EXPECT_TRUE(context_writer.WriteEverything(&file_writer)); 41 EXPECT_TRUE(context_writer.WriteEverything(&string_file));
42 ASSERT_EQ(sizeof(MinidumpContextX86), file_writer.string().size()); 42 ASSERT_EQ(sizeof(MinidumpContextX86), string_file.string().size());
43 43
44 const MinidumpContextX86* observed = 44 const MinidumpContextX86* observed =
45 MinidumpWritableAtRVA<MinidumpContextX86>(file_writer.string(), 0); 45 MinidumpWritableAtRVA<MinidumpContextX86>(string_file.string(), 0);
46 ASSERT_TRUE(observed); 46 ASSERT_TRUE(observed);
47 47
48 ExpectMinidumpContextX86(0, observed, false); 48 ExpectMinidumpContextX86(0, observed, false);
49 } 49 }
50 50
51 { 51 {
52 SCOPED_TRACE("nonzero"); 52 SCOPED_TRACE("nonzero");
53 53
54 file_writer.Reset(); 54 string_file.Reset();
55 const uint32_t kSeed = 0x8086; 55 const uint32_t kSeed = 0x8086;
56 56
57 MinidumpContextX86Writer context_writer; 57 MinidumpContextX86Writer context_writer;
58 InitializeMinidumpContextX86(context_writer.context(), kSeed); 58 InitializeMinidumpContextX86(context_writer.context(), kSeed);
59 59
60 EXPECT_TRUE(context_writer.WriteEverything(&file_writer)); 60 EXPECT_TRUE(context_writer.WriteEverything(&string_file));
61 ASSERT_EQ(sizeof(MinidumpContextX86), file_writer.string().size()); 61 ASSERT_EQ(sizeof(MinidumpContextX86), string_file.string().size());
62 62
63 const MinidumpContextX86* observed = 63 const MinidumpContextX86* observed =
64 MinidumpWritableAtRVA<MinidumpContextX86>(file_writer.string(), 0); 64 MinidumpWritableAtRVA<MinidumpContextX86>(string_file.string(), 0);
65 ASSERT_TRUE(observed); 65 ASSERT_TRUE(observed);
66 66
67 ExpectMinidumpContextX86(kSeed, observed, false); 67 ExpectMinidumpContextX86(kSeed, observed, false);
68 } 68 }
69 } 69 }
70 70
71 TEST(MinidumpContextWriter, MinidumpContextAMD64Writer) { 71 TEST(MinidumpContextWriter, MinidumpContextAMD64Writer) {
72 StringFileWriter file_writer; 72 StringFile string_file;
73 73
74 { 74 {
75 // Make sure that a context writer that’s untouched writes a zeroed-out 75 // Make sure that a context writer that’s untouched writes a zeroed-out
76 // context. 76 // context.
77 SCOPED_TRACE("zero"); 77 SCOPED_TRACE("zero");
78 78
79 MinidumpContextAMD64Writer context_writer; 79 MinidumpContextAMD64Writer context_writer;
80 80
81 EXPECT_TRUE(context_writer.WriteEverything(&file_writer)); 81 EXPECT_TRUE(context_writer.WriteEverything(&string_file));
82 ASSERT_EQ(sizeof(MinidumpContextAMD64), file_writer.string().size()); 82 ASSERT_EQ(sizeof(MinidumpContextAMD64), string_file.string().size());
83 83
84 const MinidumpContextAMD64* observed = 84 const MinidumpContextAMD64* observed =
85 MinidumpWritableAtRVA<MinidumpContextAMD64>(file_writer.string(), 0); 85 MinidumpWritableAtRVA<MinidumpContextAMD64>(string_file.string(), 0);
86 ASSERT_TRUE(observed); 86 ASSERT_TRUE(observed);
87 87
88 ExpectMinidumpContextAMD64(0, observed, false); 88 ExpectMinidumpContextAMD64(0, observed, false);
89 } 89 }
90 90
91 { 91 {
92 SCOPED_TRACE("nonzero"); 92 SCOPED_TRACE("nonzero");
93 93
94 file_writer.Reset(); 94 string_file.Reset();
95 const uint32_t kSeed = 0x808664; 95 const uint32_t kSeed = 0x808664;
96 96
97 MinidumpContextAMD64Writer context_writer; 97 MinidumpContextAMD64Writer context_writer;
98 InitializeMinidumpContextAMD64(context_writer.context(), kSeed); 98 InitializeMinidumpContextAMD64(context_writer.context(), kSeed);
99 99
100 EXPECT_TRUE(context_writer.WriteEverything(&file_writer)); 100 EXPECT_TRUE(context_writer.WriteEverything(&string_file));
101 ASSERT_EQ(sizeof(MinidumpContextAMD64), file_writer.string().size()); 101 ASSERT_EQ(sizeof(MinidumpContextAMD64), string_file.string().size());
102 102
103 const MinidumpContextAMD64* observed = 103 const MinidumpContextAMD64* observed =
104 MinidumpWritableAtRVA<MinidumpContextAMD64>(file_writer.string(), 0); 104 MinidumpWritableAtRVA<MinidumpContextAMD64>(string_file.string(), 0);
105 ASSERT_TRUE(observed); 105 ASSERT_TRUE(observed);
106 106
107 ExpectMinidumpContextAMD64(kSeed, observed, false); 107 ExpectMinidumpContextAMD64(kSeed, observed, false);
108 } 108 }
109 } 109 }
110 110
111 TEST(MinidumpContextWriter, CreateFromSnapshot_X86) { 111 TEST(MinidumpContextWriter, CreateFromSnapshot_X86) {
112 const uint32_t kSeed = 32; 112 const uint32_t kSeed = 32;
113 113
114 CPUContextX86 context_snapshot_x86; 114 CPUContextX86 context_snapshot_x86;
115 CPUContext context_snapshot; 115 CPUContext context_snapshot;
116 context_snapshot.x86 = &context_snapshot_x86; 116 context_snapshot.x86 = &context_snapshot_x86;
117 InitializeCPUContextX86(&context_snapshot, kSeed); 117 InitializeCPUContextX86(&context_snapshot, kSeed);
118 118
119 scoped_ptr<MinidumpContextWriter> context_writer = 119 scoped_ptr<MinidumpContextWriter> context_writer =
120 MinidumpContextWriter::CreateFromSnapshot(&context_snapshot); 120 MinidumpContextWriter::CreateFromSnapshot(&context_snapshot);
121 ASSERT_TRUE(context_writer); 121 ASSERT_TRUE(context_writer);
122 122
123 StringFileWriter file_writer; 123 StringFile string_file;
124 ASSERT_TRUE(context_writer->WriteEverything(&file_writer)); 124 ASSERT_TRUE(context_writer->WriteEverything(&string_file));
125 125
126 const MinidumpContextX86* observed = 126 const MinidumpContextX86* observed =
127 MinidumpWritableAtRVA<MinidumpContextX86>(file_writer.string(), 0); 127 MinidumpWritableAtRVA<MinidumpContextX86>(string_file.string(), 0);
128 ASSERT_TRUE(observed); 128 ASSERT_TRUE(observed);
129 129
130 ExpectMinidumpContextX86(kSeed, observed, true); 130 ExpectMinidumpContextX86(kSeed, observed, true);
131 } 131 }
132 132
133 TEST(MinidumpContextWriter, CreateFromSnapshot_AMD64) { 133 TEST(MinidumpContextWriter, CreateFromSnapshot_AMD64) {
134 const uint32_t kSeed = 64; 134 const uint32_t kSeed = 64;
135 135
136 CPUContextX86_64 context_snapshot_x86_64; 136 CPUContextX86_64 context_snapshot_x86_64;
137 CPUContext context_snapshot; 137 CPUContext context_snapshot;
138 context_snapshot.x86_64 = &context_snapshot_x86_64; 138 context_snapshot.x86_64 = &context_snapshot_x86_64;
139 InitializeCPUContextX86_64(&context_snapshot, kSeed); 139 InitializeCPUContextX86_64(&context_snapshot, kSeed);
140 140
141 scoped_ptr<MinidumpContextWriter> context_writer = 141 scoped_ptr<MinidumpContextWriter> context_writer =
142 MinidumpContextWriter::CreateFromSnapshot(&context_snapshot); 142 MinidumpContextWriter::CreateFromSnapshot(&context_snapshot);
143 ASSERT_TRUE(context_writer); 143 ASSERT_TRUE(context_writer);
144 144
145 StringFileWriter file_writer; 145 StringFile string_file;
146 ASSERT_TRUE(context_writer->WriteEverything(&file_writer)); 146 ASSERT_TRUE(context_writer->WriteEverything(&string_file));
147 147
148 const MinidumpContextAMD64* observed = 148 const MinidumpContextAMD64* observed =
149 MinidumpWritableAtRVA<MinidumpContextAMD64>(file_writer.string(), 0); 149 MinidumpWritableAtRVA<MinidumpContextAMD64>(string_file.string(), 0);
150 ASSERT_TRUE(observed); 150 ASSERT_TRUE(observed);
151 151
152 ExpectMinidumpContextAMD64(kSeed, observed, true); 152 ExpectMinidumpContextAMD64(kSeed, observed, true);
153 } 153 }
154 154
155 } // namespace 155 } // namespace
156 } // namespace test 156 } // namespace test
157 } // namespace crashpad 157 } // namespace crashpad
OLDNEW
« no previous file with comments | « no previous file | minidump/minidump_crashpad_info_writer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698