Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / gpu / command_buffer / client / client_test_helper.cc
blob258e8217a846ababc37fbf3396832242c51897b9
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() : put_offset_(0) {
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 = 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_.token = 10000; // All token checks in the tests should pass.
54 // Get's the Id of the next transfer buffer that will be returned
55 // by CreateTransferBuffer. This is useful for testing expected ids.
56 int32 MockCommandBufferBase::GetNextFreeTransferBufferId() {
57 for (size_t ii = 0; ii < arraysize(transfer_buffer_buffers_); ++ii) {
58 if (!transfer_buffer_buffers_[ii].get()) {
59 return kTransferBufferBaseId + ii;
62 return -1;
65 scoped_refptr<gpu::Buffer> MockCommandBufferBase::CreateTransferBuffer(
66 size_t size,
67 int32* id) {
68 *id = GetNextFreeTransferBufferId();
69 if (*id >= 0) {
70 int32 ndx = *id - kTransferBufferBaseId;
71 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory());
72 shared_memory->CreateAndMapAnonymous(size);
73 transfer_buffer_buffers_[ndx] =
74 MakeBufferFromSharedMemory(shared_memory.Pass(), size);
76 return GetTransferBuffer(*id);
79 void MockCommandBufferBase::DestroyTransferBufferHelper(int32 id) {
80 DCHECK_GE(id, kTransferBufferBaseId);
81 DCHECK_LT(id, kTransferBufferBaseId + kMaxTransferBuffers);
82 id -= kTransferBufferBaseId;
83 transfer_buffer_buffers_[id] = NULL;
86 scoped_refptr<Buffer> MockCommandBufferBase::GetTransferBuffer(int32 id) {
87 DCHECK_GE(id, kTransferBufferBaseId);
88 DCHECK_LT(id, kTransferBufferBaseId + kMaxTransferBuffers);
89 return transfer_buffer_buffers_[id - kTransferBufferBaseId];
92 void MockCommandBufferBase::FlushHelper(int32 put_offset) {
93 put_offset_ = put_offset;
96 void MockCommandBufferBase::SetToken(int32 token) {
97 NOTREACHED();
98 state_.token = token;
101 void MockCommandBufferBase::SetParseError(error::Error error) {
102 NOTREACHED();
103 state_.error = error;
106 void MockCommandBufferBase::SetContextLostReason(
107 error::ContextLostReason reason) {
108 NOTREACHED();
109 state_.context_lost_reason = reason;
112 int32 MockCommandBufferBase::GetPutOffset() {
113 return put_offset_;
116 // GCC requires these declarations, but MSVC requires they not be present
117 #ifndef _MSC_VER
118 const int32 MockCommandBufferBase::kTransferBufferBaseId;
119 const int32 MockCommandBufferBase::kMaxTransferBuffers;
120 #endif
122 MockClientCommandBuffer::MockClientCommandBuffer() {
123 DelegateToFake();
126 MockClientCommandBuffer::~MockClientCommandBuffer() {
129 void MockClientCommandBuffer::Flush(int32 put_offset) {
130 FlushHelper(put_offset);
133 void MockClientCommandBuffer::OrderingBarrier(int32 put_offset) {
134 FlushHelper(put_offset);
137 void MockClientCommandBuffer::DelegateToFake() {
138 ON_CALL(*this, DestroyTransferBuffer(_))
139 .WillByDefault(Invoke(
140 this, &MockCommandBufferBase::DestroyTransferBufferHelper));
143 MockClientCommandBufferMockFlush::MockClientCommandBufferMockFlush() {
144 DelegateToFake();
147 MockClientCommandBufferMockFlush::~MockClientCommandBufferMockFlush() {
150 void MockClientCommandBufferMockFlush::DelegateToFake() {
151 MockClientCommandBuffer::DelegateToFake();
152 ON_CALL(*this, Flush(_))
153 .WillByDefault(Invoke(
154 this, &MockCommandBufferBase::FlushHelper));
157 MockClientGpuControl::MockClientGpuControl() {
160 MockClientGpuControl::~MockClientGpuControl() {
163 } // namespace gpu