avs-device-sdk/CapabilityAgents/PlaybackController/test/PlaybackRouterTest.cpp

123 lines
4.2 KiB
C++
Raw Normal View History

Version 1.4.0 alexa-client-sdk Changes in this update: **Enhancements** * Added the Notifications Capability Agent. This allows a client to receive notification indicators from Alexa. * Added support for the `SoftwareInfo` event. This code is triggered in the `SampleApp` by providing a positive decimal integer as the "firmwareVersion" value in "sampleApp" object of the `AlexaClientSDKConfig.json`. The reported firmware version can be updated after starting the `SampleApp` by calling `SoftwareInfoSender::setFirmwareVersion()`. This code path can be exercised in the `SampleApp` with the new command: `f`. * Added unit tests for Alerts. * The GStreamer-based pipeline allows for the configuration of `MediaPlayer` output based on information provided in `Config`. * Playlist streaming now uses a `BLOCKING` writer, which improves streaming efficiency. **Bug Fixes** * Fixed bug where `SpeechSynthesizer` would not stop playback when a state change timeout was encountered. * Fixed the `SampleApplication` destructor to avoid segfaults if the object is not constructed correctly. * Fixed bug where `AudioPlayer` would erroneously call `executeStop()` in `cancelDirective()`. * [Issue 396](https://github.com/alexa/avs-device-sdk/issues/396) - Fixed bug for compilation error with GCC7 in `AVSCommon/SDKInterfaces/include/AVSCommon/SDKInterfaces/Audio/AlertsAudioFactoryInterface.h` * [Issue 384](https://github.com/alexa/avs-device-sdk/issues/384) - Fixed bug that caused `AuthServer.py` to crash. * Fixed bug where a long delay was encountered after pausing and resuming a large Audible chapter. * Fixed bug that caused named timers and reminders to loop for an additional `loopCount` . * Fixed memory corruption bug in `MessageInterpreter`. * Fixed illegal memory accesses in `MediaPlayer` logging. **Known Issues** * The `ACL` may encounter issues if audio attachments are received but not consumed. * Display Cards for Kindle don't render. * If using the GStreamer-based `MediaPlayer` implementation, after muting and un-muting an audio item, the next item in the queue will begin playing rather than continuing playback of the originally muted audio item. * `SpeechSynthesizerState` currently uses `GAINING_FOCUS` and `LOSING_FOCUS` as a workaround for handling intermediate state. These states may be removed in a future release. * Music playback doesn't immediately stop when a user barges-in on iHeartRadio.
2018-01-12 23:45:42 +00:00
/*
* Copyright 2017-2018 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 <AVSCommon/SDKInterfaces/MockPlaybackHandler.h>
#include "PlaybackController/PlaybackRouter.h"
namespace alexaClientSDK {
namespace capabilityAgents {
namespace playbackController {
namespace test {
using namespace testing;
using namespace avsCommon::avs;
using namespace avsCommon::sdkInterfaces;
using namespace avsCommon::sdkInterfaces::test;
class PlaybackRouterTest : public ::testing::Test {
public:
void SetUp() override;
void TearDown() override;
protected:
std::shared_ptr<PlaybackRouter> m_playbackRouter;
std::shared_ptr<StrictMock<MockPlaybackHandler>> m_defaultPlaybackHandler;
std::shared_ptr<StrictMock<MockPlaybackHandler>> m_secondPlaybackHandler;
};
/// Set up a test harness for running a test.
void PlaybackRouterTest::SetUp() {
m_defaultPlaybackHandler = std::make_shared<StrictMock<MockPlaybackHandler>>();
m_playbackRouter = PlaybackRouter::create(m_defaultPlaybackHandler);
m_secondPlaybackHandler = std::make_shared<StrictMock<MockPlaybackHandler>>();
}
void PlaybackRouterTest::TearDown() {
m_playbackRouter->shutdown();
}
/**
* Test default handler is called.
*/
TEST_F(PlaybackRouterTest, defaultHandler) {
EXPECT_CALL(*m_defaultPlaybackHandler, onButtonPressed(PlaybackButton::PLAY));
m_playbackRouter->playButtonPressed();
EXPECT_CALL(*m_defaultPlaybackHandler, onButtonPressed(PlaybackButton::PAUSE));
m_playbackRouter->pauseButtonPressed();
EXPECT_CALL(*m_defaultPlaybackHandler, onButtonPressed(PlaybackButton::NEXT));
m_playbackRouter->nextButtonPressed();
EXPECT_CALL(*m_defaultPlaybackHandler, onButtonPressed(PlaybackButton::PREVIOUS));
m_playbackRouter->previousButtonPressed();
}
/**
* Test 2nd handler is called after registration.
*/
TEST_F(PlaybackRouterTest, secondHandler) {
m_playbackRouter->setHandler(m_defaultPlaybackHandler);
EXPECT_CALL(*m_defaultPlaybackHandler, onButtonPressed(PlaybackButton::PLAY));
m_playbackRouter->playButtonPressed();
m_playbackRouter->setHandler(m_secondPlaybackHandler);
EXPECT_CALL(*m_secondPlaybackHandler, onButtonPressed(PlaybackButton::PLAY));
m_playbackRouter->playButtonPressed();
EXPECT_CALL(*m_secondPlaybackHandler, onButtonPressed(PlaybackButton::PAUSE));
m_playbackRouter->pauseButtonPressed();
EXPECT_CALL(*m_secondPlaybackHandler, onButtonPressed(PlaybackButton::NEXT));
m_playbackRouter->nextButtonPressed();
EXPECT_CALL(*m_secondPlaybackHandler, onButtonPressed(PlaybackButton::PREVIOUS));
m_playbackRouter->previousButtonPressed();
}
/**
* Test default handler is called again after @c switchToDefaultHandler has been called.
*/
TEST_F(PlaybackRouterTest, switchToDefaultHandler) {
EXPECT_CALL(*m_defaultPlaybackHandler, onButtonPressed(PlaybackButton::PLAY));
m_playbackRouter->playButtonPressed();
m_playbackRouter->setHandler(m_secondPlaybackHandler);
EXPECT_CALL(*m_secondPlaybackHandler, onButtonPressed(PlaybackButton::PLAY));
m_playbackRouter->playButtonPressed();
m_playbackRouter->switchToDefaultHandler();
EXPECT_CALL(*m_defaultPlaybackHandler, onButtonPressed(PlaybackButton::PLAY));
m_playbackRouter->playButtonPressed();
EXPECT_CALL(*m_defaultPlaybackHandler, onButtonPressed(PlaybackButton::PAUSE));
m_playbackRouter->pauseButtonPressed();
EXPECT_CALL(*m_defaultPlaybackHandler, onButtonPressed(PlaybackButton::NEXT));
m_playbackRouter->nextButtonPressed();
EXPECT_CALL(*m_defaultPlaybackHandler, onButtonPressed(PlaybackButton::PREVIOUS));
m_playbackRouter->previousButtonPressed();
}
} // namespace test
} // namespace playbackController
} // namespace capabilityAgents
} // namespace alexaClientSDK