| 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 "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 Waiter waiter; | 284 Waiter waiter; |
| 285 HandleSignalsState hss; | 285 HandleSignalsState hss; |
| 286 uint32_t context = 0; | 286 uint32_t context = 0; |
| 287 | 287 |
| 288 scoped_refptr<DataPipe> dp(CreateLocal(sizeof(int32_t), 1000)); | 288 scoped_refptr<DataPipe> dp(CreateLocal(sizeof(int32_t), 1000)); |
| 289 // This is the consumer dispatcher we'll send. | 289 // This is the consumer dispatcher we'll send. |
| 290 scoped_refptr<DataPipeConsumerDispatcher> consumer = | 290 scoped_refptr<DataPipeConsumerDispatcher> consumer = |
| 291 DataPipeConsumerDispatcher::Create(); | 291 DataPipeConsumerDispatcher::Create(); |
| 292 consumer->Init(dp); | 292 consumer->Init(dp); |
| 293 | 293 |
| 294 uint32_t num_bytes = static_cast<uint32_t>(10u * sizeof(int32_t)); | |
| 295 void* write_ptr = nullptr; | 294 void* write_ptr = nullptr; |
| 295 uint32_t num_bytes = 0u; |
| 296 EXPECT_EQ(MOJO_RESULT_OK, | 296 EXPECT_EQ(MOJO_RESULT_OK, |
| 297 dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr), | 297 dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr), |
| 298 MakeUserPointer(&num_bytes), false)); | 298 MakeUserPointer(&num_bytes))); |
| 299 ASSERT_GE(num_bytes, 1u * sizeof(int32_t)); | 299 ASSERT_GE(num_bytes, 1u * sizeof(int32_t)); |
| 300 | 300 |
| 301 // Write the consumer to MP 0 (port 0). Wait and receive on MP 1 (port 0). | 301 // Write the consumer to MP 0 (port 0). Wait and receive on MP 1 (port 0). |
| 302 // (Add the waiter first, to avoid any handling the case where it's already | 302 // (Add the waiter first, to avoid any handling the case where it's already |
| 303 // readable.) | 303 // readable.) |
| 304 waiter.Init(); | 304 waiter.Init(); |
| 305 ASSERT_EQ(MOJO_RESULT_OK, | 305 ASSERT_EQ(MOJO_RESULT_OK, |
| 306 message_pipe(1)->AddAwakable( | 306 message_pipe(1)->AddAwakable( |
| 307 0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 307 0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
| 308 { | 308 { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 Waiter waiter; | 394 Waiter waiter; |
| 395 HandleSignalsState hss; | 395 HandleSignalsState hss; |
| 396 uint32_t context = 0; | 396 uint32_t context = 0; |
| 397 | 397 |
| 398 scoped_refptr<DataPipe> dp(CreateLocal(sizeof(int32_t), 1000)); | 398 scoped_refptr<DataPipe> dp(CreateLocal(sizeof(int32_t), 1000)); |
| 399 // This is the consumer dispatcher we'll send. | 399 // This is the consumer dispatcher we'll send. |
| 400 scoped_refptr<DataPipeConsumerDispatcher> consumer = | 400 scoped_refptr<DataPipeConsumerDispatcher> consumer = |
| 401 DataPipeConsumerDispatcher::Create(); | 401 DataPipeConsumerDispatcher::Create(); |
| 402 consumer->Init(dp); | 402 consumer->Init(dp); |
| 403 | 403 |
| 404 uint32_t num_bytes = static_cast<uint32_t>(10u * sizeof(int32_t)); | |
| 405 void* write_ptr = nullptr; | 404 void* write_ptr = nullptr; |
| 405 uint32_t num_bytes = 0u; |
| 406 EXPECT_EQ(MOJO_RESULT_OK, | 406 EXPECT_EQ(MOJO_RESULT_OK, |
| 407 dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr), | 407 dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr), |
| 408 MakeUserPointer(&num_bytes), false)); | 408 MakeUserPointer(&num_bytes))); |
| 409 ASSERT_GE(num_bytes, 1u * sizeof(int32_t)); | 409 ASSERT_GE(num_bytes, 1u * sizeof(int32_t)); |
| 410 *static_cast<int32_t*>(write_ptr) = 123456; | 410 *static_cast<int32_t*>(write_ptr) = 123456; |
| 411 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerEndWriteData( | 411 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerEndWriteData( |
| 412 static_cast<uint32_t>(1u * sizeof(int32_t)))); | 412 static_cast<uint32_t>(1u * sizeof(int32_t)))); |
| 413 | 413 |
| 414 num_bytes = static_cast<uint32_t>(10u * sizeof(int32_t)); | |
| 415 write_ptr = nullptr; | 414 write_ptr = nullptr; |
| 415 num_bytes = 0u; |
| 416 EXPECT_EQ(MOJO_RESULT_OK, | 416 EXPECT_EQ(MOJO_RESULT_OK, |
| 417 dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr), | 417 dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr), |
| 418 MakeUserPointer(&num_bytes), false)); | 418 MakeUserPointer(&num_bytes))); |
| 419 ASSERT_GE(num_bytes, 1u * sizeof(int32_t)); | 419 ASSERT_GE(num_bytes, 1u * sizeof(int32_t)); |
| 420 | 420 |
| 421 // Write the consumer to MP 0 (port 0). Wait and receive on MP 1 (port 0). | 421 // Write the consumer to MP 0 (port 0). Wait and receive on MP 1 (port 0). |
| 422 // (Add the waiter first, to avoid any handling the case where it's already | 422 // (Add the waiter first, to avoid any handling the case where it's already |
| 423 // readable.) | 423 // readable.) |
| 424 waiter.Init(); | 424 waiter.Init(); |
| 425 ASSERT_EQ(MOJO_RESULT_OK, | 425 ASSERT_EQ(MOJO_RESULT_OK, |
| 426 message_pipe(1)->AddAwakable( | 426 message_pipe(1)->AddAwakable( |
| 427 0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 427 0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
| 428 { | 428 { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 EXPECT_EQ(123456, elements[0]); | 501 EXPECT_EQ(123456, elements[0]); |
| 502 EXPECT_EQ(789012, elements[1]); | 502 EXPECT_EQ(789012, elements[1]); |
| 503 EXPECT_EQ(0, elements[2]); | 503 EXPECT_EQ(0, elements[2]); |
| 504 | 504 |
| 505 consumer->Close(); | 505 consumer->Close(); |
| 506 } | 506 } |
| 507 | 507 |
| 508 } // namespace | 508 } // namespace |
| 509 } // namespace system | 509 } // namespace system |
| 510 } // namespace mojo | 510 } // namespace mojo |
| OLD | NEW |