avs-device-sdk/AVSCommon/AVS/test/Attachment/AttachmentTest.cpp

155 lines
4.7 KiB
C++
Raw Normal View History

/*
* AttachmentTest.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.
*/
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "AVSCommon/AVS/Attachment/InProcessAttachment.h"
#include "Common/Common.h"
using namespace ::testing;
using namespace alexaClientSDK::avsCommon::avs::attachment;
using namespace alexaClientSDK::avsCommon::utils::sds;
namespace alexaClientSDK {
namespace avsCommon {
namespace avs {
namespace test {
/**
* A class which helps drive this unit test suite.
*/
class AttachmentTest : public ::testing::Test {
public:
/**
* Construtor.
*/
AttachmentTest() : m_attachment{std::make_shared<InProcessAttachment>(TEST_ATTACHMENT_ID_STRING_ONE)} {
}
/**
* Utility function to test creating a reader with a parameterized policy.
*
* @param policy The policy for the reader to be created.
*/
void testCreateReader(AttachmentReader::Policy policy);
/// A local attachment object to simplify test code.
std::shared_ptr<InProcessAttachment> m_attachment;
};
void AttachmentTest::testCreateReader(AttachmentReader::Policy policy) {
// Test create reader where there is no writer.
auto reader = m_attachment->createReader(policy);
ASSERT_NE(reader, nullptr);
// Verify a second reader can't be created.
reader = m_attachment->createReader(policy);
ASSERT_EQ(reader, nullptr);
// Start with a fresh attachment - this time test where there is a writer
m_attachment = std::make_shared<InProcessAttachment>(TEST_ATTACHMENT_ID_STRING_ONE);
m_attachment->createWriter();
reader = m_attachment->createReader(policy);
ASSERT_NE(reader, nullptr);
// Verify a second reader can't be created.
reader = m_attachment->createReader(policy);
ASSERT_EQ(reader, nullptr);
}
/**
* Verify the ID is correctly stored and accessed from an Attachment.
*/
TEST_F(AttachmentTest, testGetAttachmentId) {
ASSERT_EQ(TEST_ATTACHMENT_ID_STRING_ONE, m_attachment->getId());
}
/**
* Verify that an Attachment can create a blocking reader in various scenarios.
*/
TEST_F(AttachmentTest, testAttachmentCreateBlockingReader) {
testCreateReader(AttachmentReader::Policy::BLOCKING);
}
/**
* Verify that an Attachment can create a non-blocking reader in various scenarios.
*/
TEST_F(AttachmentTest, testAttachmentCreateNonBlockingReader) {
testCreateReader(AttachmentReader::Policy::NON_BLOCKING);
}
/**
* Verify that an Attachment can create a writer in various scenarios.
*/
TEST_F(AttachmentTest, testAttachmentCreateWriter) {
// Test create writer where there is no reader.
auto writer = m_attachment->createWriter();
ASSERT_NE(writer, nullptr);
// Verify a second writer can't be created.
writer = m_attachment->createWriter();
ASSERT_EQ(writer, nullptr);
// Once again - this time test where there is a reader.
m_attachment = std::make_shared<InProcessAttachment>(TEST_ATTACHMENT_ID_STRING_ONE);
m_attachment->createReader(AttachmentReader::Policy::NON_BLOCKING);
writer = m_attachment->createWriter();
ASSERT_NE(writer, nullptr);
// Verify a second writer can't be created.
writer = m_attachment->createWriter();
ASSERT_EQ(writer, nullptr);
}
/**
* Test creating an Attachment with an existing SDS.
*/
TEST_F(AttachmentTest, testCreateAttachmentWithSDS) {
auto sds = createSDS(TEST_SDS_BUFFER_SIZE_IN_BYTES);
auto attachment = std::make_shared<InProcessAttachment>(TEST_ATTACHMENT_ID_STRING_ONE, std::move(sds));
// Test member functions, ensure they appear to work correctly.
ASSERT_EQ(TEST_ATTACHMENT_ID_STRING_ONE, attachment->getId());
auto reader = attachment->createReader(AttachmentReader::Policy::NON_BLOCKING);
ASSERT_NE(reader, nullptr);
auto writer = attachment->createWriter();
ASSERT_NE(writer, nullptr);
}
/**
* Verify an Attachment can't create multiple writers.
*/
TEST_F(AttachmentTest, testAttachmentCreateMultipleWriters) {
auto writer1 = m_attachment->createWriter();
auto writer2 = m_attachment->createWriter();
ASSERT_NE(writer1, nullptr);
ASSERT_EQ(writer2, nullptr);
}
Version 1.1.0 alexa-client-sdk - Changes in this update: - Better GStreamer error reporting. MediaPlayer used to only report `MEDIA_ERROR_UNKNOWN`, now reports more specific errors as defined in `ErrorType.h`. - Codebase has been formatted for easier reading. - `DirectiveRouter::removeDirectiveHandler()` signature changed and now returns a bool indicating if given handler should be successfully removed or not. - Cleanup of raw and shared pointers in the creation of `Transport` objects. - `HTTP2Stream`s now have IDs assigned as they are acquired as opposed to created, making associated logs easier to interpret. - `AlertsCapabilityAgent` has been refactored. - Alert management has been factored out into an `AlertScheduler` class. - Creation of Reminder (implements Alert) class. - Added new capability agent for `PlaybackController` with unit tests. - Added Settings interface with unit tests. - Return type of `getOffsetInMilliseconds()` changed from `int64_t` to `std::chronology::milliseconds`. - Added `AudioPlayer` unit tests. - Added teardown for all Integration tests except Alerts. - Implemented PlaylistParser. - Bug fixes: - AIP getting stuck in `LISTENING` or `THINKING` and refusing user input on network outage. - SampleApp crashing if running for 5 minutes after network disconnect. - Issue where on repeated user barge-ins, `AudioPlayer` would not pause. Specifically, the third attempt to “Play iHeartRadio” would not result in currently-playing music pausing. - Utterances being ignored after particularly long TTS. - GStreamer errors cropping up on SampleApp exit as a result of accessing the pipeline before it’s been setup. - Crashing when playing one URL after another. - Buffer overrun in Alerts Renderer. - [SampleApp crashing when issuing "Alexa skip" command with iHeartRadio.](https://github.com/alexa/avs-device-sdk/issues/153) - [`HTTP2Transport` network thread triggering a join on itself.](https://github.com/alexa/avs-device-sdk/issues/127) - [`HTTP2Stream` request handling truncating exception messages.](https://github.com/alexa/avs-device-sdk/issues/67) - [`AudioPlayer` was attempting an incorrect state transition from `STOPPED` to `PLAYING` through a `playbackResumed`.](https://github.com/alexa/avs-device-sdk/issues/138)
2017-10-02 22:59:05 +00:00
} // namespace test
} // namespace avs
} // namespace avsCommon
} // namespace alexaClientSDK