2017-02-10 23:39:10 +00:00
|
|
|
/*
|
2018-02-12 23:31:53 +00:00
|
|
|
* Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2017-02-10 23:39:10 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2017-08-08 00:04:43 +00:00
|
|
|
/// @file AVSConnectionManagerTest.cpp
|
|
|
|
|
2017-02-10 23:39:10 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <gmock/gmock.h>
|
2017-08-08 00:04:43 +00:00
|
|
|
#include <AVSCommon/AVS/Initialization/AlexaClientSDKInit.h>
|
2017-02-10 23:39:10 +00:00
|
|
|
#include "ACL/AVSConnectionManager.h"
|
|
|
|
|
|
|
|
namespace alexaClientSDK {
|
|
|
|
namespace acl {
|
2017-06-09 23:23:31 +00:00
|
|
|
namespace test {
|
2017-02-10 23:39:10 +00:00
|
|
|
|
|
|
|
using namespace ::testing;
|
2017-08-08 00:04:43 +00:00
|
|
|
using namespace alexaClientSDK::avsCommon::avs::initialization;
|
2017-06-23 23:26:34 +00:00
|
|
|
using namespace alexaClientSDK::avsCommon::sdkInterfaces;
|
2017-02-10 23:39:10 +00:00
|
|
|
|
2017-08-08 00:04:43 +00:00
|
|
|
/// This class allows us to test MessageObserver interaction
|
|
|
|
class MockMessageObserver : public MessageObserverInterface {
|
|
|
|
public:
|
2017-10-02 22:59:05 +00:00
|
|
|
MockMessageObserver() {
|
|
|
|
}
|
|
|
|
MOCK_METHOD2(receive, void(const std::string& contextId, const std::string& message));
|
2017-08-08 00:04:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// This class allows us to test ConnectionStatusObserver interaction
|
|
|
|
class MockConnectionStatusObserver : public ConnectionStatusObserverInterface {
|
|
|
|
public:
|
2017-10-02 22:59:05 +00:00
|
|
|
MockConnectionStatusObserver() {
|
|
|
|
}
|
|
|
|
MOCK_METHOD2(
|
|
|
|
onConnectionStatusChanged,
|
|
|
|
void(
|
|
|
|
ConnectionStatusObserverInterface::Status status,
|
|
|
|
ConnectionStatusObserverInterface::ChangedReason reason));
|
2017-08-08 00:04:43 +00:00
|
|
|
};
|
|
|
|
|
2017-02-10 23:39:10 +00:00
|
|
|
/**
|
|
|
|
* This class allows us to test MessageRouter interaction.
|
|
|
|
*/
|
|
|
|
class MockMessageRouter : public MessageRouterInterface {
|
|
|
|
public:
|
2017-10-02 22:59:05 +00:00
|
|
|
MockMessageRouter() : MessageRouterInterface{"MockMessageRouter"} {
|
|
|
|
}
|
2017-02-10 23:39:10 +00:00
|
|
|
|
|
|
|
MOCK_METHOD0(enable, void());
|
|
|
|
MOCK_METHOD0(disable, void());
|
2017-10-02 22:59:05 +00:00
|
|
|
MOCK_METHOD0(doShutdown, void());
|
2017-06-23 23:26:34 +00:00
|
|
|
MOCK_METHOD0(getConnectionStatus, MessageRouterInterface::ConnectionStatus());
|
2017-08-08 00:04:43 +00:00
|
|
|
// TODO: ACSDK-421: Revert this to use send().
|
|
|
|
MOCK_METHOD1(sendMessage, void(std::shared_ptr<avsCommon::avs::MessageRequest> request));
|
2017-02-10 23:39:10 +00:00
|
|
|
MOCK_METHOD1(setAVSEndpoint, void(const std::string& avsEndpoint));
|
|
|
|
MOCK_METHOD1(setObserver, void(std::shared_ptr<MessageRouterObserverInterface> observer));
|
|
|
|
};
|
|
|
|
|
2017-08-08 00:04:43 +00:00
|
|
|
/// Test harness for @c AVSConnectionManager class
|
2017-02-10 23:39:10 +00:00
|
|
|
class AVSConnectionManagerTest : public ::testing::Test {
|
|
|
|
public:
|
2017-08-08 00:04:43 +00:00
|
|
|
void SetUp() override;
|
|
|
|
void TearDown() override;
|
2017-02-10 23:39:10 +00:00
|
|
|
|
|
|
|
std::shared_ptr<AVSConnectionManager> m_avsConnectionManager;
|
|
|
|
std::shared_ptr<MockMessageRouter> m_messageRouter;
|
2017-08-08 00:04:43 +00:00
|
|
|
std::shared_ptr<MockConnectionStatusObserver> m_observer;
|
|
|
|
std::shared_ptr<MockMessageObserver> m_messageObserver;
|
2017-02-10 23:39:10 +00:00
|
|
|
};
|
|
|
|
|
2017-08-08 00:04:43 +00:00
|
|
|
void AVSConnectionManagerTest::SetUp() {
|
Version 1.7.0 of the avs-device-sdk
Changes in this update:
**Enhancements**
* `AuthDelegate` and `AuthServer.py` have been replaced by `CBLAUthDelegate`, which provides a more straightforward path to authorization.
* Added a new configuration property called [`cblAuthDelegate`](https://github.com/alexa/avs-device-sdk/blob/master/Integration/AlexaClientSDKConfig.json#L2). This object specifies parameters for `CBLAuthDelegate`.
* Added a new configuration property called [`miscDatabase`](https://github.com/alexa/avs-device-sdk/blob/master/Integration/AlexaClientSDKConfig.json#L34), which is a generic key/value database to be used by various components.
* Added a new configuration property called [`dcfDelegate`](https://github.com/alexa/avs-device-sdk/blob/master/Integration/AlexaClientSDKConfig.json#L17) This object specifies parameters for `DCFDelegate`. Within this object, values were added for the 'endpoint' and `overridenDcfPublishMessageBody`. 'endpoint' is the endpoint to connect to in order to send device capabilities. `overridenDcfPublishMessageBody`is the message that will get sent out to the Capabilities API. Note: values within the `dcfDelegate` object will only work in `DEBUG` builds.
* Added a new configuration property called [`deviceInfo`](https://github.com/alexa/avs-device-sdk/blob/master/Integration/AlexaClientSDKConfig.json#L9) which specifies device-identifying information for use by the Device Capability Framework (DCF), and for authorization (CBLAuthDelegate).
* Updated the Directive Sequencer to support wildcard directive handlers. This allows a handler for a given AVS interface to register at the namespace level, rather than specifying the names of all directives within that namespace.
* Updated the Raspberry Pi installation script to include `alsasink` in the configuration file.
* Added `audioSink` as a configuration option. This allows users to override the audio sink element used in `Gstreamer`.
* Added an interface for monitoring internet connection status: `InternetConnectionMonitorInterface.h`.
* The Alexa Communications Library (ACL) is no longer required to wait until authorization has succeeded before attempting to connect to AVS. Instead, `HTTP2Transport` handles waiting for authorization to complete.
* Added the Device Capabilities Framework (DCF) delegate. Device capabilities can now be sent for each capability interface using DCF publish messages.
* The sample app has been updated to send DCF publish messages, which will automatically occur when the sample app starts. Note: a DCF publish message must be successfully sent in order for communication with AVS to occur.
* The SDK now supports HTTP PUT messages.
* Added support for opt-arg style arguments and multiple configuration files. Now, the sample app can be invoked by either of these commands: `SampleApp <configfile> <debuglevel>` OR `SampleApp -C file1 -C file2 ... -L loglevel`.
**Bug Fixes**
* Issues [447](https://github.com/alexa/avs-device-sdk/issues/447) and [553](https://github.com/alexa/avs-device-sdk/issues/553) Fixed the `AttachmentRenderSource`'s handling of `BLOCKING` `AttachmentReaders`.
* Updated the `Logger` implementation to be more resilient to `nullptr` string inputs.
* Fixed a `TimeUtils` utility-related compile issue.
* Fixed a bug in which alerts failed to activate if the system was restarted without network connection.
* Fixed Android 64-bit build failure issue.
**Known Issues**
* The `ACL` may encounter issues if audio attachments are received but not consumed.
* `SpeechSynthesizerState` currently uses `GAINING_FOCUS` and `LOSING_FOCUS` as a workaround for handling intermediate state. These states may be removed in a future release.
* Some ERROR messages may be printed during start-up event if initialization proceeds normally and successfully.
* If an unrecoverable authorization error or an unrecoverable DCF error is encountered, the sample app may crash on shutdown.
* If a non-CBL `clientId` is included in the `deviceInfo` section of `AlexaClientSDKConfig.json`, the error will be reported as an unrecoverable authorization error, rather than a more specific error.
2018-04-18 22:17:28 +00:00
|
|
|
AlexaClientSDKInit::initialize(std::vector<std::shared_ptr<std::istream>>());
|
2017-08-08 00:04:43 +00:00
|
|
|
m_messageRouter = std::make_shared<MockMessageRouter>();
|
|
|
|
m_observer = std::make_shared<MockConnectionStatusObserver>();
|
|
|
|
m_messageObserver = std::make_shared<MockMessageObserver>();
|
|
|
|
m_avsConnectionManager = AVSConnectionManager::create(
|
2017-10-02 22:59:05 +00:00
|
|
|
m_messageRouter,
|
|
|
|
true,
|
|
|
|
std::unordered_set<std::shared_ptr<ConnectionStatusObserverInterface>>(),
|
|
|
|
std::unordered_set<std::shared_ptr<MessageObserverInterface>>());
|
2017-08-08 00:04:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AVSConnectionManagerTest::TearDown() {
|
|
|
|
AlexaClientSDKInit::uninitialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test @c create with valid messageRouter, ConnectionStatusObserver, MessageObservers
|
|
|
|
*/
|
|
|
|
TEST_F(AVSConnectionManagerTest, createTest) {
|
|
|
|
EXPECT_CALL(*m_messageRouter, setObserver(_)).Times(1);
|
|
|
|
EXPECT_CALL(*m_messageRouter, enable()).Times(1);
|
|
|
|
ASSERT_NE(nullptr, m_avsConnectionManager->create(m_messageRouter, true, {m_observer}, {m_messageObserver}));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test @c create with different combinations of messageRouter, ConnectionStatusObserver, MessageObservers
|
|
|
|
*/
|
|
|
|
TEST_F(AVSConnectionManagerTest, createWithNullMessageRouterAndObservers) {
|
|
|
|
ASSERT_EQ(nullptr, m_avsConnectionManager->create(nullptr, true, {m_observer}, {m_messageObserver}));
|
|
|
|
ASSERT_EQ(nullptr, m_avsConnectionManager->create(m_messageRouter, true, {nullptr}, {m_messageObserver}));
|
|
|
|
ASSERT_EQ(nullptr, m_avsConnectionManager->create(m_messageRouter, true, {m_observer}, {nullptr}));
|
|
|
|
std::shared_ptr<MockConnectionStatusObserver> validConnectionStatusObserver;
|
|
|
|
validConnectionStatusObserver = std::make_shared<MockConnectionStatusObserver>();
|
2017-10-02 22:59:05 +00:00
|
|
|
ASSERT_EQ(
|
|
|
|
nullptr,
|
|
|
|
m_avsConnectionManager->create(
|
|
|
|
m_messageRouter, true, {m_observer, nullptr, validConnectionStatusObserver}, {m_messageObserver}));
|
2017-08-08 00:04:43 +00:00
|
|
|
std::shared_ptr<MockMessageObserver> validMessageObserver;
|
|
|
|
validMessageObserver = std::make_shared<MockMessageObserver>();
|
2017-10-02 22:59:05 +00:00
|
|
|
ASSERT_EQ(
|
|
|
|
nullptr,
|
|
|
|
m_avsConnectionManager->create(
|
|
|
|
m_messageRouter, true, {m_observer}, {m_messageObserver, nullptr, validMessageObserver}));
|
2017-08-08 00:04:43 +00:00
|
|
|
ASSERT_EQ(nullptr, m_avsConnectionManager->create(m_messageRouter, true, {nullptr}, {nullptr}));
|
|
|
|
// create should pass with empty set of ConnectionStatusObservers
|
2017-10-02 22:59:05 +00:00
|
|
|
ASSERT_NE(
|
|
|
|
nullptr,
|
|
|
|
m_avsConnectionManager->create(
|
|
|
|
m_messageRouter,
|
|
|
|
true,
|
|
|
|
std::unordered_set<std::shared_ptr<ConnectionStatusObserverInterface>>(),
|
|
|
|
{validMessageObserver}));
|
2017-08-08 00:04:43 +00:00
|
|
|
// create should pass with empty set of MessageObservers
|
2017-10-02 22:59:05 +00:00
|
|
|
ASSERT_NE(
|
|
|
|
nullptr,
|
|
|
|
m_avsConnectionManager->create(
|
|
|
|
m_messageRouter,
|
|
|
|
true,
|
|
|
|
{validConnectionStatusObserver},
|
|
|
|
std::unordered_set<std::shared_ptr<MessageObserverInterface>>()));
|
2017-08-08 00:04:43 +00:00
|
|
|
// create should pass with valid messageRouter, ConnectionStatusObservers and MessageObservers
|
2017-10-02 22:59:05 +00:00
|
|
|
ASSERT_NE(
|
|
|
|
nullptr,
|
|
|
|
m_avsConnectionManager->create(m_messageRouter, true, {validConnectionStatusObserver}, {validMessageObserver}));
|
2017-08-08 00:04:43 +00:00
|
|
|
}
|
|
|
|
|
2017-06-23 23:26:34 +00:00
|
|
|
/**
|
|
|
|
* Test addConnectionStatusObserver with a @c nullptr observer, expecting no errors.
|
|
|
|
*/
|
|
|
|
TEST_F(AVSConnectionManagerTest, addConnectionStatusObserverNull) {
|
2017-08-08 00:04:43 +00:00
|
|
|
EXPECT_CALL(*m_messageRouter, getConnectionStatus()).Times(0);
|
2017-06-23 23:26:34 +00:00
|
|
|
m_avsConnectionManager->addConnectionStatusObserver(nullptr);
|
|
|
|
}
|
|
|
|
|
2017-08-08 00:04:43 +00:00
|
|
|
/**
|
|
|
|
* Test with addConnectionStatusObserver with MockConnectionStatusObserver.
|
|
|
|
*/
|
|
|
|
TEST_F(AVSConnectionManagerTest, addConnectionStatusObserverValid) {
|
|
|
|
EXPECT_CALL(*m_observer, onConnectionStatusChanged(_, _)).Times(1);
|
|
|
|
m_avsConnectionManager->addConnectionStatusObserver(m_observer);
|
|
|
|
}
|
|
|
|
|
2017-06-23 23:26:34 +00:00
|
|
|
/**
|
|
|
|
* Test removeConnectionStatusObserver with a @c nullptr observer, expecting no errors.
|
|
|
|
*/
|
|
|
|
TEST_F(AVSConnectionManagerTest, removeConnectionStatusObserverNull) {
|
|
|
|
m_avsConnectionManager->removeConnectionStatusObserver(nullptr);
|
|
|
|
}
|
|
|
|
|
2017-07-18 22:25:37 +00:00
|
|
|
/**
|
|
|
|
* Test addMessageObserver with a @c nullptr observer, expecting no errors.
|
|
|
|
*/
|
|
|
|
TEST_F(AVSConnectionManagerTest, addMessageObserverNull) {
|
|
|
|
m_avsConnectionManager->addMessageObserver(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test removeMessageObserver with a @c nullptr observer, expecting no errors.
|
|
|
|
*/
|
|
|
|
TEST_F(AVSConnectionManagerTest, removeMessageObserverNull) {
|
|
|
|
m_avsConnectionManager->removeMessageObserver(nullptr);
|
|
|
|
}
|
|
|
|
|
2017-08-08 00:04:43 +00:00
|
|
|
/**
|
|
|
|
* Test enable and disable function of AVSConnectionManager
|
|
|
|
*/
|
|
|
|
TEST_F(AVSConnectionManagerTest, enableAndDisableFunction) {
|
|
|
|
EXPECT_CALL(*m_messageRouter, enable()).Times(1);
|
|
|
|
m_avsConnectionManager->enable();
|
|
|
|
ASSERT_TRUE(m_avsConnectionManager->isEnabled());
|
|
|
|
EXPECT_CALL(*m_messageRouter, disable()).Times(1);
|
|
|
|
m_avsConnectionManager->disable();
|
|
|
|
ASSERT_FALSE(m_avsConnectionManager->isEnabled());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests sendMessage with a @c nullptr request, expecting no errors.
|
|
|
|
*/
|
|
|
|
TEST_F(AVSConnectionManagerTest, sendMessageRequestTest) {
|
|
|
|
// TODO: ACSDK-421: Revert this to use send().
|
|
|
|
EXPECT_CALL(*m_messageRouter, sendMessage(_)).Times(1);
|
|
|
|
m_avsConnectionManager->sendMessage(nullptr);
|
|
|
|
// TODO: ACSDK-421: Revert this to use send().
|
|
|
|
EXPECT_CALL(*m_messageRouter, sendMessage(_)).Times(1);
|
|
|
|
std::shared_ptr<avsCommon::avs::MessageRequest> messageRequest;
|
Version 1.7.0 of the avs-device-sdk
Changes in this update:
**Enhancements**
* `AuthDelegate` and `AuthServer.py` have been replaced by `CBLAUthDelegate`, which provides a more straightforward path to authorization.
* Added a new configuration property called [`cblAuthDelegate`](https://github.com/alexa/avs-device-sdk/blob/master/Integration/AlexaClientSDKConfig.json#L2). This object specifies parameters for `CBLAuthDelegate`.
* Added a new configuration property called [`miscDatabase`](https://github.com/alexa/avs-device-sdk/blob/master/Integration/AlexaClientSDKConfig.json#L34), which is a generic key/value database to be used by various components.
* Added a new configuration property called [`dcfDelegate`](https://github.com/alexa/avs-device-sdk/blob/master/Integration/AlexaClientSDKConfig.json#L17) This object specifies parameters for `DCFDelegate`. Within this object, values were added for the 'endpoint' and `overridenDcfPublishMessageBody`. 'endpoint' is the endpoint to connect to in order to send device capabilities. `overridenDcfPublishMessageBody`is the message that will get sent out to the Capabilities API. Note: values within the `dcfDelegate` object will only work in `DEBUG` builds.
* Added a new configuration property called [`deviceInfo`](https://github.com/alexa/avs-device-sdk/blob/master/Integration/AlexaClientSDKConfig.json#L9) which specifies device-identifying information for use by the Device Capability Framework (DCF), and for authorization (CBLAuthDelegate).
* Updated the Directive Sequencer to support wildcard directive handlers. This allows a handler for a given AVS interface to register at the namespace level, rather than specifying the names of all directives within that namespace.
* Updated the Raspberry Pi installation script to include `alsasink` in the configuration file.
* Added `audioSink` as a configuration option. This allows users to override the audio sink element used in `Gstreamer`.
* Added an interface for monitoring internet connection status: `InternetConnectionMonitorInterface.h`.
* The Alexa Communications Library (ACL) is no longer required to wait until authorization has succeeded before attempting to connect to AVS. Instead, `HTTP2Transport` handles waiting for authorization to complete.
* Added the Device Capabilities Framework (DCF) delegate. Device capabilities can now be sent for each capability interface using DCF publish messages.
* The sample app has been updated to send DCF publish messages, which will automatically occur when the sample app starts. Note: a DCF publish message must be successfully sent in order for communication with AVS to occur.
* The SDK now supports HTTP PUT messages.
* Added support for opt-arg style arguments and multiple configuration files. Now, the sample app can be invoked by either of these commands: `SampleApp <configfile> <debuglevel>` OR `SampleApp -C file1 -C file2 ... -L loglevel`.
**Bug Fixes**
* Issues [447](https://github.com/alexa/avs-device-sdk/issues/447) and [553](https://github.com/alexa/avs-device-sdk/issues/553) Fixed the `AttachmentRenderSource`'s handling of `BLOCKING` `AttachmentReaders`.
* Updated the `Logger` implementation to be more resilient to `nullptr` string inputs.
* Fixed a `TimeUtils` utility-related compile issue.
* Fixed a bug in which alerts failed to activate if the system was restarted without network connection.
* Fixed Android 64-bit build failure issue.
**Known Issues**
* The `ACL` may encounter issues if audio attachments are received but not consumed.
* `SpeechSynthesizerState` currently uses `GAINING_FOCUS` and `LOSING_FOCUS` as a workaround for handling intermediate state. These states may be removed in a future release.
* Some ERROR messages may be printed during start-up event if initialization proceeds normally and successfully.
* If an unrecoverable authorization error or an unrecoverable DCF error is encountered, the sample app may crash on shutdown.
* If a non-CBL `clientId` is included in the `deviceInfo` section of `AlexaClientSDKConfig.json`, the error will be reported as an unrecoverable authorization error, rather than a more specific error.
2018-04-18 22:17:28 +00:00
|
|
|
messageRequest = std::make_shared<avsCommon::avs::MessageRequest>("Test message");
|
2017-08-08 00:04:43 +00:00
|
|
|
m_avsConnectionManager->sendMessage(messageRequest);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test setAVSEndpoint and expect a call to messageRouter's setAVSEndpoint.
|
|
|
|
*/
|
|
|
|
TEST_F(AVSConnectionManagerTest, setAVSEndpointTest) {
|
|
|
|
EXPECT_CALL(*m_messageRouter, setAVSEndpoint(_)).Times(1);
|
|
|
|
m_avsConnectionManager->setAVSEndpoint("AVSEndpoint");
|
|
|
|
}
|
2017-10-02 22:59:05 +00:00
|
|
|
} // namespace test
|
|
|
|
} // namespace acl
|
|
|
|
} // namespace alexaClientSDK
|
2017-08-08 00:04:43 +00:00
|
|
|
|
2017-10-02 22:59:05 +00:00
|
|
|
int main(int argc, char** argv) {
|
2017-08-08 00:04:43 +00:00
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|