avs-device-sdk/AVSGatewayManager/test/AVSGatewayManagerTest.cpp

249 lines
8.7 KiB
C++
Raw Normal View History

Version 1.17.0 alexa-client-sdk Changes in this update: **Enhancements** - Added support for [captions for TTS](https://developer.amazon.com/docs/avs-device-sdk/features.html#captions). This enhancement allows you to print onscreen captions for Alexa voice responses. - Added support for [SpeechSynthesizer Interface 1.3](https://developer.amazon.com/docs/alexa-voice-service/speechsynthesizer.html). This interface supports the new `captions` parameter. - Added support for [AudioPlayer Interface 1.3](https://developer.amazon.com/docs/alexa-voice-service/audioplayer.html). This interface supports the new `captions` parameter. - Added support for [Interaction Model 1.2](https://developer.amazon.com/docs/alexa-voice-service/interactionmodel-interface.html). - Added support for [System 2.0](https://developer.amazon.com/en-US/docs/alexa/alexa-voice-service/system.html). - Added support for Alarm Volume Ramp. This feature lets you to fade in alarms for a more pleasant experience. You enable alarm volume ramp in the sample app through the settings menu. - Added support for using certified senders for URI path extensions. This change allows you to specify the URI path extension when sending messages with [`CertifiedSender::sendJSONMessage`](https://alexa.github.io/avs-device-sdk/classalexa_client_s_d_k_1_1certified_sender_1_1_certified_sender.html#a4c0706d79717b226ba77d1a9c3280fe6). - Added new [`Metrics`](https://alexa.github.io/avs-device-sdk/classalexa_client_s_d_k_1_1avs_common_1_1utils_1_1_metrics.html) interfaces and helper classes. These additions help you create and consume [`Metrics`](https://alexa.github.io/avs-device-sdk/classalexa_client_s_d_k_1_1avs_common_1_1utils_1_1_metrics.html) events. - **Interfaces** - `MetricRecorderInterface`, `MetricSinkInterface`. - **Helper Classes** - `DataPointStringBuilder`, `DataPointCounterBuilder`, `DataPointDurationBuilder`, `MetricEventBuilder`. - Added support for the following AVS [endpoint](../avs-device-sdk/endpoints.html) controller capabilities: - [Alexa.ModeController](https://developer.amazon.com/docs/alexa-voice-service/alexa-modecontroller.html) - [Alexa.RangeController](https://developer.amazon.com/docs/alexa-voice-service/alexa-rangecontroller.html) - [Alexa.PowerController](https://developer.amazon.com/docs/alexa-voice-service/alexa-powercontroller.html) - [Alexa.ToggleController](https://developer.amazon.com/docs/alexa-voice-service/alexa-togglecontroller.html) - Added `PowerResourceManagerInterface`. This interface allows the SDK to control power resource levels for components such as the `AudioInputProcessor` and `SpeechSynthesizer`. - Added `AlexaInterfaceCapabilityAgent`. This Capability Agent handles common directives and endpoint controller capabilities support by [`Alexa.AlexaInterface`](../alexa-voice-service/alexa.html). - Added `AlexaInterfaceMessageSenderInterface`. This interface is required to send common events defined by the `Alexa.AlexaInterface` interface. - Added `BufferingComplete` to [`MediaPlayerObserverInterface`](https://alexa.github.io/avs-device-sdk/classalexa_client_s_d_k_1_1avs_common_1_1utils_1_1media_player_1_1_media_player_observer_interface.html). This method helps improve performance in poor networking conditions by making sure `MediaPlayer` pre-buffers correctly. - Added `SendDTMF` to `CallManagerInterface`. This method allows you to send DTMF tones during calls. **New build options** - CAPTIONS - **ADDED** [`CAPTIONS`](https://developer.amazon.com/docs/avs-device-sdk/cmake-parameters.html#captions) - **ADDED** [`LIBWEBVTT_LIB_PATH`](https://developer.amazon.com/docs/avs-device-sdk/cmake-parameters.html#captions) - **ADDED** [`LIBWEBVTT_INCLUDE_DIR`](https://developer.amazon.com/docs//avs-device-sdk/cmake-parameters.html#captions) - METRICS - **ADDED** [`METRICS`](https://developer.amazon.com/docs//avs-device-sdk/cmake-parameters.html#metrics) - ENDPONTS - **ADDED** [`ENABLE_ALL_ENDPOINT_CONTROLLERS`](https://developer.amazon.com/docs/avs-device-sdk/cmake-parameters.html#endpoints) - **ADDED** [`ENABLE_POWER_CONTROLLER`](https://developer.amazon.com/docs/avs-device-sdk/cmake-parameters.html#endpoints) - **ADDED** [`ENABLE_TOGGLE_CONTROLLER`](https://developer.amazon.com/docs/avs-device-sdk/cmake-parameters.html#endpoints) - **ADDED** [`ENABLE_RANGE_CONTROLLER`](https://developer.amazon.com/docs/avs-device-sdk/cmake-parameters.html#endpoints) - **ADDED** [`ENABLE_MODE_CONTROLLER`](https://developer.amazon.com/docs/avs-device-sdk/cmake-parameters.html#endpoints) **New dependencies** - To use captions, you must install a [new dependency](https://developer.amazon.com/docs/avs-device-sdk/dependencies) – the [libwebvtt parsing library](https://github.com/alexa/webvtt). Webvtt is a C/C++ library for interpreting and authoring conformant WebVTT content. WebVTT is a caption and subtitle format designed for use with HTML5 audio and video elements. **Bug fixes** - Fixed [`MimeResponseSink::onReceiveNonMimeData`](https://alexa.github.io/avs-device-sdk/classalexa_client_s_d_k_1_1acl_1_1_mime_response_sink.html) [data issue](https://github.com/alexa/avs-device-sdk/issues/1519) that returned invalid data. - Fixed [data type issue](https://github.com/alexa/avs-device-sdk/issues/1519) that incorrectly used `finalResponseCode` instead of [`FinalResponseCodeId`](https://github.com/alexa/avs-device-sdk/blob/master/AVSCommon/Utils/src/LibcurlUtils/LibCurlHttpContentFetcher.cpp#L370). - Fixed [`UrlContentToAttachmentConverter`](https://alexa.github.io/avs-device-sdk/classalexa_client_s_d_k_1_1playlist_parser_1_1_url_content_to_attachment_converter.html) issue that used the incorrect range parameter. - Fixed `FinallyGuard` [linking issue](https://github.com/alexa/avs-device-sdk/issues/1517) that caused problems compiling the SDK on iOS. - Fixed a [Bluetooth Capability Agent](https://alexa.github.io/avs-device-sdk/classalexa_client_s_d_k_1_1capability_agents_1_1bluetooth_1_1_bluetooth.html) bug that prevented devices from initializing. **Known Issues** * The WebVTT dependency required for `captions` isn't supported for Windows/Android. * Music playback history isn't displayed in the Alexa app for certain account and device types. * When using Gnu Compiler Collection 8+ (GCC 8+), `-Wclass-memaccess` triggers warnings. You can ignore these, they don't cause the build to fail. * Android error `libDefaultClient.so not found` might occur. Resolve this by upgrading to ADB version 1.0.40. * If a device loses a network connection, the lost connection status isn't returned via local TTS. * ACL encounters issues if it receives audio attachments but doesn't consume them. * `SpeechSynthesizerState` uses `GAINING_FOCUS` and `LOSING_FOCUS` as a workaround for handling intermediate states. * Media steamed through Bluetooth might abruptly stop. To restart playback, resume the media in the source application or toggle next/previous. * If a connected Bluetooth device is inactive, the Alexa app might indicates that audio is playing. * The Bluetooth agent assumes that the Bluetooth adapter is always connected to a power source. Disconnecting from a power source during operation isn't yet supported. * When using some products, interrupted Bluetooth playback might not resume if other content is locally streamed. * `make integration` isn't available for Android. To run Android integration tests, manually upload the test binary and input file and run ADB. * Alexa might truncate the beginning of speech when responding to text-to-speech (TTS) user events. This only impacts Raspberry Pi devices running Android Things with HDMI output audio. * A reminder TTS message doesn't play if the sample app restarts and loses a network connection. Instead, the default alarm tone plays twice. * `ServerDisconnectIntegratonTest` tests are disabled until they are updated to reflect new service behavior. * Bluetooth initialization must complete before connecting devices, otherwise devices are ignored. * The `DirectiveSequencerTest.test_handleBlockingThenImmediatelyThenNonBockingOnSameDialogId` test fails intermittently. * On some devices, Alexa gets stuck in a permanent listening state. Pressing `t` and `h` in the Sample App doesn't exit the listening state. * Exiting the settings menu doesn't provide a message to indicate that you're back in the main menu.
2019-12-10 21:02:09 +00:00
/*
* Copyright 2019 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 <fstream>
#include <string>
#include <gmock/gmock.h>
#include <AVSGatewayManager/AVSGatewayManager.h>
#include <AVSCommon/SDKInterfaces/MockAVSGatewayAssigner.h>
#include <AVSCommon/Utils/Configuration/ConfigurationNode.h>
#include <RegistrationManager/CustomerDataManager.h>
namespace alexaClientSDK {
namespace avsGatewayManager {
namespace test {
using namespace avsCommon::sdkInterfaces::test;
using namespace avsCommon::utils::configuration;
using namespace ::testing;
/// Test AVS Gateway
static const std::string TEST_AVS_GATEWAY = "www.test-avs-gateway.com";
/// Default AVS Gateway
static const std::string DEFAULT_AVS_GATEWAY = "https://alexa.na.gateway.devices.a2z.com";
/// Stored AVS Gateway
static const std::string STORED_AVS_GATEWAY = "www.avs-gatewa-from-storage.com";
// clang-format off
static const std::string AVS_GATEWAY_MANAGER_JSON = R"(
{
"avsGatewayManager" : {
"avsGateway":")" + TEST_AVS_GATEWAY + R"("
}
}
)";
// clang-format on
// clang-format off
static const std::string AVS_GATEWAY_MANAGER_JSON_NO_GATEWAY = R"(
{
"avsGatewayManager" : {
}
}
)";
// clang-format on
// clang-format off
static const std::string AVS_GATEWAY_MANAGER_JSON_EMPTY_GATEWAY = R"(
{
"avsGatewayManager" : {
"avsGateway":""
}
}
)";
// clang-format on
class MockAVSGatewayManagerStorage : public storage::AVSGatewayManagerStorageInterface {
public:
MOCK_METHOD0(init, bool());
MOCK_METHOD1(loadState, bool(GatewayVerifyState*));
MOCK_METHOD1(saveState, bool(const GatewayVerifyState&));
MOCK_METHOD0(clear, void());
};
/**
* Test harness for @c AVSGatewayManager class.
*/
class AVSGatewayManagerTest : public Test {
public:
/// Setup the test harness for running the test.
void SetUp() override;
/// Clean up the test harness after running the test.
void TearDown() override;
protected:
/// Initializes the @c ConfigurationRoot.
void initializeConfigRoot(const std::string& configJson);
/// Creates the @c AVSGatewayManager used in the tests.
void createAVSGatewayManager();
/// The @c CustomerDataManager.
std::shared_ptr<registrationManager::CustomerDataManager> m_customerDataManager;
/// The mock @c AVSGatewayAssigner.
std::shared_ptr<MockAVSGatewayAssigner> m_mockAvsGatewayAssigner;
/// The mock @c AVSGatewayManagerStorageInterface.
std::shared_ptr<MockAVSGatewayManagerStorage> m_mockAVSGatewayManagerStorage;
/// The instance of the @c AVSGatewayManagerStorage that will be used in the tests.
std::shared_ptr<AVSGatewayManager> m_avsGatewayManager;
};
void AVSGatewayManagerTest::SetUp() {
m_mockAVSGatewayManagerStorage = std::make_shared<NiceMock<MockAVSGatewayManagerStorage>>();
m_mockAvsGatewayAssigner = std::make_shared<NiceMock<MockAVSGatewayAssigner>>();
m_customerDataManager = std::make_shared<registrationManager::CustomerDataManager>();
}
void AVSGatewayManagerTest::TearDown() {
ConfigurationNode::uninitialize();
}
void AVSGatewayManagerTest::initializeConfigRoot(const std::string& configJson) {
auto json = std::shared_ptr<std::stringstream>(new std::stringstream());
*json << configJson;
std::vector<std::shared_ptr<std::istream>> jsonStream;
jsonStream.push_back(json);
ASSERT_TRUE(ConfigurationNode::initialize(jsonStream));
}
void AVSGatewayManagerTest::createAVSGatewayManager() {
EXPECT_CALL(*m_mockAVSGatewayManagerStorage, init()).Times(1).WillOnce(Return(true));
EXPECT_CALL(*m_mockAVSGatewayManagerStorage, loadState(_)).Times(1).WillOnce(Return(true));
m_avsGatewayManager =
AVSGatewayManager::create(m_mockAVSGatewayManagerStorage, m_customerDataManager, ConfigurationNode::getRoot());
ASSERT_NE(m_avsGatewayManager, nullptr);
}
TEST_F(AVSGatewayManagerTest, test_createAVSGatewayManagerWithInvalidParameters) {
auto instance = AVSGatewayManager::create(nullptr, m_customerDataManager, ConfigurationNode::getRoot());
ASSERT_EQ(instance, nullptr);
instance = AVSGatewayManager::create(m_mockAVSGatewayManagerStorage, nullptr, ConfigurationNode::getRoot());
ASSERT_EQ(instance, nullptr);
}
/**
* Test if a call to setAVSGatewayAssigner uses the gateway URL from the configuration file.
*/
TEST_F(AVSGatewayManagerTest, test_defaultAVSGatewayFromConfigFile) {
initializeConfigRoot(AVS_GATEWAY_MANAGER_JSON);
createAVSGatewayManager();
EXPECT_CALL(*m_mockAvsGatewayAssigner, setAVSGateway(_)).WillOnce(Invoke([](const std::string& gatewayURL) {
ASSERT_EQ(gatewayURL, TEST_AVS_GATEWAY);
}));
m_avsGatewayManager->setAVSGatewayAssigner(m_mockAvsGatewayAssigner);
}
/**
* Test if a call to setAVSGatewayAssigner uses the default gateway URL if configuration is not specified.
*/
TEST_F(AVSGatewayManagerTest, test_defaultAVSGatewayFromConfigFileWithNoGateway) {
initializeConfigRoot(AVS_GATEWAY_MANAGER_JSON_NO_GATEWAY);
createAVSGatewayManager();
EXPECT_CALL(*m_mockAvsGatewayAssigner, setAVSGateway(_)).WillOnce(Invoke([](const std::string& gatewayURL) {
ASSERT_EQ(gatewayURL, DEFAULT_AVS_GATEWAY);
}));
m_avsGatewayManager->setAVSGatewayAssigner(m_mockAvsGatewayAssigner);
}
/**
* Test if a call to setAVSGatewayAssigner uses the default gateway URL if avsGateway in configuration is empty.
*/
TEST_F(AVSGatewayManagerTest, test_defaultAVSGatewayFromConfigFileWithEmptyGateway) {
initializeConfigRoot(AVS_GATEWAY_MANAGER_JSON_EMPTY_GATEWAY);
createAVSGatewayManager();
EXPECT_CALL(*m_mockAvsGatewayAssigner, setAVSGateway(_)).WillOnce(Invoke([](const std::string& gatewayURL) {
ASSERT_EQ(gatewayURL, DEFAULT_AVS_GATEWAY);
}));
m_avsGatewayManager->setAVSGatewayAssigner(m_mockAvsGatewayAssigner);
}
/**
* Test if a call to setAVSGatewayAssigner uses the gateway URL from storage.
*/
TEST_F(AVSGatewayManagerTest, test_avsGatewayFromStorage) {
initializeConfigRoot(AVS_GATEWAY_MANAGER_JSON);
EXPECT_CALL(*m_mockAVSGatewayManagerStorage, init()).Times(1).WillOnce(Return(true));
EXPECT_CALL(*m_mockAVSGatewayManagerStorage, loadState(_)).WillOnce(Invoke([](GatewayVerifyState* state) {
state->avsGatewayURL = STORED_AVS_GATEWAY;
state->isVerified = true;
return true;
}));
m_avsGatewayManager =
AVSGatewayManager::create(m_mockAVSGatewayManagerStorage, m_customerDataManager, ConfigurationNode::getRoot());
ASSERT_NE(m_avsGatewayManager, nullptr);
EXPECT_CALL(*m_mockAvsGatewayAssigner, setAVSGateway(_)).WillOnce(Invoke([](const std::string& gatewayURL) {
ASSERT_EQ(gatewayURL, STORED_AVS_GATEWAY);
}));
m_avsGatewayManager->setAVSGatewayAssigner(m_mockAvsGatewayAssigner);
}
/**
* Test if a call to setGatewayURL() with a new URL calls the setAVSGateway() method on @c AVSGatewayAssigner and calls
* storeState() on @c AVSGatewayManagerStorage.
*/
TEST_F(AVSGatewayManagerTest, test_setAVSGatewayURLWithNewURL) {
initializeConfigRoot(AVS_GATEWAY_MANAGER_JSON);
createAVSGatewayManager();
EXPECT_CALL(*m_mockAvsGatewayAssigner, setAVSGateway(_)).Times(2);
EXPECT_CALL(*m_mockAVSGatewayManagerStorage, saveState(_)).Times(1);
m_avsGatewayManager->setAVSGatewayAssigner(m_mockAvsGatewayAssigner);
m_avsGatewayManager->setGatewayURL(DEFAULT_AVS_GATEWAY);
}
/**
* Test if a call to setGatewayURL with the same URL does not trigger calls to @c AVSGatewayAssigner and @c
* AVSGatewayManagerStorage.
*/
TEST_F(AVSGatewayManagerTest, test_setAVSGatewayURLWithSameURL) {
initializeConfigRoot(AVS_GATEWAY_MANAGER_JSON);
createAVSGatewayManager();
EXPECT_CALL(*m_mockAvsGatewayAssigner, setAVSGateway(_)).Times(1);
EXPECT_CALL(*m_mockAVSGatewayManagerStorage, saveState(_)).Times(0);
m_avsGatewayManager->setAVSGatewayAssigner(m_mockAvsGatewayAssigner);
m_avsGatewayManager->setGatewayURL(TEST_AVS_GATEWAY);
}
/**
* Test if a call to clearData() invokes call to clear() on the storage.
*/
TEST_F(AVSGatewayManagerTest, test_clearData) {
initializeConfigRoot(AVS_GATEWAY_MANAGER_JSON);
createAVSGatewayManager();
EXPECT_CALL(*m_mockAVSGatewayManagerStorage, clear()).Times(1);
m_avsGatewayManager->clearData();
}
} // namespace test
} // namespace avsGatewayManager
} // namespace alexaClientSDK