Alex Vakulenko | ba98115 | 2015-12-05 13:58:22 -0800 | [diff] [blame] | 1 | // Copyright 2015 The Weave 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. |
| 4 | |
| 5 | #ifndef LIBWEAVE_SRC_MOCK_COMPONENT_MANAGER_H_ |
| 6 | #define LIBWEAVE_SRC_MOCK_COMPONENT_MANAGER_H_ |
| 7 | |
| 8 | #include "src/component_manager.h" |
| 9 | |
| 10 | #include <gmock/gmock.h> |
| 11 | |
| 12 | namespace weave { |
| 13 | |
| 14 | class MockComponentManager : public ComponentManager { |
| 15 | public: |
| 16 | ~MockComponentManager() override {} |
| 17 | MOCK_METHOD2(LoadTraits, bool(const base::DictionaryValue& dict, |
| 18 | ErrorPtr* error)); |
| 19 | MOCK_METHOD2(LoadTraits, bool(const std::string& json, ErrorPtr* error)); |
| 20 | MOCK_METHOD1(AddTraitDefChangedCallback, void(const base::Closure& callback)); |
| 21 | MOCK_METHOD4(AddComponent, bool(const std::string& path, |
| 22 | const std::string& name, |
| 23 | const std::vector<std::string>& traits, |
| 24 | ErrorPtr* error)); |
| 25 | MOCK_METHOD4(AddComponentArrayItem, |
| 26 | bool(const std::string& path, |
| 27 | const std::string& name, |
| 28 | const std::vector<std::string>& traits, |
| 29 | ErrorPtr* error)); |
| 30 | MOCK_METHOD1(AddComponentTreeChangedCallback, |
| 31 | void(const base::Closure& callback)); |
Alex Vakulenko | d91d625 | 2015-12-05 17:14:39 -0800 | [diff] [blame^] | 32 | MOCK_METHOD1(MockAddCommand, void(CommandInstance* command_instance)); |
| 33 | MOCK_METHOD5(MockParseCommandInstance, |
| 34 | CommandInstance*(const base::DictionaryValue& command, |
Alex Vakulenko | b736c98 | 2015-12-05 14:09:27 -0800 | [diff] [blame] | 35 | Command::Origin command_origin, |
Alex Vakulenko | ba98115 | 2015-12-05 13:58:22 -0800 | [diff] [blame] | 36 | UserRole role, |
| 37 | std::string* id, |
| 38 | ErrorPtr* error)); |
| 39 | MOCK_METHOD1(FindCommand, CommandInstance*(const std::string& id)); |
| 40 | MOCK_METHOD1(AddCommandAddedCallback, |
| 41 | void(const CommandQueue::CommandCallback& callback)); |
| 42 | MOCK_METHOD1(AddCommandRemovedCallback, |
| 43 | void(const CommandQueue::CommandCallback& callback)); |
| 44 | MOCK_METHOD3(AddCommandHandler, |
| 45 | void(const std::string& component_path, |
| 46 | const std::string& command_name, |
| 47 | const Device::CommandHandlerCallback& callback)); |
| 48 | MOCK_CONST_METHOD2(FindComponent, |
| 49 | const base::DictionaryValue*(const std::string& path, |
| 50 | ErrorPtr* error)); |
| 51 | MOCK_CONST_METHOD1(FindTraitDefinition, |
| 52 | const base::DictionaryValue*(const std::string& name)); |
| 53 | MOCK_CONST_METHOD1( |
| 54 | FindCommandDefinition, |
| 55 | const base::DictionaryValue*(const std::string& command_name)); |
| 56 | MOCK_CONST_METHOD3(GetMinimalRole, bool(const std::string& command_name, |
| 57 | UserRole* minimal_role, |
| 58 | ErrorPtr* error)); |
| 59 | MOCK_CONST_METHOD0(GetTraits, const base::DictionaryValue&()); |
| 60 | MOCK_CONST_METHOD0(GetComponents, const base::DictionaryValue&()); |
| 61 | MOCK_METHOD3(SetStateProperties, bool(const std::string& component_path, |
| 62 | const base::DictionaryValue& dict, |
| 63 | ErrorPtr* error)); |
| 64 | MOCK_METHOD3(SetStatePropertiesFromJson, |
| 65 | bool(const std::string& component_path, |
| 66 | const std::string& json, |
| 67 | ErrorPtr* error)); |
| 68 | MOCK_CONST_METHOD3(GetStateProperty, |
| 69 | const base::Value*(const std::string& component_path, |
| 70 | const std::string& name, |
| 71 | ErrorPtr* error)); |
| 72 | MOCK_METHOD4(SetStateProperty, bool(const std::string& component_path, |
| 73 | const std::string& name, |
| 74 | const base::Value& value, |
| 75 | ErrorPtr* error)); |
| 76 | MOCK_METHOD1(AddStateChangedCallback, void(const base::Closure& callback)); |
| 77 | MOCK_METHOD0(MockGetAndClearRecordedStateChanges, StateSnapshot&()); |
| 78 | MOCK_METHOD1(NotifyStateUpdatedOnServer, void(UpdateID id)); |
| 79 | MOCK_CONST_METHOD0(GetLastStateChangeId, UpdateID()); |
| 80 | MOCK_METHOD1(MockAddServerStateUpdatedCallback, |
| 81 | base::CallbackList<void(UpdateID)>::Subscription*( |
| 82 | const base::Callback<void(UpdateID)>& callback)); |
| 83 | MOCK_CONST_METHOD1(FindComponentWithTrait, |
| 84 | std::string(const std::string& trait)); |
Alex Vakulenko | 6b394d1 | 2015-12-05 15:52:54 -0800 | [diff] [blame] | 85 | MOCK_METHOD2(AddLegacyCommandDefinitions, |
| 86 | bool(const base::DictionaryValue& dict, ErrorPtr* error)); |
| 87 | MOCK_METHOD2(AddLegacyStateDefinitions, |
| 88 | bool(const base::DictionaryValue& dict, ErrorPtr* error)); |
| 89 | MOCK_CONST_METHOD0(GetLegacyState, const base::DictionaryValue&()); |
| 90 | MOCK_CONST_METHOD0(GetLegacyCommandDefinitions, |
| 91 | const base::DictionaryValue&()); |
Alex Vakulenko | ba98115 | 2015-12-05 13:58:22 -0800 | [diff] [blame] | 92 | |
| 93 | private: |
Alex Vakulenko | d91d625 | 2015-12-05 17:14:39 -0800 | [diff] [blame^] | 94 | void AddCommand(std::unique_ptr<CommandInstance> command_instance) override { |
| 95 | MockAddCommand(command_instance.get()); |
| 96 | } |
| 97 | std::unique_ptr<CommandInstance> ParseCommandInstance( |
| 98 | const base::DictionaryValue& command, |
| 99 | Command::Origin command_origin, |
| 100 | UserRole role, |
| 101 | std::string* id, |
| 102 | ErrorPtr* error) { |
| 103 | return std::unique_ptr<CommandInstance>{MockParseCommandInstance( |
| 104 | command, command_origin, role, id, error)}; |
| 105 | } |
Alex Vakulenko | ba98115 | 2015-12-05 13:58:22 -0800 | [diff] [blame] | 106 | StateSnapshot GetAndClearRecordedStateChanges() override { |
| 107 | return std::move(MockGetAndClearRecordedStateChanges()); |
| 108 | } |
| 109 | Token AddServerStateUpdatedCallback( |
| 110 | const base::Callback<void(UpdateID)>& callback) override { |
| 111 | return Token{MockAddServerStateUpdatedCallback(callback)}; |
| 112 | } |
| 113 | }; |
| 114 | |
| 115 | } // namespace weave |
| 116 | |
| 117 | #endif // LIBWEAVE_SRC_COMPONENT_MANAGER_H_ |