OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stdint.h> | 5 #include <stdint.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
| 9 #include <memory> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
14 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
15 #include "base/location.h" | 16 #include "base/location.h" |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
18 #include "mojo/edk/embedder/platform_channel_pair.h" | 19 #include "mojo/edk/embedder/platform_channel_pair.h" |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 // receiving this message, |PassIncomingMessagePipe()| is used to obtain the | 331 // receiving this message, |PassIncomingMessagePipe()| is used to obtain the |
331 // message pipe on the other side. | 332 // message pipe on the other side. |
332 scoped_refptr<MessagePipe> mp2(MessagePipe::CreateLocalLocal()); | 333 scoped_refptr<MessagePipe> mp2(MessagePipe::CreateLocalLocal()); |
333 ASSERT_TRUE(channels(0)); | 334 ASSERT_TRUE(channels(0)); |
334 size_t max_endpoint_info_size; | 335 size_t max_endpoint_info_size; |
335 size_t max_platform_handle_count; | 336 size_t max_platform_handle_count; |
336 mp2->StartSerialize(1, channels(0), &max_endpoint_info_size, | 337 mp2->StartSerialize(1, channels(0), &max_endpoint_info_size, |
337 &max_platform_handle_count); | 338 &max_platform_handle_count); |
338 EXPECT_GT(max_endpoint_info_size, 0u); | 339 EXPECT_GT(max_endpoint_info_size, 0u); |
339 ASSERT_EQ(0u, max_platform_handle_count); | 340 ASSERT_EQ(0u, max_platform_handle_count); |
340 scoped_ptr<char[]> endpoint_info(new char[max_endpoint_info_size]); | 341 std::unique_ptr<char[]> endpoint_info(new char[max_endpoint_info_size]); |
341 size_t endpoint_info_size; | 342 size_t endpoint_info_size; |
342 mp2->EndSerialize(1, channels(0), endpoint_info.get(), &endpoint_info_size, | 343 mp2->EndSerialize(1, channels(0), endpoint_info.get(), &endpoint_info_size, |
343 nullptr); | 344 nullptr); |
344 EXPECT_EQ(max_endpoint_info_size, endpoint_info_size); | 345 EXPECT_EQ(max_endpoint_info_size, endpoint_info_size); |
345 | 346 |
346 waiter.Init(); | 347 waiter.Init(); |
347 ASSERT_EQ( | 348 ASSERT_EQ( |
348 MOJO_RESULT_OK, | 349 MOJO_RESULT_OK, |
349 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 350 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
350 | 351 |
351 EXPECT_EQ(MOJO_RESULT_OK, | 352 EXPECT_EQ(MOJO_RESULT_OK, |
352 mp0->WriteMessage(0, UserPointer<const void>(endpoint_info.get()), | 353 mp0->WriteMessage(0, UserPointer<const void>(endpoint_info.get()), |
353 static_cast<uint32_t>(endpoint_info_size), | 354 static_cast<uint32_t>(endpoint_info_size), |
354 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 355 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
355 | 356 |
356 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 357 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
357 EXPECT_EQ(123u, context); | 358 EXPECT_EQ(123u, context); |
358 hss = HandleSignalsState(); | 359 hss = HandleSignalsState(); |
359 mp1->RemoveAwakable(1, &waiter, &hss); | 360 mp1->RemoveAwakable(1, &waiter, &hss); |
360 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 361 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
361 hss.satisfied_signals); | 362 hss.satisfied_signals); |
362 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 363 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
363 | 364 |
364 EXPECT_EQ(endpoint_info_size, channels(1)->GetSerializedEndpointSize()); | 365 EXPECT_EQ(endpoint_info_size, channels(1)->GetSerializedEndpointSize()); |
365 scoped_ptr<char[]> received_endpoint_info(new char[endpoint_info_size]); | 366 std::unique_ptr<char[]> received_endpoint_info(new char[endpoint_info_size]); |
366 buffer_size = static_cast<uint32_t>(endpoint_info_size); | 367 buffer_size = static_cast<uint32_t>(endpoint_info_size); |
367 EXPECT_EQ(MOJO_RESULT_OK, | 368 EXPECT_EQ(MOJO_RESULT_OK, |
368 mp1->ReadMessage(1, UserPointer<void>(received_endpoint_info.get()), | 369 mp1->ReadMessage(1, UserPointer<void>(received_endpoint_info.get()), |
369 MakeUserPointer(&buffer_size), nullptr, nullptr, | 370 MakeUserPointer(&buffer_size), nullptr, nullptr, |
370 MOJO_READ_MESSAGE_FLAG_NONE)); | 371 MOJO_READ_MESSAGE_FLAG_NONE)); |
371 EXPECT_EQ(endpoint_info_size, static_cast<size_t>(buffer_size)); | 372 EXPECT_EQ(endpoint_info_size, static_cast<size_t>(buffer_size)); |
372 EXPECT_EQ(0, memcmp(received_endpoint_info.get(), endpoint_info.get(), | 373 EXPECT_EQ(0, memcmp(received_endpoint_info.get(), endpoint_info.get(), |
373 endpoint_info_size)); | 374 endpoint_info_size)); |
374 | 375 |
375 // Warning: The local side of mp3 is port 0, not port 1. | 376 // Warning: The local side of mp3 is port 0, not port 1. |
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 mp0->Close(0); | 1357 mp0->Close(0); |
1357 mp1->Close(1); | 1358 mp1->Close(1); |
1358 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 1359 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
1359 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. | 1360 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. |
1360 local_mp->Close(1); | 1361 local_mp->Close(1); |
1361 } | 1362 } |
1362 | 1363 |
1363 } // namespace | 1364 } // namespace |
1364 } // namespace system | 1365 } // namespace system |
1365 } // namespace mojo | 1366 } // namespace mojo |
OLD | NEW |