OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "gpu/command_buffer/common/cmd_buffer_common.h" |
6 #include "gpu/command_buffer/service/command_buffer_service.h" | 7 #include "gpu/command_buffer/service/command_buffer_service.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
9 | 10 |
10 using base::SharedMemory; | 11 using base::SharedMemory; |
11 using testing::_; | 12 using testing::_; |
12 using testing::DoAll; | 13 using testing::DoAll; |
13 using testing::Return; | 14 using testing::Return; |
14 using testing::SetArgumentPointee; | 15 using testing::SetArgumentPointee; |
15 using testing::StrictMock; | 16 using testing::StrictMock; |
16 | 17 |
17 namespace gpu { | 18 namespace gpu { |
18 | 19 |
19 class CommandBufferServiceTest : public testing::Test { | 20 class CommandBufferServiceTest : public testing::Test { |
20 protected: | 21 protected: |
21 virtual void SetUp() { | 22 virtual void SetUp() { |
22 command_buffer_.reset(new CommandBufferService); | 23 command_buffer_.reset(new CommandBufferService); |
23 } | 24 } |
24 | 25 |
25 scoped_ptr<CommandBufferService> command_buffer_; | 26 scoped_ptr<CommandBufferService> command_buffer_; |
26 }; | 27 }; |
27 | 28 |
28 TEST_F(CommandBufferServiceTest, NullRingBufferByDefault) { | 29 TEST_F(CommandBufferServiceTest, NullRingBufferByDefault) { |
29 EXPECT_TRUE(NULL == command_buffer_->GetRingBuffer()); | 30 EXPECT_TRUE(NULL == command_buffer_->GetRingBuffer().ptr); |
30 } | 31 } |
31 | 32 |
32 TEST_F(CommandBufferServiceTest, InitializesCommandBuffer) { | 33 TEST_F(CommandBufferServiceTest, InitializesCommandBuffer) { |
33 base::SharedMemory* ring_buffer = command_buffer_->Initialize(1024); | 34 EXPECT_TRUE(command_buffer_->Initialize(1024)); |
34 EXPECT_TRUE(NULL != ring_buffer); | 35 EXPECT_TRUE(NULL != command_buffer_->GetRingBuffer().ptr); |
35 EXPECT_EQ(ring_buffer, command_buffer_->GetRingBuffer()); | 36 EXPECT_EQ(1024, command_buffer_->GetSize()); |
36 EXPECT_GT(command_buffer_->GetSize(), 0); | 37 EXPECT_EQ(1024 * sizeof(CommandBufferEntry), |
| 38 command_buffer_->GetRingBuffer().size); |
| 39 } |
| 40 |
| 41 TEST_F(CommandBufferServiceTest, InitializationSizeIsInEntriesNotBytes) { |
| 42 EXPECT_TRUE(command_buffer_->Initialize(1024)); |
| 43 EXPECT_TRUE(NULL != command_buffer_->GetRingBuffer().ptr); |
| 44 EXPECT_GE(1024 * sizeof(CommandBufferEntry), |
| 45 command_buffer_->GetRingBuffer().size); |
37 } | 46 } |
38 | 47 |
39 TEST_F(CommandBufferServiceTest, InitializeFailsSecondTime) { | 48 TEST_F(CommandBufferServiceTest, InitializeFailsSecondTime) { |
40 SharedMemory* ring_buffer = new SharedMemory; | 49 SharedMemory* ring_buffer = new SharedMemory; |
41 EXPECT_TRUE(NULL != command_buffer_->Initialize(1024)); | 50 EXPECT_TRUE(command_buffer_->Initialize(1024)); |
42 EXPECT_TRUE(NULL == command_buffer_->Initialize(1024)); | 51 EXPECT_FALSE(command_buffer_->Initialize(1024)); |
43 } | 52 } |
44 | 53 |
45 TEST_F(CommandBufferServiceTest, GetAndPutOffsetsDefaultToZero) { | 54 TEST_F(CommandBufferServiceTest, GetAndPutOffsetsDefaultToZero) { |
46 EXPECT_EQ(0, command_buffer_->GetGetOffset()); | 55 EXPECT_EQ(0, command_buffer_->GetGetOffset()); |
47 EXPECT_EQ(0, command_buffer_->GetPutOffset()); | 56 EXPECT_EQ(0, command_buffer_->GetPutOffset()); |
48 } | 57 } |
49 | 58 |
50 class MockCallback : public CallbackRunner<Tuple0> { | 59 class MockCallback : public CallbackRunner<Tuple0> { |
51 public: | 60 public: |
52 MOCK_METHOD1(RunWithParams, void(const Tuple0&)); | 61 MOCK_METHOD1(RunWithParams, void(const Tuple0&)); |
(...skipping 17 matching lines...) Expand all Loading... |
70 command_buffer_->SetGetOffset(2); | 79 command_buffer_->SetGetOffset(2); |
71 EXPECT_EQ(2, command_buffer_->GetGetOffset()); | 80 EXPECT_EQ(2, command_buffer_->GetGetOffset()); |
72 EXPECT_CALL(*put_offset_change_callback, RunWithParams(_)); | 81 EXPECT_CALL(*put_offset_change_callback, RunWithParams(_)); |
73 EXPECT_EQ(2, command_buffer_->SyncOffsets(6)); | 82 EXPECT_EQ(2, command_buffer_->SyncOffsets(6)); |
74 | 83 |
75 EXPECT_EQ(-1, command_buffer_->SyncOffsets(-1)); | 84 EXPECT_EQ(-1, command_buffer_->SyncOffsets(-1)); |
76 EXPECT_EQ(-1, command_buffer_->SyncOffsets(1024)); | 85 EXPECT_EQ(-1, command_buffer_->SyncOffsets(1024)); |
77 } | 86 } |
78 | 87 |
79 TEST_F(CommandBufferServiceTest, ZeroHandleMapsToNull) { | 88 TEST_F(CommandBufferServiceTest, ZeroHandleMapsToNull) { |
80 EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(0)); | 89 EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(0).ptr); |
81 } | 90 } |
82 | 91 |
83 TEST_F(CommandBufferServiceTest, NegativeHandleMapsToNull) { | 92 TEST_F(CommandBufferServiceTest, NegativeHandleMapsToNull) { |
84 EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(-1)); | 93 EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(-1).ptr); |
85 } | 94 } |
86 | 95 |
87 TEST_F(CommandBufferServiceTest, OutOfRangeHandleMapsToNull) { | 96 TEST_F(CommandBufferServiceTest, OutOfRangeHandleMapsToNull) { |
88 EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(1)); | 97 EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(1).ptr); |
89 } | 98 } |
90 | 99 |
91 TEST_F(CommandBufferServiceTest, CanCreateTransferBuffers) { | 100 TEST_F(CommandBufferServiceTest, CanCreateTransferBuffers) { |
92 int32 handle = command_buffer_->CreateTransferBuffer(1024); | 101 int32 handle = command_buffer_->CreateTransferBuffer(1024); |
93 EXPECT_EQ(1, handle); | 102 EXPECT_EQ(1, handle); |
94 SharedMemory* buffer = command_buffer_->GetTransferBuffer(handle); | 103 Buffer buffer = command_buffer_->GetTransferBuffer(handle); |
95 ASSERT_TRUE(NULL != buffer); | 104 ASSERT_TRUE(NULL != buffer.ptr); |
96 EXPECT_EQ(1024, buffer->max_size()); | 105 EXPECT_EQ(1024, buffer.size); |
97 } | 106 } |
98 | 107 |
99 TEST_F(CommandBufferServiceTest, CreateTransferBufferReturnsDistinctHandles) { | 108 TEST_F(CommandBufferServiceTest, CreateTransferBufferReturnsDistinctHandles) { |
100 EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); | 109 EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); |
101 } | 110 } |
102 | 111 |
103 TEST_F(CommandBufferServiceTest, | 112 TEST_F(CommandBufferServiceTest, |
104 CreateTransferBufferReusesUnregisteredHandles) { | 113 CreateTransferBufferReusesUnregisteredHandles) { |
105 EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); | 114 EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); |
106 EXPECT_EQ(2, command_buffer_->CreateTransferBuffer(1024)); | 115 EXPECT_EQ(2, command_buffer_->CreateTransferBuffer(1024)); |
107 command_buffer_->DestroyTransferBuffer(1); | 116 command_buffer_->DestroyTransferBuffer(1); |
108 EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); | 117 EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); |
109 EXPECT_EQ(3, command_buffer_->CreateTransferBuffer(1024)); | 118 EXPECT_EQ(3, command_buffer_->CreateTransferBuffer(1024)); |
110 } | 119 } |
111 | 120 |
112 TEST_F(CommandBufferServiceTest, CannotUnregisterHandleZero) { | 121 TEST_F(CommandBufferServiceTest, CannotUnregisterHandleZero) { |
113 command_buffer_->DestroyTransferBuffer(0); | 122 command_buffer_->DestroyTransferBuffer(0); |
114 EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(0)); | 123 EXPECT_TRUE(NULL == command_buffer_->GetTransferBuffer(0).ptr); |
115 EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); | 124 EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); |
116 } | 125 } |
117 | 126 |
118 TEST_F(CommandBufferServiceTest, CannotUnregisterNegativeHandles) { | 127 TEST_F(CommandBufferServiceTest, CannotUnregisterNegativeHandles) { |
119 command_buffer_->DestroyTransferBuffer(-1); | 128 command_buffer_->DestroyTransferBuffer(-1); |
120 EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); | 129 EXPECT_EQ(1, command_buffer_->CreateTransferBuffer(1024)); |
121 } | 130 } |
122 | 131 |
123 TEST_F(CommandBufferServiceTest, CannotUnregisterUnregisteredHandles) { | 132 TEST_F(CommandBufferServiceTest, CannotUnregisterUnregisteredHandles) { |
124 command_buffer_->DestroyTransferBuffer(1); | 133 command_buffer_->DestroyTransferBuffer(1); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 TEST_F(CommandBufferServiceTest, DefaultErrorStatusIsFalse) { | 174 TEST_F(CommandBufferServiceTest, DefaultErrorStatusIsFalse) { |
166 EXPECT_FALSE(command_buffer_->GetErrorStatus()); | 175 EXPECT_FALSE(command_buffer_->GetErrorStatus()); |
167 } | 176 } |
168 | 177 |
169 TEST_F(CommandBufferServiceTest, CanRaiseErrorStatus) { | 178 TEST_F(CommandBufferServiceTest, CanRaiseErrorStatus) { |
170 command_buffer_->RaiseErrorStatus(); | 179 command_buffer_->RaiseErrorStatus(); |
171 EXPECT_TRUE(command_buffer_->GetErrorStatus()); | 180 EXPECT_TRUE(command_buffer_->GetErrorStatus()); |
172 } | 181 } |
173 | 182 |
174 } // namespace gpu | 183 } // namespace gpu |
OLD | NEW |