Merge pull request #3685 from aws-lumberyard-dev/cgalvan/UpdateProjectConfiguratorReferences
Updated remaining Project Configurator references to Project Manager and consolidated JsonUtils API usage.
This commit is contained in:
@@ -11,11 +11,12 @@
|
||||
|
||||
#include <AzCore/Component/Entity.h>
|
||||
#include <AzCore/IO/Path/Path.h>
|
||||
#include <AzCore/Serialization/Json/JsonUtils.h>
|
||||
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
|
||||
#include <AzCore/StringFunc/StringFunc.h>
|
||||
#include <AzCore/Utils/Utils.h>
|
||||
|
||||
#include <AzFramework/Asset/AssetSystemBus.h>
|
||||
#include <AzFramework/FileFunc/FileFunc.h>
|
||||
#include <AzToolsFramework/API/EditorAssetSystemAPI.h>
|
||||
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
|
||||
#include <AzToolsFramework/Prefab/PrefabDomUtils.h>
|
||||
@@ -134,7 +135,7 @@ namespace AzToolsFramework
|
||||
}
|
||||
|
||||
// Read Template's prefab file from disk and parse Prefab DOM from file.
|
||||
AZ::Outcome<PrefabDom, AZStd::string> readPrefabFileResult = AzFramework::FileFunc::ReadJsonFromString(fileContent);
|
||||
AZ::Outcome<PrefabDom, AZStd::string> readPrefabFileResult = AZ::JsonSerializationUtils::ReadJsonString(fileContent);
|
||||
if (!readPrefabFileResult.IsSuccess())
|
||||
{
|
||||
AZ_Error(
|
||||
@@ -346,7 +347,7 @@ namespace AzToolsFramework
|
||||
return false;
|
||||
}
|
||||
|
||||
auto outcome = AzFramework::FileFunc::WriteJsonFile(domAndFilepath->first, GetFullPath(domAndFilepath->second));
|
||||
auto outcome = AZ::JsonSerializationUtils::WriteJsonFile(domAndFilepath->first, GetFullPath(domAndFilepath->second).Native());
|
||||
if (!outcome.IsSuccess())
|
||||
{
|
||||
AZ_Error(
|
||||
@@ -387,7 +388,7 @@ namespace AzToolsFramework
|
||||
return false;
|
||||
}
|
||||
|
||||
auto outcome = AzFramework::FileFunc::WriteJsonFile(domAndFilepath->first, absolutePath);
|
||||
auto outcome = AZ::JsonSerializationUtils::WriteJsonFile(domAndFilepath->first, absolutePath.Native());
|
||||
if (!outcome.IsSuccess())
|
||||
{
|
||||
AZ_Error(
|
||||
@@ -410,7 +411,7 @@ namespace AzToolsFramework
|
||||
return false;
|
||||
}
|
||||
|
||||
auto outcome = AzFramework::FileFunc::WriteJsonToString(domAndFilepath->first, output);
|
||||
auto outcome = AZ::JsonSerializationUtils::WriteJsonString(domAndFilepath->first, output);
|
||||
if (!outcome.IsSuccess())
|
||||
{
|
||||
AZ_Error(
|
||||
|
||||
@@ -26,20 +26,6 @@
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
namespace AzFramework
|
||||
{
|
||||
namespace FileFunc
|
||||
{
|
||||
namespace Internal
|
||||
{
|
||||
AZ::Outcome<void,AZStd::string> UpdateCfgContents(AZStd::string& cfgContents, const AZStd::list<AZStd::string>& updateRules);
|
||||
AZ::Outcome<void,AZStd::string> UpdateCfgContents(AZStd::string& cfgContents, const AZStd::string& header, const AZStd::string& key, const AZStd::string& value);
|
||||
AZ::Outcome<void, AZStd::string> WriteJsonToStream(const rapidjson::Document& document, AZ::IO::GenericStream& stream,
|
||||
WriteJsonSettings settings = WriteJsonSettings{});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
class FileFuncTest : public ScopedAllocatorSetupFixture
|
||||
@@ -62,110 +48,6 @@ namespace UnitTest
|
||||
AZ::IO::FileIOBase* m_prevFileIO;
|
||||
};
|
||||
|
||||
TEST_F(FileFuncTest, UpdateCfgContents_InValidInput_Fail)
|
||||
{
|
||||
AZStd::string cfgContents = "[Foo]\n";
|
||||
AZStd::list<AZStd::string> updateRules;
|
||||
|
||||
updateRules.push_back(AZStd::string("Foo/one*1"));
|
||||
auto result = AzFramework::FileFunc::Internal::UpdateCfgContents(cfgContents, updateRules);
|
||||
ASSERT_FALSE(result.IsSuccess());
|
||||
}
|
||||
|
||||
TEST_F(FileFuncTest, UpdateCfgContents_ValidInput_Success)
|
||||
{
|
||||
AZStd::string cfgContents =
|
||||
"[Foo]\n"
|
||||
"one =2 \n"
|
||||
"two= 3\n"
|
||||
"three = 4\n"
|
||||
"\n"
|
||||
"[Bar]\n"
|
||||
"four=3\n"
|
||||
"five=3\n"
|
||||
"six=3\n"
|
||||
"eight=3\n";
|
||||
|
||||
AZStd::list<AZStd::string> updateRules;
|
||||
|
||||
updateRules.push_back(AZStd::string("Foo/one=1"));
|
||||
updateRules.push_back(AZStd::string("Foo/two=2"));
|
||||
updateRules.push_back(AZStd::string("three=3"));
|
||||
auto result = AzFramework::FileFunc::Internal::UpdateCfgContents(cfgContents, updateRules);
|
||||
EXPECT_TRUE(result.IsSuccess());
|
||||
|
||||
AZStd::string compareCfgContents =
|
||||
"[Foo]\n"
|
||||
"one =1\n"
|
||||
"two= 2\n"
|
||||
"three = 3\n"
|
||||
"\n"
|
||||
"[Bar]\n"
|
||||
"four=3\n"
|
||||
"five=3\n"
|
||||
"six=3\n"
|
||||
"eight=3\n";
|
||||
|
||||
bool equals = cfgContents.compare(compareCfgContents) == 0;
|
||||
ASSERT_TRUE(equals);
|
||||
}
|
||||
|
||||
TEST_F(FileFuncTest, UpdateCfgContents_ValidInputNewEntrySameHeader_Success)
|
||||
{
|
||||
AZStd::string cfgContents =
|
||||
"[Foo]\n"
|
||||
"one =2 \n"
|
||||
"two= 3\n"
|
||||
"three = 4\n";
|
||||
|
||||
AZStd::string header("[Foo]");
|
||||
AZStd::string key("four");
|
||||
AZStd::string value("4");
|
||||
auto result = AzFramework::FileFunc::Internal::UpdateCfgContents(cfgContents, header, key, value);
|
||||
EXPECT_TRUE(result.IsSuccess());
|
||||
|
||||
AZStd::string compareCfgContents =
|
||||
"[Foo]\n"
|
||||
"four=4\n"
|
||||
"one =2 \n"
|
||||
"two= 3\n"
|
||||
"three = 4\n";
|
||||
|
||||
bool equals = cfgContents.compare(compareCfgContents) == 0;
|
||||
ASSERT_TRUE(equals);
|
||||
}
|
||||
|
||||
TEST_F(FileFuncTest, UpdateCfgContents_ValidInputNewEntryDifferentHeader_Success)
|
||||
{
|
||||
AZStd::string cfgContents =
|
||||
";Sample Data\n"
|
||||
"[Foo]\n"
|
||||
"one =2 \n"
|
||||
"two= 3\n"
|
||||
"three = 4\n";
|
||||
|
||||
AZStd::list<AZStd::string> updateRules;
|
||||
|
||||
AZStd::string header("[Bar]");
|
||||
AZStd::string key("four");
|
||||
AZStd::string value("4");
|
||||
auto result = AzFramework::FileFunc::Internal::UpdateCfgContents(cfgContents, header, key, value);
|
||||
EXPECT_TRUE(result.IsSuccess());
|
||||
|
||||
AZStd::string compareCfgContents =
|
||||
";Sample Data\n"
|
||||
"[Foo]\n"
|
||||
"one =2 \n"
|
||||
"two= 3\n"
|
||||
"three = 4\n"
|
||||
"\n"
|
||||
"[Bar]\n"
|
||||
"four=4\n";
|
||||
|
||||
bool equals = cfgContents.compare(compareCfgContents) == 0;
|
||||
ASSERT_TRUE(equals);
|
||||
}
|
||||
|
||||
static bool CreateDummyFile(const QString& fullPathToFile, const QString& tempStr = {})
|
||||
{
|
||||
QFileInfo fi(fullPathToFile);
|
||||
@@ -268,213 +150,4 @@ namespace UnitTest
|
||||
ASSERT_NE(findElement, result.GetValue().end());
|
||||
}
|
||||
}
|
||||
|
||||
class JsonFileFuncTest
|
||||
: public FrameworkApplicationFixture
|
||||
{
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
FrameworkApplicationFixture::SetUp();
|
||||
|
||||
AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get();
|
||||
auto projectPathKey =
|
||||
AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path";
|
||||
registry->Set(projectPathKey, "AutomatedTesting");
|
||||
AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry);
|
||||
|
||||
m_serializeContext = AZStd::make_unique<AZ::SerializeContext>();
|
||||
m_jsonRegistrationContext = AZStd::make_unique<AZ::JsonRegistrationContext>();
|
||||
m_jsonSystemComponent = AZStd::make_unique<AZ::JsonSystemComponent>();
|
||||
|
||||
m_serializationSettings.m_serializeContext = m_serializeContext.get();
|
||||
m_serializationSettings.m_registrationContext = m_jsonRegistrationContext.get();
|
||||
|
||||
m_deserializationSettings.m_serializeContext = m_serializeContext.get();
|
||||
m_deserializationSettings.m_registrationContext = m_jsonRegistrationContext.get();
|
||||
|
||||
m_jsonSystemComponent->Reflect(m_jsonRegistrationContext.get());
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
m_jsonRegistrationContext->EnableRemoveReflection();
|
||||
m_jsonSystemComponent->Reflect(m_jsonRegistrationContext.get());
|
||||
m_jsonRegistrationContext->DisableRemoveReflection();
|
||||
|
||||
m_jsonRegistrationContext.reset();
|
||||
m_serializeContext.reset();
|
||||
m_jsonSystemComponent.reset();
|
||||
|
||||
FrameworkApplicationFixture::TearDown();
|
||||
}
|
||||
|
||||
AZStd::unique_ptr<AZ::SerializeContext> m_serializeContext;
|
||||
AZStd::unique_ptr<AZ::JsonRegistrationContext> m_jsonRegistrationContext;
|
||||
AZStd::unique_ptr<AZ::JsonSystemComponent> m_jsonSystemComponent;
|
||||
|
||||
AZ::JsonSerializerSettings m_serializationSettings;
|
||||
AZ::JsonDeserializerSettings m_deserializationSettings;
|
||||
};
|
||||
|
||||
TEST_F(JsonFileFuncTest, WriteJsonString_ValidJson_ExpectSuccess)
|
||||
{
|
||||
rapidjson::Document document;
|
||||
document.SetObject();
|
||||
document.AddMember("a", 1, document.GetAllocator());
|
||||
document.AddMember("b", 2, document.GetAllocator());
|
||||
document.AddMember("c", 3, document.GetAllocator());
|
||||
|
||||
AZStd::string expectedJsonText =
|
||||
R"({
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
"c": 3
|
||||
})";
|
||||
expectedJsonText.erase(AZStd::remove_if(expectedJsonText.begin(), expectedJsonText.end(), ::isspace), expectedJsonText.end());
|
||||
|
||||
AZStd::string outString;
|
||||
AZ::Outcome<void, AZStd::string> result = AzFramework::FileFunc::WriteJsonToString(document, outString);
|
||||
EXPECT_TRUE(result.IsSuccess());
|
||||
|
||||
outString.erase(AZStd::remove_if(outString.begin(), outString.end(), ::isspace), outString.end());
|
||||
EXPECT_EQ(expectedJsonText, outString) << "expected:\n" << expectedJsonText.c_str() << "\nactual:\n" << outString.c_str();
|
||||
}
|
||||
|
||||
TEST_F(JsonFileFuncTest, WriteJsonStream_ValidJson_ExpectSuccess)
|
||||
{
|
||||
rapidjson::Document document;
|
||||
document.SetObject();
|
||||
document.AddMember("a", 1, document.GetAllocator());
|
||||
document.AddMember("b", 2, document.GetAllocator());
|
||||
document.AddMember("c", 3, document.GetAllocator());
|
||||
|
||||
AZStd::string expectedJsonText =
|
||||
R"({
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
"c": 3
|
||||
})";
|
||||
expectedJsonText.erase(AZStd::remove_if(expectedJsonText.begin(), expectedJsonText.end(), ::isspace), expectedJsonText.end());
|
||||
|
||||
AZStd::vector<char> outBuffer;
|
||||
AZ::IO::ByteContainerStream<AZStd::vector<char>> outStream{ &outBuffer };
|
||||
AZ::Outcome<void, AZStd::string> result = AzFramework::FileFunc::Internal::WriteJsonToStream(document, outStream);
|
||||
EXPECT_TRUE(result.IsSuccess());
|
||||
|
||||
outBuffer.push_back(0);
|
||||
AZStd::string outString = outBuffer.data();
|
||||
outString.erase(AZStd::remove_if(outString.begin(), outString.end(), ::isspace), outString.end());
|
||||
EXPECT_EQ(expectedJsonText, outString) << "expected:\n" << expectedJsonText.c_str() << "\nactual:\n" << outString.c_str();
|
||||
}
|
||||
|
||||
TEST_F(JsonFileFuncTest, WriteJsonFile_ValidJson_ExpectSuccess)
|
||||
{
|
||||
AZ::Test::ScopedAutoTempDirectory tempDir;
|
||||
|
||||
rapidjson::Document document;
|
||||
document.SetObject();
|
||||
document.AddMember("a", 1, document.GetAllocator());
|
||||
document.AddMember("b", 2, document.GetAllocator());
|
||||
document.AddMember("c", 3, document.GetAllocator());
|
||||
|
||||
AZStd::string expectedJsonText =
|
||||
R"({
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
"c": 3
|
||||
})";
|
||||
expectedJsonText.erase(AZStd::remove_if(expectedJsonText.begin(), expectedJsonText.end(), ::isspace), expectedJsonText.end());
|
||||
|
||||
AZStd::string pathStr;
|
||||
AzFramework::StringFunc::Path::ConstructFull(tempDir.GetDirectory(), "test.json", pathStr, true);
|
||||
|
||||
// Write the JSON to a file
|
||||
AZ::IO::Path path(pathStr);
|
||||
AZ::Outcome<void, AZStd::string> saveResult = AzFramework::FileFunc::WriteJsonFile(document, path);
|
||||
EXPECT_TRUE(saveResult.IsSuccess());
|
||||
|
||||
// Verify that the contents of the file is what we expect
|
||||
AZ::Outcome<AZStd::string, AZStd::string> readResult = AZ::Utils::ReadFile(pathStr);
|
||||
EXPECT_TRUE(readResult.IsSuccess());
|
||||
AZStd::string outString(readResult.TakeValue());
|
||||
outString.erase(AZStd::remove_if(outString.begin(), outString.end(), ::isspace), outString.end());
|
||||
EXPECT_EQ(outString, expectedJsonText);
|
||||
|
||||
// Clean up
|
||||
AZ::IO::FileIOBase::GetInstance()->Remove(path.c_str());
|
||||
}
|
||||
|
||||
TEST_F(JsonFileFuncTest, ReadJsonString_ValidJson_ExpectSuccess)
|
||||
{
|
||||
const char* jsonText =
|
||||
R"(
|
||||
{
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
"c": 3
|
||||
})";
|
||||
|
||||
AZ::Outcome<rapidjson::Document, AZStd::string> result = AzFramework::FileFunc::ReadJsonFromString(jsonText);
|
||||
|
||||
EXPECT_TRUE(result.IsSuccess());
|
||||
EXPECT_TRUE(result.GetValue().IsObject());
|
||||
EXPECT_TRUE(result.GetValue().HasMember("a"));
|
||||
EXPECT_TRUE(result.GetValue().HasMember("b"));
|
||||
EXPECT_TRUE(result.GetValue().HasMember("c"));
|
||||
EXPECT_EQ(result.GetValue()["a"].GetInt(), 1);
|
||||
EXPECT_EQ(result.GetValue()["b"].GetInt(), 2);
|
||||
EXPECT_EQ(result.GetValue()["c"].GetInt(), 3);
|
||||
}
|
||||
|
||||
TEST_F(JsonFileFuncTest, ReadJsonString_InvalidJson_ErrorReportsLineNumber)
|
||||
{
|
||||
const char* jsonText =
|
||||
R"(
|
||||
{
|
||||
"a": "This line is missing a comma"
|
||||
"b": 2,
|
||||
"c": 3
|
||||
}
|
||||
)";
|
||||
|
||||
AZ::Outcome<rapidjson::Document, AZStd::string> result = AzFramework::FileFunc::ReadJsonFromString(jsonText);
|
||||
|
||||
EXPECT_FALSE(result.IsSuccess());
|
||||
EXPECT_TRUE(result.GetError().find("JSON parse error at line 4:") == 0);
|
||||
}
|
||||
|
||||
TEST_F(JsonFileFuncTest, ReadJsonFile_ValidJson_ExpectSuccess)
|
||||
{
|
||||
AZ::Test::ScopedAutoTempDirectory tempDir;
|
||||
|
||||
const char* inputJsonText =
|
||||
R"({
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
"c": 3
|
||||
})";
|
||||
|
||||
rapidjson::Document expectedDocument;
|
||||
expectedDocument.SetObject();
|
||||
expectedDocument.AddMember("a", 1, expectedDocument.GetAllocator());
|
||||
expectedDocument.AddMember("b", 2, expectedDocument.GetAllocator());
|
||||
expectedDocument.AddMember("c", 3, expectedDocument.GetAllocator());
|
||||
|
||||
// Create test file
|
||||
AZStd::string path;
|
||||
AzFramework::StringFunc::Path::ConstructFull(tempDir.GetDirectory(), "test.json", path, true);
|
||||
AZ::Outcome<void, AZStd::string> writeResult = AZ::Utils::WriteFile(inputJsonText, path);
|
||||
EXPECT_TRUE(writeResult.IsSuccess());
|
||||
|
||||
|
||||
// Read the JSON from the test file
|
||||
AZ::Outcome<rapidjson::Document, AZStd::string> readResult = AzFramework::FileFunc::ReadJsonFile(path);
|
||||
EXPECT_TRUE(readResult.IsSuccess());
|
||||
|
||||
EXPECT_EQ(expectedDocument, readResult.GetValue());
|
||||
|
||||
// Clean up
|
||||
AZ::IO::FileIOBase::GetInstance()->Remove(path.c_str());
|
||||
}
|
||||
} // namespace UnitTest
|
||||
|
||||
Reference in New Issue
Block a user