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

Unified 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: Add ShellSurface::SetTitle 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 side-by-side diff with in-line comments
Download patch
Index: components/exo/shared_memory_unittest.cc
diff --git a/components/exo/shared_memory_unittest.cc b/components/exo/shared_memory_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9ea9dd7459f3fe4cc593af69087a4f8ca06ca728
--- /dev/null
+++ b/components/exo/shared_memory_unittest.cc
@@ -0,0 +1,53 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/exo/buffer.h"
+#include "components/exo/shared_memory.h"
+#include "components/exo/test/exo_test_base.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/gfx/buffer_format_util.h"
+
+namespace exo {
+namespace {
+
+using SharedMemoryTest = test::ExoTestBase;
+
+scoped_ptr<SharedMemory> CreateSharedMemory(size_t size) {
+ scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory);
+ bool rv = shared_memory->CreateAnonymous(size);
+ DCHECK(rv);
+ base::SharedMemoryHandle handle =
+ base::SharedMemory::DuplicateHandle(shared_memory->handle());
+ DCHECK(base::SharedMemory::IsHandleValid(handle));
+ return make_scoped_ptr(new SharedMemory(handle));
+}
+
+TEST_F(SharedMemoryTest, CreateBuffer) {
+ const gfx::Size buffer_size(256, 256);
+ const gfx::BufferFormat format = gfx::BufferFormat::RGBA_8888;
+
+ scoped_ptr<SharedMemory> shared_memory =
+ CreateSharedMemory(gfx::BufferSizeForBufferFormat(buffer_size, format));
+ ASSERT_TRUE(shared_memory);
+
+ // Creating a buffer with valid parameters should succeed.
+ scoped_ptr<Buffer> buffer1 = shared_memory->CreateBuffer(
+ buffer_size, format, 0,
+ gfx::RowSizeForBufferFormat(buffer_size.width(), format, 0));
+ EXPECT_TRUE(buffer1);
+
+ // Creating a buffer with an invalid offset should fail.
+ scoped_ptr<Buffer> buffer2 = shared_memory->CreateBuffer(
+ buffer_size, format, -1,
+ gfx::RowSizeForBufferFormat(buffer_size.width(), format, 0));
+ EXPECT_FALSE(buffer2);
+
+ // Creating a buffer with an invalid stride should fail.
+ scoped_ptr<Buffer> buffer3 =
+ shared_memory->CreateBuffer(buffer_size, format, 0, -1);
+ EXPECT_FALSE(buffer3);
+}
+
+} // namespace
+} // namespace exo

Powered by Google App Engine
This is Rietveld 408576698