AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
MockSpeakerInterface.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 
16 #ifndef ALEXA_CLIENT_SDK_AVSCOMMON_SDKINTERFACES_TEST_AVSCOMMON_SDKINTERFACES_MOCKSPEAKERINTERFACE_H_
17 #define ALEXA_CLIENT_SDK_AVSCOMMON_SDKINTERFACES_TEST_AVSCOMMON_SDKINTERFACES_MOCKSPEAKERINTERFACE_H_
18 
19 #include <gmock/gmock.h>
20 
23 
24 namespace alexaClientSDK {
25 namespace avsCommon {
26 namespace sdkInterfaces {
27 namespace test {
28 
29 using namespace avsCommon::avs::speakerConstants;
30 using namespace ::testing;
31 
33 static const bool MUTE(true);
34 
36 static const std::string MUTE_STRING("true");
37 
39 static const bool UNMUTE(false);
40 
42 static const std::string UNMUTE_STRING("false");
43 
46 
47 /*
48  * Mock class that implements the SpeakerInterface. This is the delegate speaker class which
49  * implements the SpeakerInterface methods.
50  */
51 class MockSpeaker : public SpeakerInterface {
52 public:
53  bool setVolume(int8_t volume) override;
54  bool setMute(bool mute) override;
55  bool getSpeakerSettings(SpeakerInterface::SpeakerSettings* settings) override;
56 
58  MockSpeaker();
59 
60 private:
63 };
64 
65 inline bool MockSpeaker::setVolume(int8_t volume) {
66  m_settings.volume = volume;
67  return true;
68 }
69 
70 inline bool MockSpeaker::setMute(bool mute) {
71  m_settings.mute = mute;
72  return true;
73 }
74 
76  if (!settings) {
77  return false;
78  }
79 
80  settings->volume = m_settings.volume;
81  settings->mute = m_settings.mute;
82 
83  return true;
84 }
85 
87  m_settings = DEFAULT_SETTINGS;
88 }
89 
90 /*
91  * Mock class that implements the SpeakerInterface. This class delegates the Speaker
92  * methods to the MockSpeaker object.
93  */
95 public:
96  MOCK_METHOD1(setVolume, bool(int8_t));
97 
98  MOCK_METHOD1(setMute, bool(bool));
99 
100  MOCK_METHOD1(getSpeakerSettings, bool(SpeakerInterface::SpeakerSettings*));
101 
103  void DelegateToReal();
104 
105 private:
107  MockSpeaker m_speaker;
108 };
109 
111  ON_CALL(*this, setVolume(_)).WillByDefault(Invoke(&m_speaker, &SpeakerInterface::setVolume));
112  ON_CALL(*this, setMute(_)).WillByDefault(Invoke(&m_speaker, &SpeakerInterface::setMute));
113  ON_CALL(*this, getSpeakerSettings(_)).WillByDefault(Invoke(&m_speaker, &SpeakerInterface::getSpeakerSettings));
114 }
115 } // namespace test
116 } // namespace sdkInterfaces
117 } // namespace avsCommon
118 } // namespace alexaClientSDK
119 
120 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_SDKINTERFACES_TEST_AVSCOMMON_SDKINTERFACES_MOCKSPEAKERINTERFACE_H_
Definition: gmock-actions.h:53
Definition: AmdMetricWrapperTest.cpp:24
::std::string string
Definition: gtest-port.h:1097
#define ON_CALL(obj, call)
Definition: gmock-spec-builders.h:1841
MockSpeaker()
Constructor.
Definition: MockSpeakerInterface.h:86
bool mute
True means muted, false means unmuted.
Definition: SpeakerInterface.h:46
static const std::string UNMUTE_STRING("false")
String value for unmute.
void DelegateToReal()
Delegate call from Mock Speaker object to an object with actual implementation.
Definition: MockSpeakerInterface.h:110
bool getSpeakerSettings(SpeakerInterface::SpeakerSettings *settings) override
Definition: MockSpeakerInterface.h:75
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Definition: gmock-more-actions.h:114
const int8_t AVS_SET_VOLUME_MIN
AVS setVolume Minimum.
Definition: SpeakerConstants.h:30
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
int8_t volume
Must be within [AVS_SET_VOLUME_MIN, AVS_SET_VOLUME_MAX].
Definition: SpeakerInterface.h:44
static const SpeakerInterface::SpeakerSettings DEFAULT_SETTINGS
Value for default volume settings.
Definition: MockSpeakerInterface.h:45
const internal::AnythingMatcher _
Definition: gmock-matchers.h:3729
static const bool UNMUTE(false)
Value for unmute.
#define MOCK_METHOD1(m,...)
Definition: gmock-generated-function-mockers.h:676
static const std::string MUTE_STRING("true")
String value for mute.
virtual bool getSpeakerSettings(SpeakerSettings *settings)=0
bool setMute(bool mute) override
Definition: MockSpeakerInterface.h:70
static const bool MUTE(true)
Value for mute.
bool setVolume(int8_t volume) override
Definition: MockSpeakerInterface.h:65

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