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

Side by Side Diff: snapshot/mac/process_types_test.cc

Issue 700383007: Use implicit_cast<> instead of static_cast<> whenever possible (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 1 month 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
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 "snapshot/mac/process_types.h" 15 #include "snapshot/mac/process_types.h"
16 16
17 #include <AvailabilityMacros.h> 17 #include <AvailabilityMacros.h>
18 #include <mach/mach.h> 18 #include <mach/mach.h>
19 #include <string.h> 19 #include <string.h>
20 20
21 #include <vector> 21 #include <vector>
22 22
23 #include "base/basictypes.h"
23 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
24 #include "gtest/gtest.h" 25 #include "gtest/gtest.h"
25 #include "util/mac/mac_util.h" 26 #include "util/mac/mac_util.h"
26 #include "util/test/mac/dyld.h" 27 #include "util/test/mac/dyld.h"
27 28
28 namespace crashpad { 29 namespace crashpad {
29 namespace test { 30 namespace test {
30 namespace { 31 namespace {
31 32
32 #define TEST_STRING(process_reader, self_view, proctype_view, field) \ 33 #define TEST_STRING(process_reader, self_view, proctype_view, field) \
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 115 }
115 if (proctype_image_infos.version >= 3) { 116 if (proctype_image_infos.version >= 3) {
116 EXPECT_EQ(reinterpret_cast<uint64_t>(self_image_infos->jitInfo), 117 EXPECT_EQ(reinterpret_cast<uint64_t>(self_image_infos->jitInfo),
117 proctype_image_infos.jitInfo); 118 proctype_image_infos.jitInfo);
118 } 119 }
119 if (proctype_image_infos.version >= 5) { 120 if (proctype_image_infos.version >= 5) {
120 EXPECT_EQ(reinterpret_cast<uint64_t>(self_image_infos->dyldVersion), 121 EXPECT_EQ(reinterpret_cast<uint64_t>(self_image_infos->dyldVersion),
121 proctype_image_infos.dyldVersion); 122 proctype_image_infos.dyldVersion);
122 EXPECT_EQ(reinterpret_cast<uint64_t>(self_image_infos->errorMessage), 123 EXPECT_EQ(reinterpret_cast<uint64_t>(self_image_infos->errorMessage),
123 proctype_image_infos.errorMessage); 124 proctype_image_infos.errorMessage);
124 EXPECT_EQ(static_cast<uint64_t>(self_image_infos->terminationFlags), 125 EXPECT_EQ(implicit_cast<uint64_t>(self_image_infos->terminationFlags),
125 proctype_image_infos.terminationFlags); 126 proctype_image_infos.terminationFlags);
126 127
127 TEST_STRING( 128 TEST_STRING(
128 process_reader, self_image_infos, proctype_image_infos, dyldVersion); 129 process_reader, self_image_infos, proctype_image_infos, dyldVersion);
129 TEST_STRING( 130 TEST_STRING(
130 process_reader, self_image_infos, proctype_image_infos, errorMessage); 131 process_reader, self_image_infos, proctype_image_infos, errorMessage);
131 } 132 }
132 if (proctype_image_infos.version >= 6) { 133 if (proctype_image_infos.version >= 6) {
133 EXPECT_EQ( 134 EXPECT_EQ(
134 reinterpret_cast<uint64_t>(self_image_infos->coreSymbolicationShmPage), 135 reinterpret_cast<uint64_t>(self_image_infos->coreSymbolicationShmPage),
135 proctype_image_infos.coreSymbolicationShmPage); 136 proctype_image_infos.coreSymbolicationShmPage);
136 } 137 }
137 if (proctype_image_infos.version >= 7) { 138 if (proctype_image_infos.version >= 7) {
138 EXPECT_EQ(static_cast<uint64_t>(self_image_infos->systemOrderFlag), 139 EXPECT_EQ(implicit_cast<uint64_t>(self_image_infos->systemOrderFlag),
139 proctype_image_infos.systemOrderFlag); 140 proctype_image_infos.systemOrderFlag);
140 } 141 }
141 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 142 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
142 if (proctype_image_infos.version >= 8) { 143 if (proctype_image_infos.version >= 8) {
143 EXPECT_EQ(static_cast<uint64_t>(self_image_infos->uuidArrayCount), 144 EXPECT_EQ(implicit_cast<uint64_t>(self_image_infos->uuidArrayCount),
144 proctype_image_infos.uuidArrayCount); 145 proctype_image_infos.uuidArrayCount);
145 } 146 }
146 if (proctype_image_infos.version >= 9) { 147 if (proctype_image_infos.version >= 9) {
147 EXPECT_EQ( 148 EXPECT_EQ(
148 reinterpret_cast<uint64_t>(self_image_infos->dyldAllImageInfosAddress), 149 reinterpret_cast<uint64_t>(self_image_infos->dyldAllImageInfosAddress),
149 proctype_image_infos.dyldAllImageInfosAddress); 150 proctype_image_infos.dyldAllImageInfosAddress);
150 } 151 }
151 if (proctype_image_infos.version >= 10) { 152 if (proctype_image_infos.version >= 10) {
152 EXPECT_EQ(static_cast<uint64_t>(self_image_infos->initialImageCount), 153 EXPECT_EQ(implicit_cast<uint64_t>(self_image_infos->initialImageCount),
153 proctype_image_infos.initialImageCount); 154 proctype_image_infos.initialImageCount);
154 } 155 }
155 if (proctype_image_infos.version >= 11) { 156 if (proctype_image_infos.version >= 11) {
156 EXPECT_EQ(static_cast<uint64_t>(self_image_infos->errorKind), 157 EXPECT_EQ(implicit_cast<uint64_t>(self_image_infos->errorKind),
157 proctype_image_infos.errorKind); 158 proctype_image_infos.errorKind);
158 EXPECT_EQ( 159 EXPECT_EQ(
159 reinterpret_cast<uint64_t>(self_image_infos->errorClientOfDylibPath), 160 reinterpret_cast<uint64_t>(self_image_infos->errorClientOfDylibPath),
160 proctype_image_infos.errorClientOfDylibPath); 161 proctype_image_infos.errorClientOfDylibPath);
161 EXPECT_EQ( 162 EXPECT_EQ(
162 reinterpret_cast<uint64_t>(self_image_infos->errorTargetDylibPath), 163 reinterpret_cast<uint64_t>(self_image_infos->errorTargetDylibPath),
163 proctype_image_infos.errorTargetDylibPath); 164 proctype_image_infos.errorTargetDylibPath);
164 EXPECT_EQ(reinterpret_cast<uint64_t>(self_image_infos->errorSymbol), 165 EXPECT_EQ(reinterpret_cast<uint64_t>(self_image_infos->errorSymbol),
165 proctype_image_infos.errorSymbol); 166 proctype_image_infos.errorSymbol);
166 167
167 TEST_STRING(process_reader, 168 TEST_STRING(process_reader,
168 self_image_infos, 169 self_image_infos,
169 proctype_image_infos, 170 proctype_image_infos,
170 errorClientOfDylibPath); 171 errorClientOfDylibPath);
171 TEST_STRING(process_reader, 172 TEST_STRING(process_reader,
172 self_image_infos, 173 self_image_infos,
173 proctype_image_infos, 174 proctype_image_infos,
174 errorTargetDylibPath); 175 errorTargetDylibPath);
175 TEST_STRING( 176 TEST_STRING(
176 process_reader, self_image_infos, proctype_image_infos, errorSymbol); 177 process_reader, self_image_infos, proctype_image_infos, errorSymbol);
177 } 178 }
178 if (proctype_image_infos.version >= 12) { 179 if (proctype_image_infos.version >= 12) {
179 EXPECT_EQ(static_cast<uint64_t>(self_image_infos->sharedCacheSlide), 180 EXPECT_EQ(implicit_cast<uint64_t>(self_image_infos->sharedCacheSlide),
180 proctype_image_infos.sharedCacheSlide); 181 proctype_image_infos.sharedCacheSlide);
181 } 182 }
182 #endif 183 #endif
183 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9 184 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9
184 if (proctype_image_infos.version >= 13) { 185 if (proctype_image_infos.version >= 13) {
185 EXPECT_EQ(0, 186 EXPECT_EQ(0,
186 memcmp(self_image_infos->sharedCacheUUID, 187 memcmp(self_image_infos->sharedCacheUUID,
187 proctype_image_infos.sharedCacheUUID, 188 proctype_image_infos.sharedCacheUUID,
188 sizeof(self_image_infos->sharedCacheUUID))); 189 sizeof(self_image_infos->sharedCacheUUID)));
189 } 190 }
190 if (proctype_image_infos.version >= 14) { 191 if (proctype_image_infos.version >= 14) {
191 for (size_t index = 0; index < arraysize(self_image_infos->reserved); 192 for (size_t index = 0; index < arraysize(self_image_infos->reserved);
192 ++index) { 193 ++index) {
193 EXPECT_EQ(static_cast<uint64_t>(self_image_infos->reserved[index]), 194 EXPECT_EQ(implicit_cast<uint64_t>(self_image_infos->reserved[index]),
194 proctype_image_infos.reserved[index]) 195 proctype_image_infos.reserved[index])
195 << "index " << index; 196 << "index " << index;
196 } 197 }
197 } 198 }
198 #endif 199 #endif
199 200
200 if (proctype_image_infos.version >= 1) { 201 if (proctype_image_infos.version >= 1) {
201 std::vector<process_types::dyld_image_info> proctype_image_info_vector( 202 std::vector<process_types::dyld_image_info> proctype_image_info_vector(
202 proctype_image_infos.infoArrayCount); 203 proctype_image_infos.infoArrayCount);
203 ASSERT_TRUE(process_types::dyld_image_info::ReadArrayInto( 204 ASSERT_TRUE(process_types::dyld_image_info::ReadArrayInto(
204 &process_reader, 205 &process_reader,
205 proctype_image_infos.infoArray, 206 proctype_image_infos.infoArray,
206 proctype_image_info_vector.size(), 207 proctype_image_info_vector.size(),
207 &proctype_image_info_vector[0])); 208 &proctype_image_info_vector[0]));
208 209
209 for (size_t index = 0; index < proctype_image_infos.infoArrayCount; 210 for (size_t index = 0; index < proctype_image_infos.infoArrayCount;
210 ++index) { 211 ++index) {
211 const dyld_image_info* self_image_info = 212 const dyld_image_info* self_image_info =
212 &self_image_infos->infoArray[index]; 213 &self_image_infos->infoArray[index];
213 const process_types::dyld_image_info& proctype_image_info = 214 const process_types::dyld_image_info& proctype_image_info =
214 proctype_image_info_vector[index]; 215 proctype_image_info_vector[index];
215 216
216 EXPECT_EQ(reinterpret_cast<uint64_t>(self_image_info->imageLoadAddress), 217 EXPECT_EQ(reinterpret_cast<uint64_t>(self_image_info->imageLoadAddress),
217 proctype_image_info.imageLoadAddress) 218 proctype_image_info.imageLoadAddress)
218 << "index " << index; 219 << "index " << index;
219 EXPECT_EQ(reinterpret_cast<uint64_t>(self_image_info->imageFilePath), 220 EXPECT_EQ(reinterpret_cast<uint64_t>(self_image_info->imageFilePath),
220 proctype_image_info.imageFilePath) 221 proctype_image_info.imageFilePath)
221 << "index " << index; 222 << "index " << index;
222 EXPECT_EQ(static_cast<uint64_t>(self_image_info->imageFileModDate), 223 EXPECT_EQ(implicit_cast<uint64_t>(self_image_info->imageFileModDate),
223 proctype_image_info.imageFileModDate) 224 proctype_image_info.imageFileModDate)
224 << "index " << index; 225 << "index " << index;
225 226
226 TEST_STRING( 227 TEST_STRING(
227 process_reader, self_image_info, proctype_image_info, imageFilePath); 228 process_reader, self_image_info, proctype_image_info, imageFilePath);
228 } 229 }
229 } 230 }
230 231
231 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 232 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
232 if (proctype_image_infos.version >= 8) { 233 if (proctype_image_infos.version >= 8) {
(...skipping 21 matching lines...) Expand all
254 sizeof(self_uuid_info->imageUUID))) 255 sizeof(self_uuid_info->imageUUID)))
255 << "index " << index; 256 << "index " << index;
256 } 257 }
257 } 258 }
258 #endif 259 #endif
259 } 260 }
260 261
261 } // namespace 262 } // namespace
262 } // namespace test 263 } // namespace test
263 } // namespace crashpad 264 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698