2017-06-23 23:26:34 +00:00
|
|
|
/*
|
2017-05-18 05:02:48 +00:00
|
|
|
* AudioInputProcessorTest.cpp
|
|
|
|
*
|
|
|
|
* Copyright 2017 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/// @file AudioInputProcessorTest.cpp
|
|
|
|
|
2017-06-09 23:23:31 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <vector>
|
2017-05-18 05:02:48 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2017-06-09 23:23:31 +00:00
|
|
|
#include <rapidjson/document.h>
|
|
|
|
#include <rapidjson/error/en.h>
|
|
|
|
#include <rapidjson/stringbuffer.h>
|
|
|
|
#include <rapidjson/writer.h>
|
|
|
|
|
2017-05-18 05:02:48 +00:00
|
|
|
#include <AVSCommon/SDKInterfaces/MockDirectiveSequencer.h>
|
|
|
|
#include <AVSCommon/SDKInterfaces/MockMessageSender.h>
|
|
|
|
#include <AVSCommon/SDKInterfaces/MockContextManager.h>
|
|
|
|
#include <AVSCommon/SDKInterfaces/MockFocusManager.h>
|
2017-06-09 23:23:31 +00:00
|
|
|
#include <AVSCommon/SDKInterfaces/MockDirectiveHandlerResult.h>
|
2017-06-23 23:26:34 +00:00
|
|
|
#include <AVSCommon/SDKInterfaces/MockExceptionEncounteredSender.h>
|
2017-06-09 23:23:31 +00:00
|
|
|
#include <AVSCommon/Utils/UUIDGeneration/UUIDGeneration.h>
|
|
|
|
#include <AVSCommon/AVS/Attachment/MockAttachmentManager.h>
|
2017-06-23 23:26:34 +00:00
|
|
|
#include <AVSCommon/Utils/Memory/Memory.h>
|
2017-05-18 05:02:48 +00:00
|
|
|
|
|
|
|
#include "AIP/AudioInputProcessor.h"
|
|
|
|
#include "MockObserver.h"
|
|
|
|
|
|
|
|
using namespace testing;
|
|
|
|
|
|
|
|
namespace alexaClientSDK {
|
2017-06-09 23:23:31 +00:00
|
|
|
namespace capabilityAgents {
|
2017-05-18 05:02:48 +00:00
|
|
|
namespace aip {
|
|
|
|
namespace test {
|
|
|
|
|
2017-06-23 23:26:34 +00:00
|
|
|
using avsCommon::sdkInterfaces::AudioInputProcessorObserverInterface;
|
|
|
|
|
2017-05-18 05:02:48 +00:00
|
|
|
/// The name of the @c FocusManager channel used by @c AudioInputProvider.
|
|
|
|
static const std::string CHANNEL_NAME = "Dialog";
|
|
|
|
|
|
|
|
/// The activityId string used with @c FocusManager by @c AudioInputProvider.
|
|
|
|
static const std::string ACTIVITY_ID = "SpeechRecognizer.Recognize";
|
|
|
|
|
|
|
|
/// The namespace for this capability agent.
|
|
|
|
static const std::string NAMESPACE = "SpeechRecognizer";
|
|
|
|
|
|
|
|
/// The StopCapture directive signature.
|
|
|
|
static const avsCommon::avs::NamespaceAndName STOP_CAPTURE{NAMESPACE, "StopCapture"};
|
|
|
|
|
|
|
|
/// The ExpectSpeech directive signature.
|
|
|
|
static const avsCommon::avs::NamespaceAndName EXPECT_SPEECH{NAMESPACE, "ExpectSpeech"};
|
|
|
|
|
|
|
|
/// The directives @c AudioInputProcessor should handle.
|
|
|
|
avsCommon::avs::NamespaceAndName DIRECTIVES[] = {STOP_CAPTURE, EXPECT_SPEECH};
|
|
|
|
|
|
|
|
/// The SpeechRecognizer context state signature.
|
|
|
|
static const avsCommon::avs::NamespaceAndName RECOGNIZER_STATE{NAMESPACE, "RecognizerState"};
|
|
|
|
|
|
|
|
/// Number of directives @c AudioInputProcessor should handle.
|
|
|
|
static const size_t NUM_DIRECTIVES = sizeof(DIRECTIVES) / sizeof(*DIRECTIVES);
|
|
|
|
|
|
|
|
/// The @c BlockingPolicy for all @c AudioInputProcessor directives.
|
|
|
|
static const auto BLOCKING_POLICY = avsCommon::avs::BlockingPolicy::NON_BLOCKING;
|
|
|
|
|
|
|
|
/// Sample rate for audio input stream.
|
|
|
|
static const unsigned int SAMPLE_RATE_HZ = 16000;
|
|
|
|
|
|
|
|
/// Sample size for audio input stream.
|
|
|
|
static const unsigned int SAMPLE_SIZE_IN_BITS = 16;
|
|
|
|
|
|
|
|
/// Number of channels in audio input stream.
|
|
|
|
static const unsigned int NUM_CHANNELS = 1;
|
|
|
|
|
2017-06-09 23:23:31 +00:00
|
|
|
/// Number of milliseconds of preroll applied for cloud-based wakeword verification.
|
|
|
|
static const std::chrono::milliseconds PREROLL_MS = std::chrono::milliseconds(500);
|
|
|
|
|
|
|
|
/// Number of words of preroll.
|
|
|
|
static const size_t PREROLL_WORDS = (SAMPLE_RATE_HZ / 1000) * PREROLL_MS.count();
|
|
|
|
|
|
|
|
/// Number of words in wakeword.
|
|
|
|
static const size_t WAKEWORD_WORDS = PREROLL_WORDS;
|
2017-05-18 05:02:48 +00:00
|
|
|
|
|
|
|
/// Number of words to hold in the SDS circular buffer.
|
2017-06-09 23:23:31 +00:00
|
|
|
static const size_t SDS_WORDS = PREROLL_WORDS + WAKEWORD_WORDS + 1000;
|
2017-05-18 05:02:48 +00:00
|
|
|
|
|
|
|
/// Number of bytes per word in the SDS circular buffer.
|
|
|
|
static const size_t SDS_WORDSIZE = SAMPLE_SIZE_IN_BITS / 8;
|
|
|
|
|
|
|
|
/// Maximum number of readers to support in the SDS circular buffer.
|
2017-06-09 23:23:31 +00:00
|
|
|
static const size_t SDS_MAXREADERS = 3;
|
2017-05-18 05:02:48 +00:00
|
|
|
|
|
|
|
/// Boolean value to indicate an AudioProvider is always readable.
|
|
|
|
static const bool ALWAYS_READABLE = true;
|
|
|
|
|
|
|
|
/// Boolean value to indicate an AudioProvider can override another AudioProvider.
|
|
|
|
static const bool CAN_OVERRIDE = true;
|
|
|
|
|
|
|
|
/// Boolean value to indicate an AudioProvider can be overridden by another AudioProvider.
|
|
|
|
static const bool CAN_BE_OVERRIDDEN = true;
|
|
|
|
|
2017-06-09 23:23:31 +00:00
|
|
|
/// JSON key for the wakeword field in SpeechRecognizer context state.
|
|
|
|
static const std::string STATE_WAKEWORD_KEY = "wakeword";
|
|
|
|
|
|
|
|
/// JSON key for the context section of a message.
|
|
|
|
static const std::string MESSAGE_CONTEXT_KEY = "context";
|
|
|
|
|
|
|
|
/// JSON key for the event section of a message.
|
|
|
|
static const std::string MESSAGE_EVENT_KEY = "event";
|
|
|
|
|
|
|
|
/// JSON key for the directive section of a message.
|
|
|
|
static const std::string MESSAGE_DIRECTIVE_KEY = "directive";
|
|
|
|
|
|
|
|
/// JSON key for the header section of a message.
|
|
|
|
static const std::string MESSAGE_HEADER_KEY = "header";
|
|
|
|
|
|
|
|
/// JSON key for the payload section of an message.
|
|
|
|
static const std::string MESSAGE_PAYLOAD_KEY = "payload";
|
|
|
|
|
|
|
|
/// JSON key for the namespace field of a message header.
|
|
|
|
static const std::string MESSAGE_NAMESPACE_KEY = "namespace";
|
|
|
|
|
|
|
|
/// JSON key for the name field of a message header.
|
|
|
|
static const std::string MESSAGE_NAME_KEY = "name";
|
|
|
|
|
|
|
|
/// JSON key for the message ID field of a message header.
|
|
|
|
static const std::string MESSAGE_MESSAGE_ID_KEY = "messageId";
|
|
|
|
|
|
|
|
/// JSON key for the dialog request ID field of a message header.
|
|
|
|
static const std::string MESSAGE_DIALOG_REQUEST_ID_KEY = "dialogRequestId";
|
|
|
|
|
|
|
|
/// JSON value for a recognize event's name.
|
|
|
|
static const std::string RECOGNIZE_EVENT_NAME = "Recognize";
|
|
|
|
|
|
|
|
/// JSON key for the ASR profile field of a recognize event.
|
|
|
|
static const std::string ASR_PROFILE_KEY = "profile";
|
|
|
|
|
|
|
|
/// JSON key for the audio format field of a recognize event.
|
|
|
|
static const std::string AUDIO_FORMAT_KEY = "format";
|
|
|
|
|
|
|
|
/// JSON value for a recognize event's audio format.
|
|
|
|
static const std::string AUDIO_FORMAT_VALUE = "AUDIO_L16_RATE_16000_CHANNELS_1";
|
|
|
|
|
|
|
|
/// JSON key for the initiator field of a recognize event.
|
|
|
|
static const std::string RECOGNIZE_INITIATOR_KEY = "initiator";
|
|
|
|
|
|
|
|
/// JSON key for the type field of a recognize event's initiator.
|
|
|
|
static const std::string INITIATOR_TYPE_KEY = "type";
|
|
|
|
|
|
|
|
/// JSON key for the type field of a recognize event's payload.
|
|
|
|
static const std::string INITIATOR_PAYLOAD_KEY = "payload";
|
|
|
|
|
|
|
|
/// JSON key for the wakeword indices field of a wakeword recognize event's payload.
|
|
|
|
static const std::string WAKE_WORD_INDICES_KEY = "wakeWordIndices";
|
|
|
|
|
|
|
|
/// JSON key for the start index field of a wakeword recognize event's payload.
|
|
|
|
static const std::string START_INDEX_KEY = "startIndexInSamples";
|
|
|
|
|
|
|
|
/// JSON key for the end index field of a wakeword recognize event's payload.
|
|
|
|
static const std::string END_INDEX_KEY = "endIndexInSamples";
|
|
|
|
|
|
|
|
/// Value used in tests for a state request token by the context manager.
|
|
|
|
static const unsigned int STATE_REQUEST_TOKEN = 12345;
|
|
|
|
|
|
|
|
/// Value used in the tests for an expect speech initiator.
|
2017-06-23 23:26:34 +00:00
|
|
|
static const std::string EXPECT_SPEECH_INITIATOR = R"({opaque:"expectSpeechInitiator"})";
|
2017-06-09 23:23:31 +00:00
|
|
|
|
|
|
|
/// JSON key for the timeout field of an expect speech directive.
|
|
|
|
static const std::string EXPECT_SPEECH_TIMEOUT_KEY = "timeoutInMilliseconds";
|
|
|
|
|
|
|
|
/// Value used in the tests for an expect speech timeout.
|
|
|
|
static const int64_t EXPECT_SPEECH_TIMEOUT_IN_MILLISECONDS = 100;
|
|
|
|
|
|
|
|
/// JSON key for the initiator field of an expect speech directive.
|
|
|
|
static const std::string EXPECT_SPEECH_INITIATOR_KEY = "initiator";
|
|
|
|
|
|
|
|
/// JSON value for a expect speech timed out event's name.
|
|
|
|
static const std::string EXPECT_SPEECH_TIMED_OUT_EVENT_NAME = "ExpectSpeechTimedOut";
|
|
|
|
|
|
|
|
/// Value used in the tests for a wakeword recognize event.
|
|
|
|
static const std::string KEYWORD_TEXT = "ALEXA";
|
|
|
|
|
|
|
|
/// Boolean value to indicate a directive being tested has a dialog request ID.
|
|
|
|
static const bool WITH_DIALOG_REQUEST_ID = true;
|
|
|
|
|
|
|
|
/// Boolean value to indicate an expect speech directive should time out.
|
|
|
|
static const bool VERIFY_TIMEOUT = true;
|
|
|
|
|
|
|
|
/// Utility function to parse a JSON document.
|
|
|
|
static rapidjson::Document parseJson(const std::string& json) {
|
|
|
|
rapidjson::Document document;
|
|
|
|
document.Parse(json);
|
|
|
|
EXPECT_FALSE(document.HasParseError()) <<
|
|
|
|
"rapidjson detected a parsing error at offset:" +
|
|
|
|
std::to_string(document.GetErrorOffset()) +
|
|
|
|
", error message: " +
|
|
|
|
GetParseError_En(document.GetParseError());
|
|
|
|
return document;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Utility function to look up a JSON string in a container.
|
|
|
|
static std::string getJsonString(const rapidjson::Value& container, const std::string& key) {
|
|
|
|
auto member = container.FindMember(key);
|
|
|
|
EXPECT_TRUE(member->value.IsString());
|
|
|
|
if (!member->value.IsString()) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return member->value.GetString();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Utility function to look up a JSON 'long' in a container.
|
|
|
|
static int64_t getJsonInt64(const rapidjson::Value& container, const std::string& key) {
|
|
|
|
auto member = container.FindMember(key);
|
|
|
|
EXPECT_TRUE(member->value.IsInt64());
|
|
|
|
if (!member->value.IsInt64()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return member->value.GetInt64();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility class which captures parameters to a Recognize event, and provides functions to send and verify the event
|
|
|
|
* using those parameters.
|
|
|
|
*/
|
|
|
|
class RecognizeEvent {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Constructs an object which captures the parameters to send in a Recognize Event. Parameters are passed through
|
|
|
|
* directly to @c AudioInputProcessor::recognize().
|
|
|
|
*/
|
|
|
|
RecognizeEvent(
|
|
|
|
AudioProvider audioProvider,
|
|
|
|
Initiator initiator,
|
2017-06-23 23:26:34 +00:00
|
|
|
avsCommon::avs::AudioInputStream::Index begin = AudioInputProcessor::INVALID_INDEX,
|
|
|
|
avsCommon::avs::AudioInputStream::Index keywordEnd = AudioInputProcessor::INVALID_INDEX,
|
2017-06-09 23:23:31 +00:00
|
|
|
std::string keyword = "");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function sends a recognize event using the provided @c AudioInputProcessor and the recognize parameters
|
|
|
|
* captured by this instance.
|
|
|
|
*
|
|
|
|
* @param audioInputProcessor The @c AudioInputProcessor to call @c AudioInputProcessor::recognize() on.
|
|
|
|
* @return @c true if the call succeeded, else @c false.
|
|
|
|
*/
|
|
|
|
bool send(std::shared_ptr<AudioInputProcessor> audioInputProcessor);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function verifies that the JSON state string is correct and matches the captured parameters. This function
|
|
|
|
* signature matches that of @c ContextManager::setState() so that an @c EXPECT_CALL() can @c Invoke() this
|
|
|
|
* function directly, but only the jsonState parameter is verified by this function.
|
|
|
|
*
|
|
|
|
* @param jsonState The JSON context state string to verify.
|
|
|
|
*/
|
|
|
|
void verifyJsonState(
|
|
|
|
const avsCommon::avs::NamespaceAndName&,
|
|
|
|
const std::string& jsonState,
|
2017-06-23 23:26:34 +00:00
|
|
|
const avsCommon::avs::StateRefreshPolicy&,
|
2017-06-09 23:23:31 +00:00
|
|
|
const unsigned int);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function verifies that JSON content of a recognize @c MessageRequest is correct, and that it has an
|
|
|
|
* attachment. This function signature matches that of @c MessageSenderInterface::sendMessage() so that an
|
|
|
|
* @c EXPECT_CALL() can @c Invoke() this function directly.
|
|
|
|
*
|
|
|
|
* @param request The @c MessageRequest to verify.
|
|
|
|
*/
|
|
|
|
void verifyMessage(std::shared_ptr<avsCommon::avs::MessageRequest> request);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Accessor function to get the attachment reader for a verified message.
|
|
|
|
*
|
|
|
|
* @return the attachment reader for a verified message.
|
|
|
|
*/
|
|
|
|
std::shared_ptr<avsCommon::avs::attachment::AttachmentReader> getReader();
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// The audio provider to use for this recognize event.
|
|
|
|
AudioProvider m_audioProvider;
|
|
|
|
|
|
|
|
/// The initiator to use for this recognize event.
|
|
|
|
Initiator m_initiator;
|
|
|
|
|
|
|
|
/// The begin index to use for this recognize event.
|
2017-06-23 23:26:34 +00:00
|
|
|
avsCommon::avs::AudioInputStream::Index m_begin;
|
2017-06-09 23:23:31 +00:00
|
|
|
|
|
|
|
/// The keyword end index to use for this recognize event.
|
2017-06-23 23:26:34 +00:00
|
|
|
avsCommon::avs::AudioInputStream::Index m_keywordEnd;
|
2017-06-09 23:23:31 +00:00
|
|
|
|
|
|
|
/// The keyword string to use for this recognize event.
|
|
|
|
std::string m_keyword;
|
|
|
|
|
|
|
|
/// The attachment reader saved by a call to @c verifyMessage().
|
|
|
|
std::shared_ptr<avsCommon::avs::attachment::AttachmentReader> m_reader;
|
|
|
|
};
|
|
|
|
|
|
|
|
RecognizeEvent::RecognizeEvent(
|
|
|
|
AudioProvider audioProvider,
|
|
|
|
Initiator initiator,
|
2017-06-23 23:26:34 +00:00
|
|
|
avsCommon::avs::AudioInputStream::Index begin,
|
|
|
|
avsCommon::avs::AudioInputStream::Index keywordEnd,
|
2017-06-09 23:23:31 +00:00
|
|
|
std::string keyword) :
|
|
|
|
m_audioProvider{audioProvider}, m_initiator{initiator}, m_begin{begin}, m_keywordEnd{keywordEnd},
|
|
|
|
m_keyword{keyword} {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RecognizeEvent::send(std::shared_ptr<AudioInputProcessor> audioInputProcessor) {
|
|
|
|
auto result = audioInputProcessor->recognize(m_audioProvider, m_initiator, m_begin, m_keywordEnd, m_keyword);
|
|
|
|
EXPECT_TRUE(result.valid());
|
|
|
|
return result.valid() && result.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RecognizeEvent::verifyJsonState(
|
|
|
|
const avsCommon::avs::NamespaceAndName&,
|
|
|
|
const std::string& jsonState,
|
2017-06-23 23:26:34 +00:00
|
|
|
const avsCommon::avs::StateRefreshPolicy&,
|
2017-06-09 23:23:31 +00:00
|
|
|
const unsigned int) {
|
|
|
|
rapidjson::Document document = parseJson(jsonState);
|
|
|
|
EXPECT_EQ(getJsonString(document, STATE_WAKEWORD_KEY), m_keyword);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RecognizeEvent::verifyMessage(std::shared_ptr<avsCommon::avs::MessageRequest> request) {
|
|
|
|
rapidjson::Document document;
|
|
|
|
document.Parse(request->getJsonContent().c_str());
|
|
|
|
EXPECT_FALSE(document.HasParseError()) <<
|
|
|
|
"rapidjson detected a parsing error at offset:" +
|
|
|
|
std::to_string(document.GetErrorOffset()) +
|
|
|
|
", error message: " +
|
|
|
|
GetParseError_En(document.GetParseError());
|
|
|
|
|
|
|
|
auto context = document.FindMember(MESSAGE_CONTEXT_KEY);
|
|
|
|
EXPECT_NE(context, document.MemberEnd());
|
|
|
|
auto event = document.FindMember(MESSAGE_EVENT_KEY);
|
|
|
|
EXPECT_NE(event, document.MemberEnd());
|
|
|
|
|
|
|
|
auto header = event->value.FindMember(MESSAGE_HEADER_KEY);
|
|
|
|
EXPECT_NE(header, event->value.MemberEnd());
|
|
|
|
auto payload = event->value.FindMember(MESSAGE_PAYLOAD_KEY);
|
|
|
|
EXPECT_NE(payload, event->value.MemberEnd());
|
|
|
|
|
|
|
|
EXPECT_EQ(getJsonString(header->value, MESSAGE_NAMESPACE_KEY), NAMESPACE);
|
|
|
|
EXPECT_EQ(getJsonString(header->value, MESSAGE_NAME_KEY), RECOGNIZE_EVENT_NAME);
|
|
|
|
EXPECT_NE(getJsonString(header->value, MESSAGE_MESSAGE_ID_KEY), "");
|
|
|
|
EXPECT_NE(getJsonString(header->value, MESSAGE_DIALOG_REQUEST_ID_KEY), "");
|
|
|
|
|
|
|
|
std::ostringstream profile;
|
|
|
|
profile << m_audioProvider.profile;
|
|
|
|
EXPECT_EQ(getJsonString(payload->value, ASR_PROFILE_KEY), profile.str());
|
|
|
|
EXPECT_EQ(getJsonString(payload->value, AUDIO_FORMAT_KEY), AUDIO_FORMAT_VALUE);
|
|
|
|
auto initiator = payload->value.FindMember(RECOGNIZE_INITIATOR_KEY);
|
|
|
|
EXPECT_NE(initiator, payload->value.MemberEnd());
|
|
|
|
|
|
|
|
EXPECT_EQ(getJsonString(initiator->value, INITIATOR_TYPE_KEY), initiatorToString(m_initiator));
|
|
|
|
auto initiatorPayload = initiator->value.FindMember(INITIATOR_PAYLOAD_KEY);
|
|
|
|
EXPECT_NE(initiatorPayload, initiator->value.MemberEnd());
|
|
|
|
|
|
|
|
if (
|
|
|
|
m_initiator == Initiator::WAKEWORD &&
|
|
|
|
m_begin != AudioInputProcessor::INVALID_INDEX &&
|
|
|
|
m_keywordEnd != AudioInputProcessor::INVALID_INDEX) {
|
|
|
|
auto wakeWordIndices = initiatorPayload->value.FindMember(WAKE_WORD_INDICES_KEY);
|
|
|
|
EXPECT_NE(wakeWordIndices, initiatorPayload->value.MemberEnd());
|
|
|
|
|
|
|
|
if (wakeWordIndices != initiatorPayload->value.MemberEnd()) {
|
2017-06-23 23:26:34 +00:00
|
|
|
EXPECT_EQ(getJsonInt64(wakeWordIndices->value, START_INDEX_KEY), static_cast<int64_t>(m_begin));
|
|
|
|
EXPECT_EQ(getJsonInt64(wakeWordIndices->value, END_INDEX_KEY), static_cast<int64_t>(m_keywordEnd));
|
2017-06-09 23:23:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
m_reader = request->getAttachmentReader();
|
|
|
|
EXPECT_NE(m_reader, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<avsCommon::avs::attachment::AttachmentReader> RecognizeEvent::getReader() {
|
|
|
|
return m_reader;
|
|
|
|
}
|
|
|
|
|
2017-05-18 05:02:48 +00:00
|
|
|
/// Test harness for @c AudioInputProcessor class.
|
|
|
|
class AudioInputProcessorTest: public ::testing::Test {
|
|
|
|
public:
|
|
|
|
/// Set up the test harness for running a test.
|
|
|
|
void SetUp() override;
|
|
|
|
|
|
|
|
/// Clean up the test harness after running a test.
|
|
|
|
void TearDown() override;
|
|
|
|
|
|
|
|
protected:
|
2017-06-09 23:23:31 +00:00
|
|
|
/**
|
|
|
|
* Function to send a recognize event and verify that it fails. Parameters are passed through
|
|
|
|
* to @c RecognizeEvent::RecognizeEvent().
|
|
|
|
*
|
|
|
|
* @return @c true if the recognize event failed to send correctly, else @c false.
|
|
|
|
*/
|
|
|
|
bool testRecognizeFails(
|
|
|
|
AudioProvider audioProvider,
|
|
|
|
Initiator initiator,
|
2017-06-23 23:26:34 +00:00
|
|
|
avsCommon::avs::AudioInputStream::Index begin = AudioInputProcessor::INVALID_INDEX,
|
|
|
|
avsCommon::avs::AudioInputStream::Index keywordEnd = AudioInputProcessor::INVALID_INDEX,
|
2017-06-09 23:23:31 +00:00
|
|
|
std::string keyword = "");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to send a recognize event and verify that it succeeds. Parameters are passed through
|
|
|
|
* to @c RecognizeEvent::RecognizeEvent().
|
|
|
|
*
|
|
|
|
* @return @c true if the recognize event sent correctly, else @c false.
|
|
|
|
*/
|
|
|
|
bool testRecognizeSucceeds(
|
|
|
|
AudioProvider audioProvider,
|
|
|
|
Initiator initiator,
|
2017-06-23 23:26:34 +00:00
|
|
|
avsCommon::avs::AudioInputStream::Index begin = AudioInputProcessor::INVALID_INDEX,
|
|
|
|
avsCommon::avs::AudioInputStream::Index keywordEnd = AudioInputProcessor::INVALID_INDEX,
|
2017-06-09 23:23:31 +00:00
|
|
|
std::string keyword = "");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to call @c AudioInputProcessor::stopCapture() and verify that it succeeds.
|
|
|
|
*
|
|
|
|
* @return @c true if the call works correctly, else @c false.
|
|
|
|
*/
|
|
|
|
bool testStopCaptureSucceeds();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to call AudioInputProcessor::onContextFailure() and verify that @c AudioInputProcessor responds to it
|
|
|
|
* correctly.
|
|
|
|
*
|
|
|
|
* @param error The failure type to test.
|
|
|
|
* @return @c true if the call works correctly, else @c false.
|
|
|
|
*/
|
|
|
|
bool testContextFailure(avsCommon::sdkInterfaces::ContextRequestError error);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to receive a StopCapture directive and verify that @c AudioInputProcessor responds to it
|
|
|
|
* correctly.
|
|
|
|
*
|
|
|
|
* @param withDialogRequestId A flag indicating whether to send the directive with a dialog request ID.
|
|
|
|
* @return @c true if the call works correctly, else @c false.
|
|
|
|
*/
|
|
|
|
bool testStopCaptureDirectiveSucceeds(bool withDialogRequestId);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to receive a StopCapture directive and verify that @c AudioInputProcessor rejects it.
|
|
|
|
*
|
|
|
|
* @param withDialogRequestId A flag indicating whether to send the directive with a dialog request ID.
|
|
|
|
* @return @c true if the call fails as expected, else @c false.
|
|
|
|
*/
|
|
|
|
bool testStopCaptureDirectiveFails(bool withDialogRequestId);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to send an expect speech event and verify that it succeeds.
|
|
|
|
*
|
|
|
|
* @param withDialogRequestId A flag indicating whether to send the directive with a dialog request ID.
|
|
|
|
* @return @c true if the call works correctly, else @c false.
|
|
|
|
*/
|
|
|
|
bool testExpectSpeechSucceeds(bool withDialogRequestId);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to send an expect speech event and optionally verify that it times out.
|
|
|
|
*
|
|
|
|
* @param withDialogRequestId A flag indicating whether to send the event with a dialog request ID.
|
|
|
|
* @param verifyTimeout A flag indicating whether to wait for a timeout.
|
|
|
|
* @return @c true if the call works correctly, else @c false.
|
|
|
|
*/
|
|
|
|
bool testExpectSpeechWaits(bool withDialogRequestId, bool verifyTimeout);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to send an expect speech event and optionally verify that it fails.
|
|
|
|
*
|
|
|
|
* @param withDialogRequestId A flag indicating whether to send the event with a dialog request ID.
|
|
|
|
* @return @c true if the call fails as expected, else @c false.
|
|
|
|
*/
|
|
|
|
bool testExpectSpeechFails(bool withDialogRequestId);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to construct an @c AVSDirective for the specified namespace/name.
|
|
|
|
*
|
|
|
|
* @param directive The namespace and name to use for this directive.
|
|
|
|
* @param withDialogRequestId A flag indicating whether to include a dialog request ID.
|
|
|
|
* @return the constructed @c AVSDirective.
|
|
|
|
*/
|
2017-06-23 23:26:34 +00:00
|
|
|
static std::shared_ptr<avsCommon::avs::AVSDirective> createAVSDirective(
|
2017-06-09 23:23:31 +00:00
|
|
|
const avsCommon::avs::NamespaceAndName& directive,
|
|
|
|
bool withDialogRequestId);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function verifies that JSON content of an ExpectSpeechTimedOut @c MessageRequest is correct, and that it
|
|
|
|
* does not have an attachment. This function signature matches that of @c MessageSenderInterface::sendMessage()
|
|
|
|
* so that an @c EXPECT_CALL() can @c Invoke() this function directly.
|
|
|
|
*
|
|
|
|
* @param request The @c MessageRequest to verify.
|
|
|
|
*/
|
|
|
|
static void verifyExpectSpeechTimedOut(std::shared_ptr<avsCommon::avs::MessageRequest> request);
|
|
|
|
|
|
|
|
/// This function replace @c m_audioInputProcessor with a new one that does not have a default @c AudioProvider.
|
|
|
|
void removeDefaultAudioProvider();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function replace @c m_audioInputProcessor with a new one that has an @c AudioProvider that is not
|
|
|
|
* @c alwaysReadable.
|
|
|
|
*/
|
|
|
|
void makeDefaultAudioProviderNotAlwaysReadable();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to call @c onFocusChanged() and verify that @c AudioInputProcessor responds correctly.
|
|
|
|
*
|
|
|
|
* @param state The focus state to test with.
|
|
|
|
* @return @c true if the @c AudioInputProcessor responds as expected, else @c false.
|
|
|
|
*/
|
2017-06-23 23:26:34 +00:00
|
|
|
bool testFocusChange(avsCommon::avs::FocusState state);
|
2017-06-09 23:23:31 +00:00
|
|
|
|
2017-05-18 05:02:48 +00:00
|
|
|
/// The mock @c DirectiveSequencerInterface.
|
|
|
|
std::shared_ptr<avsCommon::sdkInterfaces::test::MockDirectiveSequencer> m_mockDirectiveSequencer;
|
|
|
|
|
|
|
|
/// The mock @c MessageSenderInterface.
|
|
|
|
std::shared_ptr<avsCommon::sdkInterfaces::test::MockMessageSender> m_mockMessageSender;
|
|
|
|
|
|
|
|
/// The mock @c ContextManagerInterface.
|
|
|
|
std::shared_ptr<avsCommon::sdkInterfaces::test::MockContextManager> m_mockContextManager;
|
|
|
|
|
|
|
|
/// The mock @c FocusManagerInterface.
|
|
|
|
std::shared_ptr<avsCommon::sdkInterfaces::test::MockFocusManager> m_mockFocusManager;
|
|
|
|
|
|
|
|
/// The mock @c ExceptionEncounteredSenderInterface.
|
2017-06-23 23:26:34 +00:00
|
|
|
std::shared_ptr<avsCommon::sdkInterfaces::test::MockExceptionEncounteredSender> m_mockExceptionEncounteredSender;
|
2017-05-18 05:02:48 +00:00
|
|
|
|
2017-06-09 23:23:31 +00:00
|
|
|
/// A @c AudioInputStream::Writer to write audio data to m_audioProvider.
|
2017-06-23 23:26:34 +00:00
|
|
|
std::unique_ptr<avsCommon::avs::AudioInputStream::Writer> m_writer;
|
2017-05-18 05:02:48 +00:00
|
|
|
|
|
|
|
/// The @c AudioProvider to test with.
|
|
|
|
std::unique_ptr<AudioProvider> m_audioProvider;
|
|
|
|
|
|
|
|
/// The @c AudioInputProcessor to test.
|
|
|
|
std::shared_ptr<AudioInputProcessor> m_audioInputProcessor;
|
|
|
|
|
|
|
|
/// The mock @c ObserverInterface.
|
|
|
|
std::shared_ptr<MockObserver> m_mockObserver;
|
2017-06-09 23:23:31 +00:00
|
|
|
|
|
|
|
/// The @c RecognizeEvent from the last @c testRecognizeSucceeds() call.
|
|
|
|
std::shared_ptr<RecognizeEvent> m_recognizeEvent;
|
2017-05-18 05:02:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void AudioInputProcessorTest::SetUp() {
|
|
|
|
m_mockDirectiveSequencer = std::make_shared<avsCommon::sdkInterfaces::test::MockDirectiveSequencer>();
|
|
|
|
m_mockMessageSender = std::make_shared<avsCommon::sdkInterfaces::test::MockMessageSender>();
|
|
|
|
m_mockContextManager = std::make_shared<avsCommon::sdkInterfaces::test::MockContextManager>();
|
|
|
|
m_mockFocusManager = std::make_shared<avsCommon::sdkInterfaces::test::MockFocusManager>();
|
2017-06-23 23:26:34 +00:00
|
|
|
m_mockExceptionEncounteredSender = std::make_shared<avsCommon::sdkInterfaces::test::MockExceptionEncounteredSender>();
|
2017-05-18 05:02:48 +00:00
|
|
|
size_t bufferSize =
|
2017-06-23 23:26:34 +00:00
|
|
|
avsCommon::avs::AudioInputStream::calculateBufferSize(SDS_WORDS, SDS_WORDSIZE, SDS_MAXREADERS);
|
|
|
|
auto buffer = std::make_shared<avsCommon::avs::AudioInputStream::Buffer>(bufferSize);
|
|
|
|
auto stream = avsCommon::avs::AudioInputStream::create(buffer, SDS_WORDSIZE, SDS_MAXREADERS);
|
2017-06-09 23:23:31 +00:00
|
|
|
ASSERT_NE(stream, nullptr);
|
2017-06-23 23:26:34 +00:00
|
|
|
m_writer = stream->createWriter(avsCommon::avs::AudioInputStream::Writer::Policy::NONBLOCKABLE);
|
2017-06-09 23:23:31 +00:00
|
|
|
ASSERT_NE(m_writer, nullptr);
|
2017-06-23 23:26:34 +00:00
|
|
|
ASSERT_EQ(m_writer->write(buffer->data(), SDS_WORDS), static_cast<ssize_t>(SDS_WORDS));
|
|
|
|
avsCommon::utils::AudioFormat format = {
|
|
|
|
avsCommon::utils::AudioFormat::Encoding::LPCM,
|
|
|
|
avsCommon::utils::AudioFormat::Endianness::LITTLE,
|
2017-05-18 05:02:48 +00:00
|
|
|
SAMPLE_RATE_HZ,
|
|
|
|
SAMPLE_SIZE_IN_BITS,
|
|
|
|
NUM_CHANNELS };
|
2017-06-23 23:26:34 +00:00
|
|
|
m_audioProvider = avsCommon::utils::memory::make_unique<AudioProvider>(
|
2017-06-09 23:23:31 +00:00
|
|
|
std::move(stream),
|
|
|
|
format,
|
2017-05-18 05:02:48 +00:00
|
|
|
ASRProfile::NEAR_FIELD,
|
|
|
|
ALWAYS_READABLE,
|
|
|
|
CAN_OVERRIDE,
|
|
|
|
CAN_BE_OVERRIDDEN);
|
2017-06-09 23:23:31 +00:00
|
|
|
EXPECT_CALL(*m_mockContextManager, setStateProvider(RECOGNIZER_STATE, Ne(nullptr)));
|
2017-05-18 05:02:48 +00:00
|
|
|
m_audioInputProcessor = AudioInputProcessor::create(
|
|
|
|
m_mockDirectiveSequencer,
|
|
|
|
m_mockMessageSender,
|
|
|
|
m_mockContextManager,
|
|
|
|
m_mockFocusManager,
|
|
|
|
m_mockExceptionEncounteredSender,
|
|
|
|
*m_audioProvider);
|
|
|
|
EXPECT_NE(m_audioInputProcessor, nullptr);
|
2017-06-09 23:23:31 +00:00
|
|
|
// Note: StrictMock here so that we fail on unexpected AIP state changes
|
|
|
|
m_mockObserver = std::make_shared<StrictMock<MockObserver>>();
|
2017-05-18 05:02:48 +00:00
|
|
|
ASSERT_NE(m_mockObserver, nullptr);
|
|
|
|
m_audioInputProcessor->addObserver(m_mockObserver);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioInputProcessorTest::TearDown() {
|
2017-06-09 23:23:31 +00:00
|
|
|
EXPECT_CALL(*m_mockFocusManager, releaseChannel(CHANNEL_NAME, _)).Times(AtLeast(0));
|
2017-06-23 23:26:34 +00:00
|
|
|
EXPECT_CALL(
|
|
|
|
*m_mockObserver, onStateChanged(AudioInputProcessorObserverInterface::State::IDLE)).Times(AtLeast(0));
|
2017-05-18 05:02:48 +00:00
|
|
|
m_audioInputProcessor->resetState().wait();
|
|
|
|
}
|
|
|
|
|
2017-06-09 23:23:31 +00:00
|
|
|
bool AudioInputProcessorTest::testRecognizeFails(
|
|
|
|
AudioProvider audioProvider,
|
|
|
|
Initiator initiator,
|
2017-06-23 23:26:34 +00:00
|
|
|
avsCommon::avs::AudioInputStream::Index begin,
|
|
|
|
avsCommon::avs::AudioInputStream::Index keywordEnd,
|
2017-06-09 23:23:31 +00:00
|
|
|
std::string keyword) {
|
|
|
|
RecognizeEvent recognize(audioProvider, initiator, begin, keywordEnd, keyword);
|
|
|
|
return !recognize.send(m_audioInputProcessor);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AudioInputProcessorTest::testRecognizeSucceeds(
|
|
|
|
AudioProvider audioProvider,
|
|
|
|
Initiator initiator,
|
2017-06-23 23:26:34 +00:00
|
|
|
avsCommon::avs::AudioInputStream::Index begin,
|
|
|
|
avsCommon::avs::AudioInputStream::Index keywordEnd,
|
2017-06-09 23:23:31 +00:00
|
|
|
std::string keyword) {
|
|
|
|
std::mutex mutex;
|
|
|
|
std::condition_variable conditionVariable;
|
|
|
|
bool done = false;
|
|
|
|
bool bargeIn = m_recognizeEvent != nullptr;
|
|
|
|
|
|
|
|
rapidjson::Document contextDocument(rapidjson::kObjectType);
|
|
|
|
rapidjson::Value contextArray(rapidjson::kArrayType);
|
|
|
|
contextDocument.AddMember(rapidjson::StringRef(MESSAGE_CONTEXT_KEY), contextArray, contextDocument.GetAllocator());
|
|
|
|
rapidjson::StringBuffer contextBuffer;
|
|
|
|
rapidjson::Writer<rapidjson::StringBuffer> contextWriter(contextBuffer);
|
|
|
|
contextDocument.Accept(contextWriter);
|
|
|
|
std::string contextJson = contextBuffer.GetString();
|
|
|
|
|
|
|
|
|
|
|
|
m_recognizeEvent = std::make_shared<RecognizeEvent>(audioProvider, initiator, begin, keywordEnd, keyword);
|
|
|
|
if (keyword.empty()) {
|
|
|
|
EXPECT_CALL(*m_mockContextManager, getContext(_))
|
|
|
|
.WillOnce(InvokeWithoutArgs([this] { m_audioInputProcessor->provideState(STATE_REQUEST_TOKEN); }));
|
|
|
|
EXPECT_CALL(*m_mockContextManager, setState(
|
|
|
|
RECOGNIZER_STATE,
|
|
|
|
_,
|
2017-06-23 23:26:34 +00:00
|
|
|
avsCommon::avs::StateRefreshPolicy::NEVER,
|
2017-06-09 23:23:31 +00:00
|
|
|
STATE_REQUEST_TOKEN))
|
|
|
|
.WillOnce(DoAll(
|
|
|
|
Invoke(m_recognizeEvent.get(), &RecognizeEvent::verifyJsonState),
|
|
|
|
InvokeWithoutArgs([this, contextJson] {
|
|
|
|
m_audioInputProcessor->onContextAvailable(contextJson);
|
|
|
|
return avsCommon::sdkInterfaces::SetStateResult::SUCCESS; })));
|
|
|
|
} else {
|
|
|
|
EXPECT_CALL(*m_mockContextManager, setState(
|
|
|
|
RECOGNIZER_STATE,
|
|
|
|
_,
|
2017-06-23 23:26:34 +00:00
|
|
|
avsCommon::avs::StateRefreshPolicy::NEVER,
|
2017-06-09 23:23:31 +00:00
|
|
|
0))
|
|
|
|
.WillOnce(DoAll(
|
|
|
|
Invoke(m_recognizeEvent.get(), &RecognizeEvent::verifyJsonState),
|
|
|
|
InvokeWithoutArgs([] { return avsCommon::sdkInterfaces::SetStateResult::SUCCESS; })));
|
|
|
|
EXPECT_CALL(*m_mockContextManager, getContext(_))
|
|
|
|
.WillOnce(InvokeWithoutArgs([this, contextJson] {
|
|
|
|
m_audioInputProcessor->onContextAvailable(contextJson); }));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bargeIn) {
|
2017-06-23 23:26:34 +00:00
|
|
|
EXPECT_CALL(*m_mockObserver, onStateChanged(AudioInputProcessorObserverInterface::State::RECOGNIZING));
|
2017-06-09 23:23:31 +00:00
|
|
|
EXPECT_CALL(*m_mockFocusManager, acquireChannel(CHANNEL_NAME, _, ACTIVITY_ID))
|
|
|
|
.WillOnce(InvokeWithoutArgs([this] {
|
2017-06-23 23:26:34 +00:00
|
|
|
m_audioInputProcessor->onFocusChanged(avsCommon::avs::FocusState::FOREGROUND);
|
2017-06-09 23:23:31 +00:00
|
|
|
return true;}));
|
|
|
|
}
|
|
|
|
EXPECT_CALL(*m_mockDirectiveSequencer, setDialogRequestId(_));
|
|
|
|
EXPECT_CALL(*m_mockMessageSender, sendMessage(_))
|
|
|
|
.WillOnce(DoAll(
|
|
|
|
Invoke(m_recognizeEvent.get(), &RecognizeEvent::verifyMessage),
|
|
|
|
InvokeWithoutArgs([&] {
|
|
|
|
std::lock_guard<std::mutex> lock(mutex);
|
|
|
|
done = true;
|
|
|
|
conditionVariable.notify_one(); })));
|
|
|
|
if (m_recognizeEvent->send(m_audioInputProcessor)) {
|
|
|
|
std::unique_lock<std::mutex> lock(mutex);
|
|
|
|
return conditionVariable.wait_for(lock, std::chrono::seconds(10), [&done] { return done; } );
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AudioInputProcessorTest::testStopCaptureSucceeds() {
|
2017-06-23 23:26:34 +00:00
|
|
|
EXPECT_CALL(*m_mockObserver, onStateChanged(AudioInputProcessorObserverInterface::State::BUSY));
|
|
|
|
EXPECT_CALL(*m_mockObserver, onStateChanged(AudioInputProcessorObserverInterface::State::IDLE));
|
2017-06-09 23:23:31 +00:00
|
|
|
EXPECT_CALL(*m_mockFocusManager, releaseChannel(CHANNEL_NAME, _));
|
|
|
|
|
|
|
|
auto stopCaptureResult = m_audioInputProcessor->stopCapture();
|
|
|
|
EXPECT_TRUE(stopCaptureResult.valid());
|
|
|
|
return stopCaptureResult.valid() && stopCaptureResult.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AudioInputProcessorTest::testContextFailure(avsCommon::sdkInterfaces::ContextRequestError error) {
|
|
|
|
std::mutex mutex;
|
|
|
|
std::condition_variable conditionVariable;
|
|
|
|
bool done = false;
|
|
|
|
RecognizeEvent recognize(*m_audioProvider, Initiator::TAP);
|
|
|
|
|
|
|
|
EXPECT_CALL(*m_mockContextManager, getContext(_))
|
|
|
|
.WillOnce(InvokeWithoutArgs([this, error] { m_audioInputProcessor->onContextFailure(error); }));
|
2017-06-23 23:26:34 +00:00
|
|
|
EXPECT_CALL(*m_mockObserver, onStateChanged(AudioInputProcessorObserverInterface::State::RECOGNIZING));
|
|
|
|
EXPECT_CALL(*m_mockObserver, onStateChanged(AudioInputProcessorObserverInterface::State::IDLE))
|
2017-06-09 23:23:31 +00:00
|
|
|
.WillOnce(InvokeWithoutArgs([&] {
|
|
|
|
std::lock_guard<std::mutex> lock(mutex);
|
|
|
|
done = true;
|
|
|
|
conditionVariable.notify_one(); }));
|
|
|
|
|
|
|
|
if (recognize.send(m_audioInputProcessor)) {
|
|
|
|
std::unique_lock<std::mutex> lock(mutex);
|
|
|
|
return conditionVariable.wait_for(lock, std::chrono::seconds(10), [&done] { return done; } );
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AudioInputProcessorTest::testStopCaptureDirectiveSucceeds(bool withDialogRequestId) {
|
|
|
|
std::mutex mutex;
|
|
|
|
std::condition_variable conditionVariable;
|
|
|
|
bool done = false;
|
|
|
|
|
|
|
|
auto avsDirective = createAVSDirective(STOP_CAPTURE, withDialogRequestId);
|
|
|
|
auto result =
|
2017-06-23 23:26:34 +00:00
|
|
|
avsCommon::utils::memory::make_unique<avsCommon::sdkInterfaces::test::MockDirectiveHandlerResult>();
|
2017-06-09 23:23:31 +00:00
|
|
|
std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface> directiveHandler = m_audioInputProcessor;
|
|
|
|
|
2017-06-23 23:26:34 +00:00
|
|
|
EXPECT_CALL(*m_mockObserver, onStateChanged(AudioInputProcessorObserverInterface::State::BUSY));
|
2017-06-09 23:23:31 +00:00
|
|
|
EXPECT_CALL(*m_mockFocusManager, releaseChannel(CHANNEL_NAME, _));
|
|
|
|
if (withDialogRequestId) {
|
|
|
|
EXPECT_CALL(*result, setCompleted());
|
|
|
|
}
|
2017-06-23 23:26:34 +00:00
|
|
|
EXPECT_CALL(*m_mockObserver, onStateChanged(AudioInputProcessorObserverInterface::State::IDLE))
|
2017-06-09 23:23:31 +00:00
|
|
|
.WillOnce(InvokeWithoutArgs([&] {
|
|
|
|
std::lock_guard<std::mutex> lock(mutex);
|
|
|
|
done = true;
|
|
|
|
conditionVariable.notify_one(); }));
|
|
|
|
|
|
|
|
if (!withDialogRequestId) {
|
|
|
|
directiveHandler->handleDirectiveImmediately(avsDirective);
|
|
|
|
} else {
|
|
|
|
directiveHandler->preHandleDirective(avsDirective, std::move(result));
|
|
|
|
EXPECT_TRUE(directiveHandler->handleDirective(avsDirective->getMessageId()));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_lock<std::mutex> lock(mutex);
|
|
|
|
return conditionVariable.wait_for(lock, std::chrono::seconds(10), [&done] { return done; } );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AudioInputProcessorTest::testStopCaptureDirectiveFails(bool withDialogRequestId) {
|
|
|
|
std::mutex mutex;
|
|
|
|
std::condition_variable conditionVariable;
|
|
|
|
bool done = false;
|
|
|
|
|
|
|
|
auto avsDirective = createAVSDirective(STOP_CAPTURE, withDialogRequestId);
|
2017-06-23 23:26:34 +00:00
|
|
|
auto result = avsCommon::utils::memory::make_unique<avsCommon::sdkInterfaces::test::MockDirectiveHandlerResult>();
|
2017-06-09 23:23:31 +00:00
|
|
|
EXPECT_CALL(*result, setFailed(_))
|
|
|
|
.WillOnce(InvokeWithoutArgs([&] {
|
|
|
|
std::lock_guard<std::mutex> lock(mutex);
|
|
|
|
done = true;
|
|
|
|
conditionVariable.notify_one(); }));
|
|
|
|
std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface> directiveHandler = m_audioInputProcessor;
|
|
|
|
|
|
|
|
if (!withDialogRequestId) {
|
|
|
|
directiveHandler->handleDirectiveImmediately(avsDirective);
|
|
|
|
} else {
|
|
|
|
directiveHandler->preHandleDirective(avsDirective, std::move(result));
|
|
|
|
EXPECT_TRUE(directiveHandler->handleDirective(avsDirective->getMessageId()));
|
|
|
|
}
|
|
|
|
std::unique_lock<std::mutex> lock(mutex);
|
|
|
|
return conditionVariable.wait_for(lock, std::chrono::seconds(10), [&done] { return done; } );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AudioInputProcessorTest::testExpectSpeechSucceeds(bool withDialogRequestId) {
|
|
|
|
std::mutex mutex;
|
|
|
|
std::condition_variable conditionVariable;
|
|
|
|
bool done = false;
|
|
|
|
|
|
|
|
auto avsDirective = createAVSDirective(EXPECT_SPEECH, withDialogRequestId);
|
|
|
|
auto result =
|
2017-06-23 23:26:34 +00:00
|
|
|
avsCommon::utils::memory::make_unique<avsCommon::sdkInterfaces::test::MockDirectiveHandlerResult>();
|
2017-06-09 23:23:31 +00:00
|
|
|
std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface> directiveHandler = m_audioInputProcessor;
|
|
|
|
|
2017-06-23 23:26:34 +00:00
|
|
|
EXPECT_CALL(*m_mockObserver, onStateChanged(AudioInputProcessorObserverInterface::State::EXPECTING_SPEECH));
|
|
|
|
EXPECT_CALL(*m_mockObserver, onStateChanged(AudioInputProcessorObserverInterface::State::RECOGNIZING));
|
2017-06-09 23:23:31 +00:00
|
|
|
if (withDialogRequestId) {
|
|
|
|
EXPECT_CALL(*result, setCompleted());
|
|
|
|
}
|
|
|
|
EXPECT_CALL(*m_mockContextManager, getContext(_))
|
|
|
|
.WillOnce(InvokeWithoutArgs([&] {
|
|
|
|
std::lock_guard<std::mutex> lock(mutex);
|
|
|
|
done = true;
|
|
|
|
conditionVariable.notify_one(); }));
|
|
|
|
|
|
|
|
if (!withDialogRequestId) {
|
|
|
|
directiveHandler->handleDirectiveImmediately(avsDirective);
|
|
|
|
} else {
|
|
|
|
directiveHandler->preHandleDirective(avsDirective, std::move(result));
|
|
|
|
EXPECT_TRUE(directiveHandler->handleDirective(avsDirective->getMessageId()));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_lock<std::mutex> lock(mutex);
|
|
|
|
return conditionVariable.wait_for(lock, std::chrono::seconds(10), [&done] { return done; } );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AudioInputProcessorTest::testExpectSpeechWaits(bool withDialogRequestId, bool verifyTimeout) {
|
|
|
|
std::mutex mutex;
|
|
|
|
std::condition_variable conditionVariable;
|
|
|
|
bool done = false;
|
|
|
|
|
|
|
|
auto avsDirective = createAVSDirective(EXPECT_SPEECH, withDialogRequestId);
|
|
|
|
auto result =
|
2017-06-23 23:26:34 +00:00
|
|
|
avsCommon::utils::memory::make_unique<avsCommon::sdkInterfaces::test::MockDirectiveHandlerResult>();
|
2017-06-09 23:23:31 +00:00
|
|
|
std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface> directiveHandler = m_audioInputProcessor;
|
|
|
|
|
|
|
|
if (withDialogRequestId) {
|
|
|
|
EXPECT_CALL(*result, setCompleted());
|
|
|
|
}
|
|
|
|
if (verifyTimeout) {
|
2017-06-23 23:26:34 +00:00
|
|
|
EXPECT_CALL(*m_mockObserver, onStateChanged(AudioInputProcessorObserverInterface::State::EXPECTING_SPEECH));
|
2017-06-09 23:23:31 +00:00
|
|
|
EXPECT_CALL(*m_mockMessageSender, sendMessage(_))
|
|
|
|
.WillOnce(Invoke(&verifyExpectSpeechTimedOut));
|
2017-06-23 23:26:34 +00:00
|
|
|
EXPECT_CALL(*m_mockObserver, onStateChanged(AudioInputProcessorObserverInterface::State::IDLE))
|
2017-06-09 23:23:31 +00:00
|
|
|
.WillOnce(InvokeWithoutArgs([&] {
|
|
|
|
std::lock_guard<std::mutex> lock(mutex);
|
|
|
|
done = true;
|
|
|
|
conditionVariable.notify_one(); }));
|
|
|
|
} else {
|
2017-06-23 23:26:34 +00:00
|
|
|
EXPECT_CALL(*m_mockObserver, onStateChanged(AudioInputProcessorObserverInterface::State::EXPECTING_SPEECH))
|
2017-06-09 23:23:31 +00:00
|
|
|
.WillOnce(InvokeWithoutArgs([&] {
|
|
|
|
std::lock_guard<std::mutex> lock(mutex);
|
|
|
|
done = true;
|
|
|
|
conditionVariable.notify_one(); }));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!withDialogRequestId) {
|
|
|
|
directiveHandler->handleDirectiveImmediately(avsDirective);
|
|
|
|
} else {
|
|
|
|
directiveHandler->preHandleDirective(avsDirective, std::move(result));
|
|
|
|
EXPECT_TRUE(directiveHandler->handleDirective(avsDirective->getMessageId()));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_lock<std::mutex> lock(mutex);
|
|
|
|
return conditionVariable.wait_for(lock, std::chrono::seconds(10), [&done] { return done; } );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AudioInputProcessorTest::testExpectSpeechFails(bool withDialogRequestId) {
|
|
|
|
std::mutex mutex;
|
|
|
|
std::condition_variable conditionVariable;
|
|
|
|
bool done = false;
|
|
|
|
|
|
|
|
auto avsDirective = createAVSDirective(EXPECT_SPEECH, WITH_DIALOG_REQUEST_ID);
|
2017-06-23 23:26:34 +00:00
|
|
|
auto result = avsCommon::utils::memory::make_unique<avsCommon::sdkInterfaces::test::MockDirectiveHandlerResult>();
|
2017-06-09 23:23:31 +00:00
|
|
|
if (WITH_DIALOG_REQUEST_ID) {
|
|
|
|
EXPECT_CALL(*result, setFailed(_))
|
|
|
|
.WillOnce(InvokeWithoutArgs([&] {
|
|
|
|
std::lock_guard<std::mutex> lock(mutex);
|
|
|
|
done = true;
|
|
|
|
conditionVariable.notify_one(); }));
|
|
|
|
}
|
|
|
|
std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface> directiveHandler = m_audioInputProcessor;
|
|
|
|
|
|
|
|
if (!WITH_DIALOG_REQUEST_ID) {
|
|
|
|
directiveHandler->handleDirectiveImmediately(avsDirective);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
directiveHandler->preHandleDirective(avsDirective, std::move(result));
|
|
|
|
EXPECT_TRUE(directiveHandler->handleDirective(avsDirective->getMessageId()));
|
|
|
|
std::unique_lock<std::mutex> lock(mutex);
|
|
|
|
return conditionVariable.wait_for(lock, std::chrono::seconds(10), [&done] { return done; } );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-23 23:26:34 +00:00
|
|
|
std::shared_ptr<avsCommon::avs::AVSDirective> AudioInputProcessorTest::createAVSDirective(
|
2017-06-09 23:23:31 +00:00
|
|
|
const avsCommon::avs::NamespaceAndName& directive,
|
|
|
|
bool WITH_DIALOG_REQUEST_ID) {
|
2017-06-23 23:26:34 +00:00
|
|
|
auto header = std::make_shared<avsCommon::avs::AVSMessageHeader>(
|
2017-06-09 23:23:31 +00:00
|
|
|
directive.nameSpace,
|
|
|
|
directive.name,
|
|
|
|
avsCommon::utils::uuidGeneration::generateUUID(),
|
|
|
|
avsCommon::utils::uuidGeneration::generateUUID());
|
|
|
|
|
|
|
|
rapidjson::Document document(rapidjson::kObjectType);
|
|
|
|
rapidjson::Value directiveJson(rapidjson::kObjectType);
|
|
|
|
rapidjson::Value headerJson(rapidjson::kObjectType);
|
|
|
|
rapidjson::Value payloadJson(rapidjson::kObjectType);
|
|
|
|
rapidjson::Value namespaceJson(header->getNamespace(), document.GetAllocator());
|
|
|
|
rapidjson::Value nameJson(header->getName(), document.GetAllocator());
|
|
|
|
rapidjson::Value messageIdJson(header->getMessageId(), document.GetAllocator());
|
|
|
|
rapidjson::Value dialogRequestIdJson(header->getDialogRequestId(), document.GetAllocator());
|
|
|
|
|
|
|
|
if (EXPECT_SPEECH == directive) {
|
|
|
|
rapidjson::Value timeoutInMillisecondsJson(EXPECT_SPEECH_TIMEOUT_IN_MILLISECONDS);
|
|
|
|
rapidjson::Value initiatorJson(rapidjson::StringRef(EXPECT_SPEECH_INITIATOR));
|
|
|
|
payloadJson.AddMember(
|
|
|
|
rapidjson::StringRef(EXPECT_SPEECH_TIMEOUT_KEY),
|
|
|
|
timeoutInMillisecondsJson,
|
|
|
|
document.GetAllocator());
|
|
|
|
payloadJson.AddMember(
|
|
|
|
rapidjson::StringRef(EXPECT_SPEECH_INITIATOR_KEY),
|
|
|
|
initiatorJson,
|
|
|
|
document.GetAllocator());
|
|
|
|
}
|
|
|
|
|
|
|
|
headerJson.AddMember(rapidjson::StringRef(MESSAGE_NAMESPACE_KEY), namespaceJson, document.GetAllocator());
|
|
|
|
headerJson.AddMember(rapidjson::StringRef(MESSAGE_NAME_KEY), nameJson, document.GetAllocator());
|
|
|
|
headerJson.AddMember(rapidjson::StringRef(MESSAGE_MESSAGE_ID_KEY), messageIdJson, document.GetAllocator());
|
|
|
|
headerJson.AddMember(
|
|
|
|
rapidjson::StringRef(MESSAGE_DIALOG_REQUEST_ID_KEY),
|
|
|
|
dialogRequestIdJson,
|
|
|
|
document.GetAllocator());
|
|
|
|
directiveJson.AddMember(rapidjson::StringRef(MESSAGE_HEADER_KEY), headerJson, document.GetAllocator());
|
|
|
|
|
|
|
|
rapidjson::StringBuffer payloadBuffer;
|
|
|
|
rapidjson::Writer<rapidjson::StringBuffer> payloadWriter(payloadBuffer);
|
|
|
|
payloadJson.Accept(payloadWriter);
|
|
|
|
|
|
|
|
directiveJson.AddMember(rapidjson::StringRef(MESSAGE_PAYLOAD_KEY), payloadJson, document.GetAllocator());
|
|
|
|
document.AddMember(rapidjson::StringRef(MESSAGE_DIRECTIVE_KEY), directiveJson, document.GetAllocator());
|
|
|
|
|
|
|
|
rapidjson::StringBuffer documentBuffer;
|
|
|
|
rapidjson::Writer<rapidjson::StringBuffer> documentWriter(documentBuffer);
|
|
|
|
document.Accept(documentWriter);
|
|
|
|
|
|
|
|
auto mockAttachmentManager = std::make_shared<avsCommon::avs::attachment::test::MockAttachmentManager>();
|
2017-06-23 23:26:34 +00:00
|
|
|
return avsCommon::avs::AVSDirective::create(
|
2017-06-09 23:23:31 +00:00
|
|
|
documentBuffer.GetString(),
|
|
|
|
header,
|
|
|
|
payloadBuffer.GetString(),
|
|
|
|
mockAttachmentManager,
|
|
|
|
"");
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioInputProcessorTest::verifyExpectSpeechTimedOut(std::shared_ptr<avsCommon::avs::MessageRequest> request) {
|
|
|
|
rapidjson::Document document = parseJson(request->getJsonContent());
|
|
|
|
|
|
|
|
auto event = document.FindMember(MESSAGE_EVENT_KEY);
|
|
|
|
EXPECT_NE(event, document.MemberEnd());
|
|
|
|
|
|
|
|
auto header = event->value.FindMember(MESSAGE_HEADER_KEY);
|
|
|
|
EXPECT_NE(header, event->value.MemberEnd());
|
|
|
|
auto payload = event->value.FindMember(MESSAGE_PAYLOAD_KEY);
|
|
|
|
EXPECT_NE(payload, event->value.MemberEnd());
|
|
|
|
|
|
|
|
EXPECT_EQ(getJsonString(header->value, MESSAGE_NAMESPACE_KEY), NAMESPACE);
|
|
|
|
EXPECT_EQ(getJsonString(header->value, MESSAGE_NAME_KEY), EXPECT_SPEECH_TIMED_OUT_EVENT_NAME);
|
|
|
|
EXPECT_NE(getJsonString(header->value, MESSAGE_MESSAGE_ID_KEY), "");
|
|
|
|
|
|
|
|
EXPECT_EQ(request->getAttachmentReader(), nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioInputProcessorTest::removeDefaultAudioProvider() {
|
|
|
|
EXPECT_CALL(*m_mockContextManager, setStateProvider(RECOGNIZER_STATE, Ne(nullptr)));
|
|
|
|
m_audioInputProcessor = AudioInputProcessor::create(
|
|
|
|
m_mockDirectiveSequencer,
|
|
|
|
m_mockMessageSender,
|
|
|
|
m_mockContextManager,
|
|
|
|
m_mockFocusManager,
|
|
|
|
m_mockExceptionEncounteredSender);
|
|
|
|
EXPECT_NE(m_audioInputProcessor, nullptr);
|
|
|
|
m_audioInputProcessor->addObserver(m_mockObserver);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioInputProcessorTest::makeDefaultAudioProviderNotAlwaysReadable() {
|
|
|
|
m_audioProvider->alwaysReadable = false;
|
|
|
|
EXPECT_CALL(*m_mockContextManager, setStateProvider(RECOGNIZER_STATE, Ne(nullptr)));
|
|
|
|
m_audioInputProcessor = AudioInputProcessor::create(
|
|
|
|
m_mockDirectiveSequencer,
|
|
|
|
m_mockMessageSender,
|
|
|
|
m_mockContextManager,
|
|
|
|
m_mockFocusManager,
|
|
|
|
m_mockExceptionEncounteredSender,
|
|
|
|
*m_audioProvider);
|
|
|
|
EXPECT_NE(m_audioInputProcessor, nullptr);
|
|
|
|
m_audioInputProcessor->addObserver(m_mockObserver);
|
|
|
|
}
|
|
|
|
|
2017-06-23 23:26:34 +00:00
|
|
|
bool AudioInputProcessorTest::testFocusChange(avsCommon::avs::FocusState state) {
|
2017-06-09 23:23:31 +00:00
|
|
|
std::mutex mutex;
|
|
|
|
std::condition_variable conditionVariable;
|
|
|
|
bool done = false;
|
|
|
|
|
|
|
|
bool recognizeSucceeded = testRecognizeSucceeds(*m_audioProvider, Initiator::TAP);
|
|
|
|
EXPECT_TRUE(recognizeSucceeded);
|
|
|
|
if (!recognizeSucceeded) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
EXPECT_CALL(*m_mockFocusManager, releaseChannel(CHANNEL_NAME, _));
|
2017-06-23 23:26:34 +00:00
|
|
|
EXPECT_CALL(*m_mockObserver, onStateChanged(AudioInputProcessorObserverInterface::State::IDLE))
|
2017-06-09 23:23:31 +00:00
|
|
|
.WillOnce(InvokeWithoutArgs([&] {
|
|
|
|
std::lock_guard<std::mutex> lock(mutex);
|
|
|
|
done = true;
|
|
|
|
conditionVariable.notify_one(); }));
|
|
|
|
m_audioInputProcessor->onFocusChanged(state);
|
|
|
|
|
|
|
|
std::unique_lock<std::mutex> lock(mutex);
|
|
|
|
return conditionVariable.wait_for(lock, std::chrono::seconds(10), [&done] { return done; } );
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Function to verify that @c AudioInputProcessor::create() behaves correctly with different input parameters.
|
2017-05-18 05:02:48 +00:00
|
|
|
TEST_F(AudioInputProcessorTest, create) {
|
|
|
|
// Verify it fails to create with nullptr for any of the first four parameters.
|
|
|
|
m_audioInputProcessor = AudioInputProcessor::create(
|
|
|
|
nullptr,
|
|
|
|
m_mockMessageSender,
|
|
|
|
m_mockContextManager,
|
|
|
|
m_mockFocusManager,
|
|
|
|
m_mockExceptionEncounteredSender,
|
|
|
|
*m_audioProvider);
|
|
|
|
EXPECT_EQ(m_audioInputProcessor, nullptr);
|
|
|
|
m_audioInputProcessor = AudioInputProcessor::create(
|
|
|
|
m_mockDirectiveSequencer,
|
|
|
|
nullptr,
|
|
|
|
m_mockContextManager,
|
|
|
|
m_mockFocusManager,
|
|
|
|
m_mockExceptionEncounteredSender,
|
|
|
|
*m_audioProvider);
|
|
|
|
EXPECT_EQ(m_audioInputProcessor, nullptr);
|
|
|
|
m_audioInputProcessor = AudioInputProcessor::create(
|
|
|
|
m_mockDirectiveSequencer,
|
|
|
|
m_mockMessageSender,
|
|
|
|
nullptr,
|
|
|
|
m_mockFocusManager,
|
|
|
|
m_mockExceptionEncounteredSender,
|
|
|
|
*m_audioProvider);
|
|
|
|
EXPECT_EQ(m_audioInputProcessor, nullptr);
|
|
|
|
m_audioInputProcessor = AudioInputProcessor::create(
|
|
|
|
m_mockDirectiveSequencer,
|
|
|
|
m_mockMessageSender,
|
|
|
|
m_mockContextManager,
|
|
|
|
nullptr,
|
|
|
|
m_mockExceptionEncounteredSender,
|
|
|
|
*m_audioProvider);
|
|
|
|
EXPECT_EQ(m_audioInputProcessor, nullptr);
|
|
|
|
m_audioInputProcessor = AudioInputProcessor::create(
|
|
|
|
m_mockDirectiveSequencer,
|
|
|
|
m_mockMessageSender,
|
|
|
|
m_mockContextManager,
|
|
|
|
m_mockFocusManager,
|
|
|
|
nullptr,
|
|
|
|
*m_audioProvider);
|
|
|
|
EXPECT_EQ(m_audioInputProcessor, nullptr);
|
|
|
|
|
|
|
|
// Verify it does *not* fail to create with nullptr for the final parameter.
|
2017-06-09 23:23:31 +00:00
|
|
|
EXPECT_CALL(*m_mockContextManager, setStateProvider(RECOGNIZER_STATE, Ne(nullptr)));
|
2017-05-18 05:02:48 +00:00
|
|
|
m_audioInputProcessor = AudioInputProcessor::create(
|
|
|
|
m_mockDirectiveSequencer,
|
|
|
|
m_mockMessageSender,
|
|
|
|
m_mockContextManager,
|
|
|
|
m_mockFocusManager,
|
|
|
|
m_mockExceptionEncounteredSender,
|
|
|
|
AudioProvider::null());
|
|
|
|
EXPECT_NE(m_audioInputProcessor, nullptr);
|
|
|
|
}
|
|
|
|
|
2017-06-09 23:23:31 +00:00
|
|
|
/// Function to verify that @c AudioInputProcessor::getconfiguration() returns the expected configuration data.
|
2017-05-18 05:02:48 +00:00
|
|
|
TEST_F(AudioInputProcessorTest, getConfiguration) {
|
|
|
|
auto configuration = m_audioInputProcessor->getConfiguration();
|
|
|
|
EXPECT_EQ(configuration.size(), NUM_DIRECTIVES);
|
|
|
|
for (auto namespaceAndName: DIRECTIVES) {
|
|
|
|
auto directive = configuration.find(namespaceAndName);
|
|
|
|
EXPECT_NE(directive, configuration.end());
|
|
|
|
if (configuration.end() == directive) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-06-23 23:26:34 +00:00
|
|
|
EXPECT_EQ(directive->second, BLOCKING_POLICY);
|
2017-05-18 05:02:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-09 23:23:31 +00:00
|
|
|
/**
|
|
|
|
* Function to verify that observers can be added/removed. Nothing is directly asserted here, but this test verifies
|
|
|
|
* that these functions work without crashing.
|
|
|
|
*/
|
2017-05-18 05:02:48 +00:00
|
|
|
TEST_F(AudioInputProcessorTest, addRemoveObserver) {
|
|
|
|
// Null pointer detection.
|
|
|
|
m_audioInputProcessor->addObserver(nullptr);
|
|
|
|
m_audioInputProcessor->removeObserver(nullptr);
|
|
|
|
|
|
|
|
// Add/remove single observer.
|
|
|
|
auto observer = std::make_shared<MockObserver>();
|
|
|
|
m_audioInputProcessor->addObserver(observer);
|
|
|
|
m_audioInputProcessor->removeObserver(observer);
|
|
|
|
|
|
|
|
// Add multiple observers.
|
|
|
|
auto observer2 = std::make_shared<MockObserver>();
|
|
|
|
m_audioInputProcessor->addObserver(observer);
|
|
|
|
m_audioInputProcessor->addObserver(observer2);
|
|
|
|
|
|
|
|
// Remove both observers (out of order).
|
|
|
|
m_audioInputProcessor->removeObserver(observer);
|
|
|
|
m_audioInputProcessor->removeObserver(observer2);
|
|
|
|
|
|
|
|
// Try to re-remove an observer which is no longer registered.
|
|
|
|
m_audioInputProcessor->removeObserver(observer);
|
|
|
|
}
|
|
|
|
|
2017-06-09 23:23:31 +00:00
|
|
|
/// This function verifies that @c AudioInputProcessor::recognize() fails when given a null @c AudioProvider.
|
2017-05-18 05:02:48 +00:00
|
|
|
TEST_F(AudioInputProcessorTest, recognizeNullStream) {
|
|
|
|
auto result = m_audioInputProcessor->recognize(AudioProvider::null(), Initiator::PRESS_AND_HOLD);
|
|
|
|
ASSERT_TRUE(result.valid());
|
|
|
|
ASSERT_FALSE(result.get());
|
|
|
|
}
|
|
|
|
|
2017-06-09 23:23:31 +00:00
|
|
|
/// This function verifies that @c AudioInputProcessor::recognize() fails when given invalid @c AudioFormats.
|
|
|
|
TEST_F(AudioInputProcessorTest, recognizeInvalidAudioFormat) {
|
|
|
|
AudioProvider audioProvider = *m_audioProvider;
|
2017-06-23 23:26:34 +00:00
|
|
|
audioProvider.format.endianness = avsCommon::utils::AudioFormat::Endianness::BIG;
|
2017-06-09 23:23:31 +00:00
|
|
|
EXPECT_FALSE(m_audioInputProcessor->recognize(audioProvider, Initiator::PRESS_AND_HOLD).get());
|
|
|
|
|
|
|
|
audioProvider = *m_audioProvider;
|
|
|
|
audioProvider.format.sampleRateHz = 0;
|
|
|
|
EXPECT_FALSE(m_audioInputProcessor->recognize(audioProvider, Initiator::PRESS_AND_HOLD).get());
|
|
|
|
|
|
|
|
audioProvider = *m_audioProvider;
|
|
|
|
audioProvider.format.sampleSizeInBits = 0;
|
|
|
|
EXPECT_FALSE(m_audioInputProcessor->recognize(audioProvider, Initiator::PRESS_AND_HOLD).get());
|
2017-05-18 05:02:48 +00:00
|
|
|
|
2017-06-09 23:23:31 +00:00
|
|
|
audioProvider = *m_audioProvider;
|
|
|
|
audioProvider.format.numChannels = 0;
|
|
|
|
EXPECT_FALSE(m_audioInputProcessor->recognize(audioProvider, Initiator::PRESS_AND_HOLD).get());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that @c AudioInputProcessor::recognize() works with @c Initiator::PRESS_AND_HOLD.
|
|
|
|
TEST_F(AudioInputProcessorTest, recognizePressAndHold) {
|
|
|
|
ASSERT_TRUE(testRecognizeSucceeds(*m_audioProvider, Initiator::PRESS_AND_HOLD));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that @c AudioInputProcessor::recognize() works with @c Initiator::TAP.
|
|
|
|
TEST_F(AudioInputProcessorTest, recognizeTap) {
|
|
|
|
ASSERT_TRUE(testRecognizeSucceeds(*m_audioProvider, Initiator::TAP));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that @c AudioInputProcessor::recognize() fails with @c Initiator::WAKEWORD and no keyword.
|
|
|
|
TEST_F(AudioInputProcessorTest, recognizeWakewordWithoutKeyword) {
|
|
|
|
EXPECT_TRUE(testRecognizeFails(*m_audioProvider, Initiator::WAKEWORD));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function verifies that @c AudioInputProcessor::recognize() fails with @c Initiator::WAKEWORD and invalid begin
|
|
|
|
* index.
|
|
|
|
*/
|
|
|
|
TEST_F(AudioInputProcessorTest, recognizeWakewordWithBadBegin) {
|
2017-06-23 23:26:34 +00:00
|
|
|
avsCommon::avs::AudioInputStream::Index begin = SDS_WORDS + 1;
|
2017-06-09 23:23:31 +00:00
|
|
|
auto end = AudioInputProcessor::INVALID_INDEX;
|
|
|
|
EXPECT_TRUE(testRecognizeFails(*m_audioProvider, Initiator::WAKEWORD, begin, end, KEYWORD_TEXT));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that @c AudioInputProcessor::recognize() works with @c Initiator::WAKEWORD and keyword.
|
|
|
|
TEST_F(AudioInputProcessorTest, recognizeWakewordWithKeyword) {
|
|
|
|
auto begin = AudioInputProcessor::INVALID_INDEX;
|
|
|
|
auto end = AudioInputProcessor::INVALID_INDEX;
|
|
|
|
EXPECT_TRUE(testRecognizeSucceeds(*m_audioProvider, Initiator::WAKEWORD, begin, end, KEYWORD_TEXT));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that @c AudioInputProcessor::recognize() works with @c Initiator::WAKEWORD valid begin.
|
|
|
|
TEST_F(AudioInputProcessorTest, recognizeWakewordWithGoodBegin) {
|
2017-06-23 23:26:34 +00:00
|
|
|
avsCommon::avs::AudioInputStream::Index begin = 0;
|
2017-06-09 23:23:31 +00:00
|
|
|
auto end = AudioInputProcessor::INVALID_INDEX;
|
|
|
|
EXPECT_TRUE(testRecognizeSucceeds(*m_audioProvider, Initiator::WAKEWORD, begin, end, KEYWORD_TEXT));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function verifies that @c AudioInputProcessor::recognize() works with @c Initiator::WAKEWORD valid begin and
|
|
|
|
* end indices
|
|
|
|
*/
|
|
|
|
TEST_F(AudioInputProcessorTest, recognizeWakewordWithGoodBeginAndEnd) {
|
2017-06-23 23:26:34 +00:00
|
|
|
avsCommon::avs::AudioInputStream::Index begin = PREROLL_WORDS;
|
|
|
|
avsCommon::avs::AudioInputStream::Index end = PREROLL_WORDS + WAKEWORD_WORDS;
|
2017-06-09 23:23:31 +00:00
|
|
|
EXPECT_TRUE(testRecognizeSucceeds(*m_audioProvider, Initiator::WAKEWORD, begin, end, KEYWORD_TEXT));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that @c AudioInputProcessor::recognize() works with @c ASRProfile::CLOSE_TALK;
|
|
|
|
TEST_F(AudioInputProcessorTest, recognizeCloseTalk) {
|
|
|
|
auto audioProvider = *m_audioProvider;
|
|
|
|
audioProvider.profile = ASRProfile::CLOSE_TALK;
|
|
|
|
ASSERT_TRUE(testRecognizeSucceeds(audioProvider, Initiator::PRESS_AND_HOLD));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that @c AudioInputProcessor::recognize() works with @c ASRProfile::NEAR_FIELD;
|
|
|
|
TEST_F(AudioInputProcessorTest, recognizeNearField) {
|
|
|
|
auto audioProvider = *m_audioProvider;
|
|
|
|
audioProvider.profile = ASRProfile::NEAR_FIELD;
|
|
|
|
ASSERT_TRUE(testRecognizeSucceeds(audioProvider, Initiator::TAP));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that @c AudioInputProcessor::recognize() works with @c ASRProfile::FAR_FIELD;
|
|
|
|
TEST_F(AudioInputProcessorTest, recognizeFarField) {
|
|
|
|
auto audioProvider = *m_audioProvider;
|
|
|
|
audioProvider.profile = ASRProfile::FAR_FIELD;
|
|
|
|
ASSERT_TRUE(testRecognizeSucceeds(audioProvider, Initiator::TAP));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that @c AudioInputProcessor::recognize() works in @c State::EXPECTING_SPEECH.
|
|
|
|
TEST_F(AudioInputProcessorTest, recognizeWhileExpectingSpeech) {
|
|
|
|
removeDefaultAudioProvider();
|
|
|
|
ASSERT_TRUE(testExpectSpeechWaits(WITH_DIALOG_REQUEST_ID, !VERIFY_TIMEOUT));
|
|
|
|
ASSERT_TRUE(testRecognizeSucceeds(*m_audioProvider, Initiator::PRESS_AND_HOLD));
|
|
|
|
}
|
|
|
|
|
2017-06-23 23:26:34 +00:00
|
|
|
/**
|
|
|
|
* This function verifies that @c AudioInputProcessor::recognize() works in @c State::RECOGNIZING when the previous
|
|
|
|
* recognize used the CLOSE_TALK profile.
|
|
|
|
*/
|
|
|
|
TEST_F(AudioInputProcessorTest, recognizeBargeInWhileRecognizingCloseTalk) {
|
|
|
|
auto audioProvider = *m_audioProvider;
|
|
|
|
audioProvider.profile = ASRProfile::CLOSE_TALK;
|
|
|
|
ASSERT_TRUE(testRecognizeSucceeds(audioProvider, Initiator::TAP));
|
2017-06-09 23:23:31 +00:00
|
|
|
ASSERT_TRUE(testRecognizeSucceeds(*m_audioProvider, Initiator::TAP));
|
|
|
|
}
|
|
|
|
|
2017-06-23 23:26:34 +00:00
|
|
|
/**
|
|
|
|
* This function verifies that @c AudioInputProcessor::recognize() fails in @c State::RECOGNIZING when the previous
|
|
|
|
* recognize used the NEAR_FIELD profile.
|
|
|
|
*/
|
|
|
|
TEST_F(AudioInputProcessorTest, recognizeBargeInWhileRecognizingNearField) {
|
|
|
|
auto audioProvider = *m_audioProvider;
|
|
|
|
audioProvider.profile = ASRProfile::NEAR_FIELD;
|
|
|
|
ASSERT_TRUE(testRecognizeSucceeds(audioProvider, Initiator::TAP));
|
|
|
|
ASSERT_TRUE(testRecognizeFails(*m_audioProvider, Initiator::TAP));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function verifies that @c AudioInputProcessor::recognize() fails in @c State::RECOGNIZING when the previous
|
|
|
|
* recognize used the FAR_FIELD profile.
|
|
|
|
*/
|
|
|
|
TEST_F(AudioInputProcessorTest, recognizeBargeInWhileRecognizingFarField) {
|
|
|
|
auto audioProvider = *m_audioProvider;
|
|
|
|
audioProvider.profile = ASRProfile::FAR_FIELD;
|
|
|
|
ASSERT_TRUE(testRecognizeSucceeds(audioProvider, Initiator::TAP));
|
|
|
|
ASSERT_TRUE(testRecognizeFails(*m_audioProvider, Initiator::TAP));
|
|
|
|
}
|
|
|
|
|
2017-06-09 23:23:31 +00:00
|
|
|
/**
|
|
|
|
* This function verifies that @c AudioInputProcessor::recognize() fails in @c State::RECOGNIZING when the second
|
|
|
|
* @c AudioProvider can't override.
|
|
|
|
*/
|
|
|
|
TEST_F(AudioInputProcessorTest, recognizeBargeInWhileRecognizingCantOverride) {
|
|
|
|
ASSERT_TRUE(testRecognizeSucceeds(*m_audioProvider, Initiator::TAP));
|
|
|
|
auto audioProvider = *m_audioProvider;
|
|
|
|
audioProvider.canOverride = false;
|
|
|
|
ASSERT_TRUE(testRecognizeFails(audioProvider, Initiator::TAP));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function verifies that @c AudioInputProcessor::recognize() fails in @c State::RECOGNIZING when the
|
|
|
|
* first @c AudioProvider can't be overridden.
|
|
|
|
*/
|
|
|
|
TEST_F(AudioInputProcessorTest, recognizeBargeInWhileRecognizingCantBeOverridden) {
|
|
|
|
auto audioProvider = *m_audioProvider;
|
|
|
|
audioProvider.canBeOverridden = false;
|
|
|
|
ASSERT_TRUE(testRecognizeSucceeds(audioProvider, Initiator::TAP));
|
|
|
|
ASSERT_TRUE(testRecognizeFails(*m_audioProvider, Initiator::TAP));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that @c AudioInputProcessor::stopCapture() fails in @c State::IDLE.
|
|
|
|
TEST_F(AudioInputProcessorTest, stopCaptureWhenIdle) {
|
|
|
|
ASSERT_FALSE(m_audioInputProcessor->stopCapture().get());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that @c AudioInputProcessor::stopCapture() fails in @c State::EXPECTING_SPEECH.
|
|
|
|
TEST_F(AudioInputProcessorTest, stopCaptureWhenExpectingSpeech) {
|
|
|
|
removeDefaultAudioProvider();
|
|
|
|
ASSERT_TRUE(testExpectSpeechWaits(WITH_DIALOG_REQUEST_ID, !VERIFY_TIMEOUT));
|
|
|
|
ASSERT_FALSE(m_audioInputProcessor->stopCapture().get());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that @c AudioInputProcessor::stopCapture() works in @c State::RECOGNIZING.
|
|
|
|
TEST_F(AudioInputProcessorTest, stopCaptureWhenRecognizing) {
|
|
|
|
ASSERT_TRUE(testRecognizeSucceeds(*m_audioProvider, Initiator::TAP, 0));
|
|
|
|
|
|
|
|
std::vector<uint8_t> buf(SDS_WORDS * SDS_WORDSIZE);
|
|
|
|
auto readStatus = avsCommon::avs::attachment::AttachmentReader::ReadStatus::OK;
|
|
|
|
EXPECT_EQ(m_recognizeEvent->getReader()->read(buf.data(), SDS_WORDSIZE, &readStatus), SDS_WORDSIZE);
|
|
|
|
ASSERT_EQ(readStatus, avsCommon::avs::attachment::AttachmentReader::ReadStatus::OK);
|
|
|
|
|
|
|
|
ASSERT_TRUE(testStopCaptureSucceeds());
|
|
|
|
|
|
|
|
EXPECT_EQ(
|
|
|
|
m_recognizeEvent->getReader()->read(buf.data(), buf.size(), &readStatus),
|
|
|
|
(SDS_WORDS - 1) * SDS_WORDSIZE);
|
|
|
|
ASSERT_EQ(readStatus, avsCommon::avs::attachment::AttachmentReader::ReadStatus::OK);
|
2017-06-23 23:26:34 +00:00
|
|
|
EXPECT_EQ(m_recognizeEvent->getReader()->read(buf.data(), buf.size(), &readStatus), 0U);
|
2017-06-09 23:23:31 +00:00
|
|
|
ASSERT_EQ(readStatus, avsCommon::avs::attachment::AttachmentReader::ReadStatus::CLOSED);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that @c AudioInputProcessor::resetState() works in @c State::IDLE.
|
|
|
|
TEST_F(AudioInputProcessorTest, resetStateWhenIdle) {
|
|
|
|
m_audioInputProcessor->resetState().get();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that @c AudioInputProcessor::resetState() works in @c State::EXPECTING_SPEECH.
|
|
|
|
TEST_F(AudioInputProcessorTest, resetStateWhenExpectingSpeech) {
|
|
|
|
removeDefaultAudioProvider();
|
|
|
|
ASSERT_TRUE(testExpectSpeechWaits(WITH_DIALOG_REQUEST_ID, !VERIFY_TIMEOUT));
|
2017-06-23 23:26:34 +00:00
|
|
|
EXPECT_CALL(*m_mockObserver, onStateChanged(AudioInputProcessorObserverInterface::State::IDLE));
|
2017-06-09 23:23:31 +00:00
|
|
|
m_audioInputProcessor->resetState().get();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that @c AudioInputProcessor::resetState() works in @c State::RECOGNIZING.
|
|
|
|
TEST_F(AudioInputProcessorTest, resetStateWhenRecognizing) {
|
|
|
|
ASSERT_TRUE(testRecognizeSucceeds(*m_audioProvider, Initiator::TAP, 0));
|
|
|
|
|
|
|
|
EXPECT_CALL(*m_mockFocusManager, releaseChannel(CHANNEL_NAME, _));
|
2017-06-23 23:26:34 +00:00
|
|
|
EXPECT_CALL(*m_mockObserver, onStateChanged(AudioInputProcessorObserverInterface::State::IDLE));
|
2017-06-09 23:23:31 +00:00
|
|
|
m_audioInputProcessor->resetState().get();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function verifies that @c AudioInputProcessor responds correctly to
|
|
|
|
* @c ContextRequestError::STATE_PROVIDER_TIMEDOUT.
|
|
|
|
*/
|
|
|
|
TEST_F(AudioInputProcessorTest, contextFailureStateProviderTimedout) {
|
|
|
|
ASSERT_TRUE(testContextFailure(avsCommon::sdkInterfaces::ContextRequestError::STATE_PROVIDER_TIMEDOUT));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function verifies that @c AudioInputProcessor responds correctly to
|
|
|
|
* @c ContextRequestError::BUILD_CONTEXT_ERROR.
|
|
|
|
*/
|
|
|
|
TEST_F(AudioInputProcessorTest, contextFailureBuildContextError) {
|
|
|
|
ASSERT_TRUE(testContextFailure(avsCommon::sdkInterfaces::ContextRequestError::BUILD_CONTEXT_ERROR));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that StopCapture directives fail in @c State::IDLE.
|
|
|
|
TEST_F(AudioInputProcessorTest, preHandleAndHandleDirectiveStopCaptureWhenIdle) {
|
|
|
|
ASSERT_TRUE(testStopCaptureDirectiveFails(WITH_DIALOG_REQUEST_ID));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that StopCapture directives with dialog request ID work in @c State::RECOGNIZING.
|
|
|
|
TEST_F(AudioInputProcessorTest, preHandleAndHandleDirectiveStopCaptureWhenRecognizing) {
|
|
|
|
ASSERT_TRUE(testRecognizeSucceeds(*m_audioProvider, Initiator::TAP, 0));
|
|
|
|
ASSERT_TRUE(testStopCaptureDirectiveSucceeds(WITH_DIALOG_REQUEST_ID));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that StopCapture directives fail in @c State::EXPECTING_SPEECH.
|
|
|
|
TEST_F(AudioInputProcessorTest, preHandleAndHandleDirectiveStopCaptureWhenExpectingSpeech) {
|
|
|
|
removeDefaultAudioProvider();
|
|
|
|
ASSERT_TRUE(testExpectSpeechWaits(WITH_DIALOG_REQUEST_ID, !VERIFY_TIMEOUT));
|
|
|
|
ASSERT_TRUE(testStopCaptureDirectiveFails(WITH_DIALOG_REQUEST_ID));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that StopCapture directives without dialog request ID work in @c State::RECOGNIZING.
|
|
|
|
TEST_F(AudioInputProcessorTest, handleDirectiveImmediatelyStopCaptureWhenRecognizing) {
|
|
|
|
ASSERT_TRUE(testRecognizeSucceeds(*m_audioProvider, Initiator::TAP, 0));
|
|
|
|
ASSERT_TRUE(testStopCaptureDirectiveSucceeds(!WITH_DIALOG_REQUEST_ID));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that ExpectSpeech directives with dialog request ID work in @c State::IDLE.
|
|
|
|
TEST_F(AudioInputProcessorTest, preHandleAndHandleDirectiveExpectSpeechWhenIdle) {
|
|
|
|
ASSERT_TRUE(testExpectSpeechSucceeds(WITH_DIALOG_REQUEST_ID));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that ExpectSpeech directives without dialog request ID work in @c State::IDLE.
|
|
|
|
TEST_F(AudioInputProcessorTest, handleDirectiveImmediatelyExpectSpeechWhenIdle) {
|
|
|
|
ASSERT_TRUE(testExpectSpeechSucceeds(!WITH_DIALOG_REQUEST_ID));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that ExpectSpeech directives fail in @c State::RECOGNIZING.
|
|
|
|
TEST_F(AudioInputProcessorTest, preHandleAndHandleDirectiveExpectSpeechWhenRecognizing) {
|
|
|
|
ASSERT_TRUE(testRecognizeSucceeds(*m_audioProvider, Initiator::TAP, 0));
|
|
|
|
ASSERT_TRUE(testExpectSpeechFails(WITH_DIALOG_REQUEST_ID));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that ExpectSpeech directives fail in @c State::EXPECTING_SPEECH.
|
|
|
|
TEST_F(AudioInputProcessorTest, preHandleAndHandleDirectiveExpectSpeechWhenExpectingSpeech) {
|
|
|
|
removeDefaultAudioProvider();
|
|
|
|
ASSERT_TRUE(testExpectSpeechWaits(WITH_DIALOG_REQUEST_ID, !VERIFY_TIMEOUT));
|
|
|
|
ASSERT_TRUE(testExpectSpeechFails(WITH_DIALOG_REQUEST_ID));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that ExpectSpeech directives wait with no default and no previous @c AudioProvider.
|
|
|
|
TEST_F(AudioInputProcessorTest, expectSpeechNoDefaultNoPrevious) {
|
|
|
|
removeDefaultAudioProvider();
|
|
|
|
ASSERT_TRUE(testExpectSpeechWaits(WITH_DIALOG_REQUEST_ID, VERIFY_TIMEOUT));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that ExpectSpeech directives wait with unreadable default and no previous @c AudioProvider.
|
|
|
|
TEST_F(AudioInputProcessorTest, expectSpeechUnreadableDefaultNoPrevious) {
|
|
|
|
makeDefaultAudioProviderNotAlwaysReadable();
|
|
|
|
ASSERT_TRUE(testExpectSpeechWaits(WITH_DIALOG_REQUEST_ID, VERIFY_TIMEOUT));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function verifies that ExpectSpeech directives wait with unreadable default and unreadable previous
|
|
|
|
* @c AudioProvider.
|
|
|
|
*/
|
|
|
|
TEST_F(AudioInputProcessorTest, expectSpeechUnreadableDefaultUnreadablePrevious) {
|
|
|
|
makeDefaultAudioProviderNotAlwaysReadable();
|
|
|
|
ASSERT_TRUE(testRecognizeSucceeds(*m_audioProvider, Initiator::PRESS_AND_HOLD, 0));
|
|
|
|
ASSERT_TRUE(testStopCaptureSucceeds());
|
|
|
|
ASSERT_TRUE(testExpectSpeechWaits(WITH_DIALOG_REQUEST_ID, VERIFY_TIMEOUT));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that ExpectSpeech directives work with no default and readable previous @c AudioProvider.
|
|
|
|
TEST_F(AudioInputProcessorTest, expectSpeechNoDefaultReadablePrevious) {
|
|
|
|
removeDefaultAudioProvider();
|
|
|
|
ASSERT_TRUE(testRecognizeSucceeds(*m_audioProvider, Initiator::PRESS_AND_HOLD, 0));
|
|
|
|
ASSERT_TRUE(testStopCaptureSucceeds());
|
|
|
|
ASSERT_TRUE(testExpectSpeechSucceeds(WITH_DIALOG_REQUEST_ID));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that a focus change to @c FocusState::BACKGROUND causes the @c AudioInputProcessor to
|
|
|
|
/// release the channel and go back to @c State::IDLE.
|
|
|
|
TEST_F(AudioInputProcessorTest, focusChangedBackground) {
|
2017-06-23 23:26:34 +00:00
|
|
|
ASSERT_TRUE(testFocusChange(avsCommon::avs::FocusState::BACKGROUND));
|
2017-06-09 23:23:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// This function verifies that a focus change to @c FocusState::NONE causes the @c AudioInputProcessor to
|
|
|
|
/// release the channel and go back to @c State::IDLE.
|
|
|
|
TEST_F(AudioInputProcessorTest, focusChangedNone) {
|
2017-06-23 23:26:34 +00:00
|
|
|
ASSERT_TRUE(testFocusChange(avsCommon::avs::FocusState::NONE));
|
2017-05-18 05:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace test
|
|
|
|
} // namespace aip
|
2017-06-09 23:23:31 +00:00
|
|
|
} // namespace capabilityAgents
|
2017-05-18 05:02:48 +00:00
|
|
|
} // namespace alexaClientSDK
|