2017-06-23 23:26:34 +00:00
|
|
|
/*
|
2020-04-13 22:56:35 +00:00
|
|
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2017-05-18 05:02:48 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/// @file AlexaClientSDKInitTest.cpp
|
|
|
|
|
|
|
|
#include <sstream>
|
2021-11-15 23:35:18 +00:00
|
|
|
|
|
|
|
#include <gmock/gmock.h>
|
2017-05-18 05:02:48 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2021-11-15 23:35:18 +00:00
|
|
|
#include <AVSCommon/AVS/Initialization/AlexaClientSDKInit.h>
|
|
|
|
#include <AVSCommon/AVS/Initialization/InitializationParametersBuilder.h>
|
|
|
|
#include <AVSCommon/SDKInterfaces/Timing/MockTimerDelegateFactory.h>
|
|
|
|
#ifdef ENABLE_LPM
|
|
|
|
#include <AVSCommon/Utils/Power/NoOpPowerResourceManager.h>
|
|
|
|
#endif
|
2017-05-18 05:02:48 +00:00
|
|
|
|
|
|
|
namespace alexaClientSDK {
|
2017-06-23 23:26:34 +00:00
|
|
|
namespace avsCommon {
|
|
|
|
namespace avs {
|
2017-05-18 05:02:48 +00:00
|
|
|
namespace initialization {
|
|
|
|
namespace test {
|
|
|
|
|
2020-10-27 00:14:11 +00:00
|
|
|
static std::vector<std::shared_ptr<std::istream>> EMPTY_JSON_STREAMS;
|
|
|
|
|
2021-11-15 23:35:18 +00:00
|
|
|
using namespace sdkInterfaces::test;
|
|
|
|
using namespace ::testing;
|
|
|
|
|
|
|
|
/// Test harness for @c AlexaClientSDKInit class.
|
|
|
|
class AlexaClientSDKInitTest : public ::testing::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;
|
|
|
|
|
|
|
|
/// Test initialization parameters builder.
|
|
|
|
std::unique_ptr<InitializationParametersBuilder> m_builder;
|
|
|
|
/// Test json streams.
|
|
|
|
std::shared_ptr<std::vector<std::shared_ptr<std::istream>>> m_jsonStreamsPtr;
|
|
|
|
/// Test logger.
|
|
|
|
std::shared_ptr<utils::logger::Logger> m_logger;
|
|
|
|
};
|
|
|
|
|
|
|
|
void AlexaClientSDKInitTest::SetUp() {
|
|
|
|
m_builder = InitializationParametersBuilder::create();
|
|
|
|
m_jsonStreamsPtr = std::make_shared<std::vector<std::shared_ptr<std::istream>>>(EMPTY_JSON_STREAMS);
|
|
|
|
m_builder->withJsonStreams(m_jsonStreamsPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlexaClientSDKInitTest::TearDown() {
|
|
|
|
AlexaClientSDKInit::uninitialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests @c initialize without any initialization parameters, expecting to return @c false.
|
|
|
|
*/
|
|
|
|
TEST_F(AlexaClientSDKInitTest, test_initializeNoInitParams) {
|
|
|
|
ASSERT_FALSE(AlexaClientSDKInit::initialize(nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests @c initialize with a null timerDelegateFactory, expecting to return @c false.
|
|
|
|
*/
|
|
|
|
TEST_F(AlexaClientSDKInitTest, test_initializeWithNullTimerDelegateFactory) {
|
|
|
|
auto initParams = m_builder->build();
|
|
|
|
initParams->timerDelegateFactory = nullptr;
|
|
|
|
ASSERT_FALSE(AlexaClientSDKInit::initialize(std::move(initParams)));
|
|
|
|
}
|
2017-05-18 05:02:48 +00:00
|
|
|
|
|
|
|
/**
|
2021-11-15 23:35:18 +00:00
|
|
|
* Tests @c initialize without any JSON configuration, expecting to return @c true.
|
2017-05-18 05:02:48 +00:00
|
|
|
*
|
|
|
|
* @note This test also validates whether libcurl supports HTTP2.
|
|
|
|
*/
|
2021-11-15 23:35:18 +00:00
|
|
|
TEST_F(AlexaClientSDKInitTest, test_initializeNoJSONConfig) {
|
2020-10-27 00:14:11 +00:00
|
|
|
ASSERT_TRUE(AlexaClientSDKInit::initialize(EMPTY_JSON_STREAMS));
|
2017-05-18 05:02:48 +00:00
|
|
|
}
|
|
|
|
|
2021-11-15 23:35:18 +00:00
|
|
|
#ifdef ENABLE_LPM
|
|
|
|
/*
|
|
|
|
* Tests @c initialize with null Low Power Mode, expecting to return @c true.
|
|
|
|
*/
|
|
|
|
TEST_F(AlexaClientSDKInitTest, test_initializeNullLPM) {
|
|
|
|
auto initParams = m_builder->build();
|
|
|
|
initParams->powerResourceManager = nullptr;
|
|
|
|
ASSERT_TRUE(AlexaClientSDKInit::initialize(std::move(initParams)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tests @c initialize with Low Power Mode enabled and unsupported TimerDelegateFactory, expecting to return @c false.
|
|
|
|
*/
|
|
|
|
TEST_F(AlexaClientSDKInitTest, test_initializeLPMUnsupportedTimerDelegateFactory) {
|
|
|
|
auto powerResourceManager = std::make_shared<avsCommon::utils::power::NoOpPowerResourceManager>();
|
|
|
|
auto mockTimerDelegateFactory = std::make_shared<MockTimerDelegateFactory>();
|
|
|
|
m_builder->withTimerDelegateFactory(mockTimerDelegateFactory);
|
|
|
|
EXPECT_CALL(*mockTimerDelegateFactory, supportsLowPowerMode()).WillOnce(Return(false));
|
|
|
|
m_builder->withPowerResourceManager(powerResourceManager);
|
|
|
|
auto initParams = m_builder->build();
|
|
|
|
ASSERT_FALSE(AlexaClientSDKInit::initialize(std::move(initParams)));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-05-18 05:02:48 +00:00
|
|
|
/**
|
2021-11-15 23:35:18 +00:00
|
|
|
* Tests @c initialize with an invalid JSON configuration, expecting to return @c false.
|
2017-05-18 05:02:48 +00:00
|
|
|
*
|
|
|
|
* @note This test also validates whether libcurl supports HTTP2.
|
|
|
|
*/
|
2021-11-15 23:35:18 +00:00
|
|
|
TEST_F(AlexaClientSDKInitTest, test_initializeInvalidJSONConfig) {
|
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
|
|
|
auto invalidJSON = std::shared_ptr<std::stringstream>(new std::stringstream());
|
|
|
|
(*invalidJSON) << "{";
|
|
|
|
ASSERT_FALSE(AlexaClientSDKInit::initialize({invalidJSON}));
|
2017-05-18 05:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-15 23:35:18 +00:00
|
|
|
* Tests @c initialize with a valid JSON configuration, expecting to return @c true.
|
2017-05-18 05:02:48 +00:00
|
|
|
*
|
|
|
|
* @note This test also validates whether libcurl supports HTTP2.
|
|
|
|
*/
|
2021-11-15 23:35:18 +00:00
|
|
|
TEST_F(AlexaClientSDKInitTest, test_initializeValidJSONConfig) {
|
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
|
|
|
auto validJSON = std::shared_ptr<std::stringstream>(new std::stringstream());
|
|
|
|
(*validJSON) << R"({"key":"value"})";
|
|
|
|
ASSERT_TRUE(AlexaClientSDKInit::initialize({validJSON}));
|
2017-05-18 05:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-15 23:35:18 +00:00
|
|
|
* Tests @c isInitialized when the SDK has not been initialized yet, expecting to return @c false.
|
2017-05-18 05:02:48 +00:00
|
|
|
*/
|
2021-11-15 23:35:18 +00:00
|
|
|
TEST_F(AlexaClientSDKInitTest, test_uninitializedIsInitialized) {
|
2017-05-18 05:02:48 +00:00
|
|
|
ASSERT_FALSE(AlexaClientSDKInit::isInitialized());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-15 23:35:18 +00:00
|
|
|
* Tests @c isInitialized when the SDK is initialized, expecting to return @c true.
|
2017-05-18 05:02:48 +00:00
|
|
|
*/
|
2021-11-15 23:35:18 +00:00
|
|
|
TEST_F(AlexaClientSDKInitTest, test_isInitialized) {
|
2020-10-27 00:14:11 +00:00
|
|
|
ASSERT_TRUE(AlexaClientSDKInit::initialize(EMPTY_JSON_STREAMS));
|
2017-05-18 05:02:48 +00:00
|
|
|
EXPECT_TRUE(AlexaClientSDKInit::isInitialized());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests @c uninitialize when the SDK has not been initialized yet, expecting no crashes or exceptions.
|
|
|
|
*/
|
2021-11-15 23:35:18 +00:00
|
|
|
TEST_F(AlexaClientSDKInitTest, test_uninitialize) {
|
2017-05-18 05:02:48 +00:00
|
|
|
AlexaClientSDKInit::uninitialize();
|
|
|
|
}
|
|
|
|
|
2021-11-15 23:35:18 +00:00
|
|
|
/**
|
|
|
|
* Tests @c getCreateAlexaClientSDKInit using JSON Stream with a null logger, expecting to return @c nullptr.
|
|
|
|
*/
|
|
|
|
TEST_F(AlexaClientSDKInitTest, test_getCreateAlexaClientSDKInitNullLoggerUsingJSON) {
|
|
|
|
auto constructor = AlexaClientSDKInit::getCreateAlexaClientSDKInit(EMPTY_JSON_STREAMS);
|
|
|
|
ASSERT_EQ(constructor(nullptr), nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests @c getCreateAlexaClientSDKInit using Init Params with a null logger, expecting to return @c nullptr.
|
|
|
|
*/
|
|
|
|
TEST_F(AlexaClientSDKInitTest, test_getCreateAlexaClientSDKInitNullLoggerUsingInitParams) {
|
|
|
|
auto initParams = m_builder->build();
|
|
|
|
auto constructor = AlexaClientSDKInit::getCreateAlexaClientSDKInit(std::move(initParams));
|
|
|
|
ASSERT_EQ(constructor(nullptr), nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests @c getCreateAlexaClientSDKInit using invalid JSON Stream, expecting to return @c nullptr.
|
|
|
|
*/
|
|
|
|
TEST_F(AlexaClientSDKInitTest, test_getCreateAlexaClientSDKInitInvalidJSONStream) {
|
|
|
|
auto invalidJSON = std::shared_ptr<std::stringstream>(new std::stringstream());
|
|
|
|
(*invalidJSON) << "{";
|
|
|
|
auto constructor = AlexaClientSDKInit::getCreateAlexaClientSDKInit({invalidJSON});
|
|
|
|
ASSERT_EQ(constructor(m_logger), nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests @c getCreateAlexaClientSDKInit using valid JSON Stream, expecting to return @c true.
|
|
|
|
*/
|
|
|
|
TEST_F(AlexaClientSDKInitTest, test_getCreateAlexaClientSDKInitValidJSONStream) {
|
|
|
|
auto constructor = AlexaClientSDKInit::getCreateAlexaClientSDKInit(EMPTY_JSON_STREAMS);
|
|
|
|
auto alexaClientSDKInitInstance = constructor(m_logger);
|
|
|
|
ASSERT_FALSE(AlexaClientSDKInit::isInitialized());
|
|
|
|
alexaClientSDKInitInstance->initialize(EMPTY_JSON_STREAMS);
|
|
|
|
ASSERT_TRUE(AlexaClientSDKInit::isInitialized());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests @c getCreateAlexaClientSDKInit using valid Init Params, expecting to return @c true.
|
|
|
|
*/
|
|
|
|
TEST_F(AlexaClientSDKInitTest, test_getCreateAlexaClientSDKInitValidInitParams) {
|
|
|
|
auto initParams = m_builder->build();
|
|
|
|
auto constructor = AlexaClientSDKInit::getCreateAlexaClientSDKInit(std::move(initParams));
|
|
|
|
auto alexaClientSDKInitInstance = constructor(m_logger);
|
|
|
|
ASSERT_FALSE(AlexaClientSDKInit::isInitialized());
|
|
|
|
alexaClientSDKInitInstance->initialize(EMPTY_JSON_STREAMS);
|
|
|
|
ASSERT_TRUE(AlexaClientSDKInit::isInitialized());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests @c getCreateAlexaClientSDKInit using null Init Params, expecting to return @c nullptr.
|
|
|
|
*/
|
|
|
|
TEST_F(AlexaClientSDKInitTest, test_getCreateAlexaClientSDKInitNullInitParams) {
|
|
|
|
auto initParams = m_builder->build();
|
|
|
|
auto constructor = AlexaClientSDKInit::getCreateAlexaClientSDKInit(std::move(initParams));
|
|
|
|
ASSERT_EQ(constructor(m_logger), nullptr);
|
|
|
|
}
|
|
|
|
|
2017-10-02 22:59:05 +00:00
|
|
|
} // namespace test
|
|
|
|
} // namespace initialization
|
|
|
|
} // namespace avs
|
|
|
|
} // namespace avsCommon
|
|
|
|
} // namespace alexaClientSDK
|