| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <string> | 13 #include <string> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "gpu/command_buffer/service/cmd_parser.h" | 17 #include "gpu/command_buffer/service/cmd_parser.h" |
| 18 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 18 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
| 19 #include "gpu/command_buffer/service/memory_tracking.h" | 19 #include "gpu/command_buffer/service/memory_tracking.h" |
| 20 #include "gpu/command_buffer/service/program_cache.h" | 20 #include "gpu/command_buffer/service/program_cache.h" |
| 21 #include "gpu/command_buffer/service/shader_translator.h" | 21 #include "gpu/command_buffer/service/shader_translator.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 23 | 23 |
| 24 namespace gpu { | 24 namespace gpu { |
| 25 | 25 |
| 26 // Mocks an AsyncAPIInterface, using GMock. | 26 // Mocks an AsyncAPIInterface, using GMock. |
| 27 class AsyncAPIMock : public AsyncAPIInterface { | 27 class AsyncAPIMock : public AsyncAPIInterface { |
| 28 public: | 28 public: |
| 29 AsyncAPIMock(); | 29 explicit AsyncAPIMock(bool default_do_commands); |
| 30 virtual ~AsyncAPIMock(); | 30 virtual ~AsyncAPIMock(); |
| 31 | 31 |
| 32 error::Error FakeDoCommands(unsigned int num_commands, |
| 33 const void* buffer, |
| 34 int num_entries, |
| 35 int* entries_processed); |
| 36 |
| 32 // Predicate that matches args passed to DoCommand, by looking at the values. | 37 // Predicate that matches args passed to DoCommand, by looking at the values. |
| 33 class IsArgs { | 38 class IsArgs { |
| 34 public: | 39 public: |
| 35 IsArgs(unsigned int arg_count, const void* args) | 40 IsArgs(unsigned int arg_count, const void* args) |
| 36 : arg_count_(arg_count), | 41 : arg_count_(arg_count), |
| 37 args_(static_cast<CommandBufferEntry*>(const_cast<void*>(args))) { | 42 args_(static_cast<CommandBufferEntry*>(const_cast<void*>(args))) { |
| 38 } | 43 } |
| 39 | 44 |
| 40 bool operator() (const void* _args) const { | 45 bool operator() (const void* _args) const { |
| 41 const CommandBufferEntry* args = | 46 const CommandBufferEntry* args = |
| 42 static_cast<const CommandBufferEntry*>(_args) + 1; | 47 static_cast<const CommandBufferEntry*>(_args) + 1; |
| 43 for (unsigned int i = 0; i < arg_count_; ++i) { | 48 for (unsigned int i = 0; i < arg_count_; ++i) { |
| 44 if (args[i].value_uint32 != args_[i].value_uint32) return false; | 49 if (args[i].value_uint32 != args_[i].value_uint32) return false; |
| 45 } | 50 } |
| 46 return true; | 51 return true; |
| 47 } | 52 } |
| 48 | 53 |
| 49 private: | 54 private: |
| 50 unsigned int arg_count_; | 55 unsigned int arg_count_; |
| 51 CommandBufferEntry *args_; | 56 CommandBufferEntry *args_; |
| 52 }; | 57 }; |
| 53 | 58 |
| 54 MOCK_METHOD3(DoCommand, error::Error( | 59 MOCK_METHOD3(DoCommand, error::Error( |
| 55 unsigned int command, | 60 unsigned int command, |
| 56 unsigned int arg_count, | 61 unsigned int arg_count, |
| 57 const void* cmd_data)); | 62 const void* cmd_data)); |
| 58 | 63 |
| 64 MOCK_METHOD4(DoCommands, |
| 65 error::Error(unsigned int num_commands, |
| 66 const void* buffer, |
| 67 int num_entries, |
| 68 int* entries_processed)); |
| 69 |
| 59 const char* GetCommandName(unsigned int command_id) const { | 70 const char* GetCommandName(unsigned int command_id) const { |
| 60 return ""; | 71 return ""; |
| 61 }; | 72 }; |
| 62 | 73 |
| 63 // Sets the engine, to forward SetToken commands to it. | 74 // Sets the engine, to forward SetToken commands to it. |
| 64 void set_engine(CommandBufferEngine *engine) { engine_ = engine; } | 75 void set_engine(CommandBufferEngine *engine) { engine_ = engine; } |
| 65 | 76 |
| 66 // Forwards the SetToken commands to the engine. | 77 // Forwards the SetToken commands to the engine. |
| 67 void SetToken(unsigned int command, | 78 void SetToken(unsigned int command, |
| 68 unsigned int arg_count, | 79 unsigned int arg_count, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 private: | 155 private: |
| 145 friend class ::testing::StrictMock<MockMemoryTracker>; | 156 friend class ::testing::StrictMock<MockMemoryTracker>; |
| 146 friend class base::RefCounted< ::testing::StrictMock<MockMemoryTracker> >; | 157 friend class base::RefCounted< ::testing::StrictMock<MockMemoryTracker> >; |
| 147 virtual ~MockMemoryTracker(); | 158 virtual ~MockMemoryTracker(); |
| 148 }; | 159 }; |
| 149 | 160 |
| 150 } // namespace gles2 | 161 } // namespace gles2 |
| 151 } // namespace gpu | 162 } // namespace gpu |
| 152 | 163 |
| 153 #endif // GPU_COMMAND_BUFFER_SERVICE_MOCKS_H_ | 164 #endif // GPU_COMMAND_BUFFER_SERVICE_MOCKS_H_ |
| OLD | NEW |