OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file contains definitions for mock objects, used for testing. | 5 // This file contains definitions for mock objects, used for testing. |
6 | 6 |
7 // TODO(apatrick): This file "manually" defines some mock objects. Using gMock | 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. | 8 // would be definitely preferable, unfortunately it doesn't work on Windows yet. |
9 | 9 |
10 #ifndef GPU_COMMAND_BUFFER_SERVICE_MOCKS_H_ | 10 #ifndef GPU_COMMAND_BUFFER_SERVICE_MOCKS_H_ |
11 #define GPU_COMMAND_BUFFER_SERVICE_MOCKS_H_ | 11 #define GPU_COMMAND_BUFFER_SERVICE_MOCKS_H_ |
12 | 12 |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "gpu/command_buffer/service/cmd_parser.h" | 16 #include "gpu/command_buffer/service/cmd_parser.h" |
17 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 17 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
18 #include "gpu/command_buffer/service/shader_translator.h" | 18 #include "gpu/command_buffer/service/shader_translator.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
20 | 20 |
21 namespace gpu { | 21 namespace gpu { |
22 | 22 |
23 // Mocks an AsyncAPIInterface, using GMock. | 23 // Mocks an AsyncAPIInterface, using GMock. |
24 class AsyncAPIMock : public AsyncAPIInterface { | 24 class AsyncAPIMock : public AsyncAPIInterface { |
25 public: | 25 public: |
26 AsyncAPIMock() { | 26 AsyncAPIMock(); |
27 testing::DefaultValue<error::Error>::Set( | 27 virtual ~AsyncAPIMock(); |
28 error::kNoError); | |
29 } | |
30 | 28 |
31 // Predicate that matches args passed to DoCommand, by looking at the values. | 29 // Predicate that matches args passed to DoCommand, by looking at the values. |
32 class IsArgs { | 30 class IsArgs { |
33 public: | 31 public: |
34 IsArgs(unsigned int arg_count, const void* args) | 32 IsArgs(unsigned int arg_count, const void* args) |
35 : arg_count_(arg_count), | 33 : arg_count_(arg_count), |
36 args_(static_cast<CommandBufferEntry*>(const_cast<void*>(args))) { | 34 args_(static_cast<CommandBufferEntry*>(const_cast<void*>(args))) { |
37 } | 35 } |
38 | 36 |
39 bool operator() (const void* _args) const { | 37 bool operator() (const void* _args) const { |
(...skipping 18 matching lines...) Expand all Loading... |
58 const char* GetCommandName(unsigned int command_id) const { | 56 const char* GetCommandName(unsigned int command_id) const { |
59 return ""; | 57 return ""; |
60 }; | 58 }; |
61 | 59 |
62 // Sets the engine, to forward SetToken commands to it. | 60 // Sets the engine, to forward SetToken commands to it. |
63 void set_engine(CommandBufferEngine *engine) { engine_ = engine; } | 61 void set_engine(CommandBufferEngine *engine) { engine_ = engine; } |
64 | 62 |
65 // Forwards the SetToken commands to the engine. | 63 // Forwards the SetToken commands to the engine. |
66 void SetToken(unsigned int command, | 64 void SetToken(unsigned int command, |
67 unsigned int arg_count, | 65 unsigned int arg_count, |
68 const void* _args) { | 66 const void* _args); |
69 DCHECK(engine_); | 67 |
70 DCHECK_EQ(1u, command); | |
71 DCHECK_EQ(1u, arg_count); | |
72 const CommandBufferEntry* args = | |
73 static_cast<const CommandBufferEntry*>(_args); | |
74 engine_->set_token(args[0].value_uint32); | |
75 } | |
76 private: | 68 private: |
77 CommandBufferEngine *engine_; | 69 CommandBufferEngine *engine_; |
78 }; | 70 }; |
79 | 71 |
80 namespace gles2 { | 72 namespace gles2 { |
81 | 73 |
82 class MockShaderTranslator : public ShaderTranslatorInterface { | 74 class MockShaderTranslator : public ShaderTranslatorInterface { |
83 public: | 75 public: |
84 virtual ~MockShaderTranslator() { } | 76 MockShaderTranslator(); |
| 77 virtual ~MockShaderTranslator(); |
85 | 78 |
86 MOCK_METHOD4(Init, bool( | 79 MOCK_METHOD4(Init, bool( |
87 ShShaderType shader_type, | 80 ShShaderType shader_type, |
88 ShShaderSpec shader_spec, | 81 ShShaderSpec shader_spec, |
89 const ShBuiltInResources* resources, | 82 const ShBuiltInResources* resources, |
90 bool implementation_is_glsl_es)); | 83 bool implementation_is_glsl_es)); |
91 MOCK_METHOD1(Translate, bool(const char* shader)); | 84 MOCK_METHOD1(Translate, bool(const char* shader)); |
92 MOCK_CONST_METHOD0(translated_shader, const char*()); | 85 MOCK_CONST_METHOD0(translated_shader, const char*()); |
93 MOCK_CONST_METHOD0(info_log, const char*()); | 86 MOCK_CONST_METHOD0(info_log, const char*()); |
94 MOCK_CONST_METHOD0(attrib_map, const VariableMap&()); | 87 MOCK_CONST_METHOD0(attrib_map, const VariableMap&()); |
95 MOCK_CONST_METHOD0(uniform_map, const VariableMap&()); | 88 MOCK_CONST_METHOD0(uniform_map, const VariableMap&()); |
96 }; | 89 }; |
97 | 90 |
98 } // namespace gles2 | 91 } // namespace gles2 |
99 } // namespace gpu | 92 } // namespace gpu |
100 | 93 |
101 #endif // GPU_COMMAND_BUFFER_SERVICE_MOCKS_H_ | 94 #endif // GPU_COMMAND_BUFFER_SERVICE_MOCKS_H_ |
OLD | NEW |