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

Side by Side Diff: o3d/gpu_plugin/command_buffer_unittest.cc

Issue 234001: GPUProcessor uses O3D command buffer service to render to a window.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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
« no previous file with comments | « o3d/gpu_plugin/command_buffer_mock.h ('k') | o3d/gpu_plugin/gpu_plugin.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/thread.h" 5 #include "base/thread.h"
6 #include "o3d/gpu_plugin/command_buffer.h" 6 #include "o3d/gpu_plugin/command_buffer.h"
7 #include "o3d/gpu_plugin/np_utils/dynamic_np_object.h" 7 #include "o3d/gpu_plugin/np_utils/dynamic_np_object.h"
8 #include "o3d/gpu_plugin/np_utils/np_browser_mock.h" 8 #include "o3d/gpu_plugin/np_utils/np_browser_mock.h"
9 #include "o3d/gpu_plugin/np_utils/np_object_mock.h" 9 #include "o3d/gpu_plugin/np_utils/np_object_mock.h"
10 #include "o3d/gpu_plugin/np_utils/np_object_pointer.h" 10 #include "o3d/gpu_plugin/np_utils/np_object_pointer.h"
11 #include "o3d/gpu_plugin/system_services/shared_memory_mock.h" 11 #include "o3d/gpu_plugin/system_services/shared_memory_mock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 14
15 using testing::_; 15 using testing::_;
16 using testing::DoAll; 16 using testing::DoAll;
17 using testing::Return; 17 using testing::Return;
18 using testing::SetArgumentPointee; 18 using testing::SetArgumentPointee;
19 using testing::StrictMock; 19 using testing::StrictMock;
20 20
21 namespace o3d { 21 namespace o3d {
22 namespace gpu_plugin { 22 namespace gpu_plugin {
23 23
24 class MockSystemNPObject : public DefaultNPObject<NPObject> { 24 class MockSystemNPObject : public DefaultNPObject<NPObject> {
25 public: 25 public:
26 explicit MockSystemNPObject(NPP npp) { 26 explicit MockSystemNPObject(NPP npp) {
27 } 27 }
28 28
29 MOCK_METHOD1(CreateSharedMemory, NPObjectPointer<NPObject>(int32)); 29 MOCK_METHOD1(CreateSharedMemory, NPObjectPointer<NPObject>(int32 size));
30 30
31 NP_UTILS_BEGIN_DISPATCHER_CHAIN(MockSystemNPObject, DefaultNPObject<NPObject>) 31 NP_UTILS_BEGIN_DISPATCHER_CHAIN(MockSystemNPObject, DefaultNPObject<NPObject>)
32 NP_UTILS_DISPATCHER(CreateSharedMemory, NPObjectPointer<NPObject>(int32)) 32 NP_UTILS_DISPATCHER(CreateSharedMemory,
33 NPObjectPointer<NPObject>(int32 size))
33 NP_UTILS_END_DISPATCHER_CHAIN 34 NP_UTILS_END_DISPATCHER_CHAIN
34 35
35 private: 36 private:
36 DISALLOW_COPY_AND_ASSIGN(MockSystemNPObject); 37 DISALLOW_COPY_AND_ASSIGN(MockSystemNPObject);
37 }; 38 };
38 39
39 class CommandBufferTest : public testing::Test { 40 class CommandBufferTest : public testing::Test {
40 protected: 41 protected:
41 virtual void SetUp() { 42 virtual void SetUp() {
42 command_buffer_ = NPCreateObject<CommandBuffer>(NULL); 43 command_buffer_ = NPCreateObject<CommandBuffer>(NULL);
(...skipping 25 matching lines...) Expand all
68 69
69 NPObjectPointer<MockSharedMemory> expected_shared_memory = 70 NPObjectPointer<MockSharedMemory> expected_shared_memory =
70 NPCreateObject<StrictMock<MockSharedMemory> >(NULL); 71 NPCreateObject<StrictMock<MockSharedMemory> >(NULL);
71 72
72 EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024)) 73 EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024))
73 .WillOnce(Return(expected_shared_memory)); 74 .WillOnce(Return(expected_shared_memory));
74 75
75 EXPECT_CALL(*expected_shared_memory.Get(), Map()) 76 EXPECT_CALL(*expected_shared_memory.Get(), Map())
76 .WillOnce(Return(true)); 77 .WillOnce(Return(true));
77 78
78 EXPECT_TRUE(command_buffer_->Initialize(1024)); 79 EXPECT_TRUE(command_buffer_->Initialize(256));
79 EXPECT_EQ(expected_shared_memory, command_buffer_->GetRingBuffer()); 80 EXPECT_EQ(expected_shared_memory, command_buffer_->GetRingBuffer());
80 81
81 // Cannot reinitialize. 82 // Cannot reinitialize.
82 EXPECT_FALSE(command_buffer_->Initialize(1024)); 83 EXPECT_FALSE(command_buffer_->Initialize(256));
83 EXPECT_EQ(expected_shared_memory, command_buffer_->GetRingBuffer()); 84 EXPECT_EQ(expected_shared_memory, command_buffer_->GetRingBuffer());
84 } 85 }
85 86
87 TEST_F(CommandBufferTest, InitializeFailsIfSizeIsTooBig) {
88 EXPECT_FALSE(command_buffer_->Initialize(0x40000000));
89 }
90
86 TEST_F(CommandBufferTest, InitializeFailsIfCannotCreateSharedMemory) { 91 TEST_F(CommandBufferTest, InitializeFailsIfCannotCreateSharedMemory) {
87 EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL)) 92 EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL))
88 .WillOnce(Return(window_object_.ToReturned())); 93 .WillOnce(Return(window_object_.ToReturned()));
89 94
90 EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024)) 95 EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024))
91 .WillOnce(Return(NPObjectPointer<NPObject>())); 96 .WillOnce(Return(NPObjectPointer<NPObject>()));
92 97
93 EXPECT_FALSE(command_buffer_->Initialize(1024)); 98 EXPECT_FALSE(command_buffer_->Initialize(256));
94 EXPECT_EQ(NPObjectPointer<NPObject>(), 99 EXPECT_EQ(NPObjectPointer<NPObject>(),
95 command_buffer_->GetRingBuffer()); 100 command_buffer_->GetRingBuffer());
96 } 101 }
97 102
98 TEST_F(CommandBufferTest, InitializeFailsIfCannotMapSharedMemory) { 103 TEST_F(CommandBufferTest, InitializeFailsIfCannotMapSharedMemory) {
99 EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL)) 104 EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL))
100 .WillOnce(Return(window_object_.ToReturned())); 105 .WillOnce(Return(window_object_.ToReturned()));
101 106
102 NPObjectPointer<MockSharedMemory> expected_shared_memory = 107 NPObjectPointer<MockSharedMemory> expected_shared_memory =
103 NPCreateObject<StrictMock<MockSharedMemory> >(NULL); 108 NPCreateObject<StrictMock<MockSharedMemory> >(NULL);
104 109
105 EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024)) 110 EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024))
106 .WillOnce(Return(expected_shared_memory)); 111 .WillOnce(Return(expected_shared_memory));
107 112
108 EXPECT_CALL(*expected_shared_memory.Get(), Map()) 113 EXPECT_CALL(*expected_shared_memory.Get(), Map())
109 .WillOnce(Return(false)); 114 .WillOnce(Return(false));
110 115
111 EXPECT_FALSE(command_buffer_->Initialize(1024)); 116 EXPECT_FALSE(command_buffer_->Initialize(256));
112 EXPECT_EQ(NPObjectPointer<NPObject>(), 117 EXPECT_EQ(NPObjectPointer<NPObject>(),
113 command_buffer_->GetRingBuffer()); 118 command_buffer_->GetRingBuffer());
114 } 119 }
115 120
116 TEST_F(CommandBufferTest, GetAndPutOffsetsDefaultToZero) { 121 TEST_F(CommandBufferTest, GetAndPutOffsetsDefaultToZero) {
117 EXPECT_EQ(0, command_buffer_->GetGetOffset()); 122 EXPECT_EQ(0, command_buffer_->GetGetOffset());
118 EXPECT_EQ(0, command_buffer_->GetPutOffset()); 123 EXPECT_EQ(0, command_buffer_->GetPutOffset());
119 } 124 }
120 125
121 class MockCallback : public CallbackRunner<Tuple0> { 126 class MockCallback : public CallbackRunner<Tuple0> {
122 public: 127 public:
123 MOCK_METHOD1(RunWithParams, void(const Tuple0&)); 128 MOCK_METHOD1(RunWithParams, void(const Tuple0&));
124 }; 129 };
125 130
126 TEST_F(CommandBufferTest, CanSyncGetAndPutOffset) { 131 TEST_F(CommandBufferTest, CanSyncGetAndPutOffset) {
127 EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL)) 132 EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL))
128 .WillOnce(Return(window_object_.ToReturned())); 133 .WillOnce(Return(window_object_.ToReturned()));
129 134
130 NPObjectPointer<MockSharedMemory> expected_shared_memory = 135 NPObjectPointer<MockSharedMemory> expected_shared_memory =
131 NPCreateObject<StrictMock<MockSharedMemory> >(NULL); 136 NPCreateObject<StrictMock<MockSharedMemory> >(NULL);
132 137
133 EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024)) 138 EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024))
134 .WillOnce(Return(expected_shared_memory)); 139 .WillOnce(Return(expected_shared_memory));
135 140
136 EXPECT_CALL(*expected_shared_memory.Get(), Map()) 141 EXPECT_CALL(*expected_shared_memory.Get(), Map())
137 .WillOnce(Return(true)); 142 .WillOnce(Return(true));
138 143
139 EXPECT_TRUE(command_buffer_->Initialize(1024)); 144 EXPECT_TRUE(command_buffer_->Initialize(256));
140 145
141 StrictMock<MockCallback>* put_offset_change_callback = 146 StrictMock<MockCallback>* put_offset_change_callback =
142 new StrictMock<MockCallback>; 147 new StrictMock<MockCallback>;
143 command_buffer_->SetPutOffsetChangeCallback(put_offset_change_callback); 148 command_buffer_->SetPutOffsetChangeCallback(put_offset_change_callback);
144 149
145 EXPECT_CALL(*put_offset_change_callback, RunWithParams(_)); 150 EXPECT_CALL(*put_offset_change_callback, RunWithParams(_));
146 EXPECT_EQ(0, command_buffer_->SyncOffsets(2)); 151 EXPECT_EQ(0, command_buffer_->SyncOffsets(2));
147 EXPECT_EQ(2, command_buffer_->GetPutOffset()); 152 EXPECT_EQ(2, command_buffer_->GetPutOffset());
148 153
149 EXPECT_CALL(*put_offset_change_callback, RunWithParams(_)); 154 EXPECT_CALL(*put_offset_change_callback, RunWithParams(_));
150 EXPECT_EQ(0, command_buffer_->SyncOffsets(4)); 155 EXPECT_EQ(0, command_buffer_->SyncOffsets(4));
151 EXPECT_EQ(4, command_buffer_->GetPutOffset()); 156 EXPECT_EQ(4, command_buffer_->GetPutOffset());
152 157
153 command_buffer_->SetGetOffset(2); 158 command_buffer_->SetGetOffset(2);
154 EXPECT_EQ(2, command_buffer_->GetGetOffset()); 159 EXPECT_EQ(2, command_buffer_->GetGetOffset());
155 EXPECT_CALL(*put_offset_change_callback, RunWithParams(_)); 160 EXPECT_CALL(*put_offset_change_callback, RunWithParams(_));
156 EXPECT_EQ(2, command_buffer_->SyncOffsets(6)); 161 EXPECT_EQ(2, command_buffer_->SyncOffsets(6));
157 162
158 EXPECT_EQ(-1, command_buffer_->SyncOffsets(-1)); 163 EXPECT_EQ(-1, command_buffer_->SyncOffsets(-1));
159 EXPECT_EQ(-1, command_buffer_->SyncOffsets(1024)); 164 EXPECT_EQ(-1, command_buffer_->SyncOffsets(1024));
160 } 165 }
161 166
162 TEST_F(CommandBufferTest, ZeroHandleMapsToNull) { 167 TEST_F(CommandBufferTest, ZeroHandleMapsToNull) {
163 EXPECT_TRUE(NULL == command_buffer_->GetRegisteredObject(0).Get()); 168 EXPECT_TRUE(NULL == command_buffer_->GetRegisteredObject(0).Get());
164 } 169 }
165 170
171 TEST_F(CommandBufferTest, NegativeHandleMapsToNull) {
172 EXPECT_TRUE(NULL == command_buffer_->GetRegisteredObject(-1).Get());
173 }
174
175 TEST_F(CommandBufferTest, OutOfRangeHandleMapsToNull) {
176 EXPECT_TRUE(NULL == command_buffer_->GetRegisteredObject(1).Get());
177 }
178
166 TEST_F(CommandBufferTest, RegisteringNullObjectReturnsZero) { 179 TEST_F(CommandBufferTest, RegisteringNullObjectReturnsZero) {
167 EXPECT_EQ(0, command_buffer_->RegisterObject(NPObjectPointer<NPObject>())); 180 EXPECT_EQ(0, command_buffer_->RegisterObject(NPObjectPointer<NPObject>()));
168 } 181 }
169 182
170 TEST_F(CommandBufferTest, RegistersDistinctNonZeroHandlesForObject) { 183 TEST_F(CommandBufferTest, RegistersDistinctNonZeroHandlesForObject) {
171 EXPECT_EQ(1, command_buffer_->RegisterObject(window_object_)); 184 EXPECT_EQ(1, command_buffer_->RegisterObject(window_object_));
172 EXPECT_EQ(window_object_, command_buffer_->GetRegisteredObject(1)); 185 EXPECT_EQ(window_object_, command_buffer_->GetRegisteredObject(1));
173 EXPECT_EQ(2, command_buffer_->RegisterObject(window_object_)); 186 EXPECT_EQ(2, command_buffer_->RegisterObject(window_object_));
174 EXPECT_EQ(window_object_, command_buffer_->GetRegisteredObject(2)); 187 EXPECT_EQ(window_object_, command_buffer_->GetRegisteredObject(2));
175 } 188 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 251
239 TEST_F(CommandBufferTest, DefaultTokenIsZero) { 252 TEST_F(CommandBufferTest, DefaultTokenIsZero) {
240 EXPECT_EQ(0, command_buffer_->GetToken()); 253 EXPECT_EQ(0, command_buffer_->GetToken());
241 } 254 }
242 255
243 TEST_F(CommandBufferTest, CanSetToken) { 256 TEST_F(CommandBufferTest, CanSetToken) {
244 command_buffer_->SetToken(7); 257 command_buffer_->SetToken(7);
245 EXPECT_EQ(7, command_buffer_->GetToken()); 258 EXPECT_EQ(7, command_buffer_->GetToken());
246 } 259 }
247 260
248 TEST_F(CommandBufferTest, DefaultErrorIsNoError) { 261 TEST_F(CommandBufferTest, DefaultParseErrorIsNoError) {
249 EXPECT_EQ(CommandBuffer::ERROR_NO_ERROR, command_buffer_->ResetError()); 262 EXPECT_EQ(0, command_buffer_->ResetParseError());
250 } 263 }
251 264
252 TEST_F(CommandBufferTest, CanSetAndResetError) { 265 TEST_F(CommandBufferTest, CanSetAndResetParseError) {
253 command_buffer_->SetError(CommandBuffer::ERROR_UNKNOWN_COMMAND); 266 command_buffer_->SetParseError(1);
254 EXPECT_EQ(CommandBuffer::ERROR_UNKNOWN_COMMAND, 267 EXPECT_EQ(1, command_buffer_->ResetParseError());
255 command_buffer_->ResetError()); 268 EXPECT_EQ(0, command_buffer_->ResetParseError());
256 EXPECT_EQ(CommandBuffer::ERROR_NO_ERROR, command_buffer_->ResetError()); 269 }
270
271 TEST_F(CommandBufferTest, DefaultErrorStatusIsFalse) {
272 EXPECT_FALSE(command_buffer_->GetErrorStatus());
273 }
274
275 TEST_F(CommandBufferTest, CanRaiseErrorStatus) {
276 command_buffer_->RaiseErrorStatus();
277 EXPECT_TRUE(command_buffer_->GetErrorStatus());
257 } 278 }
258 279
259 } // namespace gpu_plugin 280 } // namespace gpu_plugin
260 } // namespace o3d 281 } // namespace o3d
OLDNEW
« no previous file with comments | « o3d/gpu_plugin/command_buffer_mock.h ('k') | o3d/gpu_plugin/gpu_plugin.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698