aboutsummaryrefslogtreecommitdiff
path: root/src/mock_component_manager.h
blob: addd6f03baa0c4bb6567cdeaab006cb23ee67f6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright 2015 The Weave Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef LIBWEAVE_SRC_MOCK_COMPONENT_MANAGER_H_
#define LIBWEAVE_SRC_MOCK_COMPONENT_MANAGER_H_

#include "src/component_manager.h"

#include <gmock/gmock.h>

namespace weave {

class MockComponentManager : public ComponentManager {
 public:
  ~MockComponentManager() override {}
  MOCK_METHOD2(LoadTraits,
               bool(const base::DictionaryValue& dict, ErrorPtr* error));
  MOCK_METHOD2(LoadTraits, bool(const std::string& json, ErrorPtr* error));
  MOCK_METHOD1(AddTraitDefChangedCallback, void(const base::Closure& callback));
  MOCK_METHOD4(AddComponent,
               bool(const std::string& path,
                    const std::string& name,
                    const std::vector<std::string>& traits,
                    ErrorPtr* error));
  MOCK_METHOD4(AddComponentArrayItem,
               bool(const std::string& path,
                    const std::string& name,
                    const std::vector<std::string>& traits,
                    ErrorPtr* error));
  MOCK_METHOD3(RemoveComponent,
               bool(const std::string& path,
                    const std::string& name,
                    ErrorPtr* error));
  MOCK_METHOD4(RemoveComponentArrayItem,
               bool(const std::string& path,
                    const std::string& name,
                    size_t index,
                    ErrorPtr* error));
  MOCK_METHOD1(AddComponentTreeChangedCallback,
               void(const base::Closure& callback));
  MOCK_METHOD1(MockAddCommand, void(CommandInstance* command_instance));
  MOCK_METHOD5(MockParseCommandInstance,
               CommandInstance*(const base::DictionaryValue& command,
                                Command::Origin command_origin,
                                UserRole role,
                                std::string* id,
                                ErrorPtr* error));
  MOCK_METHOD1(FindCommand, CommandInstance*(const std::string& id));
  MOCK_METHOD1(AddCommandAddedCallback,
               void(const CommandQueue::CommandCallback& callback));
  MOCK_METHOD1(AddCommandRemovedCallback,
               void(const CommandQueue::CommandCallback& callback));
  MOCK_METHOD3(AddCommandHandler,
               void(const std::string& component_path,
                    const std::string& command_name,
                    const Device::CommandHandlerCallback& callback));
  MOCK_CONST_METHOD2(FindComponent,
                     const base::DictionaryValue*(const std::string& path,
                                                  ErrorPtr* error));
  MOCK_CONST_METHOD1(FindTraitDefinition,
                     const base::DictionaryValue*(const std::string& name));
  MOCK_CONST_METHOD1(
      FindCommandDefinition,
      const base::DictionaryValue*(const std::string& command_name));
  MOCK_CONST_METHOD3(GetMinimalRole,
                     bool(const std::string& command_name,
                          UserRole* minimal_role,
                          ErrorPtr* error));
  MOCK_CONST_METHOD0(GetTraits, const base::DictionaryValue&());
  MOCK_CONST_METHOD0(GetComponents, const base::DictionaryValue&());
  MOCK_METHOD3(SetStateProperties,
               bool(const std::string& component_path,
                    const base::DictionaryValue& dict,
                    ErrorPtr* error));
  MOCK_METHOD3(SetStatePropertiesFromJson,
               bool(const std::string& component_path,
                    const std::string& json,
                    ErrorPtr* error));
  MOCK_CONST_METHOD3(GetStateProperty,
                     const base::Value*(const std::string& component_path,
                                        const std::string& name,
                                        ErrorPtr* error));
  MOCK_METHOD4(SetStateProperty,
               bool(const std::string& component_path,
                    const std::string& name,
                    const base::Value& value,
                    ErrorPtr* error));
  MOCK_METHOD1(AddStateChangedCallback, void(const base::Closure& callback));
  MOCK_METHOD0(MockGetAndClearRecordedStateChanges, StateSnapshot&());
  MOCK_METHOD1(NotifyStateUpdatedOnServer, void(UpdateID id));
  MOCK_CONST_METHOD0(GetLastStateChangeId, UpdateID());
  MOCK_METHOD1(MockAddServerStateUpdatedCallback,
               base::CallbackList<void(UpdateID)>::Subscription*(
                   const base::Callback<void(UpdateID)>& callback));
  MOCK_CONST_METHOD1(FindComponentWithTrait,
                     std::string(const std::string& trait));
  MOCK_METHOD2(AddLegacyCommandDefinitions,
               bool(const base::DictionaryValue& dict, ErrorPtr* error));
  MOCK_METHOD2(AddLegacyStateDefinitions,
               bool(const base::DictionaryValue& dict, ErrorPtr* error));
  MOCK_CONST_METHOD0(GetLegacyState, const base::DictionaryValue&());
  MOCK_CONST_METHOD0(GetLegacyCommandDefinitions,
                     const base::DictionaryValue&());

 private:
  void AddCommand(std::unique_ptr<CommandInstance> command_instance) override {
    MockAddCommand(command_instance.get());
  }
  std::unique_ptr<CommandInstance> ParseCommandInstance(
      const base::DictionaryValue& command,
      Command::Origin command_origin,
      UserRole role,
      std::string* id,
      ErrorPtr* error) {
    return std::unique_ptr<CommandInstance>{
        MockParseCommandInstance(command, command_origin, role, id, error)};
  }
  StateSnapshot GetAndClearRecordedStateChanges() override {
    return std::move(MockGetAndClearRecordedStateChanges());
  }
  Token AddServerStateUpdatedCallback(
      const base::Callback<void(UpdateID)>& callback) override {
    return Token{MockAddServerStateUpdatedCallback(callback)};
  }
};

}  // namespace weave

#endif  // LIBWEAVE_SRC_COMPONENT_MANAGER_H_