| 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 "media/video/capture/screen/shared_buffer.h" | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | |
| 8 | |
| 9 const uint32 kBufferSize = 4096; | |
| 10 const int kPattern = 0x12345678; | |
| 11 | |
| 12 const int kIdZero = 0; | |
| 13 const int kIdOne = 1; | |
| 14 | |
| 15 namespace media { | |
| 16 | |
| 17 TEST(SharedBufferTest, Basic) { | |
| 18 scoped_refptr<SharedBuffer> source(new SharedBuffer(kBufferSize)); | |
| 19 | |
| 20 // Make sure that the buffer is allocated, the size is recorded correctly and | |
| 21 // its ID is reset. | |
| 22 EXPECT_TRUE(source->ptr() != NULL); | |
| 23 EXPECT_EQ(source->id(), kIdZero); | |
| 24 EXPECT_EQ(source->size(), kBufferSize); | |
| 25 | |
| 26 // See if setting of the ID works. | |
| 27 source->set_id(kIdOne); | |
| 28 EXPECT_EQ(source->id(), kIdOne); | |
| 29 | |
| 30 base::SharedMemoryHandle copied_handle; | |
| 31 EXPECT_TRUE(source->ShareToProcess( | |
| 32 base::GetCurrentProcessHandle(), &copied_handle)); | |
| 33 | |
| 34 scoped_refptr<SharedBuffer> dest( | |
| 35 new SharedBuffer(kIdZero, copied_handle, kBufferSize)); | |
| 36 | |
| 37 // Make sure that the buffer is allocated, the size is recorded correctly and | |
| 38 // its ID is reset. | |
| 39 EXPECT_TRUE(dest->ptr() != NULL); | |
| 40 EXPECT_EQ(dest->id(), kIdZero); | |
| 41 EXPECT_EQ(dest->size(), kBufferSize); | |
| 42 | |
| 43 // Verify that the memory contents are the same for the two buffers. | |
| 44 int* source_ptr = reinterpret_cast<int*>(source->ptr()); | |
| 45 *source_ptr = kPattern; | |
| 46 int* dest_ptr = reinterpret_cast<int*>(dest->ptr()); | |
| 47 EXPECT_EQ(*source_ptr, *dest_ptr); | |
| 48 | |
| 49 // Check that the destination buffer is still mapped even when the source | |
| 50 // buffer is destroyed. | |
| 51 source = NULL; | |
| 52 EXPECT_EQ(0x12345678, *dest_ptr); | |
| 53 } | |
| 54 | |
| 55 } // namespace media | |
| OLD | NEW |