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

Side by Side Diff: o3d/gpu_plugin/system_services/shared_memory_unittest.cc

Issue 194049: Implemented shared memory as an NPObject. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 3 months 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 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 "o3d/gpu_plugin/np_utils/np_browser_stub.h"
7 #include "o3d/gpu_plugin/system_services/shared_memory.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10
11 using testing::_;
12 using testing::DoAll;
13 using testing::Return;
14 using testing::SetArgumentPointee;
15 using testing::StrictMock;
16
17 namespace o3d {
18 namespace gpu_plugin {
19
20 class SharedMemoryTest : public testing::Test {
21 protected:
22 virtual void SetUp() {
23 shared_memory_ = NPCreateObject<SharedMemory>(NULL);
24 }
25
26 StubNPBrowser stub_browser_;
27 NPObjectPointer<SharedMemory> shared_memory_;
28 };
29
30 TEST_F(SharedMemoryTest, MemoryIsNotMappedBeforeInitialization) {
31 EXPECT_TRUE(NULL == shared_memory_->handle);
32 EXPECT_TRUE(NULL == shared_memory_->ptr);
33 EXPECT_EQ(0, shared_memory_->size);
34 EXPECT_EQ(0, shared_memory_->GetSize());
35 }
36
37 TEST_F(SharedMemoryTest, InitializesAndReturnsMappedMemory) {
38 EXPECT_TRUE(shared_memory_->Initialize(65536));
39 EXPECT_TRUE(NULL != shared_memory_->handle);
40 EXPECT_TRUE(NULL == shared_memory_->ptr);
41 EXPECT_EQ(65536, shared_memory_->size);
42 EXPECT_EQ(65536, shared_memory_->GetSize());
43
44 EXPECT_TRUE(shared_memory_->Map());
45 ASSERT_TRUE(NULL != shared_memory_->ptr);
46 EXPECT_EQ(65536, shared_memory_->size);
47
48 // Test that memory can be written to.
49 int8* ptr = static_cast<int8*>(shared_memory_->ptr);
50 for (int i = 0; i < 65536; ++i) {
51 ptr[i] = 7;
52 }
53 }
54
55 TEST_F(SharedMemoryTest, MapFailsBeforeInitialization) {
56 EXPECT_FALSE(shared_memory_->Map());
57 }
58
59 TEST_F(SharedMemoryTest, InitializeFailsForNegativeSize) {
60 EXPECT_FALSE(shared_memory_->Initialize(-1));
61 }
62
63 TEST_F(SharedMemoryTest, SecondCallToInitializeFails) {
64 EXPECT_TRUE(shared_memory_->Initialize(65536));
65 EXPECT_FALSE(shared_memory_->Initialize(65536));
66 }
67
68 TEST_F(SharedMemoryTest, InitializeRoundsUpToPageSizeButReportsRequestedSize) {
69 EXPECT_TRUE(shared_memory_->Initialize(7));
70
71 EXPECT_TRUE(shared_memory_->Map());
72 EXPECT_EQ(7, shared_memory_->size);
73
74 // Test that memory can be written to.
75 int8* ptr = static_cast<int8*>(shared_memory_->ptr);
76 for (int i = 0; i < 7; ++i) {
77 ptr[i] = 7;
78 }
79 }
80
81 TEST_F(SharedMemoryTest, SecondMapDoesNothing) {
82 EXPECT_TRUE(shared_memory_->Initialize(65536));
83
84 EXPECT_TRUE(shared_memory_->Map());
85 ASSERT_TRUE(NULL != shared_memory_->handle);
86 ASSERT_TRUE(NULL != shared_memory_->ptr);
87 EXPECT_EQ(65536, shared_memory_->size);
88
89 void* handle = shared_memory_->handle;
90 void* ptr = shared_memory_->ptr;
91 EXPECT_TRUE(shared_memory_->Map());
92 ASSERT_EQ(ptr, shared_memory_->ptr);
93 EXPECT_EQ(65536, shared_memory_->size);
94 }
95
96 TEST_F(SharedMemoryTest, CanInitializeWithHandle) {
97 base::SharedMemory* temp_shared_memory = new base::SharedMemory;
98 EXPECT_TRUE(temp_shared_memory->Create(std::wstring(), false, false, 65536));
99
100 shared_memory_->Initialize(temp_shared_memory, 65536);
101 EXPECT_TRUE(NULL != shared_memory_->handle);
102 EXPECT_TRUE(NULL == shared_memory_->ptr);
103 EXPECT_EQ(65536, shared_memory_->size);
104
105 EXPECT_TRUE(shared_memory_->Map());
106 EXPECT_TRUE(NULL != shared_memory_->handle);
107 EXPECT_TRUE(NULL != shared_memory_->ptr);
108 EXPECT_EQ(65536, shared_memory_->size);
109 }
110
111 } // namespace gpu_plugin
112 } // namespace o3d
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698