Handle account removal correctly on all platforms.
[chromium-blink-merge.git] / gpu / command_buffer / client / client_test_helper.h
blob15f9a098797c9a0200fd594aeba183b1c5abc035
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 // Helper classes for implementing gpu client side unit tests.
7 #ifndef GPU_COMMAND_BUFFER_CLIENT_CLIENT_TEST_HELPER_H_
8 #define GPU_COMMAND_BUFFER_CLIENT_CLIENT_TEST_HELPER_H_
10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "gpu/command_buffer/client/gpu_control.h"
13 #include "gpu/command_buffer/common/cmd_buffer_common.h"
14 #include "gpu/command_buffer/common/gpu_memory_allocation.h"
15 #include "gpu/command_buffer/service/command_buffer_service.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h"
19 namespace gpu {
21 class CommandBufferHelper;
23 class MockCommandBufferBase : public CommandBufferServiceBase {
24 public:
25 static const int32 kTransferBufferBaseId = 0x123;
26 static const int32 kMaxTransferBuffers = 6;
28 MockCommandBufferBase();
29 virtual ~MockCommandBufferBase();
31 virtual bool Initialize() OVERRIDE;
32 virtual State GetLastState() OVERRIDE;
33 virtual int32 GetLastToken() OVERRIDE;
34 virtual void WaitForTokenInRange(int32 start, int32 end) OVERRIDE;
35 virtual void WaitForGetOffsetInRange(int32 start, int32 end) OVERRIDE;
36 virtual void SetGetBuffer(int transfer_buffer_id) OVERRIDE;
37 virtual void SetGetOffset(int32 get_offset) OVERRIDE;
38 virtual scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size,
39 int32* id) OVERRIDE;
40 virtual scoped_refptr<gpu::Buffer> GetTransferBuffer(int32 id) OVERRIDE;
41 virtual void SetToken(int32 token) OVERRIDE;
42 virtual void SetParseError(error::Error error) OVERRIDE;
43 virtual void SetContextLostReason(error::ContextLostReason reason) OVERRIDE;
45 // Get's the Id of the next transfer buffer that will be returned
46 // by CreateTransferBuffer. This is useful for testing expected ids.
47 int32 GetNextFreeTransferBufferId();
49 void FlushHelper(int32 put_offset);
50 void DestroyTransferBufferHelper(int32 id);
52 virtual void OnFlush() = 0;
54 private:
55 scoped_refptr<Buffer> transfer_buffer_buffers_[kMaxTransferBuffers];
56 CommandBufferEntry* ring_buffer_;
57 scoped_refptr<Buffer> ring_buffer_buffer_;
58 State state_;
61 class MockClientCommandBuffer : public MockCommandBufferBase {
62 public:
63 MockClientCommandBuffer();
64 virtual ~MockClientCommandBuffer();
66 // This is so we can use all the gmock functions when Flush is called.
67 MOCK_METHOD0(OnFlush, void());
68 MOCK_METHOD1(DestroyTransferBuffer, void(int32 id));
70 virtual void Flush(int32 put_offset) OVERRIDE;
72 void DelegateToFake();
75 class MockClientCommandBufferMockFlush : public MockClientCommandBuffer {
76 public:
77 MockClientCommandBufferMockFlush();
78 virtual ~MockClientCommandBufferMockFlush();
80 MOCK_METHOD1(Flush, void(int32 put_offset));
82 void DelegateToFake();
85 class MockClientGpuControl : public GpuControl {
86 public:
87 MockClientGpuControl();
88 virtual ~MockClientGpuControl();
90 MOCK_METHOD0(GetCapabilities, Capabilities());
91 MOCK_METHOD5(CreateGpuMemoryBuffer,
92 gfx::GpuMemoryBuffer*(size_t width,
93 size_t height,
94 unsigned internalformat,
95 unsigned usage,
96 int32* id));
97 MOCK_METHOD1(DestroyGpuMemoryBuffer, void(int32 id));
98 MOCK_METHOD0(InsertSyncPoint, uint32());
99 MOCK_METHOD0(InsertFutureSyncPoint, uint32());
100 MOCK_METHOD1(RetireSyncPoint, void(uint32 id));
101 MOCK_METHOD2(SignalSyncPoint, void(uint32 id, const base::Closure& callback));
102 MOCK_METHOD1(Echo, void(const base::Closure& callback));
104 MOCK_METHOD2(SignalQuery, void(uint32 query, const base::Closure& callback));
105 MOCK_METHOD1(SetSurfaceVisible, void(bool visible));
106 MOCK_METHOD1(CreateStreamTexture, uint32(uint32));
108 private:
109 DISALLOW_COPY_AND_ASSIGN(MockClientGpuControl);
112 } // namespace gpu
114 #endif // GPU_COMMAND_BUFFER_CLIENT_CLIENT_TEST_HELPER_H_