2017-03-10 00:01:46 +00:00
|
|
|
/*
|
2018-02-12 23:31:53 +00:00
|
|
|
* Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2017-03-10 00:01:46 +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.
|
|
|
|
*/
|
|
|
|
|
2017-12-09 00:07:37 +00:00
|
|
|
/// @file JSONUtilTest.cpp
|
2017-05-18 05:02:48 +00:00
|
|
|
|
2017-03-10 00:01:46 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <map>
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
#include <gtest/gtest.h>
|
2017-07-18 22:25:37 +00:00
|
|
|
#include <rapidjson/document.h>
|
2017-03-10 00:01:46 +00:00
|
|
|
|
2017-06-23 23:26:34 +00:00
|
|
|
#include "AVSCommon/AVS/AVSDirective.h"
|
|
|
|
#include "AVSCommon/Utils/JSON/JSONUtils.h"
|
2017-03-10 00:01:46 +00:00
|
|
|
|
|
|
|
namespace alexaClientSDK {
|
|
|
|
namespace avsCommon {
|
2017-06-23 23:26:34 +00:00
|
|
|
namespace utils {
|
|
|
|
namespace json {
|
2017-06-09 23:23:31 +00:00
|
|
|
namespace test {
|
2017-03-10 00:01:46 +00:00
|
|
|
|
|
|
|
using namespace ::testing;
|
|
|
|
using namespace alexaClientSDK::avsCommon;
|
2017-07-18 22:25:37 +00:00
|
|
|
using namespace rapidjson;
|
|
|
|
using namespace jsonUtils;
|
2017-03-10 00:01:46 +00:00
|
|
|
|
|
|
|
/// The header key in the JSON content of an AVS message.
|
|
|
|
static const std::string JSON_MESSAGE_HEADER_STRING = "header";
|
|
|
|
/// The namespace key in the JSON content of an AVS message.
|
|
|
|
static const std::string JSON_MESSAGE_NAMESPACE_STRING = "namespace";
|
|
|
|
/// The name key in the JSON content of an AVS message.
|
|
|
|
static const std::string JSON_MESSAGE_NAME_STRING = "name";
|
|
|
|
/// The messageId key in the JSON content of an AVS message.
|
|
|
|
static const std::string JSON_MESSAGE_ID_STRING = "messageId";
|
|
|
|
/// The dialogRequestId key in the JSON content of an AVS message.
|
|
|
|
static const std::string JSON_MESSAGE_DIALOG_REQUEST_ID_STRING = "dialogRequestId";
|
|
|
|
/// The payload key in the JSON content of an AVS message.
|
|
|
|
static const std::string JSON_MESSAGE_PAYLOAD_STRING = "payload";
|
|
|
|
|
|
|
|
/// The directive key in the JSON content of an AVS message
|
2017-10-30 22:14:38 +00:00
|
|
|
static const std::string DIRECTIVE_KEY = "directive";
|
2017-03-10 00:01:46 +00:00
|
|
|
/// The namespace in AVS message.
|
|
|
|
static const std::string NAMESPACE_TEST = "SpeechSynthesizer";
|
|
|
|
/// The name field in AVS message.
|
|
|
|
static const std::string NAME_TEST = "Speak";
|
|
|
|
/// The messageId in AVS message.
|
|
|
|
static const std::string MESSAGE_ID_TEST = "testMessageId";
|
|
|
|
/// The dialogRequestId in AVS message.
|
|
|
|
static const std::string DIALOG_REQUEST_ID_TEST = "dialogRequestIdTest";
|
|
|
|
/// The payload in AVS message.
|
|
|
|
static const std::string PAYLOAD_TEST = R"({"url":"cid:testCID","format":"testFormat","token":"testToken"})";
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
/// A random text to test the output value modification.
|
|
|
|
static const std::string OUTPUT_DEFAULT_TEXT_STRING = "defaultString";
|
|
|
|
/// A random integer to test the output value modification.
|
|
|
|
static const int OUTPUT_DEFAULT_INT_VALUE = 42;
|
|
|
|
/// Expected string value.
|
|
|
|
static const std::string EXPECTED_STRING_VALUE = "expectedValue";
|
|
|
|
/// Expected int value.
|
|
|
|
static const int EXPECTED_INT_VALUE = 123;
|
Version 1.11 alexa-client-sdk
Changes in this update:
**Enhancements**
* Added support for the new Alexa [DoNotDisturb](https://developer.amazon.com/docs/alexa-voice-service/donotdisturb.html) interface, which enables users to toggle the do not disturb (DND) function on their Alexa built-in products.
* The SDK now supports [Opus](https://opus-codec.org/license/) encoding, which is optional. To enable Opus, you must [set the CMake flag to `-DOPUS=ON`](https://github.com/alexa/avs-device-sdk/wiki/Build-Options#Opus-encoding), and include the [libopus library](https://github.com/alexa/avs-device-sdk/wiki/Dependencies#core-dependencies) dependency in your build.
* The MediaPlayer reference implementation has been expanded to support the SAMPLE-AES and AES-128 encryption methods for HLS streaming.
* AES-128 encryption is dependent on libcrypto, which is part of the required openSSL library, and is enabled by default.
* To enable [SAMPLE-AES](https://github.com/alexa/avs-device-sdk/wiki/Dependencies#core-dependencies/Enable-SAMPLE-AES-decryption) encryption, you must set the `-DSAMPLE_AES=ON` in your CMake command, and include the [FFMPEG](https://github.com/alexa/avs-device-sdk/wiki/Dependencies#core-dependencies/Enable-SAMPLE-AES-decryption) library dependency in your build.
* A new configuration for [deviceSettings](https://github.com/alexa/avs-device-sdk/blob/v1.11.0/Integration/AlexaClientSDKConfig.json#L59) has been added.This configuration allows you to specify the location of the device settings database.
* Added locale support for es-MX.
**Bug Fixes**
* Fixed an issue where music wouldn't resume playback in the Android app.
* Now all equalizer capabilities are fully disabled when equalizer is turned off in configuration file. Previously, devices were unconditionally required to provide support for equalizer in order to run the SDK.
* [Issue 1106](https://github.com/alexa/avs-device-sdk/issues/1106) - Fixed an issue in which the `CBLAuthDelegate` wasn't using the correct timeout during request refresh.
* [Issue 1128](https://github.com/alexa/avs-device-sdk/issues/1128) - Fixed an issue in which the `AudioPlayer` instance persisted at shutdown, due to a shared dependency with the `ProgressTimer`.
* Fixed in issue that occurred when a connection to streaming content was interrupted, the SDK did not attempt to resume the connection, and appeared to assume that the content had been fully downloaded. This triggered the next track to be played, assuming it was a playlist.
* [Issue 1040](https://github.com/alexa/avs-device-sdk/issues/1040) - Fixed an issue where alarms would continue to play after user barge-in.
**Known Issues**
* `PlaylistParser` and `IterativePlaylistParser` generate two HTTP requests (one to fetch the content type, and one to fetch the audio data) for each audio stream played.
* Music playback history isn't being displayed in the Alexa app for certain account and device types.
* On GCC 8+, issues related to `-Wclass-memaccess` will trigger warnings. However, this won't cause the build to fail, and these warnings can be ignored.
* In order to use Bluetooth source and sink PulseAudio, you must manually load and unload PulseAudio modules after the SDK starts.
* The `ACL` may encounter issues if audio attachments are received but not consumed.
* `SpeechSynthesizerState` currently uses `GAINING_FOCUS` and `LOSING_FOCUS` as a workaround for handling intermediate state. These states may be removed in a future release.
* The Alexa app doesn't always indicate when a device is successfully connected via Bluetooth.
* Connecting a product to streaming media via Bluetooth will sometimes stop media playback within the source application. Resuming playback through the source application or toggling next/previous will correct playback.
* When a source device is streaming silence via Bluetooth, the Alexa app indicates that audio content is streaming.
* The Bluetooth agent assumes that the Bluetooth adapter is always connected to a power source. Disconnecting from a power source during operation is not yet supported.
* On some products, interrupted Bluetooth playback may not resume if other content is locally streamed.
* `make integration` is currently not available for Android. In order to run integration tests on Android, you'll need to manually upload the test binary file along with any input file. At that point, the adb can be used to run the integration tests.
* On Raspberry Pi running Android Things with HDMI output audio, beginning of speech is truncated when Alexa responds to user TTS.
* When the sample app is restarted and network connection is lost, alerts don't play.
* When network connection is lost, lost connection status is not returned via local Text-to Speech (TTS).
2018-12-19 19:13:36 +00:00
|
|
|
/// Expected uint64_t value.
|
|
|
|
static const uint64_t EXPECTED_UNSIGNED_INT64_VALUE = UINT64_MAX;
|
2017-10-30 22:14:38 +00:00
|
|
|
/// Expected int value converted to a string.
|
|
|
|
static const std::string EXPECTED_INT_VALUE_STRINGIFIED = "123";
|
|
|
|
|
|
|
|
/// An invalid AVS directive JSON.``
|
|
|
|
static const std::string EMPTY_DIRECTIVE = R"({
|
2017-03-10 00:01:46 +00:00
|
|
|
"directive": {
|
|
|
|
}
|
|
|
|
})";
|
|
|
|
|
|
|
|
/// A sample AVS speak directive with all valid JSON keys.
|
2017-10-02 22:59:05 +00:00
|
|
|
// clang-format off
|
2017-03-10 00:01:46 +00:00
|
|
|
static const std::string SPEAK_DIRECTIVE = R"({
|
|
|
|
"directive": {
|
|
|
|
"header": {
|
|
|
|
"namespace":")" + NAMESPACE_TEST + R"(",
|
|
|
|
"name": ")" + NAME_TEST + R"(",
|
|
|
|
"messageId": ")" + MESSAGE_ID_TEST + R"(",
|
|
|
|
"dialogRequestId": ")" + DIALOG_REQUEST_ID_TEST + R"("
|
|
|
|
},
|
|
|
|
"payload": )" + PAYLOAD_TEST + R"(
|
|
|
|
}
|
|
|
|
})";
|
2017-10-02 22:59:05 +00:00
|
|
|
// clang-format on
|
2017-03-10 00:01:46 +00:00
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
/// The JSON key used in value reading tests.
|
|
|
|
static const std::string VALUE_KEY = "anInt64";
|
2017-05-18 05:02:48 +00:00
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
/// A JSON key *not* used in value reading tests.
|
|
|
|
static const std::string MISSING_KEY = "missingKey";
|
2017-07-18 22:25:37 +00:00
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
/// An invalid JSON string for testing.
|
|
|
|
static const std::string INVALID_JSON = "invalidTestJSON";
|
2017-12-09 00:07:37 +00:00
|
|
|
|
|
|
|
// clang-format off
|
2017-10-30 22:14:38 +00:00
|
|
|
/// A valid JSON string with scalar string value.
|
2017-12-09 00:07:37 +00:00
|
|
|
static const std::string VALID_JSON_STRING_VALUE = R"({")" + VALUE_KEY + R"(":")" + EXPECTED_STRING_VALUE + R"("})";
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
/// A valid JSON string with integer value.
|
2017-12-09 00:07:37 +00:00
|
|
|
static const std::string VALID_JSON_INTEGER_VALUE = R"({")"
|
|
|
|
+ VALUE_KEY + R"(":)" + EXPECTED_INT_VALUE_STRINGIFIED + R"(})";
|
|
|
|
|
|
|
|
// clang-format on
|
2017-07-18 22:25:37 +00:00
|
|
|
|
|
|
|
/// A double.
|
|
|
|
static const double A_DOUBLE = 1.0;
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
/// A bool used for construction of rapidjson::Value objects.
|
|
|
|
static const bool A_BOOL = false;
|
2017-03-10 00:01:46 +00:00
|
|
|
|
2017-07-18 22:25:37 +00:00
|
|
|
/// A valid string JSON Value.
|
|
|
|
static const std::string STRING_VALUE = "stringValue";
|
|
|
|
|
|
|
|
/// A valid empty string JSON Value.
|
2017-10-30 22:14:38 +00:00
|
|
|
static const std::string STRING_VALUE_EMPTY_JSON_OBJECT = "{}";
|
2017-07-18 22:25:37 +00:00
|
|
|
|
2017-03-10 00:01:46 +00:00
|
|
|
/// Define test fixture for testing AVSMessage.
|
2017-07-18 22:25:37 +00:00
|
|
|
class JSONUtilTest : public ::testing::Test {};
|
2017-03-10 00:01:46 +00:00
|
|
|
|
|
|
|
/**
|
2017-10-30 22:14:38 +00:00
|
|
|
* Tests retrieveValue(const std::string jsonString, const std::string& key, T* value)
|
|
|
|
* with T = std::string for getting child object as a string.
|
2017-03-10 00:01:46 +00:00
|
|
|
*/
|
2017-10-30 22:14:38 +00:00
|
|
|
TEST_F(JSONUtilTest, validJsonChildObjectAsString) {
|
2017-03-10 00:01:46 +00:00
|
|
|
std::string value;
|
2017-10-30 22:14:38 +00:00
|
|
|
ASSERT_TRUE(jsonUtils::retrieveValue(EMPTY_DIRECTIVE, DIRECTIVE_KEY, &value));
|
|
|
|
ASSERT_EQ(value, STRING_VALUE_EMPTY_JSON_OBJECT);
|
2017-03-10 00:01:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-30 22:14:38 +00:00
|
|
|
* Tests retrieveValue(const std::string jsonString, const std::string& key, T* value)
|
|
|
|
* with T = std::string for getting value of a scalar string.
|
2017-03-10 00:01:46 +00:00
|
|
|
*/
|
2017-10-30 22:14:38 +00:00
|
|
|
TEST_F(JSONUtilTest, validJsonScalarString) {
|
2017-03-10 00:01:46 +00:00
|
|
|
std::string value;
|
2017-10-30 22:14:38 +00:00
|
|
|
ASSERT_TRUE(jsonUtils::retrieveValue(VALID_JSON_STRING_VALUE, VALUE_KEY, &value));
|
|
|
|
ASSERT_EQ(value, EXPECTED_STRING_VALUE);
|
2017-03-10 00:01:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-30 22:14:38 +00:00
|
|
|
* Tests retrieveValue(const std::string jsonString, const std::string& key, T* value)
|
|
|
|
* with T = int64 for getting an integer value.
|
2017-03-10 00:01:46 +00:00
|
|
|
*/
|
2017-10-30 22:14:38 +00:00
|
|
|
TEST_F(JSONUtilTest, validJsonInteger) {
|
|
|
|
int64_t value = OUTPUT_DEFAULT_INT_VALUE;
|
|
|
|
ASSERT_TRUE(jsonUtils::retrieveValue(VALID_JSON_INTEGER_VALUE, VALUE_KEY, &value));
|
|
|
|
ASSERT_EQ(value, EXPECTED_INT_VALUE);
|
2017-03-10 00:01:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-30 22:14:38 +00:00
|
|
|
* Tests retrieveValue(const std::string jsonString, const std::string& key, T* value)
|
|
|
|
* with T = int64 and an invalid JSON. Returns false.
|
2017-03-10 00:01:46 +00:00
|
|
|
*/
|
2017-10-30 22:14:38 +00:00
|
|
|
TEST_F(JSONUtilTest, retrieveValueStringBasedInt64FromInvalidJSON) {
|
|
|
|
int64_t value = OUTPUT_DEFAULT_INT_VALUE;
|
|
|
|
ASSERT_FALSE(retrieveValue(INVALID_JSON, VALUE_KEY, &value));
|
|
|
|
ASSERT_EQ(value, OUTPUT_DEFAULT_INT_VALUE);
|
|
|
|
}
|
2017-03-10 00:01:46 +00:00
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
/**
|
|
|
|
* Tests retrieveValue(const std::string jsonString, const std::string& key, T* value)
|
|
|
|
* with T = std::string and an invalid JSON. Returns false.
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, retrieveValueStringBasedStringFromInvalidJSON) {
|
|
|
|
std::string value = OUTPUT_DEFAULT_TEXT_STRING;
|
|
|
|
ASSERT_FALSE(retrieveValue(INVALID_JSON, VALUE_KEY, &value));
|
|
|
|
ASSERT_EQ(value, OUTPUT_DEFAULT_TEXT_STRING);
|
|
|
|
}
|
2017-03-10 00:01:46 +00:00
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
/**
|
|
|
|
* Tests retrieveValue(const std::string jsonString, const std::string& key, T* value)
|
|
|
|
* with T = int64 and an incorrect key. Returns false.
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, retrieveValueStringBasedWithIncorrectKey) {
|
|
|
|
int64_t value = OUTPUT_DEFAULT_INT_VALUE;
|
|
|
|
ASSERT_FALSE(retrieveValue(VALID_JSON_INTEGER_VALUE, MISSING_KEY, &value));
|
|
|
|
ASSERT_EQ(value, OUTPUT_DEFAULT_INT_VALUE);
|
|
|
|
}
|
2017-03-10 00:01:46 +00:00
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
/**
|
|
|
|
* Tests retrieveValue(const std::string jsonString, const std::string& key, T* value)
|
|
|
|
* with T = int64 and a null output param. Returns false.
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, retrieveValueStringBasedWithNull) {
|
|
|
|
int64_t* value = nullptr;
|
|
|
|
ASSERT_FALSE(retrieveValue(VALID_JSON_INTEGER_VALUE, VALUE_KEY, value));
|
2017-03-10 00:01:46 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 05:02:48 +00:00
|
|
|
/**
|
2017-10-30 22:14:38 +00:00
|
|
|
* Tests retrieveValue(const rapidjson::Value& jsonNode, const std::string& key, T* value)
|
|
|
|
* with T = int64 and a value of invalid type. Returns false.
|
2017-05-18 05:02:48 +00:00
|
|
|
*/
|
2017-10-30 22:14:38 +00:00
|
|
|
TEST_F(JSONUtilTest, retrieveValueDocumentBasedWithInvalidValueType) {
|
|
|
|
Document doc;
|
|
|
|
doc.Parse(VALID_JSON_STRING_VALUE);
|
2017-05-18 05:02:48 +00:00
|
|
|
int64_t value;
|
2017-10-30 22:14:38 +00:00
|
|
|
ASSERT_FALSE(retrieveValue(doc, VALUE_KEY, &value));
|
2017-05-18 05:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-30 22:14:38 +00:00
|
|
|
* Tests retrieveValue(const rapidjson::Value& jsonNode, const std::string& key, T* value)
|
|
|
|
* with T = int64 and a null output param. Returns false.
|
2017-05-18 05:02:48 +00:00
|
|
|
*/
|
2017-10-30 22:14:38 +00:00
|
|
|
TEST_F(JSONUtilTest, retrieveValueDocumentBasedWithNull) {
|
|
|
|
Document doc;
|
|
|
|
doc.Parse(VALID_JSON_INTEGER_VALUE);
|
|
|
|
int64_t* value = nullptr;
|
|
|
|
ASSERT_FALSE(retrieveValue(doc, VALUE_KEY, value));
|
2017-05-18 05:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-30 22:14:38 +00:00
|
|
|
* Tests retrieveValue(const rapidjson::Value& jsonNode, const std::string& key, T* value)
|
|
|
|
* with T = int64 and a valid value. Returns true and obtains the correct value.
|
2017-05-18 05:02:48 +00:00
|
|
|
*/
|
2017-10-30 22:14:38 +00:00
|
|
|
TEST_F(JSONUtilTest, retrieveValueDocumentBasedWithValidInt64) {
|
|
|
|
Document doc;
|
|
|
|
doc.Parse(VALID_JSON_INTEGER_VALUE);
|
2017-05-18 05:02:48 +00:00
|
|
|
int64_t value;
|
2017-10-30 22:14:38 +00:00
|
|
|
ASSERT_TRUE(retrieveValue(doc, VALUE_KEY, &value));
|
|
|
|
ASSERT_EQ(value, EXPECTED_INT_VALUE);
|
2017-05-18 05:02:48 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 22:25:37 +00:00
|
|
|
/**
|
|
|
|
* Tests findNode with a Null output param. Returns false.
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, findNodeNull) {
|
|
|
|
Document doc;
|
|
|
|
doc.Parse(SPEAK_DIRECTIVE);
|
|
|
|
ASSERT_FALSE(findNode(doc, JSON_MESSAGE_HEADER_STRING, nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests findNode with a valid key. Returns true with iterator != MemberEnd().
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, findNodeKeyExists) {
|
|
|
|
Document doc;
|
|
|
|
doc.Parse(SPEAK_DIRECTIVE);
|
|
|
|
Value::ConstMemberIterator iterator;
|
2017-10-30 22:14:38 +00:00
|
|
|
ASSERT_TRUE(findNode(doc, DIRECTIVE_KEY, &iterator));
|
2017-07-18 22:25:37 +00:00
|
|
|
ASSERT_NE(iterator, doc.MemberEnd());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests findNode with a non-existent key. Returns false.
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, findNodeKeyMissing) {
|
|
|
|
Document doc;
|
|
|
|
doc.Parse(SPEAK_DIRECTIVE);
|
|
|
|
Value::ConstMemberIterator iterator;
|
|
|
|
ASSERT_FALSE(findNode(doc, MISSING_KEY, &iterator));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests parseJSON with a null output param. Returns false.
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, parseJSONNullOutputParam) {
|
|
|
|
ASSERT_FALSE(parseJSON(SPEAK_DIRECTIVE, nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests parseJSON with a valid json. Returns true.
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, parseJSONValidJSON) {
|
|
|
|
Document doc;
|
|
|
|
ASSERT_TRUE(parseJSON(SPEAK_DIRECTIVE, &doc));
|
|
|
|
ASSERT_FALSE(doc.HasParseError());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests parseJSON with an invalid json. Returns false.
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, parseJSONInvalidJSON) {
|
|
|
|
Document doc;
|
|
|
|
ASSERT_FALSE(parseJSON(INVALID_JSON, &doc));
|
|
|
|
ASSERT_TRUE(doc.HasParseError());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests convertToValue<std::string> with Value of rapidjson::Type::kStringType. Returns
|
|
|
|
* true and contains the correct value.
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, convertToStringValueWithString) {
|
|
|
|
rapidjson::Value expected;
|
|
|
|
expected.SetString(STRING_VALUE.c_str(), STRING_VALUE.length());
|
|
|
|
std::string actual;
|
|
|
|
ASSERT_TRUE(convertToValue(expected, &actual));
|
|
|
|
ASSERT_EQ(expected.GetString(), actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests convertToValue<std::string> with Value of rapidjson::Type::kObjectType.
|
|
|
|
* Returns true and contains the correct value.
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, convertToStringValueWithObject) {
|
|
|
|
rapidjson::Value emptyObject(kObjectType);
|
|
|
|
std::string actual;
|
|
|
|
ASSERT_TRUE(convertToValue(emptyObject, &actual));
|
2017-10-30 22:14:38 +00:00
|
|
|
ASSERT_EQ(STRING_VALUE_EMPTY_JSON_OBJECT, actual);
|
2017-07-18 22:25:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests convertToValue<std::string> with and invalid Value of rapidjson::Type::kNullType.
|
|
|
|
* Returns false.
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, convertToStringValueWithInvalidValue) {
|
|
|
|
rapidjson::Value nullValue(kNullType);
|
|
|
|
std::string value;
|
|
|
|
ASSERT_FALSE(convertToValue(nullValue, &value));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests convertToValue<std::string> with null output param.
|
|
|
|
* Returns false.
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, convertToStringValueWithNullOutputParam) {
|
|
|
|
rapidjson::Value node;
|
|
|
|
node.SetString(STRING_VALUE.c_str(), STRING_VALUE.length());
|
|
|
|
std::string* value = nullptr;
|
|
|
|
ASSERT_FALSE(convertToValue(node, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests convertToValue<int64_t> with valid int64_6. Returns true and contains the correct value.
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, convertToInt64ValueWithInt64) {
|
2017-10-30 22:14:38 +00:00
|
|
|
rapidjson::Value expected(EXPECTED_INT_VALUE);
|
2017-07-18 22:25:37 +00:00
|
|
|
int64_t actual;
|
|
|
|
ASSERT_TRUE(convertToValue(expected, &actual));
|
|
|
|
ASSERT_EQ(expected.GetInt64(), actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests convertToValue<int64_t> with double. Returns false.
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, convertToInt64ValueWithDouble) {
|
|
|
|
rapidjson::Value expected(A_DOUBLE);
|
|
|
|
int64_t actual;
|
|
|
|
ASSERT_FALSE(convertToValue(expected, &actual));
|
|
|
|
}
|
|
|
|
|
Version 1.11 alexa-client-sdk
Changes in this update:
**Enhancements**
* Added support for the new Alexa [DoNotDisturb](https://developer.amazon.com/docs/alexa-voice-service/donotdisturb.html) interface, which enables users to toggle the do not disturb (DND) function on their Alexa built-in products.
* The SDK now supports [Opus](https://opus-codec.org/license/) encoding, which is optional. To enable Opus, you must [set the CMake flag to `-DOPUS=ON`](https://github.com/alexa/avs-device-sdk/wiki/Build-Options#Opus-encoding), and include the [libopus library](https://github.com/alexa/avs-device-sdk/wiki/Dependencies#core-dependencies) dependency in your build.
* The MediaPlayer reference implementation has been expanded to support the SAMPLE-AES and AES-128 encryption methods for HLS streaming.
* AES-128 encryption is dependent on libcrypto, which is part of the required openSSL library, and is enabled by default.
* To enable [SAMPLE-AES](https://github.com/alexa/avs-device-sdk/wiki/Dependencies#core-dependencies/Enable-SAMPLE-AES-decryption) encryption, you must set the `-DSAMPLE_AES=ON` in your CMake command, and include the [FFMPEG](https://github.com/alexa/avs-device-sdk/wiki/Dependencies#core-dependencies/Enable-SAMPLE-AES-decryption) library dependency in your build.
* A new configuration for [deviceSettings](https://github.com/alexa/avs-device-sdk/blob/v1.11.0/Integration/AlexaClientSDKConfig.json#L59) has been added.This configuration allows you to specify the location of the device settings database.
* Added locale support for es-MX.
**Bug Fixes**
* Fixed an issue where music wouldn't resume playback in the Android app.
* Now all equalizer capabilities are fully disabled when equalizer is turned off in configuration file. Previously, devices were unconditionally required to provide support for equalizer in order to run the SDK.
* [Issue 1106](https://github.com/alexa/avs-device-sdk/issues/1106) - Fixed an issue in which the `CBLAuthDelegate` wasn't using the correct timeout during request refresh.
* [Issue 1128](https://github.com/alexa/avs-device-sdk/issues/1128) - Fixed an issue in which the `AudioPlayer` instance persisted at shutdown, due to a shared dependency with the `ProgressTimer`.
* Fixed in issue that occurred when a connection to streaming content was interrupted, the SDK did not attempt to resume the connection, and appeared to assume that the content had been fully downloaded. This triggered the next track to be played, assuming it was a playlist.
* [Issue 1040](https://github.com/alexa/avs-device-sdk/issues/1040) - Fixed an issue where alarms would continue to play after user barge-in.
**Known Issues**
* `PlaylistParser` and `IterativePlaylistParser` generate two HTTP requests (one to fetch the content type, and one to fetch the audio data) for each audio stream played.
* Music playback history isn't being displayed in the Alexa app for certain account and device types.
* On GCC 8+, issues related to `-Wclass-memaccess` will trigger warnings. However, this won't cause the build to fail, and these warnings can be ignored.
* In order to use Bluetooth source and sink PulseAudio, you must manually load and unload PulseAudio modules after the SDK starts.
* The `ACL` may encounter issues if audio attachments are received but not consumed.
* `SpeechSynthesizerState` currently uses `GAINING_FOCUS` and `LOSING_FOCUS` as a workaround for handling intermediate state. These states may be removed in a future release.
* The Alexa app doesn't always indicate when a device is successfully connected via Bluetooth.
* Connecting a product to streaming media via Bluetooth will sometimes stop media playback within the source application. Resuming playback through the source application or toggling next/previous will correct playback.
* When a source device is streaming silence via Bluetooth, the Alexa app indicates that audio content is streaming.
* The Bluetooth agent assumes that the Bluetooth adapter is always connected to a power source. Disconnecting from a power source during operation is not yet supported.
* On some products, interrupted Bluetooth playback may not resume if other content is locally streamed.
* `make integration` is currently not available for Android. In order to run integration tests on Android, you'll need to manually upload the test binary file along with any input file. At that point, the adb can be used to run the integration tests.
* On Raspberry Pi running Android Things with HDMI output audio, beginning of speech is truncated when Alexa responds to user TTS.
* When the sample app is restarted and network connection is lost, alerts don't play.
* When network connection is lost, lost connection status is not returned via local Text-to Speech (TTS).
2018-12-19 19:13:36 +00:00
|
|
|
/**
|
|
|
|
* Tests convertToValue<uint64_t> with null output param.
|
|
|
|
* Returns false.
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, convertToUint64ValueWithNullOutputParam) {
|
|
|
|
rapidjson::Value node(EXPECTED_UNSIGNED_INT64_VALUE);
|
|
|
|
uint64_t* value = nullptr;
|
|
|
|
ASSERT_FALSE(convertToValue(node, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests convertToValue<uint64_t> with valid uint64_t. Returns true and contains the correct value.
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, convertToUint64ValueWithUint64) {
|
|
|
|
rapidjson::Value expected(EXPECTED_UNSIGNED_INT64_VALUE);
|
|
|
|
uint64_t actual;
|
|
|
|
ASSERT_TRUE(convertToValue(expected, &actual));
|
|
|
|
ASSERT_EQ(expected.GetUint64(), actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests convertToValue<uint64_t> with double. Returns false.
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, convertToUint64ValueWithDouble) {
|
|
|
|
rapidjson::Value expected(A_DOUBLE);
|
|
|
|
uint64_t actual;
|
|
|
|
ASSERT_FALSE(convertToValue(expected, &actual));
|
|
|
|
}
|
|
|
|
|
2017-07-18 22:25:37 +00:00
|
|
|
/**
|
|
|
|
* Tests convertToValue<int64_t> with null output param.
|
|
|
|
* Returns false.
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, convertToInt64ValueWithNullOutputParam) {
|
2017-10-30 22:14:38 +00:00
|
|
|
rapidjson::Value node(EXPECTED_INT_VALUE);
|
2017-07-18 22:25:37 +00:00
|
|
|
int64_t* value = nullptr;
|
|
|
|
ASSERT_FALSE(convertToValue(node, value));
|
|
|
|
}
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
/**
|
|
|
|
* Tests convertToValue<bool> with null output param.
|
|
|
|
* Returns false.
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, convertToBoolValueWithNullOutputParam) {
|
|
|
|
rapidjson::Value node(A_BOOL);
|
|
|
|
bool* value = nullptr;
|
|
|
|
ASSERT_FALSE(convertToValue(node, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests convertToValue<bool> with a nonbool. Returns false.
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, convertToBoolValueWithNonBool) {
|
|
|
|
rapidjson::Value expected(A_DOUBLE);
|
|
|
|
bool actual;
|
|
|
|
ASSERT_FALSE(convertToValue(expected, &actual));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests convertToValue<bool> with valid bool. Returns true and contains the correct value.
|
|
|
|
*/
|
|
|
|
TEST_F(JSONUtilTest, convertToBoolValueWithBool) {
|
|
|
|
rapidjson::Value expected(A_BOOL);
|
|
|
|
bool actual;
|
|
|
|
ASSERT_TRUE(convertToValue(expected, &actual));
|
|
|
|
ASSERT_EQ(expected.GetBool(), actual);
|
|
|
|
}
|
|
|
|
|
2017-10-02 22:59:05 +00:00
|
|
|
} // namespace test
|
|
|
|
} // namespace json
|
|
|
|
} // namespace utils
|
|
|
|
} // namespace avsCommon
|
|
|
|
} // namespace alexaClientSDK
|