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 // This file contains definitions for mock objects, used for testing.
7 // TODO(apatrick): This file "manually" defines some mock objects. Using gMock
8 // would be definitely preferable, unfortunately it doesn't work on Windows yet.
10 #ifndef GPU_COMMAND_BUFFER_SERVICE_MOCKS_H_
11 #define GPU_COMMAND_BUFFER_SERVICE_MOCKS_H_
16 #include "base/logging.h"
17 #include "gpu/command_buffer/service/cmd_parser.h"
18 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
19 #include "gpu/command_buffer/service/memory_tracking.h"
20 #include "gpu/command_buffer/service/program_cache.h"
21 #include "gpu/command_buffer/service/shader_translator.h"
22 #include "testing/gmock/include/gmock/gmock.h"
26 // Mocks an AsyncAPIInterface, using GMock.
27 class AsyncAPIMock
: public AsyncAPIInterface
{
30 virtual ~AsyncAPIMock();
32 // Predicate that matches args passed to DoCommand, by looking at the values.
35 IsArgs(unsigned int arg_count
, const void* args
)
36 : arg_count_(arg_count
),
37 args_(static_cast<CommandBufferEntry
*>(const_cast<void*>(args
))) {
40 bool operator() (const void* _args
) const {
41 const CommandBufferEntry
* args
=
42 static_cast<const CommandBufferEntry
*>(_args
) + 1;
43 for (unsigned int i
= 0; i
< arg_count_
; ++i
) {
44 if (args
[i
].value_uint32
!= args_
[i
].value_uint32
) return false;
50 unsigned int arg_count_
;
51 CommandBufferEntry
*args_
;
54 MOCK_METHOD3(DoCommand
, error::Error(
56 unsigned int arg_count
,
57 const void* cmd_data
));
59 const char* GetCommandName(unsigned int command_id
) const {
63 // Sets the engine, to forward SetToken commands to it.
64 void set_engine(CommandBufferEngine
*engine
) { engine_
= engine
; }
66 // Forwards the SetToken commands to the engine.
67 void SetToken(unsigned int command
,
68 unsigned int arg_count
,
72 CommandBufferEngine
*engine_
;
77 class MockShaderTranslator
: public ShaderTranslatorInterface
{
79 MockShaderTranslator();
80 virtual ~MockShaderTranslator();
82 #if (ANGLE_SH_VERSION >= 126)
83 MOCK_METHOD5(Init
, bool(
84 sh::GLenum shader_type
,
85 ShShaderSpec shader_spec
,
86 const ShBuiltInResources
* resources
,
87 GlslImplementationType glsl_implementation_type
,
88 ShCompileOptions driver_bug_workarounds
));
90 MOCK_METHOD5(Init
, bool(
91 ShShaderType shader_type
,
92 ShShaderSpec shader_spec
,
93 const ShBuiltInResources
* resources
,
94 GlslImplementationType glsl_implementation_type
,
95 ShCompileOptions driver_bug_workarounds
));
97 MOCK_METHOD1(Translate
, bool(const char* shader
));
98 MOCK_CONST_METHOD0(translated_shader
, const char*());
99 MOCK_CONST_METHOD0(info_log
, const char*());
100 MOCK_CONST_METHOD0(attrib_map
, const VariableMap
&());
101 MOCK_CONST_METHOD0(uniform_map
, const VariableMap
&());
102 MOCK_CONST_METHOD0(varying_map
, const VariableMap
&());
103 MOCK_CONST_METHOD0(name_map
, const NameMap
&());
105 GetStringForOptionsThatWouldAffectCompilation
, std::string());
108 class MockProgramCache
: public ProgramCache
{
111 virtual ~MockProgramCache();
113 MOCK_METHOD7(LoadLinkedProgram
, ProgramLoadResult(
116 const ShaderTranslatorInterface
* translator_a
,
118 const ShaderTranslatorInterface
* translator_b
,
119 const LocationMap
* bind_attrib_location_map
,
120 const ShaderCacheCallback
& callback
));
122 MOCK_METHOD7(SaveLinkedProgram
, void(
124 const Shader
* shader_a
,
125 const ShaderTranslatorInterface
* translator_a
,
126 const Shader
* shader_b
,
127 const ShaderTranslatorInterface
* translator_b
,
128 const LocationMap
* bind_attrib_location_map
,
129 const ShaderCacheCallback
& callback
));
130 MOCK_METHOD1(LoadProgram
, void(const std::string
&));
133 MOCK_METHOD0(ClearBackend
, void());
136 class MockMemoryTracker
: public MemoryTracker
{
140 MOCK_METHOD3(TrackMemoryAllocatedChange
, void(
141 size_t old_size
, size_t new_size
, Pool pool
));
142 MOCK_METHOD1(EnsureGPUMemoryAvailable
, bool(size_t size_needed
));
145 friend class ::testing::StrictMock
<MockMemoryTracker
>;
146 friend class base::RefCounted
< ::testing::StrictMock
<MockMemoryTracker
> >;
147 virtual ~MockMemoryTracker();
153 #endif // GPU_COMMAND_BUFFER_SERVICE_MOCKS_H_