avs-device-sdk/AVSCommon/AVS/test/HandlerAndPolicyTest.cpp

119 lines
4.4 KiB
C++
Raw Normal View History

/*
* HandlerAndPolicyTest.cpp
*
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "AVSCommon/SDKInterfaces/DirectiveHandlerInterface.h"
#include "AVSCommon/AVS/HandlerAndPolicy.h"
using namespace ::testing;
namespace alexaClientSDK {
namespace avsCommon {
namespace avs {
namespace test {
/// Minimal DirectiveHandlerInterface implementation so we can generate instance pointers.
class TestDirectiveHandler : public sdkInterfaces::DirectiveHandlerInterface {
public:
Version 1.1.0 alexa-client-sdk - Changes in this update: - Better GStreamer error reporting. MediaPlayer used to only report `MEDIA_ERROR_UNKNOWN`, now reports more specific errors as defined in `ErrorType.h`. - Codebase has been formatted for easier reading. - `DirectiveRouter::removeDirectiveHandler()` signature changed and now returns a bool indicating if given handler should be successfully removed or not. - Cleanup of raw and shared pointers in the creation of `Transport` objects. - `HTTP2Stream`s now have IDs assigned as they are acquired as opposed to created, making associated logs easier to interpret. - `AlertsCapabilityAgent` has been refactored. - Alert management has been factored out into an `AlertScheduler` class. - Creation of Reminder (implements Alert) class. - Added new capability agent for `PlaybackController` with unit tests. - Added Settings interface with unit tests. - Return type of `getOffsetInMilliseconds()` changed from `int64_t` to `std::chronology::milliseconds`. - Added `AudioPlayer` unit tests. - Added teardown for all Integration tests except Alerts. - Implemented PlaylistParser. - Bug fixes: - AIP getting stuck in `LISTENING` or `THINKING` and refusing user input on network outage. - SampleApp crashing if running for 5 minutes after network disconnect. - Issue where on repeated user barge-ins, `AudioPlayer` would not pause. Specifically, the third attempt to “Play iHeartRadio” would not result in currently-playing music pausing. - Utterances being ignored after particularly long TTS. - GStreamer errors cropping up on SampleApp exit as a result of accessing the pipeline before it’s been setup. - Crashing when playing one URL after another. - Buffer overrun in Alerts Renderer. - [SampleApp crashing when issuing "Alexa skip" command with iHeartRadio.](https://github.com/alexa/avs-device-sdk/issues/153) - [`HTTP2Transport` network thread triggering a join on itself.](https://github.com/alexa/avs-device-sdk/issues/127) - [`HTTP2Stream` request handling truncating exception messages.](https://github.com/alexa/avs-device-sdk/issues/67) - [`AudioPlayer` was attempting an incorrect state transition from `STOPPED` to `PLAYING` through a `playbackResumed`.](https://github.com/alexa/avs-device-sdk/issues/138)
2017-10-02 22:59:05 +00:00
void handleDirectiveImmediately(std::shared_ptr<AVSDirective>) override {
}
void preHandleDirective(
std::shared_ptr<AVSDirective>,
std::unique_ptr<sdkInterfaces::DirectiveHandlerResultInterface>) override {
}
bool handleDirective(const std::string&) override {
return false;
}
void cancelDirective(const std::string&) override {
}
void onDeregistered() override {
}
avs::DirectiveHandlerConfiguration getConfiguration() const override {
// Not using an empty initializer list here to account for a GCC 4.9.2 regression
return avs::DirectiveHandlerConfiguration();
}
};
/**
* HandlerAndPolicyTest
*/
Version 1.1.0 alexa-client-sdk - Changes in this update: - Better GStreamer error reporting. MediaPlayer used to only report `MEDIA_ERROR_UNKNOWN`, now reports more specific errors as defined in `ErrorType.h`. - Codebase has been formatted for easier reading. - `DirectiveRouter::removeDirectiveHandler()` signature changed and now returns a bool indicating if given handler should be successfully removed or not. - Cleanup of raw and shared pointers in the creation of `Transport` objects. - `HTTP2Stream`s now have IDs assigned as they are acquired as opposed to created, making associated logs easier to interpret. - `AlertsCapabilityAgent` has been refactored. - Alert management has been factored out into an `AlertScheduler` class. - Creation of Reminder (implements Alert) class. - Added new capability agent for `PlaybackController` with unit tests. - Added Settings interface with unit tests. - Return type of `getOffsetInMilliseconds()` changed from `int64_t` to `std::chronology::milliseconds`. - Added `AudioPlayer` unit tests. - Added teardown for all Integration tests except Alerts. - Implemented PlaylistParser. - Bug fixes: - AIP getting stuck in `LISTENING` or `THINKING` and refusing user input on network outage. - SampleApp crashing if running for 5 minutes after network disconnect. - Issue where on repeated user barge-ins, `AudioPlayer` would not pause. Specifically, the third attempt to “Play iHeartRadio” would not result in currently-playing music pausing. - Utterances being ignored after particularly long TTS. - GStreamer errors cropping up on SampleApp exit as a result of accessing the pipeline before it’s been setup. - Crashing when playing one URL after another. - Buffer overrun in Alerts Renderer. - [SampleApp crashing when issuing "Alexa skip" command with iHeartRadio.](https://github.com/alexa/avs-device-sdk/issues/153) - [`HTTP2Transport` network thread triggering a join on itself.](https://github.com/alexa/avs-device-sdk/issues/127) - [`HTTP2Stream` request handling truncating exception messages.](https://github.com/alexa/avs-device-sdk/issues/67) - [`AudioPlayer` was attempting an incorrect state transition from `STOPPED` to `PLAYING` through a `playbackResumed`.](https://github.com/alexa/avs-device-sdk/issues/138)
2017-10-02 22:59:05 +00:00
class HandlerAndPolicyTest : public ::testing::Test {};
/**
* Invoke default constructor. Expect @c nameSpace and @c name properties are both empty strings.
*/
TEST_F(HandlerAndPolicyTest, testDefaultConstructor) {
HandlerAndPolicy handlerAndPolicy;
ASSERT_EQ(handlerAndPolicy.handler, nullptr);
ASSERT_EQ(handlerAndPolicy.policy, BlockingPolicy::NONE);
}
/**
* Invoke constructor with member values. Expect properties match those provided to the constructor.
*/
TEST_F(HandlerAndPolicyTest, testConstructorWithValues) {
auto handler = std::make_shared<TestDirectiveHandler>();
HandlerAndPolicy handlerAndPolicy(handler, BlockingPolicy::NON_BLOCKING);
ASSERT_EQ(handlerAndPolicy.handler, handler);
ASSERT_EQ(handlerAndPolicy.policy, BlockingPolicy::NON_BLOCKING);
}
/**
* Create empty and non-empty HandlerAndPolicy instances. Expect that empty instances are interpreted as false and
* non-empty values are interpreted as true.
*/
TEST_F(HandlerAndPolicyTest, testOperatorBool) {
auto handler = std::make_shared<TestDirectiveHandler>();
HandlerAndPolicy defaultHandlerAndPolicy;
HandlerAndPolicy firstHalfEmpty(nullptr, BlockingPolicy::BLOCKING);
HandlerAndPolicy secondHalfEmpty(handler, BlockingPolicy::NONE);
HandlerAndPolicy nonEmpty(handler, BlockingPolicy::BLOCKING);
ASSERT_FALSE(defaultHandlerAndPolicy);
ASSERT_FALSE(firstHalfEmpty);
ASSERT_FALSE(secondHalfEmpty);
ASSERT_TRUE(nonEmpty);
}
/**
* Create instances with different and identical values. Expect that instances with different values test as
* not equal and that instances with identical values test as equal.
*/
TEST_F(HandlerAndPolicyTest, testOperatorEqualandNotEqual) {
auto handler1 = std::make_shared<TestDirectiveHandler>();
auto handler2 = std::make_shared<TestDirectiveHandler>();
HandlerAndPolicy defaultHandlerAndPolicy;
HandlerAndPolicy handlerAndPolicy1(handler1, BlockingPolicy::NON_BLOCKING);
HandlerAndPolicy handlerAndPolicy1Clone(handler1, BlockingPolicy::NON_BLOCKING);
HandlerAndPolicy handlerAndPolicy2(handler1, BlockingPolicy::BLOCKING);
HandlerAndPolicy handlerAndPolicy3(handler2, BlockingPolicy::NON_BLOCKING);
HandlerAndPolicy handlerAndPolicy4(nullptr, BlockingPolicy::NON_BLOCKING);
ASSERT_EQ(defaultHandlerAndPolicy, defaultHandlerAndPolicy);
ASSERT_NE(defaultHandlerAndPolicy, handlerAndPolicy1);
ASSERT_EQ(handlerAndPolicy1, handlerAndPolicy1Clone);
ASSERT_NE(handlerAndPolicy1, handlerAndPolicy2);
ASSERT_NE(handlerAndPolicy1, handlerAndPolicy3);
ASSERT_NE(handlerAndPolicy2, handlerAndPolicy3);
ASSERT_NE(handlerAndPolicy3, handlerAndPolicy4);
}
Version 1.1.0 alexa-client-sdk - Changes in this update: - Better GStreamer error reporting. MediaPlayer used to only report `MEDIA_ERROR_UNKNOWN`, now reports more specific errors as defined in `ErrorType.h`. - Codebase has been formatted for easier reading. - `DirectiveRouter::removeDirectiveHandler()` signature changed and now returns a bool indicating if given handler should be successfully removed or not. - Cleanup of raw and shared pointers in the creation of `Transport` objects. - `HTTP2Stream`s now have IDs assigned as they are acquired as opposed to created, making associated logs easier to interpret. - `AlertsCapabilityAgent` has been refactored. - Alert management has been factored out into an `AlertScheduler` class. - Creation of Reminder (implements Alert) class. - Added new capability agent for `PlaybackController` with unit tests. - Added Settings interface with unit tests. - Return type of `getOffsetInMilliseconds()` changed from `int64_t` to `std::chronology::milliseconds`. - Added `AudioPlayer` unit tests. - Added teardown for all Integration tests except Alerts. - Implemented PlaylistParser. - Bug fixes: - AIP getting stuck in `LISTENING` or `THINKING` and refusing user input on network outage. - SampleApp crashing if running for 5 minutes after network disconnect. - Issue where on repeated user barge-ins, `AudioPlayer` would not pause. Specifically, the third attempt to “Play iHeartRadio” would not result in currently-playing music pausing. - Utterances being ignored after particularly long TTS. - GStreamer errors cropping up on SampleApp exit as a result of accessing the pipeline before it’s been setup. - Crashing when playing one URL after another. - Buffer overrun in Alerts Renderer. - [SampleApp crashing when issuing "Alexa skip" command with iHeartRadio.](https://github.com/alexa/avs-device-sdk/issues/153) - [`HTTP2Transport` network thread triggering a join on itself.](https://github.com/alexa/avs-device-sdk/issues/127) - [`HTTP2Stream` request handling truncating exception messages.](https://github.com/alexa/avs-device-sdk/issues/67) - [`AudioPlayer` was attempting an incorrect state transition from `STOPPED` to `PLAYING` through a `playbackResumed`.](https://github.com/alexa/avs-device-sdk/issues/138)
2017-10-02 22:59:05 +00:00
} // namespace test
} // namespace avs
} // namespace avsCommon
} // namespace alexaClientSDK