fix Windows unity build
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
This commit is contained in:
@@ -10,8 +10,6 @@
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
using namespace AZ;
|
||||
|
||||
// Handle asserts
|
||||
class ToolsFrameworkHook
|
||||
: public AZ::Test::ITestEnvironment
|
||||
@@ -19,12 +17,12 @@ class ToolsFrameworkHook
|
||||
public:
|
||||
void SetupEnvironment() override
|
||||
{
|
||||
AllocatorInstance<SystemAllocator>::Create();
|
||||
AZ::AllocatorInstance<AZ::SystemAllocator>::Create();
|
||||
}
|
||||
|
||||
void TeardownEnvironment() override
|
||||
{
|
||||
AllocatorInstance<SystemAllocator>::Destroy();
|
||||
AZ::AllocatorInstance<AZ::SystemAllocator>::Destroy();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -5,13 +5,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
// All plugins suffer from the following warning:
|
||||
// warning C4273: 'GetIEditor' : inconsistent dll linkage
|
||||
// GetIEditor() is forward-declared using EDITOR_CORE_API, which without EDITOR_CORE set,
|
||||
// results in dllimport rather than dllexport. This define ensure it's consistently and
|
||||
// properly defined for export.
|
||||
#define EDITOR_CORE
|
||||
|
||||
#include <platform.h>
|
||||
|
||||
#include <IEditor.h>
|
||||
|
||||
@@ -7,10 +7,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(Q_MOC_RUN)
|
||||
#include "Include/EditorCoreAPI.h"
|
||||
#endif
|
||||
|
||||
#if !defined(Q_MOC_RUN)
|
||||
#include "Include/EditorCoreAPI.h"
|
||||
#include <QtViewPane.h>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/PlatformIncl.h>
|
||||
#include <AzToolsFramework/UI/Docking/DockWidgetUtils.h>
|
||||
|
||||
AZ_PUSH_DISABLE_WARNING(4251 4244 4458, "-Wunknown-warning-option") // 4251: 'QTextStream::d_ptr': class 'QScopedPointer<QTextStreamPrivate,QScopedPointerDeleter<T>>' needs to have dll-interface to be used by clients of class 'QTextStream'
|
||||
|
||||
@@ -14,6 +14,11 @@
|
||||
|
||||
namespace ImageProcessingAtom
|
||||
{
|
||||
float round(float x)
|
||||
{
|
||||
return ((x) >= 0) ? floor((x) + 0.5) : ceil((x)-0.5);
|
||||
}
|
||||
|
||||
void calculateFilterRange(unsigned int srcFactor, int& srcFirst, int& srcLast,
|
||||
unsigned int dstFactor, int dstFirst, int dstLast,
|
||||
double blurFactor, class IWindowFunction<double>* windowFunction)
|
||||
|
||||
@@ -22,11 +22,7 @@ namespace ImageProcessingAtom
|
||||
inline DataType minimum(const DataType& ths, const DataType& tht) { return (ths < tht ? ths : tht); }
|
||||
template<class DataType>
|
||||
inline DataType maximum(const DataType& ths, const DataType& tht) { return (ths > tht ? ths : tht); }
|
||||
|
||||
#ifndef round
|
||||
#define round(x) ((x) >= 0) ? floor((x) + 0.5) : ceil((x) - 0.5)
|
||||
#endif
|
||||
|
||||
|
||||
/* ####################################################################################################################
|
||||
*/
|
||||
|
||||
|
||||
@@ -12,12 +12,12 @@
|
||||
#include <AzCore/std/time.h>
|
||||
#include <AzCore/UnitTest/UnitTest.h>
|
||||
|
||||
using namespace AZ;
|
||||
|
||||
#define PRINTF(...) do { UnitTest::ColoredPrintf(UnitTest::COLOR_GREEN, "[ ] "); UnitTest::ColoredPrintf(UnitTest::COLOR_YELLOW, __VA_ARGS__); } while(0)
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
using namespace AZ;
|
||||
|
||||
class AllocatorTest
|
||||
: public RHITestFixture
|
||||
{
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
#include <Tests/Factory.h>
|
||||
#include <Tests/Device.h>
|
||||
|
||||
using namespace AZ;
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
using namespace AZ;
|
||||
|
||||
class BufferTests
|
||||
: public RHITestFixture
|
||||
{
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
#include <Atom/RHI/BufferScopeAttachment.h>
|
||||
#include <AzCore/Math/Random.h>
|
||||
|
||||
using namespace AZ;
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
using namespace AZ;
|
||||
|
||||
class FrameGraphTests
|
||||
: public RHITestFixture
|
||||
{
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
#include <Atom/RHI/FrameScheduler.h>
|
||||
#include <AzCore/Math/Random.h>
|
||||
|
||||
using namespace AZ;
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
using namespace AZ;
|
||||
|
||||
struct ImportedImage
|
||||
{
|
||||
RHI::AttachmentId m_id;
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
#include <AzCore/Serialization/ObjectStream.h>
|
||||
#include <AzCore/Serialization/Utils.h>
|
||||
|
||||
using namespace AZ;
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
using namespace AZ;
|
||||
|
||||
class IndirectBufferTests
|
||||
: public RHITestFixture
|
||||
{
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
#include <AzCore/Math/Random.h>
|
||||
|
||||
using namespace AZ;
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
using namespace AZ;
|
||||
|
||||
class PipelineStateTests
|
||||
: public RHITestFixture
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
namespace UnitTest
|
||||
{
|
||||
using namespace AZ;
|
||||
|
||||
RHI::ResultCode Query::BeginInternal([[maybe_unused]] RHI::CommandList& commandList, [[maybe_unused]] RHI::QueryControlFlags flags)
|
||||
{
|
||||
return RHI::ResultCode::Success;
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
#include <Tests/Device.h>
|
||||
#include <Atom/RHI/FrameEventBus.h>
|
||||
|
||||
using namespace AZ;
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
using namespace AZ;
|
||||
|
||||
class QueryTests
|
||||
: public RHITestFixture
|
||||
{
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/PlatformIncl.h>
|
||||
|
||||
#if !defined(AZ_DX12_REFCOUNTED)
|
||||
#error "Incorrect include of DX12_Windows.h, please include DX12.h instead of this header"
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -19,361 +19,363 @@
|
||||
#include <AzToolsFramework/Application/ToolsApplication.h>
|
||||
#include <Tests/AZTestShared/Utils/Utils.h>
|
||||
|
||||
using namespace LevelBuilder;
|
||||
using namespace AZ;
|
||||
using namespace AssetBuilderSDK;
|
||||
|
||||
class MockSimpleAsset
|
||||
namespace UnitTest
|
||||
{
|
||||
public:
|
||||
AZ_TYPE_INFO(MockSimpleAsset, "{A8A04FF5-1D58-450D-8FD4-2641F290B918}");
|
||||
using namespace LevelBuilder;
|
||||
using namespace AZ;
|
||||
using namespace AssetBuilderSDK;
|
||||
|
||||
static const char* GetFileFilter()
|
||||
class MockSimpleAsset
|
||||
{
|
||||
return "*.txt;";
|
||||
}
|
||||
};
|
||||
public:
|
||||
AZ_TYPE_INFO(MockSimpleAsset, "{A8A04FF5-1D58-450D-8FD4-2641F290B918}");
|
||||
|
||||
class SecondMockSimpleAsset
|
||||
{
|
||||
public:
|
||||
AZ_TYPE_INFO(SecondMockSimpleAsset, "{A443123A-FD95-45F6-9767-35B17DA2072F}");
|
||||
|
||||
static const char* GetFileFilter()
|
||||
{
|
||||
return "*.txt;*.txt1;*.txt2";
|
||||
}
|
||||
};
|
||||
|
||||
class ThirdMockSimpleAsset
|
||||
{
|
||||
public:
|
||||
AZ_TYPE_INFO(ThirdMockSimpleAsset, "{0298F78B-76EF-47CE-8812-B0BC80060016}");
|
||||
|
||||
static const char* GetFileFilter()
|
||||
{
|
||||
return "txt";
|
||||
}
|
||||
};
|
||||
|
||||
struct MockSimpleAssetRefComponent
|
||||
: public AZ::Component
|
||||
{
|
||||
AZ_COMPONENT(MockSimpleAssetRefComponent, "{7A37EE69-707B-435F-8B8C-B347C454DC6B}");
|
||||
|
||||
static void Reflect(ReflectContext* reflection)
|
||||
{
|
||||
SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(reflection);
|
||||
|
||||
AzFramework::SimpleAssetReference<MockSimpleAsset>::Register(*serializeContext);
|
||||
AzFramework::SimpleAssetReference<SecondMockSimpleAsset>::Register(*serializeContext);
|
||||
AzFramework::SimpleAssetReference<ThirdMockSimpleAsset>::Register(*serializeContext);
|
||||
|
||||
if (serializeContext)
|
||||
static const char* GetFileFilter()
|
||||
{
|
||||
serializeContext->Class<MockSimpleAssetRefComponent, AZ::Component>()
|
||||
->Field("asset", &MockSimpleAssetRefComponent::m_asset)
|
||||
->Field("secondAsset", &MockSimpleAssetRefComponent::m_secondAsset)
|
||||
->Field("thirdAsset", &MockSimpleAssetRefComponent::m_thirdAsset);
|
||||
return "*.txt;";
|
||||
}
|
||||
};
|
||||
|
||||
class SecondMockSimpleAsset
|
||||
{
|
||||
public:
|
||||
AZ_TYPE_INFO(SecondMockSimpleAsset, "{A443123A-FD95-45F6-9767-35B17DA2072F}");
|
||||
|
||||
static const char* GetFileFilter()
|
||||
{
|
||||
return "*.txt;*.txt1;*.txt2";
|
||||
}
|
||||
};
|
||||
|
||||
class ThirdMockSimpleAsset
|
||||
{
|
||||
public:
|
||||
AZ_TYPE_INFO(ThirdMockSimpleAsset, "{0298F78B-76EF-47CE-8812-B0BC80060016}");
|
||||
|
||||
static const char* GetFileFilter()
|
||||
{
|
||||
return "txt";
|
||||
}
|
||||
};
|
||||
|
||||
struct MockSimpleAssetRefComponent
|
||||
: public AZ::Component
|
||||
{
|
||||
AZ_COMPONENT(MockSimpleAssetRefComponent, "{7A37EE69-707B-435F-8B8C-B347C454DC6B}");
|
||||
|
||||
static void Reflect(ReflectContext* reflection)
|
||||
{
|
||||
SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(reflection);
|
||||
|
||||
AzFramework::SimpleAssetReference<MockSimpleAsset>::Register(*serializeContext);
|
||||
AzFramework::SimpleAssetReference<SecondMockSimpleAsset>::Register(*serializeContext);
|
||||
AzFramework::SimpleAssetReference<ThirdMockSimpleAsset>::Register(*serializeContext);
|
||||
|
||||
if (serializeContext)
|
||||
{
|
||||
serializeContext->Class<MockSimpleAssetRefComponent, AZ::Component>()
|
||||
->Field("asset", &MockSimpleAssetRefComponent::m_asset)
|
||||
->Field("secondAsset", &MockSimpleAssetRefComponent::m_secondAsset)
|
||||
->Field("thirdAsset", &MockSimpleAssetRefComponent::m_thirdAsset);
|
||||
}
|
||||
}
|
||||
|
||||
void Activate() override {}
|
||||
void Deactivate() override {}
|
||||
|
||||
AzFramework::SimpleAssetReference<MockSimpleAsset> m_asset;
|
||||
AzFramework::SimpleAssetReference<SecondMockSimpleAsset> m_secondAsset;
|
||||
AzFramework::SimpleAssetReference<ThirdMockSimpleAsset> m_thirdAsset;
|
||||
};
|
||||
|
||||
class LevelBuilderTest
|
||||
: public ::testing::Test
|
||||
, public UnitTest::TraceBusRedirector
|
||||
{
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
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_app.Start(m_descriptor);
|
||||
// Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is
|
||||
// shared across the whole engine, if multiple tests are run in parallel, the saving could cause a crash
|
||||
// in the unit tests.
|
||||
AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize);
|
||||
AZ::Debug::TraceMessageBus::Handler::BusConnect();
|
||||
|
||||
const AZStd::string engineRoot = AZ::Test::GetEngineRootPath();
|
||||
AZ::IO::FileIOBase::GetInstance()->SetAlias("@engroot@", engineRoot.c_str());
|
||||
|
||||
AZ::IO::Path assetRoot(AZ::Utils::GetProjectPath());
|
||||
assetRoot /= "Cache";
|
||||
AZ::IO::FileIOBase::GetInstance()->SetAlias("@root@", assetRoot.c_str());
|
||||
|
||||
auto* serializeContext = m_app.GetSerializeContext();
|
||||
|
||||
m_simpleAssetRefDescriptor = MockSimpleAssetRefComponent::CreateDescriptor();
|
||||
m_simpleAssetRefDescriptor->Reflect(serializeContext);
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
delete m_simpleAssetRefDescriptor;
|
||||
|
||||
m_app.Stop();
|
||||
AZ::Debug::TraceMessageBus::Handler::BusDisconnect();
|
||||
}
|
||||
|
||||
void TestFailureCase(AZStd::string_view fileName)
|
||||
{
|
||||
IO::FileIOStream fileStream;
|
||||
LevelBuilderWorker worker;
|
||||
ProductPathDependencySet productDependencies;
|
||||
|
||||
ASSERT_TRUE(OpenTestFile(fileName, fileStream));
|
||||
ASSERT_EQ(productDependencies.size(), 0);
|
||||
}
|
||||
|
||||
AZStd::string GetTestFileAliasedPath(AZStd::string_view fileName)
|
||||
{
|
||||
constexpr char testFileFolder[] = "@devroot@/Gems/LmbrCentral/Code/Tests/Levels/";
|
||||
return AZStd::string::format("%s%.*s", testFileFolder, aznumeric_cast<int>(fileName.size()), fileName.data());
|
||||
}
|
||||
|
||||
|
||||
AZStd::string GetTestFileFullPath(AZStd::string_view fileName)
|
||||
{
|
||||
AZStd::string aliasedPath = GetTestFileAliasedPath(fileName);
|
||||
char resolvedPath[AZ_MAX_PATH_LEN];
|
||||
AZ::IO::FileIOBase::GetInstance()->ResolvePath(aliasedPath.c_str(), resolvedPath, AZ_MAX_PATH_LEN);
|
||||
return AZStd::string(resolvedPath);
|
||||
}
|
||||
|
||||
bool OpenTestFile(AZStd::string_view fileName, IO::FileIOStream& fileStream)
|
||||
{
|
||||
AZStd::string aliasedPath = GetTestFileFullPath(fileName);
|
||||
return fileStream.Open(aliasedPath.c_str(), IO::OpenMode::ModeRead | IO::OpenMode::ModeBinary);
|
||||
}
|
||||
|
||||
AzToolsFramework::ToolsApplication m_app;
|
||||
AZ::ComponentApplication::Descriptor m_descriptor;
|
||||
AZ::ComponentDescriptor* m_simpleAssetRefDescriptor;
|
||||
};
|
||||
|
||||
TEST_F(LevelBuilderTest, TestLevelData_EmptyFile)
|
||||
{
|
||||
// Tests processing a leveldata.xml file that is empty
|
||||
// Should output 0 dependencies and return false
|
||||
|
||||
TestFailureCase("leveldata_test3.xml");
|
||||
}
|
||||
|
||||
void Activate() override {}
|
||||
void Deactivate() override {}
|
||||
|
||||
AzFramework::SimpleAssetReference<MockSimpleAsset> m_asset;
|
||||
AzFramework::SimpleAssetReference<SecondMockSimpleAsset> m_secondAsset;
|
||||
AzFramework::SimpleAssetReference<ThirdMockSimpleAsset> m_thirdAsset;
|
||||
};
|
||||
|
||||
class LevelBuilderTest
|
||||
: public ::testing::Test
|
||||
, public UnitTest::TraceBusRedirector
|
||||
{
|
||||
protected:
|
||||
void SetUp() override
|
||||
TEST_F(LevelBuilderTest, TestLevelData_NoSurfaceTypes)
|
||||
{
|
||||
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_app.Start(m_descriptor);
|
||||
// Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is
|
||||
// shared across the whole engine, if multiple tests are run in parallel, the saving could cause a crash
|
||||
// in the unit tests.
|
||||
AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize);
|
||||
AZ::Debug::TraceMessageBus::Handler::BusConnect();
|
||||
// Tests processing a leveldata.xml file that contains no surface types
|
||||
// Should output 0 dependencies and return false
|
||||
|
||||
const AZStd::string engineRoot = AZ::Test::GetEngineRootPath();
|
||||
AZ::IO::FileIOBase::GetInstance()->SetAlias("@engroot@", engineRoot.c_str());
|
||||
|
||||
AZ::IO::Path assetRoot(AZ::Utils::GetProjectPath());
|
||||
assetRoot /= "Cache";
|
||||
AZ::IO::FileIOBase::GetInstance()->SetAlias("@root@", assetRoot.c_str());
|
||||
|
||||
auto* serializeContext = m_app.GetSerializeContext();
|
||||
|
||||
m_simpleAssetRefDescriptor = MockSimpleAssetRefComponent::CreateDescriptor();
|
||||
m_simpleAssetRefDescriptor->Reflect(serializeContext);
|
||||
TestFailureCase("leveldata_test4.xml");
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
TEST_F(LevelBuilderTest, TestLevelData_NoLevelData)
|
||||
{
|
||||
delete m_simpleAssetRefDescriptor;
|
||||
// Tests processing a leveldata.xml file that contains no level data
|
||||
// Should output 0 dependencies and return false
|
||||
|
||||
m_app.Stop();
|
||||
AZ::Debug::TraceMessageBus::Handler::BusDisconnect();
|
||||
TestFailureCase("leveldata_test5.xml");
|
||||
}
|
||||
|
||||
void TestFailureCase(AZStd::string_view fileName)
|
||||
TEST_F(LevelBuilderTest, TestLevelData_NonXMLData)
|
||||
{
|
||||
// Tests processing a leveldata.xml file that is not an xml file
|
||||
// Should output 0 dependencies and return false
|
||||
|
||||
TestFailureCase("leveldata_test6.xml");
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, TestLevelData_MalformedXMLData)
|
||||
{
|
||||
// Tests processing a leveldata.xml file that contains malformed XML
|
||||
// Should output 0 dependencies and return false
|
||||
|
||||
TestFailureCase("leveldata_test7.xml");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEST_F(LevelBuilderTest, TestMission_MultipleDependencies)
|
||||
{
|
||||
// Tests processing a mission_*.xml file containing multiple dependencies and no Cloud texture
|
||||
// Should output 3 dependencies
|
||||
|
||||
IO::FileIOStream fileStream;
|
||||
|
||||
ASSERT_TRUE(OpenTestFile("mission_mission0_test1.xml", fileStream));
|
||||
|
||||
LevelBuilderWorker worker;
|
||||
ProductPathDependencySet productDependencies;
|
||||
|
||||
ASSERT_TRUE(OpenTestFile(fileName, fileStream));
|
||||
ASSERT_TRUE(worker.PopulateMissionDependenciesHelper(&fileStream, productDependencies));
|
||||
ASSERT_THAT(productDependencies, testing::UnorderedElementsAre(
|
||||
ProductPathDependency{ "EngineAssets/Materials/Sky/Sky.mtl", AssetBuilderSDK::ProductPathDependencyType::ProductFile },
|
||||
ProductPathDependency{ "EngineAssets/Materials/Water/Ocean_default.mtl", AssetBuilderSDK::ProductPathDependencyType::ProductFile },
|
||||
ProductPathDependency{ "Textures/Skys/Night/half_moon.dds", AssetBuilderSDK::ProductPathDependencyType::ProductFile }));
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, TestMission_NoSkyBox)
|
||||
{
|
||||
// Tests processing a mission_*.xml file with no skybox settings
|
||||
// Should output 0 dependencies and return false
|
||||
|
||||
TestFailureCase("mission_mission0_test2.xml");
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, TestMission_NoOcean)
|
||||
{
|
||||
// Tests processing a mission_*.xml file with no ocean settings
|
||||
// Should output 0 dependencies and return false
|
||||
|
||||
TestFailureCase("mission_mission0_test3.xml");
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, TestMission_NoMoon)
|
||||
{
|
||||
// Tests processing a mission_*.xml file with no moon settings
|
||||
// Should output 2 dependencies
|
||||
|
||||
IO::FileIOStream fileStream;
|
||||
|
||||
ASSERT_TRUE(OpenTestFile("mission_mission0_test4.xml", fileStream));
|
||||
|
||||
LevelBuilderWorker worker;
|
||||
ProductPathDependencySet productDependencies;
|
||||
|
||||
ASSERT_TRUE(worker.PopulateMissionDependenciesHelper(&fileStream, productDependencies));
|
||||
ASSERT_THAT(productDependencies, testing::UnorderedElementsAre(
|
||||
ProductPathDependency{ "EngineAssets/Materials/Sky/Sky.mtl", AssetBuilderSDK::ProductPathDependencyType::ProductFile },
|
||||
ProductPathDependency{ "EngineAssets/Materials/Water/Ocean_default.mtl", AssetBuilderSDK::ProductPathDependencyType::ProductFile }));
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, TestMission_NoEnvironment)
|
||||
{
|
||||
// Tests processing a mission_*.xml file with no environment settings
|
||||
// Should output 0 dependencies and return false
|
||||
|
||||
TestFailureCase("mission_mission0_test5.xml");
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, TestMission_EmptyFile)
|
||||
{
|
||||
// Tests processing an empty mission_*.xml
|
||||
// Should output 0 dependencies and return false
|
||||
|
||||
TestFailureCase("mission_mission0_test6.xml");
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, TestMission_CloudShadow)
|
||||
{
|
||||
// Tests processing a mission_*.xml file with cloud shadow texture set
|
||||
// Should output 4 dependencies and return true
|
||||
|
||||
using namespace AssetBuilderSDK;
|
||||
|
||||
IO::FileIOStream fileStream;
|
||||
|
||||
ASSERT_TRUE(OpenTestFile("mission_mission0_test7.xml", fileStream));
|
||||
|
||||
LevelBuilderWorker worker;
|
||||
ProductPathDependencySet productDependencies;
|
||||
|
||||
ASSERT_TRUE(worker.PopulateMissionDependenciesHelper(&fileStream, productDependencies));
|
||||
ASSERT_THAT(productDependencies, testing::UnorderedElementsAre(
|
||||
ProductPathDependency{ "EngineAssets/Materials/Sky/Sky.mtl", AssetBuilderSDK::ProductPathDependencyType::ProductFile },
|
||||
ProductPathDependency{ "EngineAssets/Materials/Water/Ocean_default.mtl", AssetBuilderSDK::ProductPathDependencyType::ProductFile },
|
||||
ProductPathDependency{ "Textures/Skys/Night/half_moon.dds", AssetBuilderSDK::ProductPathDependencyType::ProductFile },
|
||||
ProductPathDependency{ "textures/terrain/ftue_megatexture_02.dds", AssetBuilderSDK::ProductPathDependencyType::ProductFile }));
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, DynamicSlice_NoAssetReferences_HasNoProductDependencies)
|
||||
{
|
||||
LevelBuilderWorker worker;
|
||||
AZStd::vector<AssetBuilderSDK::ProductDependency> productDependencies;
|
||||
ProductPathDependencySet productPathDependencies;
|
||||
|
||||
AZStd::string filePath(GetTestFileAliasedPath("levelSlice_noAssetReferences.entities_xml"));
|
||||
ASSERT_TRUE(AZ::IO::FileIOBase::GetInstance()->Exists(filePath.c_str()));
|
||||
|
||||
worker.PopulateLevelSliceDependenciesHelper(filePath, productDependencies, productPathDependencies);
|
||||
ASSERT_EQ(productDependencies.size(), 0);
|
||||
ASSERT_EQ(productPathDependencies.size(), 0);
|
||||
}
|
||||
|
||||
AZStd::string GetTestFileAliasedPath(AZStd::string_view fileName)
|
||||
TEST_F(LevelBuilderTest, DynamicSlice_HasAssetReference_HasCorrectProductDependency)
|
||||
{
|
||||
constexpr char testFileFolder[] = "@devroot@/Gems/LmbrCentral/Code/Tests/Levels/";
|
||||
return AZStd::string::format("%s%.*s", testFileFolder, aznumeric_cast<int>(fileName.size()), fileName.data());
|
||||
LevelBuilderWorker worker;
|
||||
AZStd::vector<AssetBuilderSDK::ProductDependency> productDependencies;
|
||||
ProductPathDependencySet productPathDependencies;
|
||||
|
||||
AZStd::string filePath(GetTestFileAliasedPath("levelSlice_oneAssetRef.entities_xml"));
|
||||
ASSERT_TRUE(AZ::IO::FileIOBase::GetInstance()->Exists(filePath.c_str()));
|
||||
|
||||
worker.PopulateLevelSliceDependenciesHelper(filePath, productDependencies, productPathDependencies);
|
||||
ASSERT_EQ(productPathDependencies.size(), 0);
|
||||
ASSERT_EQ(productDependencies.size(), 1);
|
||||
ASSERT_EQ(productDependencies[0].m_dependencyId.m_guid, AZ::Uuid("A8970A25-5043-5519-A927-F180E7D6E8C1"));
|
||||
ASSERT_EQ(productDependencies[0].m_dependencyId.m_subId, 1);
|
||||
}
|
||||
|
||||
|
||||
AZStd::string GetTestFileFullPath(AZStd::string_view fileName)
|
||||
void BuildSliceWithSimpleAssetReference(const AZStd::vector<AZStd::string>& filePaths, AZStd::vector<AssetBuilderSDK::ProductDependency>& productDependencies, ProductPathDependencySet& productPathDependencies)
|
||||
{
|
||||
AZStd::string aliasedPath = GetTestFileAliasedPath(fileName);
|
||||
char resolvedPath[AZ_MAX_PATH_LEN];
|
||||
AZ::IO::FileIOBase::GetInstance()->ResolvePath(aliasedPath.c_str(), resolvedPath, AZ_MAX_PATH_LEN);
|
||||
return AZStd::string(resolvedPath);
|
||||
auto* assetComponent = aznew MockSimpleAssetRefComponent;
|
||||
|
||||
assetComponent->m_asset.SetAssetPath(filePaths[0].c_str());
|
||||
assetComponent->m_secondAsset.SetAssetPath(filePaths[1].c_str());
|
||||
assetComponent->m_thirdAsset.SetAssetPath(filePaths[2].c_str());
|
||||
|
||||
auto sliceAsset = AZ::Test::CreateSliceFromComponent(assetComponent, AZ::Data::AssetId(AZ::Uuid::CreateRandom(), 0));
|
||||
|
||||
LevelBuilderWorker worker;
|
||||
|
||||
worker.PopulateLevelSliceDependenciesHelper(sliceAsset, productDependencies, productPathDependencies);
|
||||
}
|
||||
|
||||
bool OpenTestFile(AZStd::string_view fileName, IO::FileIOStream& fileStream)
|
||||
TEST_F(LevelBuilderTest, DynamicSlice_HasPopulatedSimpleAssetReference_HasCorrectProductDependency)
|
||||
{
|
||||
AZStd::string aliasedPath = GetTestFileFullPath(fileName);
|
||||
return fileStream.Open(aliasedPath.c_str(), IO::OpenMode::ModeRead | IO::OpenMode::ModeBinary);
|
||||
AZStd::vector<AssetBuilderSDK::ProductDependency> productDependencies;
|
||||
ProductPathDependencySet productPathDependencies;
|
||||
AZStd::vector<AZStd::string> filePaths = { "some/test/path.txt", "", "" };
|
||||
BuildSliceWithSimpleAssetReference(filePaths, productDependencies, productPathDependencies);
|
||||
ASSERT_EQ(productDependencies.size(), 0);
|
||||
ASSERT_EQ(productPathDependencies.size(), 1);
|
||||
ASSERT_EQ(productPathDependencies.begin()->m_dependencyPath, filePaths[0]);
|
||||
}
|
||||
|
||||
AzToolsFramework::ToolsApplication m_app;
|
||||
AZ::ComponentApplication::Descriptor m_descriptor;
|
||||
AZ::ComponentDescriptor* m_simpleAssetRefDescriptor;
|
||||
};
|
||||
TEST_F(LevelBuilderTest, DynamicSlice_HasPopulatedSimpleAssetReferencesNoExtension_HasCorrectProductDependency)
|
||||
{
|
||||
AZStd::vector<AssetBuilderSDK::ProductDependency> productDependencies;
|
||||
ProductPathDependencySet productPathDependencies;
|
||||
AZStd::vector<AZStd::string> filePaths = { "some/test/path0", "some/test/path1", "some/test/path2" };
|
||||
BuildSliceWithSimpleAssetReference(filePaths, productDependencies, productPathDependencies);
|
||||
ASSERT_EQ(productDependencies.size(), 0);
|
||||
ASSERT_EQ(productPathDependencies.size(), 3);
|
||||
|
||||
TEST_F(LevelBuilderTest, TestLevelData_EmptyFile)
|
||||
{
|
||||
// Tests processing a leveldata.xml file that is empty
|
||||
// Should output 0 dependencies and return false
|
||||
ASSERT_THAT(productPathDependencies, testing::UnorderedElementsAre(
|
||||
ProductPathDependency{ "some/test/path0.txt", AssetBuilderSDK::ProductPathDependencyType::ProductFile },
|
||||
ProductPathDependency{ "some/test/path1.txt", AssetBuilderSDK::ProductPathDependencyType::ProductFile },
|
||||
ProductPathDependency{ "some/test/path2.txt", AssetBuilderSDK::ProductPathDependencyType::ProductFile }));
|
||||
}
|
||||
|
||||
TestFailureCase("leveldata_test3.xml");
|
||||
TEST_F(LevelBuilderTest, DynamicSlice_HasEmptySimpleAssetReference_HasNoProductDependency)
|
||||
{
|
||||
AZStd::vector<AssetBuilderSDK::ProductDependency> productDependencies;
|
||||
ProductPathDependencySet productPathDependencies;
|
||||
AZStd::vector<AZStd::string> filePaths = { "", "", "" };
|
||||
BuildSliceWithSimpleAssetReference(filePaths, productDependencies, productPathDependencies);
|
||||
ASSERT_EQ(productDependencies.size(), 0);
|
||||
ASSERT_EQ(productPathDependencies.size(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, TestLevelData_NoSurfaceTypes)
|
||||
{
|
||||
// Tests processing a leveldata.xml file that contains no surface types
|
||||
// Should output 0 dependencies and return false
|
||||
|
||||
TestFailureCase("leveldata_test4.xml");
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, TestLevelData_NoLevelData)
|
||||
{
|
||||
// Tests processing a leveldata.xml file that contains no level data
|
||||
// Should output 0 dependencies and return false
|
||||
|
||||
TestFailureCase("leveldata_test5.xml");
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, TestLevelData_NonXMLData)
|
||||
{
|
||||
// Tests processing a leveldata.xml file that is not an xml file
|
||||
// Should output 0 dependencies and return false
|
||||
|
||||
TestFailureCase("leveldata_test6.xml");
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, TestLevelData_MalformedXMLData)
|
||||
{
|
||||
// Tests processing a leveldata.xml file that contains malformed XML
|
||||
// Should output 0 dependencies and return false
|
||||
|
||||
TestFailureCase("leveldata_test7.xml");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEST_F(LevelBuilderTest, TestMission_MultipleDependencies)
|
||||
{
|
||||
// Tests processing a mission_*.xml file containing multiple dependencies and no Cloud texture
|
||||
// Should output 3 dependencies
|
||||
|
||||
IO::FileIOStream fileStream;
|
||||
|
||||
ASSERT_TRUE(OpenTestFile("mission_mission0_test1.xml", fileStream));
|
||||
|
||||
LevelBuilderWorker worker;
|
||||
ProductPathDependencySet productDependencies;
|
||||
|
||||
ASSERT_TRUE(worker.PopulateMissionDependenciesHelper(&fileStream, productDependencies));
|
||||
ASSERT_THAT(productDependencies, testing::UnorderedElementsAre(
|
||||
ProductPathDependency{ "EngineAssets/Materials/Sky/Sky.mtl", AssetBuilderSDK::ProductPathDependencyType::ProductFile},
|
||||
ProductPathDependency{ "EngineAssets/Materials/Water/Ocean_default.mtl", AssetBuilderSDK::ProductPathDependencyType::ProductFile},
|
||||
ProductPathDependency{ "Textures/Skys/Night/half_moon.dds", AssetBuilderSDK::ProductPathDependencyType::ProductFile}));
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, TestMission_NoSkyBox)
|
||||
{
|
||||
// Tests processing a mission_*.xml file with no skybox settings
|
||||
// Should output 0 dependencies and return false
|
||||
|
||||
TestFailureCase("mission_mission0_test2.xml");
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, TestMission_NoOcean)
|
||||
{
|
||||
// Tests processing a mission_*.xml file with no ocean settings
|
||||
// Should output 0 dependencies and return false
|
||||
|
||||
TestFailureCase("mission_mission0_test3.xml");
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, TestMission_NoMoon)
|
||||
{
|
||||
// Tests processing a mission_*.xml file with no moon settings
|
||||
// Should output 2 dependencies
|
||||
|
||||
IO::FileIOStream fileStream;
|
||||
|
||||
ASSERT_TRUE(OpenTestFile("mission_mission0_test4.xml", fileStream));
|
||||
|
||||
LevelBuilderWorker worker;
|
||||
ProductPathDependencySet productDependencies;
|
||||
|
||||
ASSERT_TRUE(worker.PopulateMissionDependenciesHelper(&fileStream, productDependencies));
|
||||
ASSERT_THAT(productDependencies, testing::UnorderedElementsAre(
|
||||
ProductPathDependency{ "EngineAssets/Materials/Sky/Sky.mtl", AssetBuilderSDK::ProductPathDependencyType::ProductFile },
|
||||
ProductPathDependency{ "EngineAssets/Materials/Water/Ocean_default.mtl", AssetBuilderSDK::ProductPathDependencyType::ProductFile }));
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, TestMission_NoEnvironment)
|
||||
{
|
||||
// Tests processing a mission_*.xml file with no environment settings
|
||||
// Should output 0 dependencies and return false
|
||||
|
||||
TestFailureCase("mission_mission0_test5.xml");
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, TestMission_EmptyFile)
|
||||
{
|
||||
// Tests processing an empty mission_*.xml
|
||||
// Should output 0 dependencies and return false
|
||||
|
||||
TestFailureCase("mission_mission0_test6.xml");
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, TestMission_CloudShadow)
|
||||
{
|
||||
// Tests processing a mission_*.xml file with cloud shadow texture set
|
||||
// Should output 4 dependencies and return true
|
||||
|
||||
using namespace AssetBuilderSDK;
|
||||
|
||||
IO::FileIOStream fileStream;
|
||||
|
||||
ASSERT_TRUE(OpenTestFile("mission_mission0_test7.xml", fileStream));
|
||||
|
||||
LevelBuilderWorker worker;
|
||||
ProductPathDependencySet productDependencies;
|
||||
|
||||
ASSERT_TRUE(worker.PopulateMissionDependenciesHelper(&fileStream, productDependencies));
|
||||
ASSERT_THAT(productDependencies, testing::UnorderedElementsAre(
|
||||
ProductPathDependency{ "EngineAssets/Materials/Sky/Sky.mtl", AssetBuilderSDK::ProductPathDependencyType::ProductFile },
|
||||
ProductPathDependency{ "EngineAssets/Materials/Water/Ocean_default.mtl", AssetBuilderSDK::ProductPathDependencyType::ProductFile },
|
||||
ProductPathDependency{ "Textures/Skys/Night/half_moon.dds", AssetBuilderSDK::ProductPathDependencyType::ProductFile },
|
||||
ProductPathDependency{ "textures/terrain/ftue_megatexture_02.dds", AssetBuilderSDK::ProductPathDependencyType::ProductFile }));
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, DynamicSlice_NoAssetReferences_HasNoProductDependencies)
|
||||
{
|
||||
LevelBuilderWorker worker;
|
||||
AZStd::vector<AssetBuilderSDK::ProductDependency> productDependencies;
|
||||
ProductPathDependencySet productPathDependencies;
|
||||
|
||||
AZStd::string filePath(GetTestFileAliasedPath("levelSlice_noAssetReferences.entities_xml"));
|
||||
ASSERT_TRUE(AZ::IO::FileIOBase::GetInstance()->Exists(filePath.c_str()));
|
||||
|
||||
worker.PopulateLevelSliceDependenciesHelper(filePath, productDependencies, productPathDependencies);
|
||||
ASSERT_EQ(productDependencies.size(), 0);
|
||||
ASSERT_EQ(productPathDependencies.size(), 0);
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, DynamicSlice_HasAssetReference_HasCorrectProductDependency)
|
||||
{
|
||||
LevelBuilderWorker worker;
|
||||
AZStd::vector<AssetBuilderSDK::ProductDependency> productDependencies;
|
||||
ProductPathDependencySet productPathDependencies;
|
||||
|
||||
AZStd::string filePath(GetTestFileAliasedPath("levelSlice_oneAssetRef.entities_xml"));
|
||||
ASSERT_TRUE(AZ::IO::FileIOBase::GetInstance()->Exists(filePath.c_str()));
|
||||
|
||||
worker.PopulateLevelSliceDependenciesHelper(filePath, productDependencies, productPathDependencies);
|
||||
ASSERT_EQ(productPathDependencies.size(), 0);
|
||||
ASSERT_EQ(productDependencies.size(), 1);
|
||||
ASSERT_EQ(productDependencies[0].m_dependencyId.m_guid, AZ::Uuid("A8970A25-5043-5519-A927-F180E7D6E8C1"));
|
||||
ASSERT_EQ(productDependencies[0].m_dependencyId.m_subId, 1);
|
||||
}
|
||||
|
||||
void BuildSliceWithSimpleAssetReference(const AZStd::vector<AZStd::string>& filePaths, AZStd::vector<AssetBuilderSDK::ProductDependency>& productDependencies, ProductPathDependencySet& productPathDependencies)
|
||||
{
|
||||
auto* assetComponent = aznew MockSimpleAssetRefComponent;
|
||||
|
||||
assetComponent->m_asset.SetAssetPath(filePaths[0].c_str());
|
||||
assetComponent->m_secondAsset.SetAssetPath(filePaths[1].c_str());
|
||||
assetComponent->m_thirdAsset.SetAssetPath(filePaths[2].c_str());
|
||||
|
||||
auto sliceAsset = AZ::Test::CreateSliceFromComponent(assetComponent, AZ::Data::AssetId(AZ::Uuid::CreateRandom(), 0));
|
||||
|
||||
LevelBuilderWorker worker;
|
||||
|
||||
worker.PopulateLevelSliceDependenciesHelper(sliceAsset, productDependencies, productPathDependencies);
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, DynamicSlice_HasPopulatedSimpleAssetReference_HasCorrectProductDependency)
|
||||
{
|
||||
AZStd::vector<AssetBuilderSDK::ProductDependency> productDependencies;
|
||||
ProductPathDependencySet productPathDependencies;
|
||||
AZStd::vector<AZStd::string> filePaths = { "some/test/path.txt", "", "" };
|
||||
BuildSliceWithSimpleAssetReference(filePaths, productDependencies, productPathDependencies);
|
||||
ASSERT_EQ(productDependencies.size(), 0);
|
||||
ASSERT_EQ(productPathDependencies.size(), 1);
|
||||
ASSERT_EQ(productPathDependencies.begin()->m_dependencyPath, filePaths[0]);
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, DynamicSlice_HasPopulatedSimpleAssetReferencesNoExtension_HasCorrectProductDependency)
|
||||
{
|
||||
AZStd::vector<AssetBuilderSDK::ProductDependency> productDependencies;
|
||||
ProductPathDependencySet productPathDependencies;
|
||||
AZStd::vector<AZStd::string> filePaths = { "some/test/path0", "some/test/path1", "some/test/path2" };
|
||||
BuildSliceWithSimpleAssetReference(filePaths, productDependencies, productPathDependencies);
|
||||
ASSERT_EQ(productDependencies.size(), 0);
|
||||
ASSERT_EQ(productPathDependencies.size(), 3);
|
||||
|
||||
ASSERT_THAT(productPathDependencies, testing::UnorderedElementsAre(
|
||||
ProductPathDependency{ "some/test/path0.txt", AssetBuilderSDK::ProductPathDependencyType::ProductFile },
|
||||
ProductPathDependency{ "some/test/path1.txt", AssetBuilderSDK::ProductPathDependencyType::ProductFile },
|
||||
ProductPathDependency{ "some/test/path2.txt", AssetBuilderSDK::ProductPathDependencyType::ProductFile }));
|
||||
}
|
||||
|
||||
TEST_F(LevelBuilderTest, DynamicSlice_HasEmptySimpleAssetReference_HasNoProductDependency)
|
||||
{
|
||||
AZStd::vector<AssetBuilderSDK::ProductDependency> productDependencies;
|
||||
ProductPathDependencySet productPathDependencies;
|
||||
AZStd::vector<AZStd::string> filePaths = { "", "", "" };
|
||||
BuildSliceWithSimpleAssetReference(filePaths, productDependencies, productPathDependencies);
|
||||
ASSERT_EQ(productDependencies.size(), 0);
|
||||
ASSERT_EQ(productPathDependencies.size(), 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,242 +17,245 @@
|
||||
#include <AzCore/IO/Path/Path.h>
|
||||
#include <AzCore/Utils/Utils.h>
|
||||
|
||||
using namespace MaterialBuilder;
|
||||
using namespace AZ;
|
||||
|
||||
class MaterialBuilderTests
|
||||
: public UnitTest::AllocatorsTestFixture
|
||||
, public UnitTest::TraceBusRedirector
|
||||
namespace UnitTest
|
||||
{
|
||||
protected:
|
||||
void SetUp() override
|
||||
using namespace MaterialBuilder;
|
||||
using namespace AZ;
|
||||
|
||||
class MaterialBuilderTests
|
||||
: public UnitTest::AllocatorsTestFixture
|
||||
, public UnitTest::TraceBusRedirector
|
||||
{
|
||||
UnitTest::AllocatorsTestFixture::SetUp();
|
||||
|
||||
m_app.reset(aznew AzToolsFramework::ToolsApplication);
|
||||
m_app->Start(AZ::ComponentApplication::Descriptor());
|
||||
// Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is
|
||||
// shared across the whole engine, if multiple tests are run in parallel, the saving could cause a crash
|
||||
// in the unit tests.
|
||||
AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize);
|
||||
AZ::Debug::TraceMessageBus::Handler::BusConnect();
|
||||
|
||||
const AZStd::string engineRoot = AZ::Test::GetEngineRootPath();
|
||||
AZ::IO::FileIOBase::GetInstance()->SetAlias("@engroot@", engineRoot.c_str());
|
||||
|
||||
AZ::IO::Path assetRoot(AZ::Utils::GetProjectPath());
|
||||
assetRoot /= "Cache";
|
||||
AZ::IO::FileIOBase::GetInstance()->SetAlias("@root@", assetRoot.c_str());
|
||||
AZ::IO::FileIOBase::GetInstance()->SetAlias("@assets@", assetRoot.c_str());
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
AZ::Debug::TraceMessageBus::Handler::BusDisconnect();
|
||||
m_app->Stop();
|
||||
m_app.reset();
|
||||
|
||||
UnitTest::AllocatorsTestFixture::TearDown();
|
||||
}
|
||||
|
||||
AZStd::string GetTestFileAliasedPath(AZStd::string_view fileName)
|
||||
{
|
||||
constexpr char testFileFolder[] = "@engroot@/Gems/LmbrCentral/Code/Tests/Materials/";
|
||||
return AZStd::string::format("%s%.*s", testFileFolder, aznumeric_cast<int>(fileName.size()), fileName.data());
|
||||
}
|
||||
|
||||
AZStd::string GetTestFileFullPath(AZStd::string_view fileName)
|
||||
{
|
||||
AZStd::string aliasedPath = GetTestFileAliasedPath(fileName);
|
||||
char resolvedPath[AZ_MAX_PATH_LEN];
|
||||
AZ::IO::FileIOBase::GetInstance()->ResolvePath(aliasedPath.c_str(), resolvedPath, AZ_MAX_PATH_LEN);
|
||||
return AZStd::string(resolvedPath);
|
||||
}
|
||||
|
||||
void TestFailureCase(AZStd::string_view fileName, [[maybe_unused]] int expectedErrorCount)
|
||||
{
|
||||
MaterialBuilderWorker worker;
|
||||
AZStd::vector<AZStd::string> resolvedPaths;
|
||||
|
||||
AZStd::string absoluteMatPath = GetTestFileFullPath(fileName);
|
||||
|
||||
AZ_TEST_START_ASSERTTEST;
|
||||
ASSERT_FALSE(worker.GetResolvedTexturePathsFromMaterial(absoluteMatPath, resolvedPaths));
|
||||
AZ_TEST_STOP_ASSERTTEST(expectedErrorCount * 2); // The assert tests double count AZ errors, so just multiply expected count by 2
|
||||
ASSERT_EQ(resolvedPaths.size(), 0);
|
||||
}
|
||||
|
||||
void TestSuccessCase(AZStd::string_view fileName, AZStd::vector<const char*>& expectedTextures)
|
||||
{
|
||||
MaterialBuilderWorker worker;
|
||||
AZStd::vector<AZStd::string> resolvedPaths;
|
||||
size_t texturesInMaterialFile = expectedTextures.size();
|
||||
|
||||
AZStd::string absoluteMatPath = GetTestFileFullPath(fileName);
|
||||
ASSERT_TRUE(worker.GetResolvedTexturePathsFromMaterial(absoluteMatPath, resolvedPaths));
|
||||
ASSERT_EQ(resolvedPaths.size(), texturesInMaterialFile);
|
||||
if (texturesInMaterialFile > 0 )
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
ASSERT_THAT(resolvedPaths, testing::ElementsAreArray(expectedTextures));
|
||||
UnitTest::AllocatorsTestFixture::SetUp();
|
||||
|
||||
AssetBuilderSDK::ProductPathDependencySet dependencies;
|
||||
ASSERT_TRUE(worker.PopulateProductDependencyList(resolvedPaths, dependencies));
|
||||
ASSERT_EQ(dependencies.size(), texturesInMaterialFile);
|
||||
m_app.reset(aznew AzToolsFramework::ToolsApplication);
|
||||
m_app->Start(AZ::ComponentApplication::Descriptor());
|
||||
// Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is
|
||||
// shared across the whole engine, if multiple tests are run in parallel, the saving could cause a crash
|
||||
// in the unit tests.
|
||||
AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize);
|
||||
AZ::Debug::TraceMessageBus::Handler::BusConnect();
|
||||
|
||||
const AZStd::string engineRoot = AZ::Test::GetEngineRootPath();
|
||||
AZ::IO::FileIOBase::GetInstance()->SetAlias("@engroot@", engineRoot.c_str());
|
||||
|
||||
AZ::IO::Path assetRoot(AZ::Utils::GetProjectPath());
|
||||
assetRoot /= "Cache";
|
||||
AZ::IO::FileIOBase::GetInstance()->SetAlias("@root@", assetRoot.c_str());
|
||||
AZ::IO::FileIOBase::GetInstance()->SetAlias("@assets@", assetRoot.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void TestSuccessCase(AZStd::string_view fileName, const char* expectedTexture)
|
||||
void TearDown() override
|
||||
{
|
||||
AZ::Debug::TraceMessageBus::Handler::BusDisconnect();
|
||||
m_app->Stop();
|
||||
m_app.reset();
|
||||
|
||||
UnitTest::AllocatorsTestFixture::TearDown();
|
||||
}
|
||||
|
||||
AZStd::string GetTestFileAliasedPath(AZStd::string_view fileName)
|
||||
{
|
||||
constexpr char testFileFolder[] = "@engroot@/Gems/LmbrCentral/Code/Tests/Materials/";
|
||||
return AZStd::string::format("%s%.*s", testFileFolder, aznumeric_cast<int>(fileName.size()), fileName.data());
|
||||
}
|
||||
|
||||
AZStd::string GetTestFileFullPath(AZStd::string_view fileName)
|
||||
{
|
||||
AZStd::string aliasedPath = GetTestFileAliasedPath(fileName);
|
||||
char resolvedPath[AZ_MAX_PATH_LEN];
|
||||
AZ::IO::FileIOBase::GetInstance()->ResolvePath(aliasedPath.c_str(), resolvedPath, AZ_MAX_PATH_LEN);
|
||||
return AZStd::string(resolvedPath);
|
||||
}
|
||||
|
||||
void TestFailureCase(AZStd::string_view fileName, [[maybe_unused]] int expectedErrorCount)
|
||||
{
|
||||
MaterialBuilderWorker worker;
|
||||
AZStd::vector<AZStd::string> resolvedPaths;
|
||||
|
||||
AZStd::string absoluteMatPath = GetTestFileFullPath(fileName);
|
||||
|
||||
AZ_TEST_START_ASSERTTEST;
|
||||
ASSERT_FALSE(worker.GetResolvedTexturePathsFromMaterial(absoluteMatPath, resolvedPaths));
|
||||
AZ_TEST_STOP_ASSERTTEST(expectedErrorCount * 2); // The assert tests double count AZ errors, so just multiply expected count by 2
|
||||
ASSERT_EQ(resolvedPaths.size(), 0);
|
||||
}
|
||||
|
||||
void TestSuccessCase(AZStd::string_view fileName, AZStd::vector<const char*>& expectedTextures)
|
||||
{
|
||||
MaterialBuilderWorker worker;
|
||||
AZStd::vector<AZStd::string> resolvedPaths;
|
||||
size_t texturesInMaterialFile = expectedTextures.size();
|
||||
|
||||
AZStd::string absoluteMatPath = GetTestFileFullPath(fileName);
|
||||
ASSERT_TRUE(worker.GetResolvedTexturePathsFromMaterial(absoluteMatPath, resolvedPaths));
|
||||
ASSERT_EQ(resolvedPaths.size(), texturesInMaterialFile);
|
||||
if (texturesInMaterialFile > 0)
|
||||
{
|
||||
ASSERT_THAT(resolvedPaths, testing::ElementsAreArray(expectedTextures));
|
||||
|
||||
AssetBuilderSDK::ProductPathDependencySet dependencies;
|
||||
ASSERT_TRUE(worker.PopulateProductDependencyList(resolvedPaths, dependencies));
|
||||
ASSERT_EQ(dependencies.size(), texturesInMaterialFile);
|
||||
}
|
||||
}
|
||||
|
||||
void TestSuccessCase(AZStd::string_view fileName, const char* expectedTexture)
|
||||
{
|
||||
AZStd::vector<const char*> expectedTextures;
|
||||
expectedTextures.push_back(expectedTexture);
|
||||
TestSuccessCase(fileName, expectedTextures);
|
||||
}
|
||||
|
||||
void TestSuccessCaseNoDependencies(AZStd::string_view fileName)
|
||||
{
|
||||
AZStd::vector<const char*> expectedTextures;
|
||||
TestSuccessCase(fileName, expectedTextures);
|
||||
}
|
||||
|
||||
AZStd::unique_ptr<AzToolsFramework::ToolsApplication> m_app;
|
||||
};
|
||||
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_EmptyFile_ExpectFailure)
|
||||
{
|
||||
AZStd::vector<const char*> expectedTextures;
|
||||
expectedTextures.push_back(expectedTexture);
|
||||
TestSuccessCase(fileName, expectedTextures);
|
||||
// Should fail in MaterialBuilderWorker::GetResolvedTexturePathsFromMaterial, when checking for the size of the file.
|
||||
TestFailureCase("test_mat1.mtl", 1);
|
||||
}
|
||||
|
||||
void TestSuccessCaseNoDependencies(AZStd::string_view fileName)
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_MalformedMaterial_NoChildren_ExpectFailure)
|
||||
{
|
||||
AZStd::vector<const char*> expectedTextures;
|
||||
TestSuccessCase(fileName, expectedTextures);
|
||||
// Should fail in MaterialBuilderWorker::GetResolvedTexturePathsFromMaterial after calling
|
||||
// Internal::GetTexturePathsFromMaterial, which should return an AZ::Failure when both a Textures node and a
|
||||
// SubMaterials node are not found. No other AZ_Errors should be generated.
|
||||
TestFailureCase("test_mat2.mtl", 1);
|
||||
}
|
||||
|
||||
AZStd::unique_ptr<AzToolsFramework::ToolsApplication> m_app;
|
||||
};
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_MalformedMaterial_EmptyTexturesNode_NoDependencies)
|
||||
{
|
||||
TestSuccessCaseNoDependencies("test_mat3.mtl");
|
||||
}
|
||||
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_EmptyFile_ExpectFailure)
|
||||
{
|
||||
// Should fail in MaterialBuilderWorker::GetResolvedTexturePathsFromMaterial, when checking for the size of the file.
|
||||
TestFailureCase("test_mat1.mtl", 1);
|
||||
}
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_MalformedMaterial_EmptySubMaterialNode_ExpectFailure)
|
||||
{
|
||||
// Should fail in MaterialBuilderWorker::GetResolvedTexturePathsFromMaterial after calling
|
||||
// Internal::GetTexturePathsFromMaterial, which should return an AZ::Failure when a SubMaterials node is present,
|
||||
// but has no children Material node. No other AZ_Errors should be generated.
|
||||
TestFailureCase("test_mat4.mtl", 1);
|
||||
}
|
||||
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_MalformedMaterial_NoChildren_ExpectFailure)
|
||||
{
|
||||
// Should fail in MaterialBuilderWorker::GetResolvedTexturePathsFromMaterial after calling
|
||||
// Internal::GetTexturePathsFromMaterial, which should return an AZ::Failure when both a Textures node and a
|
||||
// SubMaterials node are not found. No other AZ_Errors should be generated.
|
||||
TestFailureCase("test_mat2.mtl", 1);
|
||||
}
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_MalformedMaterial_EmptyTextureNode_NoDependencies)
|
||||
{
|
||||
TestSuccessCaseNoDependencies("test_mat5.mtl");
|
||||
}
|
||||
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_MalformedMaterial_EmptyTexturesNode_NoDependencies)
|
||||
{
|
||||
TestSuccessCaseNoDependencies("test_mat3.mtl");
|
||||
}
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_MalformedMaterial_EmptyMaterialInSubMaterial_ExpectFailure)
|
||||
{
|
||||
// Should fail in MaterialBuilderWorker::GetResolvedTexturePathsFromMaterial after calling
|
||||
// Internal::GetTexturePathsFromMaterial, which should return an AZ::Failure when a SubMaterials node is present,
|
||||
// but a child Material node has no child Textures node and no child SubMaterials node. No other AZ_Errors should
|
||||
// be generated.
|
||||
TestFailureCase("test_mat6.mtl", 1);
|
||||
}
|
||||
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_MalformedMaterial_EmptySubMaterialNode_ExpectFailure)
|
||||
{
|
||||
// Should fail in MaterialBuilderWorker::GetResolvedTexturePathsFromMaterial after calling
|
||||
// Internal::GetTexturePathsFromMaterial, which should return an AZ::Failure when a SubMaterials node is present,
|
||||
// but has no children Material node. No other AZ_Errors should be generated.
|
||||
TestFailureCase("test_mat4.mtl", 1);
|
||||
}
|
||||
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_MalformedMaterial_EmptyTextureNode_NoDependencies)
|
||||
{
|
||||
TestSuccessCaseNoDependencies("test_mat5.mtl");
|
||||
}
|
||||
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_MalformedMaterial_EmptyMaterialInSubMaterial_ExpectFailure)
|
||||
{
|
||||
// Should fail in MaterialBuilderWorker::GetResolvedTexturePathsFromMaterial after calling
|
||||
// Internal::GetTexturePathsFromMaterial, which should return an AZ::Failure when a SubMaterials node is present,
|
||||
// but a child Material node has no child Textures node and no child SubMaterials node. No other AZ_Errors should
|
||||
// be generated.
|
||||
TestFailureCase("test_mat6.mtl", 1);
|
||||
}
|
||||
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_MalformedMaterial_EmptyTextureNodeInSubMaterial_NoDependencies)
|
||||
{
|
||||
TestSuccessCaseNoDependencies("test_mat7.mtl");
|
||||
}
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_MalformedMaterial_EmptyTextureNodeInSubMaterial_NoDependencies)
|
||||
{
|
||||
TestSuccessCaseNoDependencies("test_mat7.mtl");
|
||||
}
|
||||
|
||||
#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS // The following test file 'test_mat8.mtl' has a windows-specific absolute path, so this test is only valid on windows
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_TextureAbsolutePath_NoDependencies)
|
||||
{
|
||||
TestSuccessCaseNoDependencies("test_mat8.mtl");
|
||||
}
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_TextureAbsolutePath_NoDependencies)
|
||||
{
|
||||
TestSuccessCaseNoDependencies("test_mat8.mtl");
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_TextureRuntimeAlias_NoDependencies)
|
||||
{
|
||||
TestSuccessCaseNoDependencies("test_mat9.mtl");
|
||||
}
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_TextureRuntimeAlias_NoDependencies)
|
||||
{
|
||||
TestSuccessCaseNoDependencies("test_mat9.mtl");
|
||||
}
|
||||
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_TextureRuntimeTexture_NoDependencies)
|
||||
{
|
||||
TestSuccessCaseNoDependencies("test_mat10.mtl");
|
||||
}
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_TextureRuntimeTexture_NoDependencies)
|
||||
{
|
||||
TestSuccessCaseNoDependencies("test_mat10.mtl");
|
||||
}
|
||||
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_SingleMaterialSingleTexture_ValidSourceFormat)
|
||||
{
|
||||
// texture referenced is textures/natural/terrain/am_floor_tile_ddn.png
|
||||
const char* expectedPath = "textures/natural/terrain/am_floor_tile_ddn.dds";
|
||||
TestSuccessCase("test_mat11.mtl", expectedPath);
|
||||
}
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_SingleMaterialSingleTexture_ValidSourceFormat)
|
||||
{
|
||||
// texture referenced is textures/natural/terrain/am_floor_tile_ddn.png
|
||||
const char* expectedPath = "textures/natural/terrain/am_floor_tile_ddn.dds";
|
||||
TestSuccessCase("test_mat11.mtl", expectedPath);
|
||||
}
|
||||
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_SingleMaterialSingleTexture_ValidProductFormat)
|
||||
{
|
||||
// texture referenced is textures/natural/terrain/am_floor_tile_ddn.dds
|
||||
const char* expectedPath = "textures/natural/terrain/am_floor_tile_ddn.dds";
|
||||
TestSuccessCase("test_mat12.mtl", expectedPath);
|
||||
}
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_SingleMaterialSingleTexture_ValidProductFormat)
|
||||
{
|
||||
// texture referenced is textures/natural/terrain/am_floor_tile_ddn.dds
|
||||
const char* expectedPath = "textures/natural/terrain/am_floor_tile_ddn.dds";
|
||||
TestSuccessCase("test_mat12.mtl", expectedPath);
|
||||
}
|
||||
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_SingleMaterialSingleTexture_InvalidSourceFormat_NoDependenices)
|
||||
{
|
||||
// texture referenced is textures/natural/terrain/am_floor_tile_ddn.txt
|
||||
TestSuccessCaseNoDependencies("test_mat13.mtl");
|
||||
}
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_SingleMaterialSingleTexture_InvalidSourceFormat_NoDependenices)
|
||||
{
|
||||
// texture referenced is textures/natural/terrain/am_floor_tile_ddn.txt
|
||||
TestSuccessCaseNoDependencies("test_mat13.mtl");
|
||||
}
|
||||
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_TextureAnimSequence)
|
||||
{
|
||||
AZStd::vector<const char*> expectedPaths = {
|
||||
"path/to/my/textures/test_anim_sequence_01_texture000.dds",
|
||||
"path/to/my/textures/test_anim_sequence_01_texture001.dds",
|
||||
"path/to/my/textures/test_anim_sequence_01_texture002.dds",
|
||||
"path/to/my/textures/test_anim_sequence_01_texture003.dds",
|
||||
"path/to/my/textures/test_anim_sequence_01_texture004.dds",
|
||||
"path/to/my/textures/test_anim_sequence_01_texture005.dds"
|
||||
};
|
||||
TestSuccessCase("test_mat14.mtl", expectedPaths);
|
||||
}
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_TextureAnimSequence)
|
||||
{
|
||||
AZStd::vector<const char*> expectedPaths = {
|
||||
"path/to/my/textures/test_anim_sequence_01_texture000.dds",
|
||||
"path/to/my/textures/test_anim_sequence_01_texture001.dds",
|
||||
"path/to/my/textures/test_anim_sequence_01_texture002.dds",
|
||||
"path/to/my/textures/test_anim_sequence_01_texture003.dds",
|
||||
"path/to/my/textures/test_anim_sequence_01_texture004.dds",
|
||||
"path/to/my/textures/test_anim_sequence_01_texture005.dds"
|
||||
};
|
||||
TestSuccessCase("test_mat14.mtl", expectedPaths);
|
||||
}
|
||||
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_SingleMaterialMultipleTexture)
|
||||
{
|
||||
AZStd::vector<const char*> expectedPaths = {
|
||||
"engineassets/textures/hex.dds",
|
||||
"engineassets/textures/hex_ddn.dds"
|
||||
};
|
||||
TestSuccessCase("test_mat15.mtl", expectedPaths);
|
||||
}
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_SingleMaterialMultipleTexture)
|
||||
{
|
||||
AZStd::vector<const char*> expectedPaths = {
|
||||
"engineassets/textures/hex.dds",
|
||||
"engineassets/textures/hex_ddn.dds"
|
||||
};
|
||||
TestSuccessCase("test_mat15.mtl", expectedPaths);
|
||||
}
|
||||
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_MalformedMaterial_MultipleTextures_OneEmptyTexture)
|
||||
{
|
||||
TestSuccessCase("test_mat16.mtl", "engineassets/textures/hex_ddn.dds");
|
||||
}
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_MalformedMaterial_MultipleTextures_OneEmptyTexture)
|
||||
{
|
||||
TestSuccessCase("test_mat16.mtl", "engineassets/textures/hex_ddn.dds");
|
||||
}
|
||||
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_SingleMaterialMultipleTexture_ResolveLeadingSeparatorsAndAliases)
|
||||
{
|
||||
AZStd::vector<const char*> expectedPaths = {
|
||||
"engineassets/textures/hex.dds", // resolved from "/engineassets/textures/hex.dds"
|
||||
"engineassets/textures/hex_ddn.dds", // resolved from "./engineassets/textures/hex_ddn.dds"
|
||||
"engineassets/textures/hex_spec.dds" // resolved from "@assets@/engineassets/textures/hex_spec.dds"
|
||||
};
|
||||
TestSuccessCase("test_mat17.mtl", expectedPaths);
|
||||
}
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_SingleMaterialMultipleTexture_ResolveLeadingSeparatorsAndAliases)
|
||||
{
|
||||
AZStd::vector<const char*> expectedPaths = {
|
||||
"engineassets/textures/hex.dds", // resolved from "/engineassets/textures/hex.dds"
|
||||
"engineassets/textures/hex_ddn.dds", // resolved from "./engineassets/textures/hex_ddn.dds"
|
||||
"engineassets/textures/hex_spec.dds" // resolved from "@assets@/engineassets/textures/hex_spec.dds"
|
||||
};
|
||||
TestSuccessCase("test_mat17.mtl", expectedPaths);
|
||||
}
|
||||
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_SubMaterialSingleTexture)
|
||||
{
|
||||
AZStd::vector<const char*> expectedPaths = {
|
||||
"engineassets/textures/scratch.dds",
|
||||
"engineassets/textures/perlinnoise2d.dds"
|
||||
};
|
||||
TestSuccessCase("test_mat18.mtl", expectedPaths);
|
||||
}
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_SubMaterialSingleTexture)
|
||||
{
|
||||
AZStd::vector<const char*> expectedPaths = {
|
||||
"engineassets/textures/scratch.dds",
|
||||
"engineassets/textures/perlinnoise2d.dds"
|
||||
};
|
||||
TestSuccessCase("test_mat18.mtl", expectedPaths);
|
||||
}
|
||||
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_SubMaterialMultipleTexture)
|
||||
{
|
||||
AZStd::vector<const char*> expectedPaths = {
|
||||
"engineassets/textures/scratch.dds",
|
||||
"engineassets/textures/scratch_ddn.dds",
|
||||
"engineassets/textures/perlinnoise2d.dds",
|
||||
"engineassets/textures/perlinnoisenormal_ddn.dds"
|
||||
};
|
||||
TestSuccessCase("test_mat19.mtl", expectedPaths);
|
||||
TEST_F(MaterialBuilderTests, MaterialBuilder_SubMaterialMultipleTexture)
|
||||
{
|
||||
AZStd::vector<const char*> expectedPaths = {
|
||||
"engineassets/textures/scratch.dds",
|
||||
"engineassets/textures/scratch_ddn.dds",
|
||||
"engineassets/textures/perlinnoise2d.dds",
|
||||
"engineassets/textures/perlinnoisenormal_ddn.dds"
|
||||
};
|
||||
TestSuccessCase("test_mat19.mtl", expectedPaths);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user