avs-device-sdk/Settings/test/SettingsManagerTest.cpp

157 lines
5.5 KiB
C++
Raw Normal View History

Version 1.11 alexa-client-sdk Changes in this update: **Enhancements** * Added support for the new Alexa [DoNotDisturb](https://developer.amazon.com/docs/alexa-voice-service/donotdisturb.html) interface, which enables users to toggle the do not disturb (DND) function on their Alexa built-in products. * The SDK now supports [Opus](https://opus-codec.org/license/) encoding, which is optional. To enable Opus, you must [set the CMake flag to `-DOPUS=ON`](https://github.com/alexa/avs-device-sdk/wiki/Build-Options#Opus-encoding), and include the [libopus library](https://github.com/alexa/avs-device-sdk/wiki/Dependencies#core-dependencies) dependency in your build. * The MediaPlayer reference implementation has been expanded to support the SAMPLE-AES and AES-128 encryption methods for HLS streaming. * AES-128 encryption is dependent on libcrypto, which is part of the required openSSL library, and is enabled by default. * To enable [SAMPLE-AES](https://github.com/alexa/avs-device-sdk/wiki/Dependencies#core-dependencies/Enable-SAMPLE-AES-decryption) encryption, you must set the `-DSAMPLE_AES=ON` in your CMake command, and include the [FFMPEG](https://github.com/alexa/avs-device-sdk/wiki/Dependencies#core-dependencies/Enable-SAMPLE-AES-decryption) library dependency in your build. * A new configuration for [deviceSettings](https://github.com/alexa/avs-device-sdk/blob/v1.11.0/Integration/AlexaClientSDKConfig.json#L59) has been added.This configuration allows you to specify the location of the device settings database. * Added locale support for es-MX. **Bug Fixes** * Fixed an issue where music wouldn't resume playback in the Android app. * Now all equalizer capabilities are fully disabled when equalizer is turned off in configuration file. Previously, devices were unconditionally required to provide support for equalizer in order to run the SDK. * [Issue 1106](https://github.com/alexa/avs-device-sdk/issues/1106) - Fixed an issue in which the `CBLAuthDelegate` wasn't using the correct timeout during request refresh. * [Issue 1128](https://github.com/alexa/avs-device-sdk/issues/1128) - Fixed an issue in which the `AudioPlayer` instance persisted at shutdown, due to a shared dependency with the `ProgressTimer`. * Fixed in issue that occurred when a connection to streaming content was interrupted, the SDK did not attempt to resume the connection, and appeared to assume that the content had been fully downloaded. This triggered the next track to be played, assuming it was a playlist. * [Issue 1040](https://github.com/alexa/avs-device-sdk/issues/1040) - Fixed an issue where alarms would continue to play after user barge-in. **Known Issues** * `PlaylistParser` and `IterativePlaylistParser` generate two HTTP requests (one to fetch the content type, and one to fetch the audio data) for each audio stream played. * Music playback history isn't being displayed in the Alexa app for certain account and device types. * On GCC 8+, issues related to `-Wclass-memaccess` will trigger warnings. However, this won't cause the build to fail, and these warnings can be ignored. * In order to use Bluetooth source and sink PulseAudio, you must manually load and unload PulseAudio modules after the SDK starts. * 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. * The Alexa app doesn't always indicate when a device is successfully connected via Bluetooth. * Connecting a product to streaming media via Bluetooth will sometimes stop media playback within the source application. Resuming playback through the source application or toggling next/previous will correct playback. * When a source device is streaming silence via Bluetooth, the Alexa app indicates that audio content is streaming. * The Bluetooth agent assumes that the Bluetooth adapter is always connected to a power source. Disconnecting from a power source during operation is not yet supported. * On some products, interrupted Bluetooth playback may not resume if other content is locally streamed. * `make integration` is currently not available for Android. In order to run integration tests on Android, you'll need to manually upload the test binary file along with any input file. At that point, the adb can be used to run the integration tests. * On Raspberry Pi running Android Things with HDMI output audio, beginning of speech is truncated when Alexa responds to user TTS. * When the sample app is restarted and network connection is lost, alerts don't play. * When network connection is lost, lost connection status is not returned via local Text-to Speech (TTS).
2018-12-19 19:13:36 +00:00
/*
* Copyright 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 <memory>
#include <string>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <Settings/DeviceSettingsManager.h>
#include <Settings/SettingsManager.h>
#include <Settings/SettingObserverInterface.h>
namespace alexaClientSDK {
namespace settings {
namespace test {
enum TestSettingId { TEST_ID_INT = 0, TEST_ID_STRING };
/// @defgroup Define initial, new and default values to be used in the test.
/// @{
constexpr int INITIAL_INT_VALUE = 20;
constexpr int NEW_INT_VALUE = -20;
constexpr int DEFAULT_INT_VALUE = 0;
/// @}
/// Settings stub that just set the value immediately.
template <typename ValueT>
class SettingStub : public SettingInterface<ValueT> {
public:
SetSettingResult setLocalChange(const ValueT& value) override {
this->m_value = value;
return SetSettingResult::ENQUEUED;
}
SettingStub(const ValueT& value) : SettingInterface<ValueT>{value} {
}
};
/// Just an empty observer.
template <typename SettingT>
class TestObserver : public SettingT::ObserverType {
public:
void onSettingNotification(const typename SettingT::ValueType& value, SettingNotifications notification) override {
}
};
/// @defgroup Define settings types used in the tests.
/// @{
using SettingInt = SettingStub<int>;
using SettingString = SettingStub<std::string>;
/// @}
/// Test class.
class SettingsManagerTest : public testing::Test {
protected:
/// Settings Manager.
SettingsManager<SettingInt, SettingString> m_manager;
};
/// Test add settings and setting the setting value.
TEST_F(SettingsManagerTest, testSetExistingSetting) {
auto setting = std::make_shared<SettingInt>(INITIAL_INT_VALUE);
auto expectedResult = std::pair<bool, int>{true, NEW_INT_VALUE};
EXPECT_TRUE((m_manager.addSetting<TEST_ID_INT>(setting)));
EXPECT_EQ((m_manager.setValue<TEST_ID_INT>(NEW_INT_VALUE)), SetSettingResult::ENQUEUED);
EXPECT_EQ((m_manager.getValue<TEST_ID_INT>(DEFAULT_INT_VALUE)), expectedResult);
}
/// Test set value for setting that hasn't been registered.
TEST_F(SettingsManagerTest, testSetSettingUnavailable) {
SettingsManager<SettingInt, SettingString> manager;
EXPECT_EQ((m_manager.setValue<TEST_ID_INT>(NEW_INT_VALUE)), SetSettingResult::UNAVAILABLE_SETTING);
}
/// Test get value for setting that hasn't been registered.
TEST_F(SettingsManagerTest, testGetExistingSetting) {
auto setting = std::make_shared<SettingInt>(INITIAL_INT_VALUE);
auto expectedResult = std::pair<bool, int>{true, INITIAL_INT_VALUE};
EXPECT_TRUE((m_manager.addSetting<TEST_ID_INT>(setting)));
EXPECT_EQ((m_manager.getValue<TEST_ID_INT>(DEFAULT_INT_VALUE)), expectedResult);
}
/// Test get value for setting that hasn't been registered.
TEST_F(SettingsManagerTest, testGetSettingUnavailable) {
auto expectedResult = std::pair<bool, int>{false, DEFAULT_INT_VALUE};
EXPECT_EQ((m_manager.getValue<TEST_ID_INT>(DEFAULT_INT_VALUE)), expectedResult);
}
/// Test registering a setting that already exists.
TEST_F(SettingsManagerTest, testAddExistingSetting) {
auto setting1 = std::make_shared<SettingInt>(INITIAL_INT_VALUE);
auto setting2 = std::make_shared<SettingInt>(INITIAL_INT_VALUE);
EXPECT_TRUE((m_manager.addSetting<TEST_ID_INT>(setting1)));
EXPECT_FALSE((m_manager.addSetting<TEST_ID_INT>(setting2)));
}
/// Test addObserver for a setting that exists.
TEST_F(SettingsManagerTest, testAddObserver) {
auto setting = std::make_shared<SettingInt>(INITIAL_INT_VALUE);
auto observer = std::make_shared<TestObserver<SettingInt>>();
EXPECT_TRUE((m_manager.addSetting<TEST_ID_INT>(setting)));
EXPECT_TRUE((m_manager.addObserver<TEST_ID_INT>(observer)));
}
/// Test addObserver for a setting that doesn't exist.
TEST_F(SettingsManagerTest, testAddObserverFailed) {
auto observer = std::make_shared<TestObserver<SettingInt>>();
EXPECT_FALSE((m_manager.addObserver<TEST_ID_INT>(observer)));
}
/// Test addObserver for a setting that exists.
TEST_F(SettingsManagerTest, testRemoveObserver) {
auto setting = std::make_shared<SettingInt>(INITIAL_INT_VALUE);
auto observer = std::make_shared<TestObserver<SettingInt>>();
EXPECT_TRUE((m_manager.addSetting<TEST_ID_INT>(setting)));
EXPECT_TRUE((m_manager.addObserver<TEST_ID_INT>(observer)));
m_manager.removeObserver<TEST_ID_INT>(observer);
}
/// Test addObserver for a setting that doesn't exist.
TEST_F(SettingsManagerTest, testRemoveObserverFailed) {
auto observer = std::make_shared<TestObserver<SettingInt>>();
m_manager.removeObserver<TEST_ID_INT>(observer);
}
/// Test manager operations for string setting.
TEST_F(SettingsManagerTest, testSetExistingStringSetting) {
std::string initialValue = "";
auto setting = std::make_shared<SettingString>(initialValue);
EXPECT_TRUE((m_manager.addSetting<TEST_ID_STRING>(setting)));
EXPECT_EQ((m_manager.setValue<TEST_ID_STRING>("test")), SetSettingResult::ENQUEUED);
}
} // namespace test
} // namespace settings
} // namespace alexaClientSDK