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/common/cmd_buffer_common.h"
13 #include "gpu/command_buffer/common/command_buffer.h"
14 #include "gpu/command_buffer/common/gpu_control.h"
15 #include "gpu/command_buffer/common/gpu_memory_allocation.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h"
21 class CommandBufferHelper
;
23 class MockCommandBufferBase
: public CommandBuffer
{
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
GetState() OVERRIDE
;
33 virtual State
GetLastState() OVERRIDE
;
34 virtual int32
GetLastToken() OVERRIDE
;
35 virtual State
FlushSync(int32 put_offset
, int32 last_known_get
) OVERRIDE
;
36 virtual void SetGetBuffer(int transfer_buffer_id
) OVERRIDE
;
37 virtual void SetGetOffset(int32 get_offset
) OVERRIDE
;
38 virtual Buffer
CreateTransferBuffer(size_t size
, int32
* id
) OVERRIDE
;
39 virtual Buffer
GetTransferBuffer(int32 id
) OVERRIDE
;
40 virtual void SetToken(int32 token
) OVERRIDE
;
41 virtual void SetParseError(error::Error error
) OVERRIDE
;
42 virtual void SetContextLostReason(error::ContextLostReason reason
) OVERRIDE
;
44 // Get's the Id of the next transfer buffer that will be returned
45 // by CreateTransferBuffer. This is useful for testing expected ids.
46 int32
GetNextFreeTransferBufferId();
48 void FlushHelper(int32 put_offset
);
49 void DestroyTransferBufferHelper(int32 id
);
51 virtual void OnFlush() = 0;
54 scoped_ptr
<int8
[]> transfer_buffers_
[kMaxTransferBuffers
];
55 Buffer transfer_buffer_buffers_
[kMaxTransferBuffers
];
56 CommandBufferEntry
* ring_buffer_
;
57 Buffer ring_buffer_buffer_
;
61 class MockClientCommandBuffer
: public MockCommandBufferBase
{
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
{
77 MockClientCommandBufferMockFlush();
78 virtual ~MockClientCommandBufferMockFlush();
80 MOCK_METHOD1(Flush
, void(int32 put_offset
));
82 void DelegateToFake();
85 class MockClientGpuControl
: public GpuControl
{
87 MockClientGpuControl();
88 virtual ~MockClientGpuControl();
90 MOCK_METHOD0(GetCapabilities
, Capabilities());
91 MOCK_METHOD4(CreateGpuMemoryBuffer
,
92 gfx::GpuMemoryBuffer
*(size_t width
,
94 unsigned internalformat
,
96 MOCK_METHOD1(DestroyGpuMemoryBuffer
, void(int32 id
));
97 MOCK_METHOD2(GenerateMailboxNames
, bool(unsigned num
,
98 std::vector
<gpu::Mailbox
>* names
));
99 MOCK_METHOD0(InsertSyncPoint
, uint32());
100 MOCK_METHOD2(SignalSyncPoint
, void(uint32 id
,
101 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(SendManagedMemoryStats
,
107 void(const ManagedMemoryStats
& stats
));
108 MOCK_METHOD1(CreateStreamTexture
, uint32(uint32
));
111 DISALLOW_COPY_AND_ASSIGN(MockClientGpuControl
);
116 #endif // GPU_COMMAND_BUFFER_CLIENT_CLIENT_TEST_HELPER_H_