Files
o3de/Code/Framework/AzToolsFramework/Tests/EntityInspectorTests.cpp
T
lumberyard-employee-dm 3dec5d3b71 LYN-2537 engine assets (#254)
* LYN-2537 Moved the Engine and Editor folder to be within the EngineAssets folder

* Fixed Documentation in bootstrap.cfg to correct the path to the user project specific registry file

* Adding a newline to the output of AssetCatalog 'Registering asset..., but type is not set' message

* Updating the AssetProcessorPlatformConfig.setreg Scan Folder to detect
the @ENGINEROOT@/EngineAssets/Engine path for engine runtime assets and
@ENGINEROOT@/EngineAssets/Editor path for engine tool assets

* Updating references to Icons and other assets to account for moving the
Engine and Editor folder under a single EngineAssets folder

* Moving the Engine Settings Registry folder from Engine/Registry -> Registry

* Removed the LY_PROJECT_CMAKE_PATH define as it is not portable to other locations. It is hard coded to the project location that was used for the CMake configuration. Furthermore it paths with backslashes within it are treated as escape characters and not a path separator

* Updated the LyTestTools asset_processor.py script to copy the exclude.filetag from the EngineAssets/Engine directory now

* Fixed Atom Shader Preprocessing when running using an External Project

* Updated the TSGenerateAction.cpp to fix the build error with using a renamed variable

* Updated the Install_Common.cmake ly_setup_others function to install the
EngineAssets directory and the each of the Gem's Assets directory while
maintaining the relative directory structure to the Engine Root
Also updated the install step to install the Registry folder at the
engine root

* Fixed the copying of the Registry folder to be in the install root, instead of under a second 'Registry' folder

* Moving the AssetProcessorPlatformConfig.setreg file over to the Registry folder

* Updated the LyTestTools and C++ code to point that the new location of
the AssetProcessorPlatformConfig.setreg file inside of the Registry
folder

* Renamed Test AssetProcessor*Config.ini files to have the .setreg extension

* Converted the AssetProcessor test setreg files from ini format to json
format using the SerializeContextTools convert-ini command

* Updated the AssetProcessor CMakeLists.txt to copy over the test setreg files to the build folder

* Updated the assetprocessor test file list to point at the renamed AsssetProcessor*Config setreg filenames

* Removed the Output Prefix code from the AssetProcessor. The complexity that it brought to the AP code is not needed, as users can replicate the behavior by just moving there assets underneath a another folder, underneath the scan folder

* Adding back support to read the AssetProcessorPlatformConfig.setreg file from the asset root. This is only needed for C++ UnitTests as they run in an environment where the accessing the Engine Settings Registry is not available

* Updating the Install_common.cmake logic to copy any "Assets" folder to
the install layout.
The Script has also been updated to copy over the "Assets" folder in the
Engine Root to the install layout instead of an "EngineAssets" folder

* Updating References to EngineAssets source asset folder in code to be the Assets source folder

* Moved the Engine Source Asset folder of 'EngineAssets' to a new folder name of 'Assets'. This is inline with the naming scheme we use for Gem asset folders

* Adding the EngineFinder.cmake to the AutomatedTesting project to allow it to work in a project centric manner

* Updating the LyTestTools copy_assets_to_project function to be able to copy assets with folders to the temporary project root
Fixed an issue in LyTestTools where the temporary log directory could have shutil.rmtree being called twice on it leading to an exception which fails an automated test

Updated the asset_procesor_gui_tests_2 AddScanFolder test to not use the
output prefix, but instead place the source asset root into a
subdirectory

* Correct the AssetProcessorPlatformConfig Scan Folders for the EngineAssets directory to point at the Assets directory

* Updated the asset procesor batch dependency test scan folder to point at the 'Assets' folder instead of 'EngineAssets'
2021-04-28 21:38:43 -05:00

381 lines
17 KiB
C++

/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Test Environment
#include <AzCore/UnitTest/TestTypes.h>
#include <AzCore/Component/Component.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/UserSettings/UserSettingsComponent.h>
#include <AzToolsFramework/Application/ToolsApplication.h>
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
#include <AzToolsFramework/UnitTest/ToolsTestApplication.h>
// Inspector Test Includes
#include <AzToolsFramework/UI/ComponentPalette/ComponentPaletteUtil.hxx>
namespace UnitTest
{
// Test component that is NOT available for a user to interact with
// It does not appear in the Add Component menu in the Editor
// It is not a system or game component
class Inspector_TestComponent1
: public AZ::Component
{
public:
AZ_COMPONENT(Inspector_TestComponent1, "{BD25A077-DF38-4B67-BEA5-F4587A747A36}", AZ::Component);
static void Reflect(AZ::ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<Inspector_TestComponent1, AZ::Component>()
->Field("Data", &Inspector_TestComponent1::m_data)
;
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
{
editContext->Class<Inspector_TestComponent1>("InspectorTestComponent1", "Component 1 for AZ Tools Framework Unit Tests")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::AddableByUser, false)
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::Hide)
->Attribute(AZ::Edit::Attributes::SliceFlags, AZ::Edit::SliceFlags::NotPushable)
->Attribute(AZ::Edit::Attributes::HideIcon, true);
}
}
}
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services)
{
services.push_back(AZ_CRC("InspectorTestService1"));
}
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& services)
{
services.push_back(AZ_CRC("InspectorTestService1"));
}
virtual ~Inspector_TestComponent1() override
{
}
void SetData(int data)
{
m_data = data;
};
int GetData()
{
return m_data;
}
private:
void Init() override
{}
void Activate() override
{}
void Deactivate() override
{}
/// Whether this entity is locked
int m_data = 0;
};
// Test component that IS available for a user to interact with
// It does appear in the Add Component menu in the editor and is a game component
class Inspector_TestComponent2
: public AZ::Component
{
public:
AZ_COMPONENT(Inspector_TestComponent2, "{57D1C818-FD31-4FCD-A4DB-705EABF4E98B}", AZ::Component);
static void Reflect(AZ::ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<Inspector_TestComponent2, AZ::Component>()
->Field("Data", &Inspector_TestComponent2::m_data)
;
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
{
editContext->Class<Inspector_TestComponent2>("InspectorTestComponent2", "Component 2 for AZ Tools Framework Unit Tests")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::AddableByUser, true)
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game"))
->Attribute(AZ::Edit::Attributes::Category, "Inspector Test Components")
->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/Tag.png")
->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/Tag.png")
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://www.amazongames.com/")
->DataElement(AZ::Edit::UIHandlers::Default, &Inspector_TestComponent2::m_data, "Data", "The component's Data");
}
}
}
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services)
{
services.push_back(AZ_CRC("InspectorTestService2"));
}
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& services)
{
services.push_back(AZ_CRC("InspectorTestService2"));
}
virtual ~Inspector_TestComponent2() override
{
}
void SetData(int data)
{
m_data = data;
};
int GetData()
{
return m_data;
}
private:
void Init() override
{}
void Activate() override
{}
void Deactivate() override
{}
/// Whether this entity is locked
int m_data = 0;
};
// Test component that IS available for a user to interact with
// It does appear in an Add Component menu and is a system component
class Inspector_TestComponent3
: public AZ::Component
{
public:
AZ_COMPONENT(Inspector_TestComponent3, "{552CCFB1-135E-4B02-A492-25A3BBDFA381}", AZ::Component);
static void Reflect(AZ::ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<Inspector_TestComponent3, AZ::Component>()
->Field("Data", &Inspector_TestComponent3::m_data)
;
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
{
editContext->Class<Inspector_TestComponent3>("InspectorTestComponent3", "Component 3 for AZ Tools Framework Unit Tests")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::AddableByUser, true)
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System"))
->Attribute(AZ::Edit::Attributes::Category, "Inspector Test Components")
->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/Tag.png")
->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/Tag.png")
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://www.amazongames.com/")
->DataElement(AZ::Edit::UIHandlers::Default, &Inspector_TestComponent3::m_data, "Data", "The component's Data");
}
}
}
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services)
{
services.push_back(AZ_CRC("InspectorTestService3"));
}
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& services)
{
services.push_back(AZ_CRC("InspectorTestService3"));
}
virtual ~Inspector_TestComponent3() override
{
}
void SetData(int data)
{
m_data = data;
};
int GetData()
{
return m_data;
}
private:
void Init() override
{}
void Activate() override
{}
void Deactivate() override
{}
/// Whether this entity is locked
int m_data = 0;
};
// Component Filters for Testing
bool Filter_IsTestComponent1(const AZ::SerializeContext::ClassData& classData)
{
AZ::Uuid testComponent1_typeId = azrtti_typeid<Inspector_TestComponent1>();
return classData.m_typeId == testComponent1_typeId;
}
// Component Filters for Testing
bool Filter_IsTestComponent2(const AZ::SerializeContext::ClassData& classData)
{
AZ::Uuid testComponent2_typeId = azrtti_typeid<Inspector_TestComponent2>();
return classData.m_typeId == testComponent2_typeId;
}
// Component Filters for Testing
bool Filter_IsTestComponent3(const AZ::SerializeContext::ClassData& classData)
{
AZ::Uuid testComponent3_typeId = azrtti_typeid<Inspector_TestComponent2>();
return classData.m_typeId == testComponent3_typeId;
}
class ComponentPaletteTests
: public AllocatorsTestFixture
{
public:
ComponentPaletteTests()
: AllocatorsTestFixture()
{ }
void SetUp() override
{
AZ::ComponentApplication::Descriptor componentApplicationDesc;
componentApplicationDesc.m_useExistingAllocator = true;
m_application = aznew ToolsTestApplication("ComponentPaletteTests");
m_application->Start(componentApplicationDesc);
// 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);
}
void TearDown() override
{
// Release all slice asset references, so AssetManager doens't complain.
delete m_application;
}
public:
ToolsTestApplication* m_application = nullptr;
};
// Test pushing slices to create news slices that could result in cyclic
// dependency, e.g. push slice1 => slice2 and slice2 => slice1 at the same
// time.
TEST_F(ComponentPaletteTests, TestComponentPalleteUtilities)
{
AZ::SerializeContext* context = m_application->GetSerializeContext();
// Register our test components (This process also reflects them to the appropriate contexts)
auto* Inspector_TestComponent1Descriptor = Inspector_TestComponent1::CreateDescriptor();
auto* Inspector_TestComponent2Descriptor = Inspector_TestComponent2::CreateDescriptor();
auto* Inspector_TestComponent3Descriptor = Inspector_TestComponent3::CreateDescriptor();
m_application->RegisterComponentDescriptor(Inspector_TestComponent1Descriptor);
m_application->RegisterComponentDescriptor(Inspector_TestComponent2Descriptor);
m_application->RegisterComponentDescriptor(Inspector_TestComponent3Descriptor);
AZ::Uuid testComponent1_typeId = azrtti_typeid<Inspector_TestComponent1>();
AZ::Uuid testComponent2_typeId = azrtti_typeid<Inspector_TestComponent2>();
//////////////////////////////////////////////////////////////////////////
// TEST OffersRequiredServices()
//////////////////////////////////////////////////////////////////////////
// Verify that OffersRequiredServices returns true with the services provided by the component.
AZ::ComponentDescriptor::DependencyArrayType testComponent1_ProvidedServices;
Inspector_TestComponent1::GetProvidedServices(testComponent1_ProvidedServices);
AZ_TEST_ASSERT(testComponent1_ProvidedServices.size() == 1);
const AZ::SerializeContext::ClassData* testComponent1_ClassData = context->FindClassData(testComponent1_typeId);
EXPECT_TRUE(AzToolsFramework::ComponentPaletteUtil::OffersRequiredServices(testComponent1_ClassData, testComponent1_ProvidedServices));
// Verify that OffersRequiredServices returns when given services provided by a different component
AZ::ComponentDescriptor::DependencyArrayType testComponent2_ProvidedServices;
Inspector_TestComponent2::GetProvidedServices(testComponent2_ProvidedServices);
AZ_TEST_ASSERT(testComponent2_ProvidedServices.size() == 1);
AZ_TEST_ASSERT(testComponent1_ProvidedServices != testComponent2_ProvidedServices);
EXPECT_FALSE(AzToolsFramework::ComponentPaletteUtil::OffersRequiredServices(testComponent1_ClassData, testComponent2_ProvidedServices));
// verify that OffersRequiredServices returns true when provided with an empty list of services
EXPECT_TRUE(AzToolsFramework::ComponentPaletteUtil::OffersRequiredServices(testComponent1_ClassData, AZ::ComponentDescriptor::DependencyArrayType()));
//////////////////////////////////////////////////////////////////////////
// TEST IsAddableByUser()
//////////////////////////////////////////////////////////////////////////
// Verify that IsAddableByUser returns false when given a component that is not editable or viewable by the user
EXPECT_FALSE(AzToolsFramework::ComponentPaletteUtil::IsAddableByUser(testComponent1_ClassData));
// Verify that IsAddableByUser returns true when given a component that has the appropriate edit context reflection
const AZ::SerializeContext::ClassData* testComponent2_ClassData = context->FindClassData(testComponent2_typeId);
EXPECT_TRUE(AzToolsFramework::ComponentPaletteUtil::IsAddableByUser(testComponent2_ClassData));
//////////////////////////////////////////////////////////////////////////
// TEST ContainsEditableComponents()
//////////////////////////////////////////////////////////////////////////
// Remove reflection of Test Component 2 for the first test
m_application->UnregisterComponentDescriptor(Inspector_TestComponent2Descriptor);
context->EnableRemoveReflection();
Inspector_TestComponent2::Reflect(context);
context->DisableRemoveReflection();
// Verify that there are no components that satisfy the AppearsInGameComponentMenu filter without service dependency conditions
EXPECT_FALSE(AzToolsFramework::ComponentPaletteUtil::ContainsEditableComponents(context, &Filter_IsTestComponent2, AZ::ComponentDescriptor::DependencyArrayType()));
// Reflect Test Component 2 for subsequent tests
Inspector_TestComponent2::Reflect(context);
m_application->RegisterComponentDescriptor(Inspector_TestComponent2Descriptor);
// Verify that there is now a component that satisfies the AppearsInGameComponentMenu filter without service dependency conditions
EXPECT_TRUE(AzToolsFramework::ComponentPaletteUtil::ContainsEditableComponents(context, &Filter_IsTestComponent2, AZ::ComponentDescriptor::DependencyArrayType()));
// Verify that true is returned here because test component 2 is editable and provides test component 2 services
EXPECT_TRUE(AzToolsFramework::ComponentPaletteUtil::ContainsEditableComponents(context, &Filter_IsTestComponent2, testComponent2_ProvidedServices));
// Verify that false is returned here because test component 2 does not provide any of the required services
EXPECT_FALSE(AzToolsFramework::ComponentPaletteUtil::ContainsEditableComponents(context, &Filter_IsTestComponent2, testComponent1_ProvidedServices));
// Verify that even though Test Component 1 exists and is returned by the filter and there are no services to match, false is returned
// because Test Component 1 is not editable.
EXPECT_FALSE(AzToolsFramework::ComponentPaletteUtil::ContainsEditableComponents(context, &Filter_IsTestComponent1, AZ::ComponentDescriptor::DependencyArrayType()));
// Verify that true is returned here when a system component is editable
EXPECT_TRUE(AzToolsFramework::ComponentPaletteUtil::ContainsEditableComponents(context, &Filter_IsTestComponent3, AZ::ComponentDescriptor::DependencyArrayType()));
}
}