avs-device-sdk/AVSCommon/Utils/test/StreambufTest.cpp

157 lines
4.4 KiB
C++
Raw Normal View History

v1.3.0 released 12/08/2017: **Enhancements** * ContextManager now passes the namespace/name of the desired state to StateProv iderInterface::provideState(). This is helpful when a single StateProvider obje ct provides multiple states, and needs to know which one ContextManager is askin g for. * The mime parser was hardened against duplicate boundaries. * Added functionality to add and remove AudioPlayer observers to the DefaultClie nt. * Unit tests for Alerts were added. * Added en-IN, en-CA and ja-JP to the SampleApp locale selection menu. * Added default alert and timer audio data to the SDK SampleApp. There is no lo nger a requirement to download these audio files and configure them in the json configuration file. * Added support in SDS Reader and AttachmentReader for seeking into the future. This allows a reader to move to an index which has not yet arrived in the SDS a nd poll/block until it arrives. * Added support for blocking Writers in the SharedDataStream class. * Changed the default status code sent by MessageRequestObserverInterface::onSen dCompleted() to SERVER_OTHER_ERROR, and mapped HTTP code 500 to SERVER_INTERNAL_ ERROR_V2. * Added support for parsing stream duration out of playlists. * Added a configuration option ("sampleApp":"displayCardsSupported") that allows the displaying of display cards to be enabled or disabled. * Named Timers and Reminders have been updated to fall back to the on-device bac kground audio sound when cloud urls cannot be accessed or rendered. **Bug Fixes** * Removed floating point dependencies from core SDK libraries. * Fixed bug in SpeechSynthesizer where it's erroneously calling stop more than once. * Fixed an issue in ContentFetcher where it could hang during destruction until an active GET request completed. * Fixed a couple of parsing bugs in LibCurlHttpContentFetcher related to case-sensitivity and mime-type handling. * Fixed a bug where MediaPlayerObserverInterface::onPlaybackResumed() wasn't being called after resuming from a pause with a pending play/resume. * Fixed a bug in LibCurlContentFetcher where it could error out if data is written to the SDS faster than it is consumed. * The GStreamer-based MediaPlayer reference implementation now uses the ACL HTTP configured client. * An API change has been made to MediaPlayerInterface::setSource(). This method now takes in an optional offset as well to allow for immediately streaming to the offset if possible. * Next and Previous buttons now work with Audible. * Pandora resume stuttering is addressed. * Pausing and resuming Amazon music no longer seeks back to the beginning of the song. * libcurl CURLOPT_NOSIGNAL option is set to 1 (https://curl.haxx.se/libcurl/c/CURLOPT_NOSIGNAL.html) to avoid crashes observed in SampleApp. * Fixed the timing of the PlaybackReportIntervalEvent and PlaybackReportDelayEvent as specified in the directives. * Fixed potential deadlocks in MediaPlayer during shutdown related to queued callbacks. * Fixed a crash in MediaPlayer that could occur if the network is disconnected during playback. * Fixed a bug where music could keep playing while Alexa is speaking. * Fixed a bug which was causing problems with pause/resume and next/previous with Amazon Music. * Fixed a bug where music could briefly start playing between speaks. * Fixed a bug where HLS playlists would stop streaming after the initial playlist had been played to completion. * Fixed a bug where Audible playback could not advance to the next chapter. * Fixed some occurrences of SDK entering the IDLE state during the transition between Listening and Speaking states. * Fixed a bug where PlaybackFinished events were not reporting the correct offset. * An API change has been made to MediaPlayerInterface::getOffset(). This method is now required to return the final offset when called after playback has stopped. * Fixed a problem where AIP was erroneously resetting its state upon getting a cancelDirective() callback. **Known Issues** * Capability agent for Notifications is not included in this release. * `ACL`'s asynchronous receipt of audio attachments may manage resources poorly in scenarios where attachments are received but not consumed. * GUI cards don't show for Kindle. * The new SpeechSynthesizerState state values GAINING_FOCUS and LOSING_FOCUS were added as part of a work-around. The will likely be removed in subsequent releases. * With the gstreamer-based MediaPlayer, after muting and unmuting, the next item starts playing rather than continuing with the current item.
2017-12-09 00:07:37 +00:00
/*
Version 1.5.0 alexa-client-sdk Changes in this update: **Enhancements** * Added the `ExternalMediaPlayer` Capability Agent. This allows playback from music providers that control their own playback queue. Example: Spotify. * Added support for AU and NZ to the `SampleApp`. * Firmware version can now be sent to Alexa via the `SoftwareInfo` event. The firmware version is specified in the config file under the `sampleApp` object as an integer value named [`firmwareVersion`](https://github.com/alexa/avs-device-sdk/blob/master/Integration/AlexaClientSDKConfig.json#L52). * The new `f` command was added to the `SampleApp` which allows the firmware version to be updated at run-time. * Optional configuration changes have been introduced. Now a [default log level](https://github.com/alexa/avs-device-sdk/blob/master/Integration/AlexaClientSDKConfig.json#L93) can be set for `ACSDK_LOG_MODULE` components, globally or individually. This value is specified under a new root level configuration object called `logger`, and the value itself is named `logLevel`. This allows you to limit the degree of logging to that default value, such as `ERROR`or `INFO`. **Bug Fixes** * Fixed bug where `AudioPlayer` progress reports were not being sent, or were being sent incorrectly. * [Issue 408](https://github.com/alexa/avs-device-sdk/issues/408) - Irrelevant code related to `UrlSource` was removed from the `GStreamer-based MediaPlayer` implementation. * The `TZ` variable no longer needs to be set to `UTC` when building the `SampleApp`. * Fixed a bug where `CurlEasyHandleWrapper` logged unwanted data on failure conditions. * Fixed a bug to improve `SIGPIPE` handling. * Fixed a bug where the filename and classname were mismatched. Changed `UrlToAttachmentConverter.h` to `UrlContentToAttachmentConverter.h`,and `UrlToAttachmentConverter.cpp` to `UrlContentToAttachmentConverter.cpp` **Known Issues** * The `ACL` may encounter issues if audio attachments are received but not consumed. * Display Cards for Kindle don't render. * If using the GStreamer-based `MediaPlayer` implementation, after muting and un-muting an audio item, the next item in the queue will begin playing rather than continuing playback of the originally muted audio item. * `SpeechSynthesizerState` currently uses `GAINING_FOCUS` and `LOSING_FOCUS` as a workaround for handling intermediate state. These states may be removed in a future release. * Music playback doesn't immediately stop when a user barges-in on iHeartRadio.
2018-02-12 23:31:53 +00:00
* Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
v1.3.0 released 12/08/2017: **Enhancements** * ContextManager now passes the namespace/name of the desired state to StateProv iderInterface::provideState(). This is helpful when a single StateProvider obje ct provides multiple states, and needs to know which one ContextManager is askin g for. * The mime parser was hardened against duplicate boundaries. * Added functionality to add and remove AudioPlayer observers to the DefaultClie nt. * Unit tests for Alerts were added. * Added en-IN, en-CA and ja-JP to the SampleApp locale selection menu. * Added default alert and timer audio data to the SDK SampleApp. There is no lo nger a requirement to download these audio files and configure them in the json configuration file. * Added support in SDS Reader and AttachmentReader for seeking into the future. This allows a reader to move to an index which has not yet arrived in the SDS a nd poll/block until it arrives. * Added support for blocking Writers in the SharedDataStream class. * Changed the default status code sent by MessageRequestObserverInterface::onSen dCompleted() to SERVER_OTHER_ERROR, and mapped HTTP code 500 to SERVER_INTERNAL_ ERROR_V2. * Added support for parsing stream duration out of playlists. * Added a configuration option ("sampleApp":"displayCardsSupported") that allows the displaying of display cards to be enabled or disabled. * Named Timers and Reminders have been updated to fall back to the on-device bac kground audio sound when cloud urls cannot be accessed or rendered. **Bug Fixes** * Removed floating point dependencies from core SDK libraries. * Fixed bug in SpeechSynthesizer where it's erroneously calling stop more than once. * Fixed an issue in ContentFetcher where it could hang during destruction until an active GET request completed. * Fixed a couple of parsing bugs in LibCurlHttpContentFetcher related to case-sensitivity and mime-type handling. * Fixed a bug where MediaPlayerObserverInterface::onPlaybackResumed() wasn't being called after resuming from a pause with a pending play/resume. * Fixed a bug in LibCurlContentFetcher where it could error out if data is written to the SDS faster than it is consumed. * The GStreamer-based MediaPlayer reference implementation now uses the ACL HTTP configured client. * An API change has been made to MediaPlayerInterface::setSource(). This method now takes in an optional offset as well to allow for immediately streaming to the offset if possible. * Next and Previous buttons now work with Audible. * Pandora resume stuttering is addressed. * Pausing and resuming Amazon music no longer seeks back to the beginning of the song. * libcurl CURLOPT_NOSIGNAL option is set to 1 (https://curl.haxx.se/libcurl/c/CURLOPT_NOSIGNAL.html) to avoid crashes observed in SampleApp. * Fixed the timing of the PlaybackReportIntervalEvent and PlaybackReportDelayEvent as specified in the directives. * Fixed potential deadlocks in MediaPlayer during shutdown related to queued callbacks. * Fixed a crash in MediaPlayer that could occur if the network is disconnected during playback. * Fixed a bug where music could keep playing while Alexa is speaking. * Fixed a bug which was causing problems with pause/resume and next/previous with Amazon Music. * Fixed a bug where music could briefly start playing between speaks. * Fixed a bug where HLS playlists would stop streaming after the initial playlist had been played to completion. * Fixed a bug where Audible playback could not advance to the next chapter. * Fixed some occurrences of SDK entering the IDLE state during the transition between Listening and Speaking states. * Fixed a bug where PlaybackFinished events were not reporting the correct offset. * An API change has been made to MediaPlayerInterface::getOffset(). This method is now required to return the final offset when called after playback has stopped. * Fixed a problem where AIP was erroneously resetting its state upon getting a cancelDirective() callback. **Known Issues** * Capability agent for Notifications is not included in this release. * `ACL`'s asynchronous receipt of audio attachments may manage resources poorly in scenarios where attachments are received but not consumed. * GUI cards don't show for Kindle. * The new SpeechSynthesizerState state values GAINING_FOCUS and LOSING_FOCUS were added as part of a work-around. The will likely be removed in subsequent releases. * With the gstreamer-based MediaPlayer, after muting and unmuting, the next item starts playing rather than continuing with the current item.
2017-12-09 00:07:37 +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 <gtest/gtest.h>
#include <AVSCommon/Utils/Stream/Streambuf.h>
namespace alexaClientSDK {
namespace avsCommon {
namespace utils {
namespace test {
static const std::vector<unsigned char> testData = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
class StreambufTest : public ::testing::Test {
public:
StreambufTest() : m_sb(testData.data(), testData.size()) {
}
protected:
stream::Streambuf m_sb;
};
/**
* Verify that the Streambuf is created correctly
*/
TEST_F(StreambufTest, Creation) {
ASSERT_EQ(testData[0], m_sb.sgetc());
}
/**
* Verify that the seekoff can be called based from the beginning
*/
TEST_F(StreambufTest, seekoffBeginning) {
const std::vector<std::streampos> positions = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
for (const auto& pos : positions) {
ASSERT_EQ(pos, m_sb.seekoff(pos, std::ios_base::beg));
ASSERT_EQ(testData[pos], m_sb.sgetc());
}
}
/**
* Verify that the seekoff can be called based from the current positon
*/
TEST_F(StreambufTest, seekoffCurrentForward) {
const std::streampos pos = 3;
ASSERT_EQ(pos, m_sb.seekoff(pos, std::ios_base::cur));
ASSERT_EQ(testData[pos], m_sb.sgetc());
ASSERT_EQ(2 * pos, m_sb.seekoff(pos, std::ios_base::cur));
ASSERT_EQ(testData[2 * pos], m_sb.sgetc());
}
/**
* Verify that you can seek all the way until the end correctly
*/
TEST_F(StreambufTest, seekoffFromBeginningUntilEnd) {
const std::streampos step = 1;
m_sb.seekoff(0, std::ios_base::beg);
for (size_t i = 0; i < testData.size() - 1; ++i) {
ASSERT_EQ(testData[i], m_sb.sgetc());
ASSERT_NE(-1, m_sb.seekoff(step, std::ios_base::cur));
}
ASSERT_EQ(testData[testData.size() - 1], m_sb.sgetc());
ASSERT_EQ(-1, m_sb.seekoff(step, std::ios_base::cur));
}
/**
* Verify that you can seek all the way from the end to the beginning
*/
TEST_F(StreambufTest, seekoffFromEndUntilBeginning) {
const std::streampos step = -1;
m_sb.seekoff(-1, std::ios_base::end);
for (size_t i = 0; i < testData.size() - 1; ++i) {
ASSERT_EQ(testData[testData.size() - i - 1], m_sb.sgetc());
ASSERT_NE(-1, m_sb.seekoff(step, std::ios_base::cur));
}
ASSERT_EQ(testData[0], m_sb.sgetc());
ASSERT_EQ(-1, m_sb.seekoff(step, std::ios_base::cur));
}
/**
* Verify that you can seek backward from the end
*/
TEST_F(StreambufTest, seekoffCurrentBackward) {
auto end = m_sb.seekoff(-1, std::ios_base::end);
const std::streampos pos = 3;
ASSERT_EQ(end - pos, m_sb.seekoff(-pos, std::ios_base::cur));
ASSERT_EQ(testData[end - pos], m_sb.sgetc());
ASSERT_EQ(end - (2 * pos), m_sb.seekoff(-pos, std::ios_base::cur));
ASSERT_EQ(testData[end - (2 * pos)], m_sb.sgetc());
}
/**
* Verify that a seek to before the stream results in an error
*/
TEST_F(StreambufTest, seekoffBeforeStart) {
ASSERT_EQ(-1, m_sb.seekoff(-1, std::ios_base::beg));
}
/**
* Verify that a seek to after the stream results in an error
*/
TEST_F(StreambufTest, seekoffPastEnd) {
ASSERT_EQ(-1, m_sb.seekoff(1, std::ios_base::end));
}
/**
* Verify that a basic seekpos works
*/
TEST_F(StreambufTest, seekpos) {
const std::streampos pos = 3;
ASSERT_EQ(pos, m_sb.seekpos(pos));
ASSERT_EQ(testData[pos], m_sb.sgetc());
}
/**
* Verify that a basic seekpos before the beginning results in an error
*/
TEST_F(StreambufTest, seekposBeforeStart) {
ASSERT_EQ(-1, m_sb.seekpos(-1));
}
/**
* Verify that a basic seekpos after the end results in an error
*/
TEST_F(StreambufTest, seekposAfterEnd) {
ASSERT_EQ(-1, m_sb.seekpos(sizeof(testData) + 1));
}
/**
* Verify that a seekpos to the end is correct
*/
TEST_F(StreambufTest, seekposToEnd) {
auto end = m_sb.seekoff(0, std::ios_base::end);
ASSERT_EQ(end, m_sb.seekpos(end));
}
} // namespace test
} // namespace utils
} // namespace avsCommon
} // namespace alexaClientSDK