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, 18 bool(const base::DictionaryValue& dict, 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, 22 bool(const std::string& path, 23 const std::string& name, 24 const std::vector<std::string>& traits, 25 ErrorPtr* error)); 26 MOCK_METHOD4(AddComponentArrayItem, 27 bool(const std::string& path, 28 const std::string& name, 29 const std::vector<std::string>& traits, 30 ErrorPtr* error)); 31 MOCK_METHOD3(RemoveComponent, 32 bool(const std::string& path, 33 const std::string& name, 34 ErrorPtr* error)); 35 MOCK_METHOD4(RemoveComponentArrayItem, 36 bool(const std::string& path, 37 const std::string& name, 38 size_t index, 39 ErrorPtr* error)); 40 MOCK_METHOD1(AddComponentTreeChangedCallback, 41 void(const base::Closure& callback)); 42 MOCK_METHOD1(MockAddCommand, void(CommandInstance* command_instance)); 43 MOCK_METHOD5(MockParseCommandInstance, 44 CommandInstance*(const base::DictionaryValue& command, 45 Command::Origin command_origin, 46 UserRole role, 47 std::string* id, 48 ErrorPtr* error)); 49 MOCK_METHOD1(FindCommand, CommandInstance*(const std::string& id)); 50 MOCK_METHOD1(AddCommandAddedCallback, 51 void(const CommandQueue::CommandCallback& callback)); 52 MOCK_METHOD1(AddCommandRemovedCallback, 53 void(const CommandQueue::CommandCallback& callback)); 54 MOCK_METHOD3(AddCommandHandler, 55 void(const std::string& component_path, 56 const std::string& command_name, 57 const Device::CommandHandlerCallback& callback)); 58 MOCK_CONST_METHOD2(FindComponent, 59 const base::DictionaryValue*(const std::string& path, 60 ErrorPtr* error)); 61 MOCK_CONST_METHOD1(FindTraitDefinition, 62 const base::DictionaryValue*(const std::string& name)); 63 MOCK_CONST_METHOD1( 64 FindCommandDefinition, 65 const base::DictionaryValue*(const std::string& command_name)); 66 MOCK_CONST_METHOD3(GetMinimalRole, 67 bool(const std::string& command_name, 68 UserRole* minimal_role, 69 ErrorPtr* error)); 70 MOCK_CONST_METHOD0(GetTraits, const base::DictionaryValue&()); 71 MOCK_CONST_METHOD0(GetComponents, const base::DictionaryValue&()); 72 MOCK_METHOD3(SetStateProperties, 73 bool(const std::string& component_path, 74 const base::DictionaryValue& dict, 75 ErrorPtr* error)); 76 MOCK_METHOD3(SetStatePropertiesFromJson, 77 bool(const std::string& component_path, 78 const std::string& json, 79 ErrorPtr* error)); 80 MOCK_CONST_METHOD3(GetStateProperty, 81 const base::Value*(const std::string& component_path, 82 const std::string& name, 83 ErrorPtr* error)); 84 MOCK_METHOD4(SetStateProperty, 85 bool(const std::string& component_path, 86 const std::string& name, 87 const base::Value& value, 88 ErrorPtr* error)); 89 MOCK_METHOD1(AddStateChangedCallback, void(const base::Closure& callback)); 90 MOCK_METHOD0(MockGetAndClearRecordedStateChanges, StateSnapshot&()); 91 MOCK_METHOD1(NotifyStateUpdatedOnServer, void(UpdateID id)); 92 MOCK_CONST_METHOD0(GetLastStateChangeId, UpdateID()); 93 MOCK_METHOD1(MockAddServerStateUpdatedCallback, 94 base::CallbackList<void(UpdateID)>::Subscription*( 95 const base::Callback<void(UpdateID)>& callback)); 96 MOCK_CONST_METHOD1(FindComponentWithTrait, 97 std::string(const std::string& trait)); 98 MOCK_METHOD2(AddLegacyCommandDefinitions, 99 bool(const base::DictionaryValue& dict, ErrorPtr* error)); 100 MOCK_METHOD2(AddLegacyStateDefinitions, 101 bool(const base::DictionaryValue& dict, ErrorPtr* error)); 102 MOCK_CONST_METHOD0(GetLegacyState, const base::DictionaryValue&()); 103 MOCK_CONST_METHOD0(GetLegacyCommandDefinitions, 104 const base::DictionaryValue&()); 105 106 private: 107 void AddCommand(std::unique_ptr<CommandInstance> command_instance) override { 108 MockAddCommand(command_instance.get()); 109 } 110 std::unique_ptr<CommandInstance> ParseCommandInstance( 111 const base::DictionaryValue& command, 112 Command::Origin command_origin, 113 UserRole role, 114 std::string* id, 115 ErrorPtr* error) { 116 return std::unique_ptr<CommandInstance>{ 117 MockParseCommandInstance(command, command_origin, role, id, error)}; 118 } 119 StateSnapshot GetAndClearRecordedStateChanges() override { 120 return std::move(MockGetAndClearRecordedStateChanges()); 121 } 122 Token AddServerStateUpdatedCallback( 123 const base::Callback<void(UpdateID)>& callback) override { 124 return Token{MockAddServerStateUpdatedCallback(callback)}; 125 } 126 }; 127 128 } // namespace weave 129 130 #endif // LIBWEAVE_SRC_COMPONENT_MANAGER_H_ 131