AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
MockSettingProtocol.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 #ifndef ALEXA_CLIENT_SDK_SETTINGS_TEST_SETTINGS_MOCKSETTINGPROTOCOL_H_
16 #define ALEXA_CLIENT_SDK_SETTINGS_TEST_SETTINGS_MOCKSETTINGPROTOCOL_H_
17 
18 #include <functional>
19 #include <string>
20 
21 #include <gmock/gmock.h>
22 
24 
25 namespace alexaClientSDK {
26 namespace settings {
27 namespace test {
28 
35 public:
36  MockSettingProtocol(const std::string& initialValue, bool applyChange, bool revertChange);
37 
41  ApplyChangeFunction applyChange,
42  RevertChangeFunction revertChange,
43  SettingNotificationFunction notifyObservers) override;
44 
45  bool avsChange(
46  ApplyChangeFunction applyChange,
47  RevertChangeFunction revertChange,
48  SettingNotificationFunction notifyObservers) override;
49 
50  bool restoreValue(ApplyDbChangeFunction applyChange, SettingNotificationFunction notifyObservers) override;
51 
52  bool clearData() override;
54 
60  bool isDataCleared();
61 
62 private:
64  std::string m_initialValue;
65 
67  bool m_applyChange;
68 
70  bool m_revertChange;
71 
73  bool m_isClearedData;
74 };
75 
76 MockSettingProtocol::MockSettingProtocol(const std::string& initialValue, bool applyChange, bool revertChange) :
77  m_initialValue{initialValue},
78  m_applyChange{applyChange},
79  m_revertChange{revertChange},
80  m_isClearedData{false} {
81 }
82 
84  ApplyChangeFunction applyChange,
85  RevertChangeFunction revertChange,
86  SettingNotificationFunction notifyObservers) {
87  if (m_applyChange) {
88  applyChange();
89  }
90 
91  if (m_revertChange) {
92  revertChange();
93  }
94 
95  notifyObservers(SettingNotifications::LOCAL_CHANGE);
97 }
98 
100  ApplyChangeFunction applyChange,
101  RevertChangeFunction revertChange,
102  SettingNotificationFunction notifyObservers) {
103  if (m_applyChange) {
104  applyChange();
105  }
106 
107  if (m_revertChange) {
108  revertChange();
109  }
110 
111  notifyObservers(SettingNotifications::AVS_CHANGE);
112  return true;
113 }
114 
116  if (m_applyChange) {
117  applyChange(m_initialValue);
118  }
119  return true;
120 }
121 
123  m_isClearedData = true;
124  return true;
125 }
126 
128  return m_isClearedData;
129 }
130 
131 } // namespace test
132 } // namespace settings
133 } // namespace alexaClientSDK
134 
135 #endif // ALEXA_CLIENT_SDK_SETTINGS_TEST_SETTINGS_MOCKSETTINGPROTOCOL_H_
std::function< std::pair< bool, std::string >()> ApplyChangeFunction
Definition: SettingProtocolInterface.h:46
std::function< std::pair< bool, std::string >(const std::string &dbValue)> ApplyDbChangeFunction
Definition: SettingProtocolInterface.h:56
MockSettingProtocol(const std::string &initialValue, bool applyChange, bool revertChange)
Definition: MockSettingProtocol.h:76
Definition: MockSettingProtocol.h:34
bool clearData() override
Definition: MockSettingProtocol.h:122
Definition: AmdMetricWrapperTest.cpp:24
::std::string string
Definition: gtest-port.h:1097
SetSettingResult localChange(ApplyChangeFunction applyChange, RevertChangeFunction revertChange, SettingNotificationFunction notifyObservers) override
Definition: MockSettingProtocol.h:83
bool isDataCleared()
Definition: MockSettingProtocol.h:127
std::function< void(SettingNotifications notification)> SettingNotificationFunction
Definition: SettingProtocolInterface.h:63
Setting value changed due to a local change.
bool restoreValue(ApplyDbChangeFunction applyChange, SettingNotificationFunction notifyObservers) override
Definition: MockSettingProtocol.h:115
std::function< std::string()> RevertChangeFunction
Definition: SettingProtocolInterface.h:70
SetSettingResult
Definition: SetSettingResult.h:23
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
Definition: SettingProtocolInterface.h:38
bool avsChange(ApplyChangeFunction applyChange, RevertChangeFunction revertChange, SettingNotificationFunction notifyObservers) override
Definition: MockSettingProtocol.h:99
Setting value changed due to a change requested via cloud.
The change request has been enqueued. There will be a follow up notification to inform the operation ...

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0