| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/process_util.h" | |
| 6 #include "ipc/ipc_platform_file.h" | |
| 7 #include "remoting/capturer/shared_buffer.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 const uint32 kBufferSize = 4096; | |
| 11 const int kPattern = 0x12345678; | |
| 12 | |
| 13 const int kIdZero = 0; | |
| 14 const int kIdOne = 1; | |
| 15 | |
| 16 namespace remoting { | |
| 17 | |
| 18 TEST(SharedBufferTest, Basic) { | |
| 19 scoped_refptr<SharedBuffer> source(new SharedBuffer(kBufferSize)); | |
| 20 | |
| 21 // Make sure that the buffer is allocated, the size is recorded correctly and | |
| 22 // its ID is reset. | |
| 23 EXPECT_TRUE(source->ptr() != NULL); | |
| 24 EXPECT_EQ(source->id(), kIdZero); | |
| 25 EXPECT_EQ(source->size(), kBufferSize); | |
| 26 | |
| 27 // See if setting of the ID works. | |
| 28 source->set_id(kIdOne); | |
| 29 EXPECT_EQ(source->id(), kIdOne); | |
| 30 | |
| 31 #if defined(OS_POSIX) | |
| 32 base::PlatformFile source_handle = source->handle().fd; | |
| 33 #else // !defined(OS_POSIX) | |
| 34 base::PlatformFile source_handle = source->handle(); | |
| 35 #endif // !defined(OS_POSIX) | |
| 36 | |
| 37 // Duplicate the source handle. | |
| 38 IPC::PlatformFileForTransit copied_handle = IPC::GetFileHandleForProcess( | |
| 39 source_handle, base::GetCurrentProcessHandle(), false); | |
| 40 | |
| 41 scoped_refptr<SharedBuffer> dest( | |
| 42 new SharedBuffer(kIdZero, copied_handle, kBufferSize)); | |
| 43 | |
| 44 // Make sure that the buffer is allocated, the size is recorded correctly and | |
| 45 // its ID is reset. | |
| 46 EXPECT_TRUE(dest->ptr() != NULL); | |
| 47 EXPECT_EQ(dest->id(), kIdZero); | |
| 48 EXPECT_EQ(dest->size(), kBufferSize); | |
| 49 | |
| 50 // Verify that the memory contents are the same for the two buffers. | |
| 51 int* source_ptr = reinterpret_cast<int*>(source->ptr()); | |
| 52 *source_ptr = kPattern; | |
| 53 int* dest_ptr = reinterpret_cast<int*>(dest->ptr()); | |
| 54 EXPECT_EQ(*source_ptr, *dest_ptr); | |
| 55 | |
| 56 // Check that the destination buffer is still mapped even when the source | |
| 57 // buffer is destroyed. | |
| 58 source = NULL; | |
| 59 EXPECT_EQ(0x12345678, *dest_ptr); | |
| 60 } | |
| 61 | |
| 62 } // namespace remoting | |
| OLD | NEW |