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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 EXPECT_TRUE(buffer2.is_valid()); | 474 EXPECT_TRUE(buffer2.is_valid()); |
475 | 475 |
476 // If this fails to close buffer1, ScopedHandleBase::CloseIfNecessary() will | 476 // If this fails to close buffer1, ScopedHandleBase::CloseIfNecessary() will |
477 // assert. | 477 // assert. |
478 buffer1 = std::move(buffer2); | 478 buffer1 = std::move(buffer2); |
479 | 479 |
480 EXPECT_TRUE(buffer1.is_valid()); | 480 EXPECT_TRUE(buffer1.is_valid()); |
481 EXPECT_FALSE(buffer2.is_valid()); | 481 EXPECT_FALSE(buffer2.is_valid()); |
482 } | 482 } |
483 | 483 |
| 484 TEST(CoreCppTest, BasicSharedBuffer) { |
| 485 ScopedSharedBufferHandle h0; |
| 486 |
| 487 // Create a shared buffer (|h0|). |
| 488 { |
| 489 SharedBuffer buffer(100); |
| 490 h0 = std::move(buffer.handle); |
| 491 } |
| 492 |
| 493 // Map everything. |
| 494 ScopedSharedBufferMapping mapping = h0->Map(100); |
| 495 ASSERT_TRUE(mapping); |
| 496 static_cast<char*>(mapping.get())[50] = 'x'; |
| 497 |
| 498 // Duplicate |h0| to |h1|. |
| 499 ScopedSharedBufferHandle h1 = |
| 500 h0->Clone(SharedBufferHandle::AccessMode::READ_ONLY); |
| 501 ASSERT_TRUE(h1.is_valid()); |
| 502 |
| 503 // Close |h0|. |
| 504 h0.reset(); |
| 505 |
| 506 // The mapping should still be good. |
| 507 static_cast<char*>(mapping.get())[51] = 'y'; |
| 508 |
| 509 // Unmap it. |
| 510 mapping.reset(); |
| 511 |
| 512 // Map half of |h1|. |
| 513 mapping = h1->MapAtOffset(50, 50); |
| 514 ASSERT_TRUE(mapping); |
| 515 |
| 516 // It should have what we wrote. |
| 517 EXPECT_EQ('x', static_cast<char*>(mapping.get())[0]); |
| 518 EXPECT_EQ('y', static_cast<char*>(mapping.get())[1]); |
| 519 |
| 520 // Unmap it. |
| 521 mapping.reset(); |
| 522 h1.reset(); |
| 523 } |
| 524 |
484 // TODO(vtl): Write data pipe tests. | 525 // TODO(vtl): Write data pipe tests. |
485 | 526 |
486 } // namespace | 527 } // namespace |
487 } // namespace mojo | 528 } // namespace mojo |
OLD | NEW |