AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
MockFocusManagerObserver.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_MOCKFOCUSMANAGEROBSERVER_H_
17 #define ALEXA_CLIENT_SDK_AVSCOMMON_SDKINTERFACES_TEST_AVSCOMMON_SDKINTERFACES_MOCKFOCUSMANAGEROBSERVER_H_
18 
20 
21 #include <gmock/gmock.h>
22 
23 #include <chrono>
24 #include <mutex>
25 #include <condition_variable>
26 
27 namespace alexaClientSDK {
28 namespace avsCommon {
29 namespace sdkInterfaces {
30 namespace test {
31 
34 public:
36 
37  MOCK_METHOD2(onFocusChanged, void(const std::string& channelName, avs::FocusState newFocus));
38 
45  void expectFocusChange(const std::string& channelName, avs::FocusState newFocus);
46 
53  bool waitForFocusChanges(std::chrono::milliseconds timeout = std::chrono::milliseconds::zero());
54 
55 private:
56  size_t m_expects;
57  std::mutex m_mutex;
58  std::condition_variable m_conditionVariable;
59 };
60 
62 }
63 
64 inline void MockFocusManagerObserver::expectFocusChange(const std::string& channelName, avs::FocusState newFocus) {
65  std::lock_guard<std::mutex> lock(m_mutex);
66  EXPECT_CALL(*this, onFocusChanged(testing::StrEq(channelName), newFocus))
67  .WillOnce(testing::InvokeWithoutArgs([this] {
68  std::lock_guard<std::mutex> lock(m_mutex);
69  --m_expects;
70  m_conditionVariable.notify_all();
71  }));
72  ++m_expects;
73 }
74 
75 inline bool MockFocusManagerObserver::waitForFocusChanges(std::chrono::milliseconds timeout) {
76  std::unique_lock<std::mutex> lock(m_mutex);
77  return m_conditionVariable.wait_for(lock, timeout, [this] { return !m_expects; });
78 }
79 
80 } // namespace test
81 } // namespace sdkInterfaces
82 } // namespace avsCommon
83 } // namespace alexaClientSDK
84 
85 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_SDKINTERFACES_TEST_AVSCOMMON_SDKINTERFACES_MOCKFOCUSMANAGEROBSERVER_H_
void expectFocusChange(const std::string &channelName, avs::FocusState newFocus)
Definition: MockFocusManagerObserver.h:64
An interface that clients can extend to register to observe focus changes.
Definition: FocusManagerObserverInterface.h:26
Definition: AmdMetricWrapperTest.cpp:24
::std::string string
Definition: gtest-port.h:1097
virtual void onFocusChanged(const std::string &channelName, avsCommon::avs::FocusState newFocus)=0
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Definition: gmock-actions.h:1168
FocusState
Definition: FocusState.h:29
MOCK_METHOD2(onFocusChanged, void(const std::string &channelName, avs::FocusState newFocus))
MockFocusManagerObserver()
Definition: MockFocusManagerObserver.h:61
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
#define EXPECT_CALL(obj, call)
Definition: gmock-spec-builders.h:1845
bool waitForFocusChanges(std::chrono::milliseconds timeout=std::chrono::milliseconds::zero())
Definition: MockFocusManagerObserver.h:75
PolymorphicMatcher< internal::StrEqualityMatcher< internal::string > > StrEq(const internal::string &str)
Definition: gmock-matchers.h:3955
Mock class that implements the FocusManagerObserver.
Definition: MockFocusManagerObserver.h:33

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