| Index: ipc/ipc_message_attachment_set_posix_unittest.cc
|
| diff --git a/ipc/ipc_message_attachment_set_posix_unittest.cc b/ipc/ipc_message_attachment_set_posix_unittest.cc
|
| index 0a358fb16b9cea2f99b2adbc8872e0c468517720..416a7d2589cb9cbac99afe0204347fa84f404ed5 100644
|
| --- a/ipc/ipc_message_attachment_set_posix_unittest.cc
|
| +++ b/ipc/ipc_message_attachment_set_posix_unittest.cc
|
| @@ -11,6 +11,7 @@
|
|
|
| #include "base/basictypes.h"
|
| #include "base/posix/eintr_wrapper.h"
|
| +#include "ipc/ipc_platform_file_attachment_posix.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace IPC {
|
| @@ -42,7 +43,8 @@ TEST(MessageAttachmentSet, BasicAdd) {
|
|
|
| ASSERT_EQ(set->size(), 0u);
|
| ASSERT_TRUE(set->empty());
|
| - ASSERT_TRUE(set->AddToBorrow(kFDBase));
|
| + ASSERT_TRUE(
|
| + set->AddAttachment(new internal::PlatformFileAttachment(kFDBase)));
|
| ASSERT_EQ(set->size(), 1u);
|
| ASSERT_TRUE(!set->empty());
|
|
|
| @@ -57,7 +59,8 @@ TEST(MessageAttachmentSet, BasicAddAndClose) {
|
| ASSERT_EQ(set->size(), 0u);
|
| ASSERT_TRUE(set->empty());
|
| const int fd = GetSafeFd();
|
| - ASSERT_TRUE(set->AddToOwn(base::ScopedFD(fd)));
|
| + ASSERT_TRUE(set->AddAttachment(
|
| + new internal::PlatformFileAttachment(base::ScopedFD(fd))));
|
| ASSERT_EQ(set->size(), 1u);
|
| ASSERT_TRUE(!set->empty());
|
|
|
| @@ -69,9 +72,11 @@ TEST(MessageAttachmentSet, MaxSize) {
|
| scoped_refptr<MessageAttachmentSet> set(new MessageAttachmentSet);
|
|
|
| for (size_t i = 0; i < MessageAttachmentSet::kMaxDescriptorsPerMessage; ++i)
|
| - ASSERT_TRUE(set->AddToBorrow(kFDBase + 1 + i));
|
| + ASSERT_TRUE(set->AddAttachment(
|
| + new internal::PlatformFileAttachment(kFDBase + 1 + i)));
|
|
|
| - ASSERT_TRUE(!set->AddToBorrow(kFDBase));
|
| + ASSERT_TRUE(
|
| + !set->AddAttachment(new internal::PlatformFileAttachment(kFDBase)));
|
|
|
| set->CommitAll();
|
| }
|
| @@ -98,7 +103,8 @@ TEST(MessageAttachmentSet, PeekDescriptors) {
|
| scoped_refptr<MessageAttachmentSet> set(new MessageAttachmentSet);
|
|
|
| set->PeekDescriptors(NULL);
|
| - ASSERT_TRUE(set->AddToBorrow(kFDBase));
|
| + ASSERT_TRUE(
|
| + set->AddAttachment(new internal::PlatformFileAttachment(kFDBase)));
|
|
|
| int fds[1];
|
| fds[0] = 0;
|
| @@ -113,13 +119,16 @@ TEST(MessageAttachmentSet, WalkInOrder) {
|
|
|
| // TODO(morrita): This test is wrong. TakeDescriptorAt() shouldn't be
|
| // used to retrieve borrowed descriptors. That never happens in production.
|
| - ASSERT_TRUE(set->AddToBorrow(kFDBase));
|
| - ASSERT_TRUE(set->AddToBorrow(kFDBase + 1));
|
| - ASSERT_TRUE(set->AddToBorrow(kFDBase + 2));
|
| + ASSERT_TRUE(
|
| + set->AddAttachment(new internal::PlatformFileAttachment(kFDBase)));
|
| + ASSERT_TRUE(
|
| + set->AddAttachment(new internal::PlatformFileAttachment(kFDBase + 1)));
|
| + ASSERT_TRUE(
|
| + set->AddAttachment(new internal::PlatformFileAttachment(kFDBase + 2)));
|
|
|
| - ASSERT_EQ(set->TakeDescriptorAt(0), kFDBase);
|
| - ASSERT_EQ(set->TakeDescriptorAt(1), kFDBase + 1);
|
| - ASSERT_EQ(set->TakeDescriptorAt(2), kFDBase + 2);
|
| + ASSERT_EQ(set->GetAttachmentAt(0)->TakePlatformFile(), kFDBase);
|
| + ASSERT_EQ(set->GetAttachmentAt(1)->TakePlatformFile(), kFDBase + 1);
|
| + ASSERT_EQ(set->GetAttachmentAt(2)->TakePlatformFile(), kFDBase + 2);
|
|
|
| set->CommitAll();
|
| }
|
| @@ -129,12 +138,15 @@ TEST(MessageAttachmentSet, WalkWrongOrder) {
|
|
|
| // TODO(morrita): This test is wrong. TakeDescriptorAt() shouldn't be
|
| // used to retrieve borrowed descriptors. That never happens in production.
|
| - ASSERT_TRUE(set->AddToBorrow(kFDBase));
|
| - ASSERT_TRUE(set->AddToBorrow(kFDBase + 1));
|
| - ASSERT_TRUE(set->AddToBorrow(kFDBase + 2));
|
| + ASSERT_TRUE(
|
| + set->AddAttachment(new internal::PlatformFileAttachment(kFDBase)));
|
| + ASSERT_TRUE(
|
| + set->AddAttachment(new internal::PlatformFileAttachment(kFDBase + 1)));
|
| + ASSERT_TRUE(
|
| + set->AddAttachment(new internal::PlatformFileAttachment(kFDBase + 2)));
|
|
|
| - ASSERT_EQ(set->TakeDescriptorAt(0), kFDBase);
|
| - ASSERT_EQ(set->TakeDescriptorAt(2), -1);
|
| + ASSERT_EQ(set->GetAttachmentAt(0)->TakePlatformFile(), kFDBase);
|
| + ASSERT_EQ(set->GetAttachmentAt(2), nullptr);
|
|
|
| set->CommitAll();
|
| }
|
| @@ -144,19 +156,22 @@ TEST(MessageAttachmentSet, WalkCycle) {
|
|
|
| // TODO(morrita): This test is wrong. TakeDescriptorAt() shouldn't be
|
| // used to retrieve borrowed descriptors. That never happens in production.
|
| - ASSERT_TRUE(set->AddToBorrow(kFDBase));
|
| - ASSERT_TRUE(set->AddToBorrow(kFDBase + 1));
|
| - ASSERT_TRUE(set->AddToBorrow(kFDBase + 2));
|
| -
|
| - ASSERT_EQ(set->TakeDescriptorAt(0), kFDBase);
|
| - ASSERT_EQ(set->TakeDescriptorAt(1), kFDBase + 1);
|
| - ASSERT_EQ(set->TakeDescriptorAt(2), kFDBase + 2);
|
| - ASSERT_EQ(set->TakeDescriptorAt(0), kFDBase);
|
| - ASSERT_EQ(set->TakeDescriptorAt(1), kFDBase + 1);
|
| - ASSERT_EQ(set->TakeDescriptorAt(2), kFDBase + 2);
|
| - ASSERT_EQ(set->TakeDescriptorAt(0), kFDBase);
|
| - ASSERT_EQ(set->TakeDescriptorAt(1), kFDBase + 1);
|
| - ASSERT_EQ(set->TakeDescriptorAt(2), kFDBase + 2);
|
| + ASSERT_TRUE(
|
| + set->AddAttachment(new internal::PlatformFileAttachment(kFDBase)));
|
| + ASSERT_TRUE(
|
| + set->AddAttachment(new internal::PlatformFileAttachment(kFDBase + 1)));
|
| + ASSERT_TRUE(
|
| + set->AddAttachment(new internal::PlatformFileAttachment(kFDBase + 2)));
|
| +
|
| + ASSERT_EQ(set->GetAttachmentAt(0)->TakePlatformFile(), kFDBase);
|
| + ASSERT_EQ(set->GetAttachmentAt(1)->TakePlatformFile(), kFDBase + 1);
|
| + ASSERT_EQ(set->GetAttachmentAt(2)->TakePlatformFile(), kFDBase + 2);
|
| + ASSERT_EQ(set->GetAttachmentAt(0)->TakePlatformFile(), kFDBase);
|
| + ASSERT_EQ(set->GetAttachmentAt(1)->TakePlatformFile(), kFDBase + 1);
|
| + ASSERT_EQ(set->GetAttachmentAt(2)->TakePlatformFile(), kFDBase + 2);
|
| + ASSERT_EQ(set->GetAttachmentAt(0)->TakePlatformFile(), kFDBase);
|
| + ASSERT_EQ(set->GetAttachmentAt(1)->TakePlatformFile(), kFDBase + 1);
|
| + ASSERT_EQ(set->GetAttachmentAt(2)->TakePlatformFile(), kFDBase + 2);
|
|
|
| set->CommitAll();
|
| }
|
| @@ -165,7 +180,7 @@ TEST(MessageAttachmentSet, DontClose) {
|
| scoped_refptr<MessageAttachmentSet> set(new MessageAttachmentSet);
|
|
|
| const int fd = GetSafeFd();
|
| - ASSERT_TRUE(set->AddToBorrow(fd));
|
| + ASSERT_TRUE(set->AddAttachment(new internal::PlatformFileAttachment(fd)));
|
| set->CommitAll();
|
|
|
| ASSERT_FALSE(VerifyClosed(fd));
|
| @@ -175,7 +190,8 @@ TEST(MessageAttachmentSet, DoClose) {
|
| scoped_refptr<MessageAttachmentSet> set(new MessageAttachmentSet);
|
|
|
| const int fd = GetSafeFd();
|
| - ASSERT_TRUE(set->AddToOwn(base::ScopedFD(fd)));
|
| + ASSERT_TRUE(set->AddAttachment(
|
| + new internal::PlatformFileAttachment(base::ScopedFD(fd))));
|
| set->CommitAll();
|
|
|
| ASSERT_TRUE(VerifyClosed(fd));
|
|
|