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 MOCK_METHOD5(Init
, bool(
83 ShShaderType shader_type
,
84 ShShaderSpec shader_spec
,
85 const ShBuiltInResources
* resources
,
86 GlslImplementationType glsl_implementation_type
,
87 ShCompileOptions driver_bug_workarounds
));
88 MOCK_METHOD1(Translate
, bool(const char* shader
));
89 MOCK_CONST_METHOD0(translated_shader
, const char*());
90 MOCK_CONST_METHOD0(info_log
, const char*());
91 MOCK_CONST_METHOD0(attrib_map
, const VariableMap
&());
92 MOCK_CONST_METHOD0(uniform_map
, const VariableMap
&());
93 MOCK_CONST_METHOD0(varying_map
, const VariableMap
&());
94 MOCK_CONST_METHOD0(name_map
, const NameMap
&());
96 GetStringForOptionsThatWouldAffectCompilation
, std::string());
99 class MockProgramCache
: public ProgramCache
{
102 virtual ~MockProgramCache();
104 MOCK_METHOD7(LoadLinkedProgram
, ProgramLoadResult(
107 const ShaderTranslatorInterface
* translator_a
,
109 const ShaderTranslatorInterface
* translator_b
,
110 const LocationMap
* bind_attrib_location_map
,
111 const ShaderCacheCallback
& callback
));
113 MOCK_METHOD7(SaveLinkedProgram
, void(
115 const Shader
* shader_a
,
116 const ShaderTranslatorInterface
* translator_a
,
117 const Shader
* shader_b
,
118 const ShaderTranslatorInterface
* translator_b
,
119 const LocationMap
* bind_attrib_location_map
,
120 const ShaderCacheCallback
& callback
));
121 MOCK_METHOD1(LoadProgram
, void(const std::string
&));
124 MOCK_METHOD0(ClearBackend
, void());
127 class MockMemoryTracker
: public MemoryTracker
{
131 MOCK_METHOD3(TrackMemoryAllocatedChange
, void(
132 size_t old_size
, size_t new_size
, Pool pool
));
133 MOCK_METHOD1(EnsureGPUMemoryAvailable
, bool(size_t size_needed
));
136 friend class ::testing::StrictMock
<MockMemoryTracker
>;
137 friend class base::RefCounted
< ::testing::StrictMock
<MockMemoryTracker
> >;
138 virtual ~MockMemoryTracker();
144 #endif // GPU_COMMAND_BUFFER_SERVICE_MOCKS_H_