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

107 lines
4.3 KiB
C++
Raw Normal View History

/*
* RequiresShutdownTest.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 RequiresShutdownTest.cpp
#include <gtest/gtest.h>
#include "AVSCommon/Utils/RequiresShutdown.h"
namespace alexaClientSDK {
namespace avsCommon {
namespace utils {
namespace test {
/// Test class which implements RequiresShutdown
class Object : public alexaClientSDK::avsCommon::utils::RequiresShutdown {
public:
/**
* Constructor.
*
* @param name of object to log in any messages.
*/
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
Object(const std::string& name) : alexaClientSDK::avsCommon::utils::RequiresShutdown(name), properShutdown{true} {
}
/// Dummy shutdown function which doesn't do anything.
void doShutdown() override;
/// A shared_ptr which can be used to create loops.
std::shared_ptr<Object> object;
/// A flag indicating whether doShutdown should actually clean up object
bool properShutdown;
};
void Object::doShutdown() {
if (properShutdown) {
object.reset();
}
}
/**
* This test covers all cases for RequiresShutdown. It is written this way because the errors are detected when the
* program exits, so there is no benefit to breaking these out into separate test functions. Also note that there are
* no EXPECT/ASSERT calls here because there are no outputs from RequiresShutdown. Running this as a unit test
* verifies that we don't crash, but functional verification currently requires a manual examination of the console
* output from this test.
*/
TEST(RequiresShutdownTest, allTestCases) {
// shared_ptr loop that implements and calls proper shutdown functions
auto loopCallGoodShutdownMemberA = std::make_shared<Object>("loopCallGoodShutdownMemberA");
auto loopCallGoodShutdownMemberB = std::make_shared<Object>("loopCallGoodShutdownMemberB");
loopCallGoodShutdownMemberA->object = loopCallGoodShutdownMemberB;
loopCallGoodShutdownMemberB->object = loopCallGoodShutdownMemberA;
loopCallGoodShutdownMemberA->shutdown();
loopCallGoodShutdownMemberB->shutdown();
loopCallGoodShutdownMemberA.reset();
loopCallGoodShutdownMemberB.reset();
// shared_ptr loop that implements proper shutdown functions, but doesn't call them (and thus leaks)
auto loopNocallGoodShutdownMemberA = std::make_shared<Object>("loopNocallGoodShutdownMemberA");
auto loopNocallGoodShutdownMemberB = std::make_shared<Object>("loopNocallGoodShutdownMemberB");
loopNocallGoodShutdownMemberA->object = loopNocallGoodShutdownMemberB;
loopNocallGoodShutdownMemberB->object = loopNocallGoodShutdownMemberA;
loopNocallGoodShutdownMemberA.reset();
loopNocallGoodShutdownMemberB.reset();
// shared_ptr loop that implements and calls shutdown functions, but they don't break the loop (and thus leak)
auto loopCallBadShutdownMemberA = std::make_shared<Object>("loopCallBadShutdownMemberA");
auto loopCallBadShutdownMemberB = std::make_shared<Object>("loopCallBadShutdownMemberB");
loopCallBadShutdownMemberA->object = loopCallBadShutdownMemberB;
loopCallBadShutdownMemberB->object = loopCallBadShutdownMemberA;
loopCallBadShutdownMemberA->properShutdown = false;
loopCallBadShutdownMemberB->properShutdown = false;
loopCallBadShutdownMemberA->shutdown();
loopCallBadShutdownMemberB->shutdown();
loopCallBadShutdownMemberA.reset();
loopCallBadShutdownMemberB.reset();
// raw pointer leak that implements and calls proper shutdown function
auto rawPointerLeakCallShutdown = new Object("rawPointerLeakCallShutdown");
rawPointerLeakCallShutdown->shutdown();
// raw pointer leak that implements and calls proper shutdown function, but doesn't call it
auto rawPointerLeakNoCallShutdown = new Object("rawPointerLeakNoCallShutdown");
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
(void)rawPointerLeakNoCallShutdown;
}
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 utils
} // namespace avsCommon
} // namespace alexaClientSDK