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

195 lines
5.5 KiB
C++
Raw Normal View History

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 2018 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 <AVSCommon/Utils/String/StringUtils.h>
namespace alexaClientSDK {
namespace avsCommon {
namespace utils {
namespace test {
using namespace alexaClientSDK::avsCommon::utils::string;
/**
* Verify that converting an empty string to an integer fails.
*/
TEST(StringUtilsTest, testEmptyStringFails) {
int result = 0;
ASSERT_FALSE(stringToInt("", &result));
}
/**
* Verify that converting a simple decimal integer string to integer succeeds.
*/
TEST(StringUtilsTest, testSimpleDecimalInteger) {
int result = 0;
ASSERT_TRUE(stringToInt("123", &result));
ASSERT_EQ(123, result);
}
/**
* Verify that converting a negative decimal integer string to integer succeeds.
*/
TEST(StringUtilsTest, testNegativeInt) {
int result = 0;
ASSERT_TRUE(stringToInt("-987654", &result));
ASSERT_EQ(-987654, result);
}
/**
* Verify that converting a decimal integer string with leading whitespace to integer succeeds.
*/
TEST(StringUtilsTest, testInitialWhitespaceSucceeds) {
int result = 0;
ASSERT_TRUE(stringToInt("\t 10101", &result));
ASSERT_EQ(10101, result);
}
/**
* Verify that converting a decimal integer string with trailing whitespace to integer succeeds.
*/
TEST(StringUtilsTest, testTrailingWhitespaceSucceeds) {
int result = 0;
ASSERT_TRUE(stringToInt("982389\t ", &result));
ASSERT_EQ(982389, result);
}
/**
* Verify that converting a decimal integer string with leading and trailing whitespace to integer succeeds.
*/
TEST(StringUtilsTest, testLeadingAndTrailingWhitespaceSucceeds) {
int result = 0;
ASSERT_TRUE(stringToInt(" 982389 ", &result));
ASSERT_EQ(982389, result);
}
/**
* Verify that converting a decimal integer with leading non-whitespace and non-decimal digit characters fails.
*/
TEST(StringUtilsTest, testNonWhitespacePrefixFails) {
int result = 0;
ASSERT_FALSE(stringToInt("a123", &result));
}
/**
* Verify that converting a decimal integer with trailing non-whitespace and non-decimal digit characters fails.
*/
TEST(StringUtilsTest, testNonWhitespaceSuffixFails) {
int result = 0;
ASSERT_FALSE(stringToInt("123a", &result));
}
/**
* Verify that converting a decimal integer with leading and trailing non-whitespace and non-decimal digit
* characters fails.
*/
TEST(StringUtilsTest, testNonWhitespacePrefixAndSuffixFails) {
int result = 0;
ASSERT_FALSE(stringToInt("a123a", &result));
}
/**
* Verify that converting a decimal integer with both leading whitespace and non-whitespace characters fails.
*/
TEST(StringUtilsTest, testNonWhitespaceAndNonWhitespacePrefixFails) {
int result = 0;
ASSERT_FALSE(stringToInt(" e123", &result));
}
/**
* Verify that converting a decimal integer with both trailing whitespace and non-whitespace characters fails.
*/
TEST(StringUtilsTest, testNonWhitespaceAndNonWhitespaceSuffixFails) {
int result = 0;
ASSERT_FALSE(stringToInt("123e ", &result));
}
/**
* Verify that converting a decimal integer with leading and trailing whitespace and non-whitespace characters fails.
*/
TEST(StringUtilsTest, testNonWhitespaceAndNonWhitespacePrefixAndSuffixFails) {
int result = 0;
ASSERT_FALSE(stringToInt(" e123e ", &result));
}
/**
* Verify that converting "0" to integer succeeds.
*/
TEST(StringUtilsTest, testZeroSucceeds) {
int result = -1;
ASSERT_TRUE(stringToInt("0", &result));
ASSERT_EQ(0, result);
}
/**
* Verify that converting a floating string to integer fails.
*/
TEST(StringUtilsTest, testDecimalFloatFails) {
int result = 0;
ASSERT_FALSE(stringToInt("1.234", &result));
}
/**
* Verify that converting an octal integer string si interpreted as decmal with a leading zero.
*/
TEST(StringUtilsTest, testOctalInterpretedAsDecimal) {
int result = 0;
ASSERT_TRUE(stringToInt("0567", &result));
ASSERT_EQ(567, result);
}
/**
* Verify that converting a hex integer string to integer fails.
*/
TEST(StringUtilsTest, testHexIntFails) {
int result = 0;
ASSERT_FALSE(stringToInt("0x321", &result));
}
/**
* Verify that converting a too large integer string to int fails.
*/
TEST(StringUtilsTest, testTooLargeIntFails) {
int result = 0;
ASSERT_FALSE(stringToInt("987654321987654321987654321", &result));
}
/**
* Verify that converting a too small integer string to int fails.
*/
TEST(StringUtilsTest, testTooSmallIntFails) {
int result = 0;
ASSERT_FALSE(stringToInt("-11111111111111111111111111", &result));
}
/**
* Verify that converting a string with multiple numbers in it fails.
*/
TEST(StringUtilsTest, testMultipleNumbers) {
int result = 0;
ASSERT_FALSE(stringToInt("123 123", &result));
ASSERT_FALSE(stringToInt(" 123 123", &result));
ASSERT_FALSE(stringToInt("123 123 ", &result));
ASSERT_FALSE(stringToInt(" 123 123 ", &result));
ASSERT_FALSE(stringToInt("1 2 3", &result));
}
} // namespace test
} // namespace utils
} // namespace avsCommon
} // namespace alexaClientSDK