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

Side by Side Diff: util/mach/mach_message_server_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,
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 request->header.msgh_size); 217 request->header.msgh_size);
218 if (options_.client_reply_port_type == Options::kReplyPortNormal) { 218 if (options_.client_reply_port_type == Options::kReplyPortNormal) {
219 EXPECT_EQ(RemotePort(), request->header.msgh_remote_port); 219 EXPECT_EQ(RemotePort(), request->header.msgh_remote_port);
220 } 220 }
221 EXPECT_EQ(LocalPort(), request->header.msgh_local_port); 221 EXPECT_EQ(LocalPort(), request->header.msgh_local_port);
222 EXPECT_EQ(kRequestMessageId, request->header.msgh_id); 222 EXPECT_EQ(kRequestMessageId, request->header.msgh_id);
223 if (options_.client_send_complex) { 223 if (options_.client_send_complex) {
224 EXPECT_EQ(1u, request->body.msgh_descriptor_count); 224 EXPECT_EQ(1u, request->body.msgh_descriptor_count);
225 EXPECT_NE(kMachPortNull, request->port_descriptor.name); 225 EXPECT_NE(kMachPortNull, request->port_descriptor.name);
226 parent_complex_message_port_ = request->port_descriptor.name; 226 parent_complex_message_port_ = request->port_descriptor.name;
227 EXPECT_EQ(static_cast<mach_msg_type_name_t>(MACH_MSG_TYPE_MOVE_SEND), 227 EXPECT_EQ(implicit_cast<mach_msg_type_name_t>(MACH_MSG_TYPE_MOVE_SEND),
228 request->port_descriptor.disposition); 228 request->port_descriptor.disposition);
229 EXPECT_EQ( 229 EXPECT_EQ(
230 static_cast<mach_msg_descriptor_type_t>(MACH_MSG_PORT_DESCRIPTOR), 230 implicit_cast<mach_msg_descriptor_type_t>(MACH_MSG_PORT_DESCRIPTOR),
231 request->port_descriptor.type); 231 request->port_descriptor.type);
232 } else { 232 } else {
233 EXPECT_EQ(0u, request->body.msgh_descriptor_count); 233 EXPECT_EQ(0u, request->body.msgh_descriptor_count);
234 EXPECT_EQ(kMachPortNull, request->port_descriptor.name); 234 EXPECT_EQ(kMachPortNull, request->port_descriptor.name);
235 EXPECT_EQ(0u, request->port_descriptor.disposition); 235 EXPECT_EQ(0u, request->port_descriptor.disposition);
236 EXPECT_EQ(0u, request->port_descriptor.type); 236 EXPECT_EQ(0u, request->port_descriptor.type);
237 } 237 }
238 EXPECT_EQ(0, memcmp(&request->ndr, &NDR_record, sizeof(NDR_record))); 238 EXPECT_EQ(0, memcmp(&request->ndr, &NDR_record, sizeof(NDR_record)));
239 EXPECT_EQ(requests_, request->number); 239 EXPECT_EQ(requests_, request->number);
240 240
241 // Look for the trailer in the right spot, depending on whether the request 241 // Look for the trailer in the right spot, depending on whether the request
242 // message was a RequestMessage or a LargeRequestMessage. 242 // message was a RequestMessage or a LargeRequestMessage.
243 const mach_msg_trailer_t* trailer; 243 const mach_msg_trailer_t* trailer;
244 if (options_.client_send_large) { 244 if (options_.client_send_large) {
245 const ReceiveLargeRequestMessage* large_request = 245 const ReceiveLargeRequestMessage* large_request =
246 reinterpret_cast<const ReceiveLargeRequestMessage*>(request); 246 reinterpret_cast<const ReceiveLargeRequestMessage*>(request);
247 for (size_t index = 0; index < sizeof(large_request->data); ++index) { 247 for (size_t index = 0; index < sizeof(large_request->data); ++index) {
248 EXPECT_EQ('!', large_request->data[index]); 248 EXPECT_EQ('!', large_request->data[index]);
249 } 249 }
250 trailer = &large_request->trailer; 250 trailer = &large_request->trailer;
251 } else { 251 } else {
252 trailer = &request->trailer; 252 trailer = &request->trailer;
253 } 253 }
254 254
255 EXPECT_EQ(static_cast<mach_msg_trailer_type_t>(MACH_MSG_TRAILER_FORMAT_0), 255 EXPECT_EQ(implicit_cast<mach_msg_trailer_type_t>(MACH_MSG_TRAILER_FORMAT_0),
256 trailer->msgh_trailer_type); 256 trailer->msgh_trailer_type);
257 EXPECT_EQ(MACH_MSG_TRAILER_MINIMUM_SIZE, trailer->msgh_trailer_size); 257 EXPECT_EQ(MACH_MSG_TRAILER_MINIMUM_SIZE, trailer->msgh_trailer_size);
258 258
259 ++requests_; 259 ++requests_;
260 260
261 ReplyMessage* reply = reinterpret_cast<ReplyMessage*>(out); 261 ReplyMessage* reply = reinterpret_cast<ReplyMessage*>(out);
262 reply->Head.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0); 262 reply->Head.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0);
263 reply->Head.msgh_size = sizeof(*reply); 263 reply->Head.msgh_size = sizeof(*reply);
264 reply->Head.msgh_remote_port = request->header.msgh_remote_port; 264 reply->Head.msgh_remote_port = request->header.msgh_remote_port;
265 reply->Head.msgh_local_port = MACH_PORT_NULL; 265 reply->Head.msgh_local_port = MACH_PORT_NULL;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 ReceiveReplyMessage reply = {}; 518 ReceiveReplyMessage reply = {};
519 kern_return_t kr = mach_msg(&reply.Head, 519 kern_return_t kr = mach_msg(&reply.Head,
520 MACH_RCV_MSG, 520 MACH_RCV_MSG,
521 0, 521 0,
522 sizeof(reply), 522 sizeof(reply),
523 LocalPort(), 523 LocalPort(),
524 MACH_MSG_TIMEOUT_NONE, 524 MACH_MSG_TIMEOUT_NONE,
525 MACH_PORT_NULL); 525 MACH_PORT_NULL);
526 ASSERT_EQ(MACH_MSG_SUCCESS, kr) << MachErrorMessage(kr, "mach_msg"); 526 ASSERT_EQ(MACH_MSG_SUCCESS, kr) << MachErrorMessage(kr, "mach_msg");
527 527
528 ASSERT_EQ(static_cast<mach_msg_bits_t>( 528 ASSERT_EQ(implicit_cast<mach_msg_bits_t>(
529 MACH_MSGH_BITS(0, MACH_MSG_TYPE_MOVE_SEND)), reply.Head.msgh_bits); 529 MACH_MSGH_BITS(0, MACH_MSG_TYPE_MOVE_SEND)), reply.Head.msgh_bits);
530 ASSERT_EQ(sizeof(ReplyMessage), reply.Head.msgh_size); 530 ASSERT_EQ(sizeof(ReplyMessage), reply.Head.msgh_size);
531 ASSERT_EQ(kMachPortNull, reply.Head.msgh_remote_port); 531 ASSERT_EQ(kMachPortNull, reply.Head.msgh_remote_port);
532 ASSERT_EQ(LocalPort(), reply.Head.msgh_local_port); 532 ASSERT_EQ(LocalPort(), reply.Head.msgh_local_port);
533 ASSERT_EQ(kReplyMessageId, reply.Head.msgh_id); 533 ASSERT_EQ(kReplyMessageId, reply.Head.msgh_id);
534 ASSERT_EQ(0, memcmp(&reply.NDR, &NDR_record, sizeof(NDR_record))); 534 ASSERT_EQ(0, memcmp(&reply.NDR, &NDR_record, sizeof(NDR_record)));
535 ASSERT_EQ(options_.server_mig_retcode, reply.RetCode); 535 ASSERT_EQ(options_.server_mig_retcode, reply.RetCode);
536 ASSERT_EQ(replies_, reply.number); 536 ASSERT_EQ(replies_, reply.number);
537 ASSERT_EQ(static_cast<mach_msg_trailer_type_t>(MACH_MSG_TRAILER_FORMAT_0), 537 ASSERT_EQ(implicit_cast<mach_msg_trailer_type_t>(MACH_MSG_TRAILER_FORMAT_0),
538 reply.trailer.msgh_trailer_type); 538 reply.trailer.msgh_trailer_type);
539 ASSERT_EQ(MACH_MSG_TRAILER_MINIMUM_SIZE, reply.trailer.msgh_trailer_size); 539 ASSERT_EQ(MACH_MSG_TRAILER_MINIMUM_SIZE, reply.trailer.msgh_trailer_size);
540 540
541 ++replies_; 541 ++replies_;
542 } 542 }
543 543
544 // For test types where the child needs to notify the server in the parent 544 // For test types where the child needs to notify the server in the parent
545 // that the child is ready, this method will send a byte via the POSIX pipe. 545 // that the child is ready, this method will send a byte via the POSIX pipe.
546 // The parent will be waiting in a read() on this pipe, and will proceed to 546 // The parent will be waiting in a read() on this pipe, and will proceed to
547 // running MachMessageServer() once it’s received. 547 // running MachMessageServer() once it’s received.
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 TestMachMessageServer::Options options; 824 TestMachMessageServer::Options options;
825 options.server_options = MACH_RCV_LARGE; 825 options.server_options = MACH_RCV_LARGE;
826 options.client_send_large = true; 826 options.client_send_large = true;
827 TestMachMessageServer test_mach_message_server(options); 827 TestMachMessageServer test_mach_message_server(options);
828 test_mach_message_server.Test(); 828 test_mach_message_server.Test();
829 } 829 }
830 830
831 } // namespace 831 } // namespace
832 } // namespace test 832 } // namespace test
833 } // namespace crashpad 833 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698