avs-device-sdk/CapabilityAgents/System/test/ReportStateHandlerTest.cpp

151 lines
6.3 KiB
C++
Raw Normal View History

Version 1.18.0 alexa-client-sdk Changes in this update: **Enhancements** * Added support for [Bluetooth Interface 2.0](https://developer.amazon.com/docs/alexa/alexa-voice-service/bluetooth.html). This interface adds support for multiple simultaneous connections to Bluetooth peripherals. * Added support for [Audio Focus Manager Library (AFML) Multi Activity](https://developer.amazon.com/docs/alexa/avs-device-sdk/sdk-interaction-model.html). This interface enhances the behavior of a device so it can handle more than one Activity per Channel. * Added the `obfuscatePrivateData` logging method to help remove certain data from logs. * Updated `MediaPlayerObserverInterface` to include metadata about playback states. * Added SDK extension point. You can integrate CMake projects into the SDK without cloning those projects into a subdirectory. **Bug fixes** * Fixed Mac/OSX issue that caused an unresponsive Sample App when not connected to the internet. * Fixed issue that prevented sample app from exiting various states. * Fixed `UIManager` issue that caused an error in the logs when the device with built without the wake word enabled. * Fixed volume issue that caused timers to ascend in volume when setting up ascending alarms. * Fixed alert volume issue that caused any changes to the alert volume to notify observers. * Fixed EQ issue where changes to the EQ band levels didn't notify observers. * Fixed Bluetooth bug that caused short notification sounds from a connected phone to stop audio playback on the device. **Known Issues** * Build errors can occur on the Raspberry Pi due to incorrect linking of the atomic library. A suggested workaround is to add the following `set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -latomic")` to the top most CMake file. * The WebVTT dependency required for `captions` isn't supported for Windows/Android. * Exiting from the setting option takes you back to the Options Menu directly. It doesn't provide a message to indicate that you're back in the main menu. * Failing Unit Tests and AIP Unit tests are disabled on Windows * `AudioInputProcessor` unit tests don't build on Windows when with the `-DCMAKE_BUILD_TYPE=DEBUG` cmake parameter. * 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 though local TTS. * ACL encounters issues if it receives audio attachments but doesn't consume them. * Media streamed 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. * The `DirectiveSequencerTest.test_handleBlockingThenImmediatelyThenNonBockingOnSameDialogId` test fails intermittently.
2020-02-19 18:35:26 +00:00
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Version 1.18.0 alexa-client-sdk Changes in this update: **Enhancements** * Added support for [Bluetooth Interface 2.0](https://developer.amazon.com/docs/alexa/alexa-voice-service/bluetooth.html). This interface adds support for multiple simultaneous connections to Bluetooth peripherals. * Added support for [Audio Focus Manager Library (AFML) Multi Activity](https://developer.amazon.com/docs/alexa/avs-device-sdk/sdk-interaction-model.html). This interface enhances the behavior of a device so it can handle more than one Activity per Channel. * Added the `obfuscatePrivateData` logging method to help remove certain data from logs. * Updated `MediaPlayerObserverInterface` to include metadata about playback states. * Added SDK extension point. You can integrate CMake projects into the SDK without cloning those projects into a subdirectory. **Bug fixes** * Fixed Mac/OSX issue that caused an unresponsive Sample App when not connected to the internet. * Fixed issue that prevented sample app from exiting various states. * Fixed `UIManager` issue that caused an error in the logs when the device with built without the wake word enabled. * Fixed volume issue that caused timers to ascend in volume when setting up ascending alarms. * Fixed alert volume issue that caused any changes to the alert volume to notify observers. * Fixed EQ issue where changes to the EQ band levels didn't notify observers. * Fixed Bluetooth bug that caused short notification sounds from a connected phone to stop audio playback on the device. **Known Issues** * Build errors can occur on the Raspberry Pi due to incorrect linking of the atomic library. A suggested workaround is to add the following `set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -latomic")` to the top most CMake file. * The WebVTT dependency required for `captions` isn't supported for Windows/Android. * Exiting from the setting option takes you back to the Options Menu directly. It doesn't provide a message to indicate that you're back in the main menu. * Failing Unit Tests and AIP Unit tests are disabled on Windows * `AudioInputProcessor` unit tests don't build on Windows when with the `-DCMAKE_BUILD_TYPE=DEBUG` cmake parameter. * 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 though local TTS. * ACL encounters issues if it receives audio attachments but doesn't consume them. * Media streamed 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. * The `DirectiveSequencerTest.test_handleBlockingThenImmediatelyThenNonBockingOnSameDialogId` test fails intermittently.
2020-02-19 18:35:26 +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.
*/
#include <chrono>
#include <memory>
#include <string>
#include <gtest/gtest.h>
#include <System/ReportStateHandler.h>
#include <RegistrationManager/CustomerDataManager.h>
#include <AVSCommon/SDKInterfaces/MockExceptionEncounteredSender.h>
#include <AVSCommon/SDKInterfaces/MockMessageSender.h>
#include <AVSCommon/SDKInterfaces/MockAVSConnectionManager.h>
#include <AVSCommon/SDKInterfaces/Storage/StubMiscStorage.h>
#include <AVSCommon/SDKInterfaces/MockDirectiveHandlerResult.h>
#include <AVSCommon/AVS/AVSMessageHeader.h>
#include <AVSCommon/AVS/AVSDirective.h>
#include <AVSCommon/AVS/MessageRequest.h>
#include <AVSCommon/AVS/Attachment/AttachmentManager.h>
using alexaClientSDK::avsCommon::avs::AVSDirective;
using alexaClientSDK::avsCommon::avs::AVSMessageHeader;
using alexaClientSDK::avsCommon::avs::MessageRequest;
using alexaClientSDK::avsCommon::avs::attachment::AttachmentManager;
using alexaClientSDK::avsCommon::sdkInterfaces::MessageRequestObserverInterface;
using alexaClientSDK::avsCommon::sdkInterfaces::storage::test::StubMiscStorage;
using alexaClientSDK::avsCommon::sdkInterfaces::test::MockAVSConnectionManager;
using alexaClientSDK::avsCommon::sdkInterfaces::test::MockDirectiveHandlerResult;
using alexaClientSDK::avsCommon::sdkInterfaces::test::MockExceptionEncounteredSender;
using alexaClientSDK::avsCommon::sdkInterfaces::test::MockMessageSender;
using alexaClientSDK::registrationManager::CustomerDataManager;
namespace alexaClientSDK {
namespace capabilityAgents {
namespace system {
namespace test {
/// Fake message ID used for testing.
static const std::string TEST_MESSAGE_ID("c88f970a-3519-4ecb-bdcc-0488aca22b87");
/// Fake request ID used for testing.
static const std::string TEST_REQUEST_ID("4b73575e-2e7d-425b-bfa4-c6615e0fbd43");
/// Fake context ID used for testing.
static const std::string TEST_CONTEXT_ID("71c967d8-ad58-47b0-924d-b752deb75e4e");
class MockStateReportGenerator : public StateReportGenerator {
public:
MockStateReportGenerator(std::function<std::string()> reportFunction) : StateReportGenerator({reportFunction}) {
}
};
class ReportStateHandlerTest : public ::testing::Test {
protected:
void SetUp() override {
m_customerDataManager = std::make_shared<CustomerDataManager>();
m_mockExceptionEncounteredSender = std::make_shared<MockExceptionEncounteredSender>();
m_mockAVSConnectionManager = std::make_shared<::testing::NiceMock<MockAVSConnectionManager>>();
m_mockMessageSender = std::make_shared<MockMessageSender>();
m_stubMiscStorage = StubMiscStorage::create();
m_attachmentManager = std::make_shared<AttachmentManager>(AttachmentManager::AttachmentType::IN_PROCESS);
m_mockDirectiveHandlerResult = std::unique_ptr<MockDirectiveHandlerResult>(new MockDirectiveHandlerResult);
}
void waitUntilEventSent() {
std::unique_lock<std::mutex> lock(m_mutex);
// This will take 2 seconds only in case it fails (normally it exits right away).
ASSERT_TRUE(m_condition.wait_for(
lock, std::chrono::seconds(2), [this] { return m_directiveCompleted && m_eventSent; }));
}
std::shared_ptr<ReportStateHandler> m_unit;
std::shared_ptr<CustomerDataManager> m_customerDataManager;
std::shared_ptr<MockExceptionEncounteredSender> m_mockExceptionEncounteredSender;
std::shared_ptr<MockMessageSender> m_mockMessageSender;
std::shared_ptr<::testing::NiceMock<MockAVSConnectionManager>> m_mockAVSConnectionManager;
std::shared_ptr<StubMiscStorage> m_stubMiscStorage;
std::vector<StateReportGenerator> generators;
std::shared_ptr<AttachmentManager> m_attachmentManager;
std::unique_ptr<MockDirectiveHandlerResult> m_mockDirectiveHandlerResult;
std::mutex m_mutex;
std::condition_variable m_condition;
bool m_directiveCompleted = false;
bool m_eventSent = false;
std::string m_eventJson;
std::shared_ptr<AVSDirective> createDirective() {
auto avsMessageHeader =
std::make_shared<AVSMessageHeader>("System", "ReportState", TEST_MESSAGE_ID, TEST_REQUEST_ID);
auto directive = AVSDirective::create("", avsMessageHeader, "", m_attachmentManager, TEST_CONTEXT_ID);
return std::move(directive);
}
};
TEST_F(ReportStateHandlerTest, testReportState) {
void* leak = new int[23];
leak = nullptr;
ASSERT_EQ(nullptr, leak);
MockStateReportGenerator mockGenerator([] { return R"({"unitTest":"ON","complaints":"OFF"})"; });
generators.push_back(mockGenerator);
m_unit = ReportStateHandler::create(
m_customerDataManager,
m_mockExceptionEncounteredSender,
m_mockAVSConnectionManager,
m_mockMessageSender,
m_stubMiscStorage,
generators);
EXPECT_CALL(*m_mockDirectiveHandlerResult, setCompleted()).WillOnce(::testing::InvokeWithoutArgs([this] {
std::lock_guard<std::mutex> lock(m_mutex);
m_directiveCompleted = true;
m_condition.notify_all();
}));
EXPECT_CALL(*m_mockMessageSender, sendMessage(::testing::_))
.WillOnce(::testing::WithArg<0>(::testing::Invoke([this](std::shared_ptr<MessageRequest> request) {
std::lock_guard<std::mutex> lock(m_mutex);
m_eventSent = true;
m_eventJson = request->getJsonContent();
request->sendCompleted(MessageRequestObserverInterface::Status::SUCCESS);
m_condition.notify_all();
})));
m_unit->CapabilityAgent::preHandleDirective(createDirective(), std::move(m_mockDirectiveHandlerResult));
m_unit->CapabilityAgent::handleDirective(TEST_MESSAGE_ID);
waitUntilEventSent();
ASSERT_TRUE(m_eventJson.find(R"("unitTest":"ON")") != m_eventJson.npos);
}
} // namespace test
} // namespace system
} // namespace capabilityAgents
} // namespace alexaClientSDK