| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // This file tests both |RemoteProducerDataPipeImpl| and | 5 // This file tests both |RemoteProducerDataPipeImpl| and |
| 6 // |RemoteConsumerDataPipeImpl|. | 6 // |RemoteConsumerDataPipeImpl|. |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 &read_handles, &read_num_handles, | 227 &read_handles, &read_num_handles, |
| 228 MOJO_READ_MESSAGE_FLAG_NONE)); | 228 MOJO_READ_MESSAGE_FLAG_NONE)); |
| 229 EXPECT_EQ(0u, static_cast<size_t>(read_buffer_size)); | 229 EXPECT_EQ(0u, static_cast<size_t>(read_buffer_size)); |
| 230 EXPECT_EQ(1u, read_handles.size()); | 230 EXPECT_EQ(1u, read_handles.size()); |
| 231 EXPECT_EQ(1u, read_num_handles); | 231 EXPECT_EQ(1u, read_num_handles); |
| 232 ASSERT_TRUE(read_handles[0]); | 232 ASSERT_TRUE(read_handles[0]); |
| 233 EXPECT_TRUE(read_handles[0].dispatcher->HasOneRef()); | 233 EXPECT_TRUE(read_handles[0].dispatcher->HasOneRef()); |
| 234 | 234 |
| 235 EXPECT_EQ(Dispatcher::Type::DATA_PIPE_CONSUMER, | 235 EXPECT_EQ(Dispatcher::Type::DATA_PIPE_CONSUMER, |
| 236 read_handles[0].dispatcher->GetType()); | 236 read_handles[0].dispatcher->GetType()); |
| 237 // TODO(vtl): Also check the rights here once they're actually preserved? | 237 EXPECT_EQ(DataPipeConsumerDispatcher::kDefaultHandleRights, |
| 238 read_handles[0].rights); |
| 238 consumer = RefPtr<DataPipeConsumerDispatcher>( | 239 consumer = RefPtr<DataPipeConsumerDispatcher>( |
| 239 static_cast<DataPipeConsumerDispatcher*>( | 240 static_cast<DataPipeConsumerDispatcher*>( |
| 240 read_handles[0].dispatcher.get())); | 241 read_handles[0].dispatcher.get())); |
| 241 read_handles.clear(); | 242 read_handles.clear(); |
| 242 | 243 |
| 243 waiter.Init(); | 244 waiter.Init(); |
| 244 hss = HandleSignalsState(); | 245 hss = HandleSignalsState(); |
| 245 MojoResult result = | 246 MojoResult result = |
| 246 consumer->AddAwakable(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, &hss); | 247 consumer->AddAwakable(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, &hss); |
| 247 if (result == MOJO_RESULT_OK) { | 248 if (result == MOJO_RESULT_OK) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 &read_handles, &read_num_handles, | 350 &read_handles, &read_num_handles, |
| 350 MOJO_READ_MESSAGE_FLAG_NONE)); | 351 MOJO_READ_MESSAGE_FLAG_NONE)); |
| 351 EXPECT_EQ(0u, static_cast<size_t>(read_buffer_size)); | 352 EXPECT_EQ(0u, static_cast<size_t>(read_buffer_size)); |
| 352 EXPECT_EQ(1u, read_handles.size()); | 353 EXPECT_EQ(1u, read_handles.size()); |
| 353 EXPECT_EQ(1u, read_num_handles); | 354 EXPECT_EQ(1u, read_num_handles); |
| 354 ASSERT_TRUE(read_handles[0]); | 355 ASSERT_TRUE(read_handles[0]); |
| 355 EXPECT_TRUE(read_handles[0].dispatcher->HasOneRef()); | 356 EXPECT_TRUE(read_handles[0].dispatcher->HasOneRef()); |
| 356 | 357 |
| 357 EXPECT_EQ(Dispatcher::Type::DATA_PIPE_CONSUMER, | 358 EXPECT_EQ(Dispatcher::Type::DATA_PIPE_CONSUMER, |
| 358 read_handles[0].dispatcher->GetType()); | 359 read_handles[0].dispatcher->GetType()); |
| 359 // TODO(vtl): Also check the rights here once they're actually preserved? | 360 EXPECT_EQ(DataPipeConsumerDispatcher::kDefaultHandleRights, |
| 361 read_handles[0].rights); |
| 360 consumer = RefPtr<DataPipeConsumerDispatcher>( | 362 consumer = RefPtr<DataPipeConsumerDispatcher>( |
| 361 static_cast<DataPipeConsumerDispatcher*>( | 363 static_cast<DataPipeConsumerDispatcher*>( |
| 362 read_handles[0].dispatcher.get())); | 364 read_handles[0].dispatcher.get())); |
| 363 read_handles.clear(); | 365 read_handles.clear(); |
| 364 | 366 |
| 365 // Now actually write the data, complete the two-phase write, and close the | 367 // Now actually write the data, complete the two-phase write, and close the |
| 366 // producer. | 368 // producer. |
| 367 *static_cast<int32_t*>(write_ptr) = 123456; | 369 *static_cast<int32_t*>(write_ptr) = 123456; |
| 368 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerEndWriteData( | 370 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerEndWriteData( |
| 369 static_cast<uint32_t>(1u * sizeof(int32_t)))); | 371 static_cast<uint32_t>(1u * sizeof(int32_t)))); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 &read_handles, &read_num_handles, | 477 &read_handles, &read_num_handles, |
| 476 MOJO_READ_MESSAGE_FLAG_NONE)); | 478 MOJO_READ_MESSAGE_FLAG_NONE)); |
| 477 EXPECT_EQ(0u, static_cast<size_t>(read_buffer_size)); | 479 EXPECT_EQ(0u, static_cast<size_t>(read_buffer_size)); |
| 478 EXPECT_EQ(1u, read_handles.size()); | 480 EXPECT_EQ(1u, read_handles.size()); |
| 479 EXPECT_EQ(1u, read_num_handles); | 481 EXPECT_EQ(1u, read_num_handles); |
| 480 ASSERT_TRUE(read_handles[0]); | 482 ASSERT_TRUE(read_handles[0]); |
| 481 EXPECT_TRUE(read_handles[0].dispatcher->HasOneRef()); | 483 EXPECT_TRUE(read_handles[0].dispatcher->HasOneRef()); |
| 482 | 484 |
| 483 EXPECT_EQ(Dispatcher::Type::DATA_PIPE_CONSUMER, | 485 EXPECT_EQ(Dispatcher::Type::DATA_PIPE_CONSUMER, |
| 484 read_handles[0].dispatcher->GetType()); | 486 read_handles[0].dispatcher->GetType()); |
| 485 // TODO(vtl): Also check the rights here once they're actually preserved? | 487 EXPECT_EQ(DataPipeConsumerDispatcher::kDefaultHandleRights, |
| 488 read_handles[0].rights); |
| 486 consumer = RefPtr<DataPipeConsumerDispatcher>( | 489 consumer = RefPtr<DataPipeConsumerDispatcher>( |
| 487 static_cast<DataPipeConsumerDispatcher*>( | 490 static_cast<DataPipeConsumerDispatcher*>( |
| 488 read_handles[0].dispatcher.get())); | 491 read_handles[0].dispatcher.get())); |
| 489 read_handles.clear(); | 492 read_handles.clear(); |
| 490 | 493 |
| 491 // Now actually write the data, complete the two-phase write, and close the | 494 // Now actually write the data, complete the two-phase write, and close the |
| 492 // producer. | 495 // producer. |
| 493 *static_cast<int32_t*>(write_ptr) = 789012; | 496 *static_cast<int32_t*>(write_ptr) = 789012; |
| 494 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerEndWriteData( | 497 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerEndWriteData( |
| 495 static_cast<uint32_t>(1u * sizeof(int32_t)))); | 498 static_cast<uint32_t>(1u * sizeof(int32_t)))); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 525 EXPECT_EQ(123456, elements[0]); | 528 EXPECT_EQ(123456, elements[0]); |
| 526 EXPECT_EQ(789012, elements[1]); | 529 EXPECT_EQ(789012, elements[1]); |
| 527 EXPECT_EQ(0, elements[2]); | 530 EXPECT_EQ(0, elements[2]); |
| 528 | 531 |
| 529 consumer->Close(); | 532 consumer->Close(); |
| 530 } | 533 } |
| 531 | 534 |
| 532 } // namespace | 535 } // namespace |
| 533 } // namespace system | 536 } // namespace system |
| 534 } // namespace mojo | 537 } // namespace mojo |
| OLD | NEW |