AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
MockDirectiveHandler.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_ADSL_TEST_COMMON_MOCKDIRECTIVEHANDLER_H_
17 #define ALEXA_CLIENT_SDK_ADSL_TEST_COMMON_MOCKDIRECTIVEHANDLER_H_
18 
19 #include <chrono>
20 #include <future>
21 #include <gtest/gtest.h>
22 #include <gmock/gmock.h>
23 
26 
27 namespace alexaClientSDK {
28 namespace adsl {
29 namespace test {
30 
36 public:
37  void preHandleDirective(
38  std::shared_ptr<avsCommon::avs::AVSDirective> directive,
39  std::unique_ptr<avsCommon::sdkInterfaces::DirectiveHandlerResultInterface> result) override;
40 
47  virtual void preHandleDirective(
48  std::shared_ptr<avsCommon::avs::AVSDirective> directive,
49  std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerResultInterface> result) = 0;
50 };
51 
63 public:
71  static std::shared_ptr<testing::NiceMock<MockDirectiveHandler>> create(
73  std::chrono::milliseconds handlingTimeMs = DEFAULT_HANDLING_TIME_MS);
74 
82  std::chrono::milliseconds handlingTimeMs);
83 
86 
92  void mockHandleDirectiveImmediately(std::shared_ptr<avsCommon::avs::AVSDirective> directive);
93 
100  void mockPreHandleDirective(
101  std::shared_ptr<avsCommon::avs::AVSDirective> directive,
102  std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerResultInterface> result);
103 
110  bool mockHandleDirective(const std::string& messageId);
111 
117  void mockCancelDirective(const std::string& messageId);
118 
122  void mockOnDeregistered();
123 
130  void doHandleDirective(const std::string& messageId);
131 
138  void doPreHandlingFailed(
139  std::shared_ptr<avsCommon::avs::AVSDirective> directive,
140  std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerResultInterface> result);
141 
145  void doHandlingCompleted();
146 
152  bool doHandlingFailed(const std::string& messageId);
153 
154  void shutdown();
155 
162  bool waitUntilPreHandling(std::chrono::milliseconds timeout = DEFAULT_DONE_TIMEOUT_MS);
163 
170  bool waitUntilHandling(std::chrono::milliseconds timeout = DEFAULT_DONE_TIMEOUT_MS);
171 
178  bool waitUntilCanceling(std::chrono::milliseconds timeout = DEFAULT_DONE_TIMEOUT_MS);
179 
186  bool waitUntilCompleted(std::chrono::milliseconds timeout = DEFAULT_DONE_TIMEOUT_MS);
187 
189  std::chrono::milliseconds m_handlingTimeMs;
190 
192  std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerResultInterface> m_result;
193 
195  std::shared_ptr<avsCommon::avs::AVSDirective> m_directive;
196 
199 
201  std::mutex m_mutex;
202 
204  std::condition_variable m_wakeNotifier;
205 
208 
211 
213  std::promise<void> m_preHandlingPromise;
214 
216  std::future<void> m_preHandlingFuture;
217 
219  std::promise<void> m_handlingPromise;
220 
222  std::future<void> m_handlingFuture;
223 
225  std::promise<void> m_cancelingPromise;
226 
228  std::shared_future<void> m_cancelingFuture;
229 
231  std::promise<void> m_completedPromise;
232 
234  std::future<void> m_completedFuture;
235 
236  MOCK_METHOD1(handleDirectiveImmediately, void(std::shared_ptr<avsCommon::avs::AVSDirective>));
237  MOCK_METHOD2(
239  void(
240  std::shared_ptr<avsCommon::avs::AVSDirective>,
241  std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerResultInterface>));
244  MOCK_METHOD0(onDeregistered, void());
246 
248  static const std::chrono::milliseconds DEFAULT_HANDLING_TIME_MS;
249 
251  static const std::chrono::milliseconds DEFAULT_DONE_TIMEOUT_MS;
252 };
253 
254 } // namespace test
255 } // namespace adsl
256 } // namespace alexaClientSDK
257 
258 #endif // ALEXA_CLIENT_SDK_ADSL_TEST_COMMON_MOCKDIRECTIVEHANDLER_H_
std::chrono::milliseconds m_handlingTimeMs
The amount of time (in milliseconds) handling a directive will take.
Definition: MockDirectiveHandler.h:189
virtual void handleDirectiveImmediately(std::shared_ptr< avsCommon::avs::AVSDirective > directive)=0
Definition: AmdMetricWrapperTest.cpp:24
::std::string string
Definition: gtest-port.h:1097
std::promise< void > m_handlingPromise
Promise fulfilled when handleDirective() begins.
Definition: MockDirectiveHandler.h:219
std::thread m_doHandleDirectiveThread
Thread to perform handleDirective() asynchronously.
Definition: MockDirectiveHandler.h:198
#define MOCK_METHOD2(m,...)
Definition: gmock-generated-function-mockers.h:677
std::mutex m_mutex
Mutex to protect m_isShuttingDown.
Definition: MockDirectiveHandler.h:201
static const std::chrono::milliseconds DEFAULT_DONE_TIMEOUT_MS
Timeout used when waiting for tests to complete (we should not reach this).
Definition: MockDirectiveHandler.h:251
Definition: MockDirectiveHandler.h:35
std::shared_ptr< avsCommon::sdkInterfaces::DirectiveHandlerResultInterface > m_result
Object used to specify the result of handling a directive.
Definition: MockDirectiveHandler.h:192
std::shared_future< void > m_cancelingFuture
Future to notify when cancelDirective() begins.
Definition: MockDirectiveHandler.h:228
std::promise< void > m_preHandlingPromise
Promise fulfilled when preHandleDirective() begins.
Definition: MockDirectiveHandler.h:213
std::condition_variable m_wakeNotifier
condition_variable use to wake doHandlingDirectiveThread.
Definition: MockDirectiveHandler.h:204
std::shared_ptr< avsCommon::avs::AVSDirective > m_directive
The AVSDirective (if any) being handled.
Definition: MockDirectiveHandler.h:195
std::promise< void > m_cancelingPromise
Promise fulfilled when cancelDirective() begins.
Definition: MockDirectiveHandler.h:225
virtual avs::DirectiveHandlerConfiguration getConfiguration() const =0
std::unordered_map< directiveRoutingRule::DirectiveRoutingRule, BlockingPolicy > DirectiveHandlerConfiguration
Definition: DirectiveHandlerConfiguration.h:32
std::future< void > m_handlingFuture
Future to notify when handleDirective() begins.
Definition: MockDirectiveHandler.h:222
bool m_isShuttingDown
Whether or not this handler is shutting down.
Definition: MockDirectiveHandler.h:210
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
void preHandleDirective(std::shared_ptr< avsCommon::avs::AVSDirective > directive, std::unique_ptr< avsCommon::sdkInterfaces::DirectiveHandlerResultInterface > result) override
std::future< void > m_completedFuture
Future to notify when a completed result is reported.
Definition: MockDirectiveHandler.h:234
Definition: MockDirectiveHandler.h:62
virtual bool handleDirective(const std::string &messageId)=0
#define MOCK_METHOD0(m,...)
Definition: gmock-generated-function-mockers.h:675
#define MOCK_METHOD1(m,...)
Definition: gmock-generated-function-mockers.h:676
std::future< void > m_preHandlingFuture
Future to notify when preHandleDirective() begins.
Definition: MockDirectiveHandler.h:216
#define MOCK_CONST_METHOD0(m,...)
Definition: gmock-generated-function-mockers.h:687
static const std::chrono::milliseconds DEFAULT_HANDLING_TIME_MS
Default amount of time taken to handle a directive (0).
Definition: MockDirectiveHandler.h:248
virtual void cancelDirective(const std::string &messageId)=0
std::promise< void > m_completedPromise
Promise fulfilled when a completed result is reported.
Definition: MockDirectiveHandler.h:231
bool m_isCompleted
Whether or not handling completed.
Definition: MockDirectiveHandler.h:207

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