OLD | NEW |
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 "o3d/gpu_plugin/command_buffer.h" | 5 #include "o3d/gpu_plugin/command_buffer.h" |
6 #include "o3d/gpu_plugin/np_utils/base_np_object_mock.h" | |
7 #include "o3d/gpu_plugin/np_utils/dynamic_np_object.h" | 6 #include "o3d/gpu_plugin/np_utils/dynamic_np_object.h" |
8 #include "o3d/gpu_plugin/np_utils/np_browser_mock.h" | 7 #include "o3d/gpu_plugin/np_utils/np_browser_mock.h" |
| 8 #include "o3d/gpu_plugin/np_utils/np_object_mock.h" |
9 #include "o3d/gpu_plugin/np_utils/np_object_pointer.h" | 9 #include "o3d/gpu_plugin/np_utils/np_object_pointer.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
12 | 12 |
13 using testing::_; | 13 using testing::_; |
14 using testing::DoAll; | 14 using testing::DoAll; |
15 using testing::Return; | 15 using testing::Return; |
16 using testing::SetArgumentPointee; | 16 using testing::SetArgumentPointee; |
17 using testing::StrictMock; | 17 using testing::StrictMock; |
18 | 18 |
19 namespace o3d { | 19 namespace o3d { |
20 namespace gpu_plugin { | 20 namespace gpu_plugin { |
21 | 21 |
22 class MockSystemNPObject : public DispatchedNPObject { | 22 class MockSystemNPObject : public DefaultNPObject<NPObject> { |
23 public: | 23 public: |
24 explicit MockSystemNPObject(NPP npp) : DispatchedNPObject(npp) { | 24 explicit MockSystemNPObject(NPP npp) { |
25 } | 25 } |
26 | 26 |
27 MOCK_METHOD1(CreateSharedMemory, NPObjectPointer<NPObject>(int32)); | 27 MOCK_METHOD1(CreateSharedMemory, NPObjectPointer<NPObject>(int32)); |
28 | 28 |
29 protected: | 29 NP_UTILS_BEGIN_DISPATCHER_CHAIN(MockSystemNPObject, DefaultNPObject<NPObject>) |
30 NP_UTILS_BEGIN_DISPATCHER_CHAIN(MockSystemNPObject, DispatchedNPObject) | |
31 NP_UTILS_DISPATCHER(CreateSharedMemory, NPObjectPointer<NPObject>(int32)) | 30 NP_UTILS_DISPATCHER(CreateSharedMemory, NPObjectPointer<NPObject>(int32)) |
32 NP_UTILS_END_DISPATCHER_CHAIN | 31 NP_UTILS_END_DISPATCHER_CHAIN |
33 | 32 |
34 private: | 33 private: |
35 DISALLOW_COPY_AND_ASSIGN(MockSystemNPObject); | 34 DISALLOW_COPY_AND_ASSIGN(MockSystemNPObject); |
36 }; | 35 }; |
37 | 36 |
38 class CommandBufferTest : public testing::Test { | 37 class CommandBufferTest : public testing::Test { |
39 protected: | 38 protected: |
40 virtual void SetUp() { | 39 virtual void SetUp() { |
(...skipping 17 matching lines...) Expand all Loading... |
58 | 57 |
59 TEST_F(CommandBufferTest, TestBehaviorWhileUninitialized) { | 58 TEST_F(CommandBufferTest, TestBehaviorWhileUninitialized) { |
60 EXPECT_EQ(NPObjectPointer<NPObject>(), command_buffer_object_->GetBuffer()); | 59 EXPECT_EQ(NPObjectPointer<NPObject>(), command_buffer_object_->GetBuffer()); |
61 EXPECT_EQ(0, command_buffer_object_->GetGetOffset()); | 60 EXPECT_EQ(0, command_buffer_object_->GetGetOffset()); |
62 } | 61 } |
63 | 62 |
64 TEST_F(CommandBufferTest, InitializesCommandBuffer) { | 63 TEST_F(CommandBufferTest, InitializesCommandBuffer) { |
65 EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL)) | 64 EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL)) |
66 .WillOnce(Return(window_object_.ToReturned())); | 65 .WillOnce(Return(window_object_.ToReturned())); |
67 | 66 |
68 NPObjectPointer<BaseNPObject> expected_buffer = | 67 NPObjectPointer<NPObject> expected_buffer = |
69 NPCreateObject<BaseNPObject>(NULL); | 68 NPCreateObject<MockNPObject>(NULL); |
70 | 69 |
71 EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024)) | 70 EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024)) |
72 .WillOnce(Return(expected_buffer)); | 71 .WillOnce(Return(expected_buffer)); |
73 | 72 |
74 NPSharedMemory shared_memory; | 73 NPSharedMemory shared_memory; |
75 | 74 |
76 EXPECT_CALL(mock_browser_, MapSharedMemory(NULL, | 75 EXPECT_CALL(mock_browser_, MapSharedMemory(NULL, |
77 expected_buffer.Get(), | 76 expected_buffer.Get(), |
78 1024, | 77 1024, |
79 false)) | 78 false)) |
80 .WillOnce(Return(&shared_memory)); | 79 .WillOnce(Return(&shared_memory)); |
81 | 80 |
82 EXPECT_TRUE(command_buffer_object_->Initialize(1024)); | 81 EXPECT_TRUE(command_buffer_object_->Initialize(1024)); |
83 EXPECT_EQ(expected_buffer, command_buffer_object_->GetBuffer()); | 82 EXPECT_EQ(expected_buffer, command_buffer_object_->GetBuffer()); |
84 | 83 |
85 // Cannot reinitialize. | 84 // Cannot reinitialize. |
86 EXPECT_FALSE(command_buffer_object_->Initialize(1024)); | 85 EXPECT_FALSE(command_buffer_object_->Initialize(1024)); |
87 EXPECT_EQ(expected_buffer, command_buffer_object_->GetBuffer()); | 86 EXPECT_EQ(expected_buffer, command_buffer_object_->GetBuffer()); |
88 } | 87 } |
89 | 88 |
90 TEST_F(CommandBufferTest, InitializeFailsIfCannotCreateSharedMemory) { | 89 TEST_F(CommandBufferTest, InitializeFailsIfCannotCreateSharedMemory) { |
91 EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL)) | 90 EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL)) |
92 .WillOnce(Return(window_object_.ToReturned())); | 91 .WillOnce(Return(window_object_.ToReturned())); |
93 | 92 |
94 EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024)) | 93 EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024)) |
95 .WillOnce(Return(NPObjectPointer<BaseNPObject>())); | 94 .WillOnce(Return(NPObjectPointer<NPObject>())); |
96 | 95 |
97 EXPECT_FALSE(command_buffer_object_->Initialize(1024)); | 96 EXPECT_FALSE(command_buffer_object_->Initialize(1024)); |
98 EXPECT_EQ(NPObjectPointer<NPObject>(), command_buffer_object_->GetBuffer()); | 97 EXPECT_EQ(NPObjectPointer<NPObject>(), command_buffer_object_->GetBuffer()); |
99 } | 98 } |
100 | 99 |
101 TEST_F(CommandBufferTest, InitializeFailsIfCannotMapSharedMemory) { | 100 TEST_F(CommandBufferTest, InitializeFailsIfCannotMapSharedMemory) { |
102 EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL)) | 101 EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL)) |
103 .WillOnce(Return(window_object_.ToReturned())); | 102 .WillOnce(Return(window_object_.ToReturned())); |
104 | 103 |
105 NPObjectPointer<BaseNPObject> expected_buffer = | 104 NPObjectPointer<NPObject> expected_buffer = |
106 NPCreateObject<BaseNPObject>(NULL); | 105 NPCreateObject<MockNPObject>(NULL); |
107 | 106 |
108 EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024)) | 107 EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024)) |
109 .WillOnce(Return(expected_buffer)); | 108 .WillOnce(Return(expected_buffer)); |
110 | 109 |
111 EXPECT_CALL(mock_browser_, MapSharedMemory(NULL, | 110 EXPECT_CALL(mock_browser_, MapSharedMemory(NULL, |
112 expected_buffer.Get(), | 111 expected_buffer.Get(), |
113 1024, | 112 1024, |
114 false)) | 113 false)) |
115 .WillOnce(Return(static_cast<NPSharedMemory*>(NULL))); | 114 .WillOnce(Return(static_cast<NPSharedMemory*>(NULL))); |
116 | 115 |
117 EXPECT_FALSE(command_buffer_object_->Initialize(1024)); | 116 EXPECT_FALSE(command_buffer_object_->Initialize(1024)); |
118 EXPECT_EQ(NPObjectPointer<NPObject>(), command_buffer_object_->GetBuffer()); | 117 EXPECT_EQ(NPObjectPointer<NPObject>(), command_buffer_object_->GetBuffer()); |
119 } | 118 } |
120 } // namespace gpu_plugin | 119 } // namespace gpu_plugin |
121 } // namespace o3d | 120 } // namespace o3d |
OLD | NEW |