OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "components/exo/buffer.h" |
| 6 #include "components/exo/shared_memory.h" |
| 7 #include "components/exo/test/exo_test_base.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/gfx/buffer_format_util.h" |
| 10 |
| 11 namespace exo { |
| 12 namespace { |
| 13 |
| 14 using SharedMemoryTest = test::ExoTestBase; |
| 15 |
| 16 scoped_ptr<SharedMemory> CreateSharedMemory(size_t size) { |
| 17 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory); |
| 18 bool rv = shared_memory->CreateAnonymous(size); |
| 19 DCHECK(rv); |
| 20 base::SharedMemoryHandle handle = |
| 21 base::SharedMemory::DuplicateHandle(shared_memory->handle()); |
| 22 DCHECK(base::SharedMemory::IsHandleValid(handle)); |
| 23 return make_scoped_ptr(new SharedMemory(handle)); |
| 24 } |
| 25 |
| 26 TEST_F(SharedMemoryTest, CreateBuffer) { |
| 27 const gfx::Size buffer_size(256, 256); |
| 28 const gfx::BufferFormat format = gfx::BufferFormat::RGBA_8888; |
| 29 |
| 30 scoped_ptr<SharedMemory> shared_memory = |
| 31 CreateSharedMemory(gfx::BufferSizeForBufferFormat(buffer_size, format)); |
| 32 ASSERT_TRUE(shared_memory); |
| 33 |
| 34 // Creating a buffer with valid parameters should succeed. |
| 35 scoped_ptr<Buffer> buffer1 = shared_memory->CreateBuffer( |
| 36 buffer_size, format, 0, |
| 37 gfx::RowSizeForBufferFormat(buffer_size.width(), format, 0)); |
| 38 EXPECT_TRUE(buffer1); |
| 39 |
| 40 // Creating a buffer with an invalid offset should fail. |
| 41 scoped_ptr<Buffer> buffer2 = shared_memory->CreateBuffer( |
| 42 buffer_size, format, -1, |
| 43 gfx::RowSizeForBufferFormat(buffer_size.width(), format, 0)); |
| 44 EXPECT_FALSE(buffer2); |
| 45 |
| 46 // Creating a buffer with an invalid stride should fail. |
| 47 scoped_ptr<Buffer> buffer3 = |
| 48 shared_memory->CreateBuffer(buffer_size, format, 0, -1); |
| 49 EXPECT_FALSE(buffer3); |
| 50 } |
| 51 |
| 52 } // namespace |
| 53 } // namespace exo |
OLD | NEW |