Handle account removal correctly on all platforms.
[chromium-blink-merge.git] / gpu / command_buffer / client / client_test_helper.cc
blob8c633efebe14435bcfd39e2d88dea1c9f42bb3df
1 // Copyright (c) 2012 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.
5 // Tests for GLES2Implementation.
7 #include "gpu/command_buffer/client/client_test_helper.h"
9 #include "gpu/command_buffer/common/command_buffer.h"
10 #include "gpu/command_buffer/client/cmd_buffer_helper.h"
11 #include "testing/gmock/include/gmock/gmock.h"
13 using ::testing::_;
14 using ::testing::Invoke;
16 namespace gpu {
18 MockCommandBufferBase::MockCommandBufferBase() {
21 MockCommandBufferBase::~MockCommandBufferBase() {
24 bool MockCommandBufferBase::Initialize() {
25 return true;
28 CommandBuffer::State MockCommandBufferBase::GetLastState() {
29 return state_;
32 int32 MockCommandBufferBase::GetLastToken() {
33 return state_.token;
36 void MockCommandBufferBase::SetGetOffset(int32 get_offset) {
37 state_.get_offset = get_offset;
40 void MockCommandBufferBase::WaitForTokenInRange(int32 start, int32 end) {}
42 void MockCommandBufferBase::WaitForGetOffsetInRange(int32 start, int32 end) {
43 state_.get_offset = state_.put_offset;
44 OnFlush();
47 void MockCommandBufferBase::SetGetBuffer(int transfer_buffer_id) {
48 ring_buffer_buffer_ = GetTransferBuffer(transfer_buffer_id);
49 ring_buffer_ =
50 static_cast<CommandBufferEntry*>(ring_buffer_buffer_->memory());
51 state_.num_entries = ring_buffer_buffer_->size() / sizeof(ring_buffer_[0]);
52 state_.token = 10000; // All token checks in the tests should pass.
55 // Get's the Id of the next transfer buffer that will be returned
56 // by CreateTransferBuffer. This is useful for testing expected ids.
57 int32 MockCommandBufferBase::GetNextFreeTransferBufferId() {
58 for (size_t ii = 0; ii < arraysize(transfer_buffer_buffers_); ++ii) {
59 if (!transfer_buffer_buffers_[ii].get()) {
60 return kTransferBufferBaseId + ii;
63 return -1;
66 scoped_refptr<gpu::Buffer> MockCommandBufferBase::CreateTransferBuffer(
67 size_t size,
68 int32* id) {
69 *id = GetNextFreeTransferBufferId();
70 if (*id >= 0) {
71 int32 ndx = *id - kTransferBufferBaseId;
72 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory());
73 shared_memory->CreateAndMapAnonymous(size);
74 transfer_buffer_buffers_[ndx] =
75 MakeBufferFromSharedMemory(shared_memory.Pass(), size);
77 return GetTransferBuffer(*id);
80 void MockCommandBufferBase::DestroyTransferBufferHelper(int32 id) {
81 DCHECK_GE(id, kTransferBufferBaseId);
82 DCHECK_LT(id, kTransferBufferBaseId + kMaxTransferBuffers);
83 id -= kTransferBufferBaseId;
84 transfer_buffer_buffers_[id] = NULL;
87 scoped_refptr<Buffer> MockCommandBufferBase::GetTransferBuffer(int32 id) {
88 DCHECK_GE(id, kTransferBufferBaseId);
89 DCHECK_LT(id, kTransferBufferBaseId + kMaxTransferBuffers);
90 return transfer_buffer_buffers_[id - kTransferBufferBaseId];
93 void MockCommandBufferBase::FlushHelper(int32 put_offset) {
94 state_.put_offset = put_offset;
97 void MockCommandBufferBase::SetToken(int32 token) {
98 NOTREACHED();
99 state_.token = token;
102 void MockCommandBufferBase::SetParseError(error::Error error) {
103 NOTREACHED();
104 state_.error = error;
107 void MockCommandBufferBase::SetContextLostReason(
108 error::ContextLostReason reason) {
109 NOTREACHED();
110 state_.context_lost_reason = reason;
113 // GCC requires these declarations, but MSVC requires they not be present
114 #ifndef _MSC_VER
115 const int32 MockCommandBufferBase::kTransferBufferBaseId;
116 const int32 MockCommandBufferBase::kMaxTransferBuffers;
117 #endif
119 MockClientCommandBuffer::MockClientCommandBuffer() {
120 DelegateToFake();
123 MockClientCommandBuffer::~MockClientCommandBuffer() {
126 void MockClientCommandBuffer::Flush(int32 put_offset) {
127 FlushHelper(put_offset);
130 void MockClientCommandBuffer::DelegateToFake() {
131 ON_CALL(*this, DestroyTransferBuffer(_))
132 .WillByDefault(Invoke(
133 this, &MockCommandBufferBase::DestroyTransferBufferHelper));
136 MockClientCommandBufferMockFlush::MockClientCommandBufferMockFlush() {
137 DelegateToFake();
140 MockClientCommandBufferMockFlush::~MockClientCommandBufferMockFlush() {
143 void MockClientCommandBufferMockFlush::DelegateToFake() {
144 MockClientCommandBuffer::DelegateToFake();
145 ON_CALL(*this, Flush(_))
146 .WillByDefault(Invoke(
147 this, &MockCommandBufferBase::FlushHelper));
150 MockClientGpuControl::MockClientGpuControl() {
153 MockClientGpuControl::~MockClientGpuControl() {
156 } // namespace gpu