Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: components/exo/shared_memory_unittest.cc

Issue 1412093006: components: Add Exosphere component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove some ifdefs Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/exo/shared_memory.cc ('k') | components/exo/shell_surface.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 full size buffer should succeed.
35 scoped_ptr<Buffer> buffer = shared_memory->CreateBuffer(
36 buffer_size, format, 0,
37 gfx::RowSizeForBufferFormat(buffer_size.width(), format, 0));
38 EXPECT_TRUE(buffer);
39
40 // Creating a buffer for the top-left rectangle should succeed.
41 const gfx::Size top_left_buffer_size(128, 128);
42 scoped_ptr<Buffer> top_left_buffer = shared_memory->CreateBuffer(
43 top_left_buffer_size, format, 0,
44 gfx::RowSizeForBufferFormat(buffer_size.width(), format, 0));
45 EXPECT_TRUE(top_left_buffer);
46
47 // Creating a buffer for the bottom-right rectangle should succeed.
48 const gfx::Size bottom_right_buffer_size(64, 64);
49 scoped_ptr<Buffer> bottom_right_buffer = shared_memory->CreateBuffer(
50 bottom_right_buffer_size, format,
51 (buffer_size.height() - bottom_right_buffer_size.height()) *
52 gfx::RowSizeForBufferFormat(buffer_size.width(), format, 0) +
53 (buffer_size.width() - bottom_right_buffer_size.width()) * 4,
54 gfx::RowSizeForBufferFormat(buffer_size.width(), format, 0));
55 EXPECT_TRUE(bottom_right_buffer);
56 }
57
58 } // namespace
59 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/shared_memory.cc ('k') | components/exo/shell_surface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698