Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / gpu / command_buffer / service / mocks.h
blob8391aeb29e9ffd605b5c138ffd74215aa18c87b4
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_
13 #include <string>
14 #include <vector>
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"
24 namespace gpu {
26 // Mocks an AsyncAPIInterface, using GMock.
27 class AsyncAPIMock : public AsyncAPIInterface {
28 public:
29 explicit AsyncAPIMock(bool default_do_commands);
30 virtual ~AsyncAPIMock();
32 error::Error FakeDoCommands(unsigned int num_commands,
33 const void* buffer,
34 int num_entries,
35 int* entries_processed);
37 // Predicate that matches args passed to DoCommand, by looking at the values.
38 class IsArgs {
39 public:
40 IsArgs(unsigned int arg_count, const void* args)
41 : arg_count_(arg_count),
42 args_(static_cast<CommandBufferEntry*>(const_cast<void*>(args))) {
45 bool operator() (const void* _args) const {
46 const CommandBufferEntry* args =
47 static_cast<const CommandBufferEntry*>(_args) + 1;
48 for (unsigned int i = 0; i < arg_count_; ++i) {
49 if (args[i].value_uint32 != args_[i].value_uint32) return false;
51 return true;
54 private:
55 unsigned int arg_count_;
56 CommandBufferEntry *args_;
59 MOCK_METHOD3(DoCommand, error::Error(
60 unsigned int command,
61 unsigned int arg_count,
62 const void* cmd_data));
64 MOCK_METHOD4(DoCommands,
65 error::Error(unsigned int num_commands,
66 const void* buffer,
67 int num_entries,
68 int* entries_processed));
70 const char* GetCommandName(unsigned int command_id) const {
71 return "";
74 // Sets the engine, to forward SetToken commands to it.
75 void set_engine(CommandBufferEngine *engine) { engine_ = engine; }
77 // Forwards the SetToken commands to the engine.
78 void SetToken(unsigned int command,
79 unsigned int arg_count,
80 const void* _args);
82 private:
83 CommandBufferEngine *engine_;
86 namespace gles2 {
88 class MockShaderTranslator : public ShaderTranslatorInterface {
89 public:
90 MockShaderTranslator();
92 MOCK_METHOD5(Init,
93 bool(sh::GLenum shader_type,
94 ShShaderSpec shader_spec,
95 const ShBuiltInResources* resources,
96 ShShaderOutput shader_output_language,
97 ShCompileOptions driver_bug_workarounds));
98 MOCK_CONST_METHOD8(Translate, bool(
99 const std::string& shader_source,
100 std::string* info_log,
101 std::string* translated_source,
102 int* shader_version,
103 AttributeMap* attrib_map,
104 UniformMap* uniform_map,
105 VaryingMap* varying_map,
106 NameMap* name_map));
107 MOCK_CONST_METHOD0(
108 GetStringForOptionsThatWouldAffectCompilation, std::string());
109 private:
110 ~MockShaderTranslator() override;
113 class MockProgramCache : public ProgramCache {
114 public:
115 MockProgramCache();
116 virtual ~MockProgramCache();
118 MOCK_METHOD7(LoadLinkedProgram, ProgramLoadResult(
119 GLuint program,
120 Shader* shader_a,
121 Shader* shader_b,
122 const LocationMap* bind_attrib_location_map,
123 const std::vector<std::string>& transform_feedback_varyings,
124 GLenum transform_feedback_buffer_mode,
125 const ShaderCacheCallback& callback));
127 MOCK_METHOD7(SaveLinkedProgram, void(
128 GLuint program,
129 const Shader* shader_a,
130 const Shader* shader_b,
131 const LocationMap* bind_attrib_location_map,
132 const std::vector<std::string>& transform_feedback_varyings,
133 GLenum transform_feedback_buffer_mode,
134 const ShaderCacheCallback& callback));
135 MOCK_METHOD1(LoadProgram, void(const std::string&));
137 private:
138 MOCK_METHOD0(ClearBackend, void());
141 class MockMemoryTracker : public MemoryTracker {
142 public:
143 MockMemoryTracker();
145 MOCK_METHOD3(TrackMemoryAllocatedChange, void(
146 size_t old_size, size_t new_size, Pool pool));
147 MOCK_METHOD1(EnsureGPUMemoryAvailable, bool(size_t size_needed));
148 MOCK_CONST_METHOD0(ClientTracingId, uint64_t());
149 MOCK_CONST_METHOD0(ClientId, int());
151 private:
152 friend class ::testing::StrictMock<MockMemoryTracker>;
153 friend class base::RefCounted< ::testing::StrictMock<MockMemoryTracker> >;
154 virtual ~MockMemoryTracker();
157 } // namespace gles2
158 } // namespace gpu
160 #endif // GPU_COMMAND_BUFFER_SERVICE_MOCKS_H_