| 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/dynamic_np_object.h" | 6 #include "o3d/gpu_plugin/np_utils/dynamic_np_object.h" |
| 7 #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" | 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 "o3d/gpu_plugin/system_services/shared_memory_mock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 12 | 13 |
| 13 using testing::_; | 14 using testing::_; |
| 14 using testing::DoAll; | 15 using testing::DoAll; |
| 15 using testing::Return; | 16 using testing::Return; |
| 16 using testing::SetArgumentPointee; | 17 using testing::SetArgumentPointee; |
| 17 using testing::StrictMock; | 18 using testing::StrictMock; |
| 18 | 19 |
| 19 namespace o3d { | 20 namespace o3d { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 49 } | 50 } |
| 50 | 51 |
| 51 MockNPBrowser mock_browser_; | 52 MockNPBrowser mock_browser_; |
| 52 NPObjectPointer<CommandBuffer> command_buffer_object_; | 53 NPObjectPointer<CommandBuffer> command_buffer_object_; |
| 53 NPObjectPointer<DynamicNPObject> window_object_; | 54 NPObjectPointer<DynamicNPObject> window_object_; |
| 54 NPObjectPointer<DynamicNPObject> chromium_object_; | 55 NPObjectPointer<DynamicNPObject> chromium_object_; |
| 55 NPObjectPointer<MockSystemNPObject> system_object_; | 56 NPObjectPointer<MockSystemNPObject> system_object_; |
| 56 }; | 57 }; |
| 57 | 58 |
| 58 TEST_F(CommandBufferTest, TestBehaviorWhileUninitialized) { | 59 TEST_F(CommandBufferTest, TestBehaviorWhileUninitialized) { |
| 59 EXPECT_EQ(NPObjectPointer<NPObject>(), command_buffer_object_->GetBuffer()); | 60 EXPECT_EQ(NPObjectPointer<NPObject>(), |
| 61 command_buffer_object_->GetSharedMemory()); |
| 60 EXPECT_EQ(0, command_buffer_object_->GetGetOffset()); | 62 EXPECT_EQ(0, command_buffer_object_->GetGetOffset()); |
| 61 } | 63 } |
| 62 | 64 |
| 63 TEST_F(CommandBufferTest, InitializesCommandBuffer) { | 65 TEST_F(CommandBufferTest, InitializesCommandBuffer) { |
| 64 EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL)) | 66 EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL)) |
| 65 .WillOnce(Return(window_object_.ToReturned())); | 67 .WillOnce(Return(window_object_.ToReturned())); |
| 66 | 68 |
| 67 NPObjectPointer<NPObject> expected_buffer = | 69 NPObjectPointer<MockSharedMemory> expected_shared_memory = |
| 68 NPCreateObject<MockNPObject>(NULL); | 70 NPCreateObject<StrictMock<MockSharedMemory> >(NULL); |
| 69 | 71 |
| 70 EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024)) | 72 EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024)) |
| 71 .WillOnce(Return(expected_buffer)); | 73 .WillOnce(Return(expected_shared_memory)); |
| 72 | 74 |
| 73 NPSharedMemory shared_memory; | 75 EXPECT_CALL(*expected_shared_memory.Get(), Map()) |
| 74 | 76 .WillOnce(Return(true)); |
| 75 EXPECT_CALL(mock_browser_, MapSharedMemory(NULL, | |
| 76 expected_buffer.Get(), | |
| 77 1024, | |
| 78 false)) | |
| 79 .WillOnce(Return(&shared_memory)); | |
| 80 | 77 |
| 81 EXPECT_TRUE(command_buffer_object_->Initialize(1024)); | 78 EXPECT_TRUE(command_buffer_object_->Initialize(1024)); |
| 82 EXPECT_EQ(expected_buffer, command_buffer_object_->GetBuffer()); | 79 EXPECT_EQ(expected_shared_memory, command_buffer_object_->GetSharedMemory()); |
| 83 | 80 |
| 84 // Cannot reinitialize. | 81 // Cannot reinitialize. |
| 85 EXPECT_FALSE(command_buffer_object_->Initialize(1024)); | 82 EXPECT_FALSE(command_buffer_object_->Initialize(1024)); |
| 86 EXPECT_EQ(expected_buffer, command_buffer_object_->GetBuffer()); | 83 EXPECT_EQ(expected_shared_memory, command_buffer_object_->GetSharedMemory()); |
| 87 } | 84 } |
| 88 | 85 |
| 89 TEST_F(CommandBufferTest, InitializeFailsIfCannotCreateSharedMemory) { | 86 TEST_F(CommandBufferTest, InitializeFailsIfCannotCreateSharedMemory) { |
| 90 EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL)) | 87 EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL)) |
| 91 .WillOnce(Return(window_object_.ToReturned())); | 88 .WillOnce(Return(window_object_.ToReturned())); |
| 92 | 89 |
| 93 EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024)) | 90 EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024)) |
| 94 .WillOnce(Return(NPObjectPointer<NPObject>())); | 91 .WillOnce(Return(NPObjectPointer<NPObject>())); |
| 95 | 92 |
| 96 EXPECT_FALSE(command_buffer_object_->Initialize(1024)); | 93 EXPECT_FALSE(command_buffer_object_->Initialize(1024)); |
| 97 EXPECT_EQ(NPObjectPointer<NPObject>(), command_buffer_object_->GetBuffer()); | 94 EXPECT_EQ(NPObjectPointer<NPObject>(), |
| 95 command_buffer_object_->GetSharedMemory()); |
| 98 } | 96 } |
| 99 | 97 |
| 100 TEST_F(CommandBufferTest, InitializeFailsIfCannotMapSharedMemory) { | 98 TEST_F(CommandBufferTest, InitializeFailsIfCannotMapSharedMemory) { |
| 101 EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL)) | 99 EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL)) |
| 102 .WillOnce(Return(window_object_.ToReturned())); | 100 .WillOnce(Return(window_object_.ToReturned())); |
| 103 | 101 |
| 104 NPObjectPointer<NPObject> expected_buffer = | 102 NPObjectPointer<MockSharedMemory> expected_shared_memory = |
| 105 NPCreateObject<MockNPObject>(NULL); | 103 NPCreateObject<StrictMock<MockSharedMemory> >(NULL); |
| 106 | 104 |
| 107 EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024)) | 105 EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024)) |
| 108 .WillOnce(Return(expected_buffer)); | 106 .WillOnce(Return(expected_shared_memory)); |
| 109 | 107 |
| 110 EXPECT_CALL(mock_browser_, MapSharedMemory(NULL, | 108 EXPECT_CALL(*expected_shared_memory.Get(), Map()) |
| 111 expected_buffer.Get(), | 109 .WillOnce(Return(false)); |
| 112 1024, | |
| 113 false)) | |
| 114 .WillOnce(Return(static_cast<NPSharedMemory*>(NULL))); | |
| 115 | 110 |
| 116 EXPECT_FALSE(command_buffer_object_->Initialize(1024)); | 111 EXPECT_FALSE(command_buffer_object_->Initialize(1024)); |
| 117 EXPECT_EQ(NPObjectPointer<NPObject>(), command_buffer_object_->GetBuffer()); | 112 EXPECT_EQ(NPObjectPointer<NPObject>(), |
| 113 command_buffer_object_->GetSharedMemory()); |
| 118 } | 114 } |
| 119 } // namespace gpu_plugin | 115 } // namespace gpu_plugin |
| 120 } // namespace o3d | 116 } // namespace o3d |
| OLD | NEW |