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:
committed by
GitHub
parent
107fad9a38
commit
0b35d27833
@@ -13,24 +13,25 @@
|
||||
#include <AzCore/UnitTest/TestTypes.h>
|
||||
#include <AzCore/Interface/Interface.h>
|
||||
#include <AzCore/Console/Console.h>
|
||||
|
||||
#include <AzCore/Settings/SettingsRegistryImpl.h>
|
||||
#include <AzCore/Utils/Utils.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
using namespace UnitTest;
|
||||
|
||||
AZ_CVAR(bool, testBool, false, nullptr, ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(char, testChar, 0, nullptr, ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(int8_t, testInt8, 0, nullptr, ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(int16_t, testInt16, 0, nullptr, ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(int32_t, testInt32, 0, nullptr, ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(int64_t, testInt64, 0, nullptr, ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(uint8_t, testUInt8, 0, nullptr, ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(bool, testBool, false, nullptr, ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(char, testChar, 0, nullptr, ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(int8_t, testInt8, 0, nullptr, ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(int16_t, testInt16, 0, nullptr, ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(int32_t, testInt32, 0, nullptr, ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(int64_t, testInt64, 0, nullptr, ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(uint8_t, testUInt8, 0, nullptr, ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(uint16_t, testUInt16, 0, nullptr, ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(uint32_t, testUInt32, 0, nullptr, ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(uint64_t, testUInt64, 0, nullptr, ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(float, testFloat, 0, nullptr, ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(double, testDouble, 0, nullptr, ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(float, testFloat, 0, nullptr, ConsoleFunctorFlags::Null, "");
|
||||
AZ_CVAR(double, testDouble, 0, nullptr, ConsoleFunctorFlags::Null, "");
|
||||
|
||||
AZ_CVAR(AZ::CVarFixedString, testString, "default", nullptr, ConsoleFunctorFlags::Null, "");
|
||||
|
||||
@@ -189,7 +190,7 @@ namespace AZ
|
||||
|
||||
TEST_F(ConsoleTests, CVar_GetSetTest_Vector2)
|
||||
{
|
||||
testVec2 = AZ::Vector2{ 0.0f, 0.0f};
|
||||
testVec2 = AZ::Vector2{ 0.0f, 0.0f };
|
||||
TestCVarHelper(testVec2, "testVec2", "testVec2 1 1", "testVec2 asdf", AZ::Vector2(100, 100), AZ::Vector2(0, 0), AZ::Vector2(1, 1));
|
||||
}
|
||||
|
||||
@@ -350,3 +351,245 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace ConsoleSettingsRegistryTests
|
||||
{
|
||||
//! ConfigFile MergeUtils Test
|
||||
struct ConfigFileParams
|
||||
{
|
||||
AZStd::string_view m_testConfigFileName;
|
||||
AZStd::string_view m_testConfigContents;
|
||||
};
|
||||
class ConsoleSettingsRegistryFixture
|
||||
: public UnitTest::ScopedAllocatorSetupFixture
|
||||
, public ::testing::WithParamInterface<ConfigFileParams>
|
||||
{
|
||||
public:
|
||||
void SetUp() override
|
||||
{
|
||||
m_registry = AZStd::make_unique<AZ::SettingsRegistryImpl>();
|
||||
// Store off the old global settings registry to restore after each test
|
||||
m_oldSettingsRegistry = AZ::SettingsRegistry::Get();
|
||||
if (m_oldSettingsRegistry != nullptr)
|
||||
{
|
||||
AZ::SettingsRegistry::Unregister(m_oldSettingsRegistry);
|
||||
}
|
||||
AZ::SettingsRegistry::Register(m_registry.get());
|
||||
|
||||
// Create a TestFile in the Test Directory
|
||||
m_testFolder = AZ::IO::FixedMaxPath(AZ::Utils::GetExecutableDirectory()) / "ConsoleTestFolder";
|
||||
auto configFileParams = GetParam();
|
||||
CreateTestFile(m_testFolder / configFileParams.m_testConfigFileName, configFileParams.m_testConfigContents);
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
// Remove the Test Directory
|
||||
DeleteFolderRecursive(m_testFolder);
|
||||
|
||||
// Restore the old global settings registry
|
||||
AZ::SettingsRegistry::Unregister(m_registry.get());
|
||||
if (m_oldSettingsRegistry != nullptr)
|
||||
{
|
||||
AZ::SettingsRegistry::Register(m_oldSettingsRegistry);
|
||||
m_oldSettingsRegistry = {};
|
||||
}
|
||||
m_registry.reset();
|
||||
}
|
||||
|
||||
void TestClassFunc(const AZ::ConsoleCommandContainer& someStrings)
|
||||
{
|
||||
m_stringArgCount = someStrings.size();
|
||||
}
|
||||
|
||||
AZ_CONSOLEFUNC(ConsoleSettingsRegistryFixture, TestClassFunc, AZ::ConsoleFunctorFlags::Null, "");
|
||||
|
||||
static void DeleteFolderRecursive(const AZ::IO::PathView& path)
|
||||
{
|
||||
auto callback = [&path](AZStd::string_view filename, bool isFile) -> bool
|
||||
{
|
||||
if (isFile)
|
||||
{
|
||||
auto filePath = AZ::IO::FixedMaxPath(path) / filename;
|
||||
AZ::IO::SystemFile::Delete(filePath.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (filename != "." && filename != "..")
|
||||
{
|
||||
auto folderPath = AZ::IO::FixedMaxPath(path) / filename;
|
||||
DeleteFolderRecursive(folderPath);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
auto searchPath = AZ::IO::FixedMaxPath(path) / "*";
|
||||
AZ::IO::SystemFile::FindFiles(searchPath.c_str(), callback);
|
||||
AZ::IO::SystemFile::DeleteDir(AZ::IO::FixedMaxPathString(path.Native()).c_str());
|
||||
}
|
||||
|
||||
static bool CreateTestFile(const AZ::IO::FixedMaxPath& testPath, AZStd::string_view content)
|
||||
{
|
||||
AZ::IO::SystemFile file;
|
||||
if (!file.Open(testPath.c_str(), AZ::IO::SystemFile::OpenMode::SF_OPEN_CREATE
|
||||
| AZ::IO::SystemFile::SF_OPEN_CREATE_PATH | AZ::IO::SystemFile::SF_OPEN_WRITE_ONLY))
|
||||
{
|
||||
AZ_Assert(false, "Unable to open test file for writing: %s", testPath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file.Write(content.data(), content.size()) != content.size())
|
||||
{
|
||||
AZ_Assert(false, "Unable to write content to test file: %s", testPath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
size_t m_stringArgCount{};
|
||||
AZStd::unique_ptr<AZ::SettingsRegistryInterface> m_registry;
|
||||
AZ::IO::FixedMaxPath m_testFolder;
|
||||
|
||||
private:
|
||||
AZ::SettingsRegistryInterface* m_oldSettingsRegistry{};
|
||||
};
|
||||
|
||||
static bool s_consoleFreeFunctionInvoked = false;
|
||||
static void TestSettingsRegistryFreeFunc(const AZ::ConsoleCommandContainer& someStrings)
|
||||
{
|
||||
EXPECT_TRUE(someStrings.empty());
|
||||
s_consoleFreeFunctionInvoked = true;
|
||||
}
|
||||
|
||||
AZ_CONSOLEFREEFUNC(TestSettingsRegistryFreeFunc, AZ::ConsoleFunctorFlags::Null, "");
|
||||
|
||||
TEST_P(ConsoleSettingsRegistryFixture, Console_AbleToLoadSettingsFile_Successfully)
|
||||
{
|
||||
AZ::Console testConsole(*m_registry);
|
||||
testConsole.LinkDeferredFunctors(AZ::ConsoleFunctorBase::GetDeferredHead());
|
||||
AZ::Interface<AZ::IConsole>::Register(&testConsole);
|
||||
AZ_CVAR_SCOPED(int32_t, testInit, 0, nullptr, AZ::ConsoleFunctorFlags::Null, "");
|
||||
s_consoleFreeFunctionInvoked = false;
|
||||
testInit = {};
|
||||
AZ::testChar = {};
|
||||
AZ::testBool = {};
|
||||
AZ::testInt8 = {};
|
||||
AZ::testInt16 = {};
|
||||
AZ::testInt32 = {};
|
||||
AZ::testInt64 = {};
|
||||
AZ::testUInt8 = {};
|
||||
AZ::testUInt16 = {};
|
||||
AZ::testUInt32 = {};
|
||||
AZ::testUInt64 = {};
|
||||
AZ::testFloat= {};
|
||||
AZ::testDouble = {};
|
||||
AZ::testString = {};
|
||||
|
||||
auto configFileParams = GetParam();
|
||||
auto testFilePath = m_testFolder / configFileParams.m_testConfigFileName;
|
||||
EXPECT_TRUE(AZ::IO::SystemFile::Exists(testFilePath.c_str()));
|
||||
testConsole.ExecuteConfigFile(testFilePath.Native());
|
||||
EXPECT_TRUE(s_consoleFreeFunctionInvoked);
|
||||
EXPECT_EQ(3, testInit);
|
||||
EXPECT_TRUE(static_cast<bool>(AZ::testBool));
|
||||
EXPECT_EQ('Q', AZ::testChar);
|
||||
EXPECT_EQ(24, AZ::testInt8);
|
||||
EXPECT_EQ(-32, AZ::testInt16);
|
||||
EXPECT_EQ(41, AZ::testInt32);
|
||||
EXPECT_EQ(-51, AZ::testInt64);
|
||||
EXPECT_EQ(3, AZ::testUInt8);
|
||||
EXPECT_EQ(5, AZ::testUInt16);
|
||||
EXPECT_EQ(6, AZ::testUInt32);
|
||||
EXPECT_EQ(0xFFFF'FFFF'FFFF'FFFF, AZ::testUInt64);
|
||||
EXPECT_FLOAT_EQ(1.0f, AZ::testFloat);
|
||||
EXPECT_DOUBLE_EQ(2, AZ::testDouble);
|
||||
EXPECT_STREQ("Stable", static_cast<AZ::CVarFixedString>(AZ::testString).c_str());
|
||||
EXPECT_EQ(3, m_stringArgCount);
|
||||
AZ::Interface<AZ::IConsole>::Unregister(&testConsole);
|
||||
}
|
||||
|
||||
|
||||
static constexpr AZStd::string_view UserINIStyleContent =
|
||||
R"(
|
||||
testInit = 3
|
||||
testBool true
|
||||
testChar Q
|
||||
testInt8 24
|
||||
testInt16 -32
|
||||
testInt32 41
|
||||
testInt64 -51
|
||||
testUInt8 3
|
||||
testUInt16 5
|
||||
testUInt32 6
|
||||
testUInt64 18446744073709551615
|
||||
testFloat 1.0
|
||||
testDouble 2
|
||||
testString Stable
|
||||
ConsoleSettingsRegistryFixture.testClassFunc Foo Bar Baz
|
||||
TestSettingsRegistryFreeFunc
|
||||
)";
|
||||
|
||||
static constexpr AZStd::string_view UserJsonMergePatchContent =
|
||||
R"(
|
||||
{
|
||||
"Amazon": {
|
||||
"AzCore": {
|
||||
"Runtime": {
|
||||
"ConsoleCommands": {
|
||||
"testInit": 3,
|
||||
"testBool": true,
|
||||
"testChar": "Q",
|
||||
"testInt8": 24,
|
||||
"testInt16": -32,
|
||||
"testInt32": 41,
|
||||
"testInt64": -51,
|
||||
"testUInt8": 3,
|
||||
"testUInt16": 5,
|
||||
"testUInt32": 6,
|
||||
"testUInt64": 18446744073709551615,
|
||||
"testFloat": 1.0,
|
||||
"testDouble": 2,
|
||||
"testString": "Stable",
|
||||
"ConsoleSettingsRegistryFixture.testClassFunc": "Foo Bar Baz",
|
||||
"TestSettingsRegistryFreeFunc": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)";
|
||||
static constexpr AZStd::string_view UserJsonPatchContent =
|
||||
R"(
|
||||
[
|
||||
{ "op": "add", "path": "/Amazon/AzCore/Runtime/ConsoleCommands/testInit", "value": 3 },
|
||||
{ "op": "add", "path": "/Amazon/AzCore/Runtime/ConsoleCommands/testBool", "value": true },
|
||||
{ "op": "add", "path": "/Amazon/AzCore/Runtime/ConsoleCommands/testChar", "value": "Q" },
|
||||
{ "op": "add", "path": "/Amazon/AzCore/Runtime/ConsoleCommands/testInt8", "value": 24 },
|
||||
{ "op": "add", "path": "/Amazon/AzCore/Runtime/ConsoleCommands/testInt16", "value": -32 },
|
||||
{ "op": "add", "path": "/Amazon/AzCore/Runtime/ConsoleCommands/testInt32", "value": 41 },
|
||||
{ "op": "add", "path": "/Amazon/AzCore/Runtime/ConsoleCommands/testInt64", "value": -51 },
|
||||
{ "op": "add", "path": "/Amazon/AzCore/Runtime/ConsoleCommands/testUInt8", "value": 3 },
|
||||
{ "op": "add", "path": "/Amazon/AzCore/Runtime/ConsoleCommands/testUInt16", "value": 5 },
|
||||
{ "op": "add", "path": "/Amazon/AzCore/Runtime/ConsoleCommands/testUInt32", "value": 6 },
|
||||
{ "op": "add", "path": "/Amazon/AzCore/Runtime/ConsoleCommands/testUInt64", "value": 18446744073709551615 },
|
||||
{ "op": "add", "path": "/Amazon/AzCore/Runtime/ConsoleCommands/testFloat", "value": 1.0 },
|
||||
{ "op": "add", "path": "/Amazon/AzCore/Runtime/ConsoleCommands/testDouble", "value": 2 },
|
||||
{ "op": "add", "path": "/Amazon/AzCore/Runtime/ConsoleCommands/testString", "value": "Stable" },
|
||||
{ "op": "add", "path": "/Amazon/AzCore/Runtime/ConsoleCommands/ConsoleSettingsRegistryFixture.testClassFunc", "value": "Foo Bar Baz" },
|
||||
{ "op": "add", "path": "/Amazon/AzCore/Runtime/ConsoleCommands/TestSettingsRegistryFreeFunc", "value": "" }
|
||||
]
|
||||
)";
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(
|
||||
ExecuteCommandFromSettingsFile,
|
||||
ConsoleSettingsRegistryFixture,
|
||||
::testing::Values(
|
||||
ConfigFileParams{"user.cfg", UserINIStyleContent},
|
||||
ConfigFileParams{"user.setreg", UserJsonMergePatchContent},
|
||||
ConfigFileParams{"user.setregpatch", UserJsonPatchContent}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace SettingsRegistryConsoleUtilsTests
|
||||
{
|
||||
constexpr const char* settingsKey = "/TestKey";
|
||||
constexpr const char* expectedValue = "TestValue";
|
||||
AZ::Console testConsole;
|
||||
AZ::Console testConsole(*m_registry);
|
||||
AZ::SettingsRegistryConsoleUtils::ConsoleFunctorHandle handle{
|
||||
AZ::SettingsRegistryConsoleUtils::RegisterAzConsoleCommands(*m_registry, testConsole) };
|
||||
EXPECT_TRUE(testConsole.PerformCommand(AZ::SettingsRegistryConsoleUtils::SettingsRegistrySet, { settingsKey, expectedValue }));
|
||||
@@ -69,7 +69,7 @@ namespace SettingsRegistryConsoleUtilsTests
|
||||
{
|
||||
constexpr const char* settingsKey = "/TestKey";
|
||||
constexpr const char* expectedValue = "TestValue";
|
||||
AZ::Console testConsole;
|
||||
AZ::Console testConsole(*m_registry);
|
||||
|
||||
// Scopes the console functor handle so that it destructs and unregisters the console functors
|
||||
{
|
||||
@@ -89,7 +89,7 @@ namespace SettingsRegistryConsoleUtilsTests
|
||||
constexpr const char* settingsKey2 = "/TestKey2";
|
||||
constexpr const char* expectedValue = R"(TestValue)";
|
||||
constexpr const char* expectedValue2 = R"(Hello World)";
|
||||
AZ::Console testConsole;
|
||||
AZ::Console testConsole(*m_registry);
|
||||
AZ::SettingsRegistryConsoleUtils::ConsoleFunctorHandle handle{
|
||||
AZ::SettingsRegistryConsoleUtils::RegisterAzConsoleCommands(*m_registry, testConsole) };
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace SettingsRegistryConsoleUtilsTests
|
||||
constexpr const char* settingsKey2 = "/TestKey2";
|
||||
constexpr const char* expectedValue = R"(TestValue)";
|
||||
constexpr const char* expectedValue2 = R"(Hello World)";
|
||||
AZ::Console testConsole;
|
||||
AZ::Console testConsole(*m_registry);
|
||||
|
||||
// Add settings to settings registry
|
||||
EXPECT_TRUE(m_registry->Set(settingsKey, expectedValue));
|
||||
@@ -137,7 +137,7 @@ namespace SettingsRegistryConsoleUtilsTests
|
||||
constexpr const char* settingsKey2 = "/TestKey2";
|
||||
constexpr const char* expectedValue = R"(TestValue)";
|
||||
constexpr const char* expectedValue2 = R"(Hello World)";
|
||||
AZ::Console testConsole;
|
||||
AZ::Console testConsole(*m_registry);
|
||||
|
||||
AZ::SettingsRegistryConsoleUtils::ConsoleFunctorHandle handle{
|
||||
AZ::SettingsRegistryConsoleUtils::RegisterAzConsoleCommands(*m_registry, testConsole) };
|
||||
@@ -195,7 +195,7 @@ namespace SettingsRegistryConsoleUtilsTests
|
||||
constexpr const char* SettingsKey2 = "TestKey2";
|
||||
constexpr const char* ExpectedValue = R"(TestValue)";
|
||||
constexpr const char* ExpectedValue2 = R"(Hello World)";
|
||||
AZ::Console testConsole;
|
||||
AZ::Console testConsole(*m_registry);
|
||||
|
||||
AZ::SettingsRegistryConsoleUtils::ConsoleFunctorHandle handle{
|
||||
AZ::SettingsRegistryConsoleUtils::RegisterAzConsoleCommands(*m_registry, testConsole) };
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user