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 // This file tests the C++ Mojo system core wrappers. | 5 // This file tests the C++ Mojo system core wrappers. |
6 // TODO(vtl): Maybe rename "CoreCppTest" -> "CoreTest" if/when this gets | 6 // TODO(vtl): Maybe rename "CoreCppTest" -> "CoreTest" if/when this gets |
7 // compiled into a different binary from the C API tests. | 7 // compiled into a different binary from the C API tests. |
8 | 8 |
9 #include "mojo/public/cpp/system/core.h" | 9 #include "mojo/public/cpp/system/core.h" |
10 | 10 |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 // Tear down a message pipe which still has a message enqueued, with the | 358 // Tear down a message pipe which still has a message enqueued, with the |
359 // message also having a valid message pipe handle. | 359 // message also having a valid message pipe handle. |
360 { | 360 { |
361 ScopedMessagePipeHandle h0; | 361 ScopedMessagePipeHandle h0; |
362 ScopedMessagePipeHandle h1; | 362 ScopedMessagePipeHandle h1; |
363 CreateMessagePipe(nullptr, &h0, &h1); | 363 CreateMessagePipe(nullptr, &h0, &h1); |
364 | 364 |
365 // Send a handle over the previously-establish message pipe. | 365 // Send a handle over the previously-establish message pipe. |
366 ScopedMessagePipeHandle h2; | 366 ScopedMessagePipeHandle h2; |
367 ScopedMessagePipeHandle h3; | 367 ScopedMessagePipeHandle h3; |
368 MojoCreateMessagePipeOptions options; | 368 if (CreateMessagePipe(nullptr, &h2, &h3) != MOJO_RESULT_OK) |
369 options.struct_size = sizeof(MojoCreateMessagePipeOptions); | |
370 options.flags = MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_TRANSFERABLE; | |
371 if (CreateMessagePipe(&options, &h2, &h3) != MOJO_RESULT_OK) | |
372 CreateMessagePipe(nullptr, &h2, &h3); // Must be old EDK. | 369 CreateMessagePipe(nullptr, &h2, &h3); // Must be old EDK. |
373 | 370 |
374 // Write a message to |h2|, before we send |h3|. | 371 // Write a message to |h2|, before we send |h3|. |
375 const char kWorld[] = "world!"; | 372 const char kWorld[] = "world!"; |
376 const uint32_t kWorldSize = static_cast<uint32_t>(sizeof(kWorld)); | 373 const uint32_t kWorldSize = static_cast<uint32_t>(sizeof(kWorld)); |
377 EXPECT_EQ(MOJO_RESULT_OK, | 374 EXPECT_EQ(MOJO_RESULT_OK, |
378 WriteMessageRaw(h2.get(), | 375 WriteMessageRaw(h2.get(), |
379 kWorld, | 376 kWorld, |
380 kWorldSize, | 377 kWorldSize, |
381 nullptr, | 378 nullptr, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 // Do this in a different order: make the enqueued message pipe handle only | 412 // Do this in a different order: make the enqueued message pipe handle only |
416 // half-alive. | 413 // half-alive. |
417 { | 414 { |
418 ScopedMessagePipeHandle h0; | 415 ScopedMessagePipeHandle h0; |
419 ScopedMessagePipeHandle h1; | 416 ScopedMessagePipeHandle h1; |
420 CreateMessagePipe(nullptr, &h0, &h1); | 417 CreateMessagePipe(nullptr, &h0, &h1); |
421 | 418 |
422 // Send a handle over the previously-establish message pipe. | 419 // Send a handle over the previously-establish message pipe. |
423 ScopedMessagePipeHandle h2; | 420 ScopedMessagePipeHandle h2; |
424 ScopedMessagePipeHandle h3; | 421 ScopedMessagePipeHandle h3; |
425 MojoCreateMessagePipeOptions options; | 422 if (CreateMessagePipe(nullptr, &h2, &h3) != MOJO_RESULT_OK) |
426 options.struct_size = sizeof(MojoCreateMessagePipeOptions); | |
427 options.flags = MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_TRANSFERABLE; | |
428 if (CreateMessagePipe(&options, &h2, &h3) != MOJO_RESULT_OK) | |
429 CreateMessagePipe(nullptr, &h2, &h3); // Must be old EDK. | 423 CreateMessagePipe(nullptr, &h2, &h3); // Must be old EDK. |
430 | 424 |
431 // Write a message to |h2|, before we send |h3|. | 425 // Write a message to |h2|, before we send |h3|. |
432 const char kWorld[] = "world!"; | 426 const char kWorld[] = "world!"; |
433 const uint32_t kWorldSize = static_cast<uint32_t>(sizeof(kWorld)); | 427 const uint32_t kWorldSize = static_cast<uint32_t>(sizeof(kWorld)); |
434 EXPECT_EQ(MOJO_RESULT_OK, | 428 EXPECT_EQ(MOJO_RESULT_OK, |
435 WriteMessageRaw(h2.get(), | 429 WriteMessageRaw(h2.get(), |
436 kWorld, | 430 kWorld, |
437 kWorldSize, | 431 kWorldSize, |
438 nullptr, | 432 nullptr, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 buffer1 = std::move(buffer2); | 478 buffer1 = std::move(buffer2); |
485 | 479 |
486 EXPECT_TRUE(buffer1.is_valid()); | 480 EXPECT_TRUE(buffer1.is_valid()); |
487 EXPECT_FALSE(buffer2.is_valid()); | 481 EXPECT_FALSE(buffer2.is_valid()); |
488 } | 482 } |
489 | 483 |
490 // TODO(vtl): Write data pipe tests. | 484 // TODO(vtl): Write data pipe tests. |
491 | 485 |
492 } // namespace | 486 } // namespace |
493 } // namespace mojo | 487 } // namespace mojo |
OLD | NEW |