| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ipc/ipc_message_utils.h" | 5 #include "ipc/ipc_message_utils.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 EXPECT_TRUE(IPC::ReadParam(&message, &iter, &result_handle)); | 151 EXPECT_TRUE(IPC::ReadParam(&message, &iter, &result_handle)); |
| 152 EXPECT_TRUE(result_handle.name.empty()); | 152 EXPECT_TRUE(result_handle.name.empty()); |
| 153 #if defined(OS_POSIX) | 153 #if defined(OS_POSIX) |
| 154 EXPECT_EQ(-1, result_handle.socket.fd); | 154 EXPECT_EQ(-1, result_handle.socket.fd); |
| 155 #elif defined(OS_WIN) | 155 #elif defined(OS_WIN) |
| 156 EXPECT_EQ(nullptr, result_handle.pipe.handle); | 156 EXPECT_EQ(nullptr, result_handle.pipe.handle); |
| 157 #endif | 157 #endif |
| 158 EXPECT_EQ(channel_handle.mojo_handle, result_handle.mojo_handle); | 158 EXPECT_EQ(channel_handle.mojo_handle, result_handle.mojo_handle); |
| 159 } | 159 } |
| 160 | 160 |
| 161 TEST(IPCMessageUtilsTest, OptionalUnset) { |
| 162 base::Optional<int> opt; |
| 163 base::Pickle pickle; |
| 164 IPC::WriteParam(&pickle, opt); |
| 165 |
| 166 base::PickleSizer sizer; |
| 167 IPC::GetParamSize(&sizer, opt); |
| 168 |
| 169 EXPECT_EQ(sizer.payload_size(), pickle.payload_size()); |
| 170 |
| 171 std::string log; |
| 172 IPC::LogParam(opt, &log); |
| 173 EXPECT_EQ("(unset)", log); |
| 174 |
| 175 base::Optional<int> unserialized_opt; |
| 176 base::PickleIterator iter(pickle); |
| 177 EXPECT_TRUE(IPC::ReadParam(&pickle, &iter, &unserialized_opt)); |
| 178 EXPECT_FALSE(unserialized_opt); |
| 179 } |
| 180 |
| 181 TEST(IPCMessageUtilsTest, OptionalSet) { |
| 182 base::Optional<int> opt(10); |
| 183 base::Pickle pickle; |
| 184 IPC::WriteParam(&pickle, opt); |
| 185 |
| 186 base::PickleSizer sizer; |
| 187 IPC::GetParamSize(&sizer, opt); |
| 188 |
| 189 EXPECT_EQ(sizer.payload_size(), pickle.payload_size()); |
| 190 |
| 191 std::string log; |
| 192 IPC::LogParam(opt, &log); |
| 193 EXPECT_EQ("10", log); |
| 194 |
| 195 base::Optional<int> unserialized_opt; |
| 196 base::PickleIterator iter(pickle); |
| 197 EXPECT_TRUE(IPC::ReadParam(&pickle, &iter, &unserialized_opt)); |
| 198 EXPECT_TRUE(unserialized_opt); |
| 199 EXPECT_EQ(opt.value(), unserialized_opt.value()); |
| 200 } |
| 201 |
| 161 } // namespace | 202 } // namespace |
| 162 } // namespace IPC | 203 } // namespace IPC |
| OLD | NEW |