avs-device-sdk/MediaPlayer/test/NormalizerTest.cpp

132 lines
3.4 KiB
C++
Raw Normal View History

Version 1.2.0 alexa-client-sdk Changes in this update * **Enhancements** * Updated MediaPlayer to solve stability issues * All capability agents were refined to work with the updated MediaPlayer * Added the TemplateRuntime capability agent * Added the SpeakerManager capability agent * Added a configuration option ("sampleApp":"endpoint") that allows the endpoint that SampleApp connects to to be specified without changing code or rebuilding * Added very verbose capture of libcurl debug information * Added an observer interface to observer audio state changes from AudioPlayer * Added support for StreamMetadataExtracted Event. Stream tags found in the stream are represented in JSON and sent to AVS * Added to the SampleApp a simple GuiRenderer as an observer to the TemplateRuntime Capability Agent * Moved shared libcurl functionality to AVSCommon/Utils * Added a CMake option to exclude tests from the "make all" build. Use "cmake <absolute-path-to-source> -DACSDK_EXCLUDE_TEST_FROM_ALL=ON" to enable it. When this option is enabled "make unit" and "make integration" still could be used to build and run the tests * **Bug fixes**: * Previously scheduled alerts now play following a restart * General stability fixes * Bug fix for CertifiedSender blocking forever if the network goes down while it's trying to send a message to AVS * Fixes for known issue of Alerts integration tests fail: AlertsTest.UserLongUnrelatedBargeInOnActiveTimer and AlertsTest.handleOneTimerWithVocalStop * Attempting to end a tap-to-talk interaction with the tap-to-talk button wouldn't work * SharedDataStream could encounter a race condition due to a combination of a blocking Reader and a Writer closing before writing any data * Bug-fix for the ordering of notifications within alerts scheduling. This fixes the issue where a local-stop on an alert would also stop a subsequent alert if it were to begin without delay * **Known Issues** * Capability agent for Notifications is not included in this release * Inconsistent playback behavior when resuming content ("Alexa, pause." / "Alexa, resume."). Specifically, handling playback offsets, which causes the content to play from the start. This behavior is also occasionally seen with "Next" / "Previous". * `ACL`'s asynchronous receipt of audio attachments may manage resources poorly in scenarios where attachments are received but not consumed.
2017-10-30 22:14:38 +00:00
/*
* NormalizerTest.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 <gmock/gmock.h>
#include <gtest/gtest.h>
#include "MediaPlayer/Normalizer.h"
namespace alexaClientSDK {
namespace mediaPlayer {
namespace test {
using namespace testing;
class NormalizerTest : public ::testing::Test {};
/**
* Test normalize with a nullptr.
*/
TEST_F(NormalizerTest, testNormalizeNullResult) {
ASSERT_FALSE(Normalizer::create(0, 1, 0, 1)->normalize(1, nullptr));
}
/**
* Test create with a source min larger than source max.
*/
TEST_F(NormalizerTest, testCreateSourceMinGreaterThanMax) {
ASSERT_EQ(Normalizer::create(100, 0, 0, 1), nullptr);
}
/**
* Test create with a source min equal to source max.
*/
TEST_F(NormalizerTest, testCreateSourceMinEqualToMax) {
ASSERT_EQ(Normalizer::create(0, 0, 0, 1), nullptr);
}
/**
* Test create with a normalized min larger than normalized max.
*/
TEST_F(NormalizerTest, testCreateNormalizeMinGreaterThanMax) {
ASSERT_EQ(Normalizer::create(0, 1, 100, 1), nullptr);
}
/**
* Test normalize with a normalized min equal to normalized max.
*/
TEST_F(NormalizerTest, testNormalizeNormalizedMinEqualToMax) {
double result;
ASSERT_TRUE(Normalizer::create(0, 10, 1, 1)->normalize(2, &result));
ASSERT_EQ(result, 1);
}
/**
* Test normalize with an input outside the source bounds.
*/
TEST_F(NormalizerTest, testNormalizeInputOutsideSourceBounds) {
double result;
ASSERT_FALSE(Normalizer::create(0, 1, 0, 1)->normalize(2, &result));
}
/**
* Test normalizing to the same range.
*/
TEST_F(NormalizerTest, testNormalizeSameScale) {
double result;
ASSERT_TRUE(Normalizer::create(0, 2, 0, 2)->normalize(1, &result));
ASSERT_EQ(result, 1);
}
/**
* Test normalizing to a smaller range.
*/
TEST_F(NormalizerTest, testNormalizeScaleDown) {
double result;
ASSERT_TRUE(Normalizer::create(0, 100, 0, 10)->normalize(50, &result));
ASSERT_EQ(result, 5);
}
/**
* Test normalizing to a larger range.
*/
TEST_F(NormalizerTest, testNormalizeScaleUp) {
double result;
ASSERT_TRUE(Normalizer::create(0, 10, 0, 100)->normalize(5, &result));
ASSERT_EQ(result, 50);
}
/**
* Test normalizing to a negative range.
*/
TEST_F(NormalizerTest, testNormalizeNegativeRange) {
double result;
ASSERT_TRUE(Normalizer::create(0, 10, -10, 0)->normalize(4, &result));
ASSERT_EQ(result, -6);
}
/**
* Test where source min != normalize min.
*/
TEST_F(NormalizerTest, testNormalizeDifferentMinimums) {
double result;
ASSERT_TRUE(Normalizer::create(1, 5, 0, 100)->normalize(2, &result));
ASSERT_EQ(result, 25);
}
/**
* Test where result is a non-integer.
*/
TEST_F(NormalizerTest, testNonInteger) {
double result;
ASSERT_TRUE(Normalizer::create(0, 2, 0, 3)->normalize(1, &result));
ASSERT_EQ(result, 1.5);
}
} // namespace test
} // namespace mediaPlayer
} // namespace alexaClientSDK