OLD | NEW |
(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 "util/mach/mach_message_util.h" |
| 16 |
| 17 #include "base/basictypes.h" |
| 18 #include "gtest/gtest.h" |
| 19 #include "util/mach/mach_extensions.h" |
| 20 |
| 21 namespace crashpad { |
| 22 namespace test { |
| 23 namespace { |
| 24 |
| 25 TEST(MachMessageUtil, PrepareMIGReplyFromRequest_SetMIGReplyError) { |
| 26 mach_msg_header_t request; |
| 27 request.msgh_bits = |
| 28 MACH_MSGH_BITS_COMPLEX | |
| 29 MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, MACH_MSG_TYPE_PORT_SEND); |
| 30 request.msgh_size = 64; |
| 31 request.msgh_remote_port = 0x01234567; |
| 32 request.msgh_local_port = 0x89abcdef; |
| 33 request.msgh_reserved = 0xa5a5a5a5; |
| 34 request.msgh_id = 1011; |
| 35 |
| 36 mig_reply_error_t reply; |
| 37 |
| 38 // PrepareMIGReplyFromRequest() doesn’t touch this field. |
| 39 reply.RetCode = MIG_TYPE_ERROR; |
| 40 |
| 41 PrepareMIGReplyFromRequest(&request, &reply.Head); |
| 42 |
| 43 EXPECT_EQ(implicit_cast<mach_msg_bits_t>( |
| 44 MACH_MSGH_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE, 0)), |
| 45 reply.Head.msgh_bits); |
| 46 EXPECT_EQ(sizeof(reply), reply.Head.msgh_size); |
| 47 EXPECT_EQ(request.msgh_remote_port, reply.Head.msgh_remote_port); |
| 48 EXPECT_EQ(kMachPortNull, reply.Head.msgh_local_port); |
| 49 EXPECT_EQ(0u, reply.Head.msgh_reserved); |
| 50 EXPECT_EQ(1111, reply.Head.msgh_id); |
| 51 EXPECT_EQ(NDR_record.mig_vers, reply.NDR.mig_vers); |
| 52 EXPECT_EQ(NDR_record.if_vers, reply.NDR.if_vers); |
| 53 EXPECT_EQ(NDR_record.reserved1, reply.NDR.reserved1); |
| 54 EXPECT_EQ(NDR_record.mig_encoding, reply.NDR.mig_encoding); |
| 55 EXPECT_EQ(NDR_record.int_rep, reply.NDR.int_rep); |
| 56 EXPECT_EQ(NDR_record.char_rep, reply.NDR.char_rep); |
| 57 EXPECT_EQ(NDR_record.float_rep, reply.NDR.float_rep); |
| 58 EXPECT_EQ(NDR_record.reserved2, reply.NDR.reserved2); |
| 59 EXPECT_EQ(MIG_TYPE_ERROR, reply.RetCode); |
| 60 |
| 61 SetMIGReplyError(&reply.Head, MIG_BAD_ID); |
| 62 |
| 63 EXPECT_EQ(MIG_BAD_ID, reply.RetCode); |
| 64 } |
| 65 |
| 66 } // namespace |
| 67 } // namespace test |
| 68 } // namespace crashpad |
OLD | NEW |