Added support to the AZ Console to be notified when the Settings Registry modifies a particular path (#691)

* Updated the SettingsRegistry CommandLineArgumentSettings delimiter function to no longer work on a character basis, but on a line basis.
This provides more control by the user to determine how to the argument into the JSON pointer and JSON value parts

Added function o the Settings Registry to specify the JSON Apply Patch settings to use when performing a JSON Patch/Merge Patch operation

Fixed the SettingsRegistryImpl::CommandLineArgument function to properly set unsigned 64-bit values into the SettingsRegistry by checking the ERRNO of strtoll and strtoull

* Updated the reporting of the JSON Patching operations to supply a JSON pointer of the patched element to the Issue Reporting callback when the patch operation is successful. This allows using the Issue Reporting callback as a notification system when field is updated during a patch operation

* Added support to the AZ Console to be able to run Console Commands based
on notifications from the Settings Registry when a field underneath the
"/Amazon/AzCore/Runtime/ConsoleCommands" object is modified.

This takes advantage of the Settings Registry RegisterNotifier API to
determine when a field is modified as well as the JSON Merger
JsonApplyPatchSettings Issue Reporting Callback to determine when a
field is modified or updated.

As a Side Note also fixed an issue with the AZ Console incorrectly
converting unsigned 64-bit types using strtoll

* Making the Console constructor which accepts an AZ::SettingsRegistryInterface explicit

* Updating string format calls which use *.s for formatting string_views, to use the AZ_STRING_ARG macro

* Addressed typos in comments around the SettingsRegistry AZ Console functions

* Fixed the SettingsRegistryTest that look for an empty value

* clang 6.0.0 constexpr build fix. For some reason clang cannot make a constexpr AZStd::string_view out of a constexpr AZStd::fixed_string despite there being a valid constexpr operator AZStd::string_view

* Mac build fix

* SettingsRegistryTest.MergeSettingsFolder_ConflictingSpecializations_ReportsErrorAndReturnsFalse test fix on Mac

* Updated the LoadSettingsFile test to validate running a console with 0 arguments

Replace the static_cast in the ConsoleTypeHelpers.inl code to convert a str to long long with an aznumeric_cast

* Added printf logging to the ConsoleCommandKeyNotificationHandler to determine if the console commands are being performed on the Jenkins Linux node

* Fixed Dangling string_view reference in the ConsoleCommandKeyNotificationHandler that was causing command execution from a file to fail.

Renamed the second TestFreeFunc function in the ConsoleTests.cpp to validate thath the first TestFreeFunc function is being tested

* Updated the Component Application AZ Console to use the SettingsRegistry as the backend when loading config and Settings Rgistry json files
This commit is contained in:
lumberyard-employee-dm
2021-05-15 16:16:49 -05:00
committed by GitHub
parent 107fad9a38
commit 0b35d27833
17 changed files with 659 additions and 247 deletions
@@ -1228,27 +1228,33 @@ namespace SettingsRegistryTests
TEST_F(SettingsRegistryTest, MergeCommandLineArgument_KeyIsTooLong_ReturnsFalse)
{
AZStd::string argument = AZStd::string::format("Te%*cst=Value", aznumeric_cast<int>(AZ::SettingsRegistryImpl::MaxJsonPathLength), ' ');
constexpr int LongKeySize = 1024;
AZStd::string argument = AZStd::string::format("Te%*cst=Value", LongKeySize, ' ');
EXPECT_FALSE(m_registry->MergeCommandLineArgument(argument, {}, {}));
}
TEST_F(SettingsRegistryTest, MergeCommandLineArgument_KeyIsTooLongWithDivider_ReturnsFalse)
{
AZStd::string argument = AZStd::string::format("/Te%*cst=Value", aznumeric_cast<int>(AZ::SettingsRegistryImpl::MaxJsonPathLength), ' ');
constexpr int LongKeySize = 1024;
AZStd::string argument = AZStd::string::format("/Te%*cst=Value", LongKeySize, ' ');
EXPECT_FALSE(m_registry->MergeCommandLineArgument(argument, "/Path", {}));
}
TEST_F(SettingsRegistryTest, MergeCommandLineArgument_ValueIsTooLong_ReturnsFalse)
{
AZStd::string argument = AZStd::string::format("Test=Val%*cue", aznumeric_cast<int>(AZ::SettingsRegistryImpl::MaxCommandLineArgumentLength), ' ');
constexpr int LongValueSize = 1024;
AZStd::string argument = AZStd::string::format("Test=Val%*cue", LongValueSize, ' ');
EXPECT_FALSE(m_registry->MergeCommandLineArgument(argument, {}, {}));
EXPECT_EQ(AZ::SettingsRegistryInterface::Type::NoType, m_registry->GetType("/Test"));
}
TEST_F(SettingsRegistryTest, MergeCommandLineArgument_MissingValue_ReturnsFalse)
TEST_F(SettingsRegistryTest, MergeCommandLineArgument_MissingValue_ReturnsEmptyString)
{
EXPECT_FALSE(m_registry->MergeCommandLineArgument("Test=", {}, {}));
EXPECT_EQ(AZ::SettingsRegistryInterface::Type::NoType, m_registry->GetType("/Test"));
EXPECT_TRUE(m_registry->MergeCommandLineArgument("Test=", {}, {}));
EXPECT_EQ(AZ::SettingsRegistryInterface::Type::String, m_registry->GetType("/Test"));
AZ::SettingsRegistryInterface::FixedValueString value;
EXPECT_TRUE(m_registry->Get(value, "/Test"));
EXPECT_TRUE(value.empty());
}
TEST_F(SettingsRegistryTest, MergeCommandLineArgument_MissingKey_ReturnsFalse)
@@ -1271,9 +1277,13 @@ namespace SettingsRegistryTests
EXPECT_FALSE(m_registry->MergeCommandLineArgument(" =Value", {}, {}));
}
TEST_F(SettingsRegistryTest, MergeCommandLineArgument_ValueIsSpaces_ReturnsFalse)
TEST_F(SettingsRegistryTest, MergeCommandLineArgument_ValueIsSpaces_ReturnsEmptyString)
{
EXPECT_FALSE(m_registry->MergeCommandLineArgument("Key= ", {}, {}));
EXPECT_TRUE(m_registry->MergeCommandLineArgument("Key= ", {}, {}));
EXPECT_EQ(AZ::SettingsRegistryInterface::Type::String, m_registry->GetType("/Key"));
AZ::SettingsRegistryInterface::FixedValueString value;
EXPECT_TRUE(m_registry->Get(value, "/Key"));
EXPECT_TRUE(value.empty());
}
TEST_F(SettingsRegistryTest, MergeCommandLineArgument_KeyAndValueAreSpaces_ReturnsFalse)
@@ -1367,9 +1377,8 @@ namespace SettingsRegistryTests
TEST_F(SettingsRegistryTest, MergeSettingsFile_PathAsSubStringThatsTooLong_ReturnsFalse)
{
char path[AZ::SettingsRegistryImpl::MaxFilePathLength + 1];
memset(path, '1', sizeof(path));
AZStd::string_view subPath(path, AZ::SettingsRegistryImpl::MaxFilePathLength);
constexpr AZStd::fixed_string<AZ::IO::MaxPathLength + 1> path(AZ::IO::MaxPathLength + 1, '1');
const AZStd::string_view subPath(path);
AZ_TEST_START_TRACE_SUPPRESSION;
bool result = m_registry->MergeSettingsFile(subPath, AZ::SettingsRegistryInterface::Format::JsonMergePatch, {}, nullptr);
@@ -1719,8 +1728,7 @@ namespace SettingsRegistryTests
TEST_F(SettingsRegistryTest, MergeSettingsFolder_PathTooLong_ReportsErrorAndReturnsFalse)
{
char path[AZ::SettingsRegistryImpl::MaxFilePathLength + 1]{};
memset(path, 'a', AZ_ARRAY_SIZE(path));
constexpr AZStd::fixed_string<AZ::IO::MaxPathLength + 1> path(AZ::IO::MaxPathLength + 1, 'a');
AZ_TEST_START_TRACE_SUPPRESSION;
bool result = m_registry->MergeSettingsFolder(path, { "editor", "test" }, {}, nullptr);
@@ -1741,7 +1749,7 @@ namespace SettingsRegistryTests
m_testFolder->push_back(AZ_CORRECT_DATABASE_SEPARATOR);
*m_testFolder += AZ::SettingsRegistryInterface::RegistryFolder;
bool result = m_registry->MergeSettingsFolder(*m_testFolder, { "editor", "test" }, {}, nullptr);
AZ_TEST_STOP_TRACE_SUPPRESSION(2);
EXPECT_GT(::UnitTest::TestRunner::Instance().StopAssertTests(), 0);
EXPECT_FALSE(result);
EXPECT_EQ(AZ::SettingsRegistryInterface::Type::Object, m_registry->GetType(AZ_SETTINGS_REGISTRY_HISTORY_KEY "/0")); // Folder and specialization settings.
@@ -1751,11 +1759,5 @@ namespace SettingsRegistryTests
EXPECT_EQ(AZ::SettingsRegistryInterface::Type::String, m_registry->GetType(AZ_SETTINGS_REGISTRY_HISTORY_KEY "/1/Path"));
EXPECT_EQ(AZ::SettingsRegistryInterface::Type::String, m_registry->GetType(AZ_SETTINGS_REGISTRY_HISTORY_KEY "/1/File1"));
EXPECT_EQ(AZ::SettingsRegistryInterface::Type::String, m_registry->GetType(AZ_SETTINGS_REGISTRY_HISTORY_KEY "/1/File2"));
EXPECT_EQ(AZ::SettingsRegistryInterface::Type::Object, m_registry->GetType(AZ_SETTINGS_REGISTRY_HISTORY_KEY "/2"));
EXPECT_EQ(AZ::SettingsRegistryInterface::Type::String, m_registry->GetType(AZ_SETTINGS_REGISTRY_HISTORY_KEY "/2/Error"));
EXPECT_EQ(AZ::SettingsRegistryInterface::Type::String, m_registry->GetType(AZ_SETTINGS_REGISTRY_HISTORY_KEY "/2/Path"));
EXPECT_EQ(AZ::SettingsRegistryInterface::Type::String, m_registry->GetType(AZ_SETTINGS_REGISTRY_HISTORY_KEY "/2/File1"));
EXPECT_EQ(AZ::SettingsRegistryInterface::Type::String, m_registry->GetType(AZ_SETTINGS_REGISTRY_HISTORY_KEY "/2/File2"));
}
} // namespace SettingsRegistryTests