2018-03-09 00:55:39 +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.
|
|
|
|
*/
|
|
|
|
|
Version 1.7.0 of the avs-device-sdk
Changes in this update:
**Enhancements**
* `AuthDelegate` and `AuthServer.py` have been replaced by `CBLAUthDelegate`, which provides a more straightforward path to authorization.
* Added a new configuration property called [`cblAuthDelegate`](https://github.com/alexa/avs-device-sdk/blob/master/Integration/AlexaClientSDKConfig.json#L2). This object specifies parameters for `CBLAuthDelegate`.
* Added a new configuration property called [`miscDatabase`](https://github.com/alexa/avs-device-sdk/blob/master/Integration/AlexaClientSDKConfig.json#L34), which is a generic key/value database to be used by various components.
* Added a new configuration property called [`dcfDelegate`](https://github.com/alexa/avs-device-sdk/blob/master/Integration/AlexaClientSDKConfig.json#L17) This object specifies parameters for `DCFDelegate`. Within this object, values were added for the 'endpoint' and `overridenDcfPublishMessageBody`. 'endpoint' is the endpoint to connect to in order to send device capabilities. `overridenDcfPublishMessageBody`is the message that will get sent out to the Capabilities API. Note: values within the `dcfDelegate` object will only work in `DEBUG` builds.
* Added a new configuration property called [`deviceInfo`](https://github.com/alexa/avs-device-sdk/blob/master/Integration/AlexaClientSDKConfig.json#L9) which specifies device-identifying information for use by the Device Capability Framework (DCF), and for authorization (CBLAuthDelegate).
* Updated the Directive Sequencer to support wildcard directive handlers. This allows a handler for a given AVS interface to register at the namespace level, rather than specifying the names of all directives within that namespace.
* Updated the Raspberry Pi installation script to include `alsasink` in the configuration file.
* Added `audioSink` as a configuration option. This allows users to override the audio sink element used in `Gstreamer`.
* Added an interface for monitoring internet connection status: `InternetConnectionMonitorInterface.h`.
* The Alexa Communications Library (ACL) is no longer required to wait until authorization has succeeded before attempting to connect to AVS. Instead, `HTTP2Transport` handles waiting for authorization to complete.
* Added the Device Capabilities Framework (DCF) delegate. Device capabilities can now be sent for each capability interface using DCF publish messages.
* The sample app has been updated to send DCF publish messages, which will automatically occur when the sample app starts. Note: a DCF publish message must be successfully sent in order for communication with AVS to occur.
* The SDK now supports HTTP PUT messages.
* Added support for opt-arg style arguments and multiple configuration files. Now, the sample app can be invoked by either of these commands: `SampleApp <configfile> <debuglevel>` OR `SampleApp -C file1 -C file2 ... -L loglevel`.
**Bug Fixes**
* Issues [447](https://github.com/alexa/avs-device-sdk/issues/447) and [553](https://github.com/alexa/avs-device-sdk/issues/553) Fixed the `AttachmentRenderSource`'s handling of `BLOCKING` `AttachmentReaders`.
* Updated the `Logger` implementation to be more resilient to `nullptr` string inputs.
* Fixed a `TimeUtils` utility-related compile issue.
* Fixed a bug in which alerts failed to activate if the system was restarted without network connection.
* Fixed Android 64-bit build failure issue.
**Known Issues**
* 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.
* Some ERROR messages may be printed during start-up event if initialization proceeds normally and successfully.
* If an unrecoverable authorization error or an unrecoverable DCF error is encountered, the sample app may crash on shutdown.
* If a non-CBL `clientId` is included in the `deviceInfo` section of `AlexaClientSDKConfig.json`, the error will be reported as an unrecoverable authorization error, rather than a more specific error.
2018-04-18 22:17:28 +00:00
|
|
|
#include <chrono>
|
2018-03-09 00:55:39 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include <AVSCommon/Utils/File/FileUtils.h>
|
|
|
|
#include <SQLiteStorage/SQLiteDatabase.h>
|
|
|
|
|
|
|
|
namespace alexaClientSDK {
|
|
|
|
namespace storage {
|
|
|
|
namespace sqliteStorage {
|
|
|
|
namespace test {
|
|
|
|
|
|
|
|
/// Variable for storing the working directory. This is where all of the test databases will be created.
|
|
|
|
static std::string g_workingDirectory;
|
|
|
|
|
|
|
|
/// An example of a path that doesn't exist in a system.
|
|
|
|
static const std::string BAD_PATH =
|
|
|
|
"_/_/_/there/is/no/way/this/path/should/exist/,/so/it/should/cause/an/error/when/creating/the/db";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function that generates a unique filepath using the passed in g_workingDirectory.
|
|
|
|
*
|
|
|
|
* @return A unique filepath.
|
|
|
|
*/
|
|
|
|
static std::string generateDbFilePath() {
|
Version 1.7.0 of the avs-device-sdk
Changes in this update:
**Enhancements**
* `AuthDelegate` and `AuthServer.py` have been replaced by `CBLAUthDelegate`, which provides a more straightforward path to authorization.
* Added a new configuration property called [`cblAuthDelegate`](https://github.com/alexa/avs-device-sdk/blob/master/Integration/AlexaClientSDKConfig.json#L2). This object specifies parameters for `CBLAuthDelegate`.
* Added a new configuration property called [`miscDatabase`](https://github.com/alexa/avs-device-sdk/blob/master/Integration/AlexaClientSDKConfig.json#L34), which is a generic key/value database to be used by various components.
* Added a new configuration property called [`dcfDelegate`](https://github.com/alexa/avs-device-sdk/blob/master/Integration/AlexaClientSDKConfig.json#L17) This object specifies parameters for `DCFDelegate`. Within this object, values were added for the 'endpoint' and `overridenDcfPublishMessageBody`. 'endpoint' is the endpoint to connect to in order to send device capabilities. `overridenDcfPublishMessageBody`is the message that will get sent out to the Capabilities API. Note: values within the `dcfDelegate` object will only work in `DEBUG` builds.
* Added a new configuration property called [`deviceInfo`](https://github.com/alexa/avs-device-sdk/blob/master/Integration/AlexaClientSDKConfig.json#L9) which specifies device-identifying information for use by the Device Capability Framework (DCF), and for authorization (CBLAuthDelegate).
* Updated the Directive Sequencer to support wildcard directive handlers. This allows a handler for a given AVS interface to register at the namespace level, rather than specifying the names of all directives within that namespace.
* Updated the Raspberry Pi installation script to include `alsasink` in the configuration file.
* Added `audioSink` as a configuration option. This allows users to override the audio sink element used in `Gstreamer`.
* Added an interface for monitoring internet connection status: `InternetConnectionMonitorInterface.h`.
* The Alexa Communications Library (ACL) is no longer required to wait until authorization has succeeded before attempting to connect to AVS. Instead, `HTTP2Transport` handles waiting for authorization to complete.
* Added the Device Capabilities Framework (DCF) delegate. Device capabilities can now be sent for each capability interface using DCF publish messages.
* The sample app has been updated to send DCF publish messages, which will automatically occur when the sample app starts. Note: a DCF publish message must be successfully sent in order for communication with AVS to occur.
* The SDK now supports HTTP PUT messages.
* Added support for opt-arg style arguments and multiple configuration files. Now, the sample app can be invoked by either of these commands: `SampleApp <configfile> <debuglevel>` OR `SampleApp -C file1 -C file2 ... -L loglevel`.
**Bug Fixes**
* Issues [447](https://github.com/alexa/avs-device-sdk/issues/447) and [553](https://github.com/alexa/avs-device-sdk/issues/553) Fixed the `AttachmentRenderSource`'s handling of `BLOCKING` `AttachmentReaders`.
* Updated the `Logger` implementation to be more resilient to `nullptr` string inputs.
* Fixed a `TimeUtils` utility-related compile issue.
* Fixed a bug in which alerts failed to activate if the system was restarted without network connection.
* Fixed Android 64-bit build failure issue.
**Known Issues**
* 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.
* Some ERROR messages may be printed during start-up event if initialization proceeds normally and successfully.
* If an unrecoverable authorization error or an unrecoverable DCF error is encountered, the sample app may crash on shutdown.
* If a non-CBL `clientId` is included in the `deviceInfo` section of `AlexaClientSDKConfig.json`, the error will be reported as an unrecoverable authorization error, rather than a more specific error.
2018-04-18 22:17:28 +00:00
|
|
|
auto currentTime = std::chrono::high_resolution_clock::now();
|
|
|
|
auto nanosecond = static_cast<int64_t>(
|
|
|
|
std::chrono::duration_cast<std::chrono::nanoseconds>(currentTime.time_since_epoch()).count());
|
|
|
|
std::string filePath =
|
|
|
|
g_workingDirectory + "/SQLiteDatabaseTest-" + std::to_string(nanosecond) + std::to_string(rand());
|
2018-03-09 00:55:39 +00:00
|
|
|
EXPECT_FALSE(avsCommon::utils::file::fileExists(filePath));
|
|
|
|
return filePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Test to close DB then open it.
|
|
|
|
TEST(SQLiteDatabaseTest, CloseThenOpen) {
|
|
|
|
auto dbFilePath = generateDbFilePath();
|
|
|
|
SQLiteDatabase db(dbFilePath);
|
|
|
|
ASSERT_TRUE(db.initialize());
|
|
|
|
db.close();
|
|
|
|
ASSERT_TRUE(db.open());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Test to initialize already existing DB.
|
|
|
|
TEST(SQLiteDatabaseTest, InitializeAlreadyExisting) {
|
|
|
|
auto dbFilePath = generateDbFilePath();
|
|
|
|
SQLiteDatabase db1(dbFilePath);
|
|
|
|
ASSERT_TRUE(db1.initialize());
|
|
|
|
|
|
|
|
SQLiteDatabase db2(dbFilePath);
|
|
|
|
ASSERT_FALSE(db2.initialize());
|
|
|
|
|
|
|
|
db2.close();
|
|
|
|
db1.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Test to initialize a bad path.
|
|
|
|
TEST(SQLiteDatabaseTest, InitializeBadPath) {
|
|
|
|
SQLiteDatabase db(BAD_PATH);
|
|
|
|
ASSERT_FALSE(db.initialize());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Test to initialize a directory.
|
|
|
|
TEST(SQLiteDatabaseTest, InitializeOnDirectory) {
|
|
|
|
SQLiteDatabase db(g_workingDirectory);
|
|
|
|
ASSERT_FALSE(db.initialize());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Test to initialize DB twice.
|
|
|
|
TEST(SQLiteDatabaseTest, InitializeTwice) {
|
|
|
|
SQLiteDatabase db(generateDbFilePath());
|
|
|
|
|
|
|
|
ASSERT_TRUE(db.initialize());
|
|
|
|
ASSERT_FALSE(db.initialize());
|
|
|
|
db.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Test to open already existing DB.
|
|
|
|
TEST(SQLiteDatabaseTest, OpenAlreadyExisting) {
|
|
|
|
auto dbFilePath = generateDbFilePath();
|
|
|
|
SQLiteDatabase db1(dbFilePath);
|
|
|
|
ASSERT_TRUE(db1.initialize());
|
|
|
|
|
|
|
|
SQLiteDatabase db2(dbFilePath);
|
|
|
|
ASSERT_TRUE(db2.open());
|
|
|
|
|
|
|
|
db2.close();
|
|
|
|
db1.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Test to open a bad path.
|
|
|
|
TEST(SQLiteDatabaseTest, OpenBadPath) {
|
|
|
|
SQLiteDatabase db(BAD_PATH);
|
|
|
|
ASSERT_FALSE(db.open());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Test to open directory.
|
|
|
|
TEST(SQLiteDatabaseTest, OpenDirectory) {
|
|
|
|
SQLiteDatabase db(g_workingDirectory);
|
|
|
|
ASSERT_FALSE(db.open());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Test to open DB twice.
|
|
|
|
TEST(SQLiteDatabaseTest, OpenTwice) {
|
|
|
|
auto dbFilePath = generateDbFilePath();
|
|
|
|
SQLiteDatabase db1(dbFilePath);
|
|
|
|
ASSERT_TRUE(db1.initialize());
|
|
|
|
|
|
|
|
SQLiteDatabase db2(dbFilePath);
|
|
|
|
ASSERT_TRUE(db2.open());
|
|
|
|
ASSERT_FALSE(db2.open());
|
|
|
|
|
|
|
|
db2.close();
|
|
|
|
db1.close();
|
|
|
|
}
|
|
|
|
|
2018-07-09 21:07:31 +00:00
|
|
|
/// Test transactions commit
|
|
|
|
TEST(SQLiteDatabaseTest, TransactionsCommit) {
|
|
|
|
auto dbFilePath = generateDbFilePath();
|
|
|
|
SQLiteDatabase db(dbFilePath);
|
|
|
|
ASSERT_TRUE(db.initialize());
|
|
|
|
|
|
|
|
{
|
|
|
|
auto transaction1 = db.beginTransaction();
|
|
|
|
ASSERT_NE(transaction1, nullptr);
|
|
|
|
ASSERT_TRUE(transaction1->commit());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should not fail because previous transaction is completed
|
|
|
|
auto transaction2 = db.beginTransaction();
|
|
|
|
ASSERT_NE(transaction2, nullptr);
|
|
|
|
|
|
|
|
db.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test transactions rollback
|
|
|
|
TEST(SQLiteDatabaseTest, TransactionsRollback) {
|
|
|
|
auto dbFilePath = generateDbFilePath();
|
|
|
|
SQLiteDatabase db(dbFilePath);
|
|
|
|
ASSERT_TRUE(db.initialize());
|
|
|
|
|
|
|
|
{
|
|
|
|
auto transaction1 = db.beginTransaction();
|
|
|
|
ASSERT_NE(transaction1, nullptr);
|
|
|
|
ASSERT_TRUE(transaction1->rollback());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should not fail because previous transaction is completed
|
|
|
|
auto transaction2 = db.beginTransaction();
|
|
|
|
ASSERT_NE(transaction2, nullptr);
|
|
|
|
|
|
|
|
db.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Test nested transactions
|
|
|
|
TEST(SQLiteDatabaseTest, NestedTransactions) {
|
|
|
|
auto dbFilePath = generateDbFilePath();
|
|
|
|
SQLiteDatabase db(dbFilePath);
|
|
|
|
ASSERT_TRUE(db.initialize());
|
|
|
|
|
|
|
|
auto transaction1 = db.beginTransaction();
|
|
|
|
ASSERT_NE(transaction1, nullptr);
|
|
|
|
auto transaction2 = db.beginTransaction();
|
|
|
|
ASSERT_EQ(transaction2, nullptr);
|
|
|
|
|
|
|
|
db.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Test transactions double commit
|
|
|
|
TEST(SQLiteDatabaseTest, DoubleCommit) {
|
|
|
|
auto dbFilePath = generateDbFilePath();
|
|
|
|
SQLiteDatabase db(dbFilePath);
|
|
|
|
ASSERT_TRUE(db.initialize());
|
|
|
|
|
|
|
|
auto transaction1 = db.beginTransaction();
|
|
|
|
ASSERT_NE(transaction1, nullptr);
|
|
|
|
ASSERT_TRUE(transaction1->commit());
|
|
|
|
ASSERT_FALSE(transaction1->commit());
|
|
|
|
|
|
|
|
db.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Test automatic rollback
|
|
|
|
TEST(SQLiteDatabaseTest, AutoRollback) {
|
|
|
|
auto dbFilePath = generateDbFilePath();
|
|
|
|
SQLiteDatabase db(dbFilePath);
|
|
|
|
ASSERT_TRUE(db.initialize());
|
|
|
|
|
|
|
|
{
|
|
|
|
auto transaction1 = db.beginTransaction();
|
|
|
|
ASSERT_NE(transaction1, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should not fail because transaction should have been automatically completed
|
|
|
|
auto transaction2 = db.beginTransaction();
|
|
|
|
ASSERT_NE(transaction2, nullptr);
|
|
|
|
|
|
|
|
db.close();
|
|
|
|
}
|
|
|
|
|
2018-03-09 00:55:39 +00:00
|
|
|
} // namespace test
|
|
|
|
} // namespace sqliteStorage
|
|
|
|
} // namespace storage
|
|
|
|
} // namespace alexaClientSDK
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
std::cerr << "Usage: " << std::string(argv[0]) << " <path to folder for test>" << std::endl;
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
alexaClientSDK::storage::sqliteStorage::test::g_workingDirectory = std::string(argv[1]);
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|
|
|
|
}
|