123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #include "EMotionFXBuilderFixture.h"
- #include <EMotionFX/Pipeline/EMotionFXBuilder/AnimGraphBuilderWorker.h>
- #include <EMotionFX/Pipeline/EMotionFXBuilder/MotionSetBuilderWorker.h>
- #include <AzTest/AzTest.h>
- #include <AzCore/Asset/AssetManager.h>
- #include <AzCore/Asset/AssetSerializer.h>
- #include <AzCore/Component/ComponentApplication.h>
- #include <AzCore/std/containers/vector.h>
- #include <AzCore/std/string/string.h>
- #include <AzCore/UnitTest/UnitTest.h>
- #include <AzFramework/IO/LocalFileIO.h>
- #include <Tests/Asset/MockLoadAssetCatalogAndHandler.h>
- namespace EMotionFX
- {
- class EMotionFXBuilderTests
- : public EMotionFXBuilderFixture
- {
- protected:
- void SetUp() override
- {
- EMotionFXBuilderFixture::SetUp();
- }
- void TearDown() override
- {
- AZ::Data::AssetManager::Instance().PrepareShutDown();
- EMotionFXBuilderFixture::TearDown();
- }
- };
- TEST_F(EMotionFXBuilderTests, TestAnimGraphAsset_HasReferenceNode_OutputProductDependencies)
- {
- AZ::Data::AssetId referencedAnimGraph("96025290-BCC9-5382-AFC0-8B47CEF63018", 0);
- AZ::Data::AssetId referencedMotionSet("6455D020-F4CE-5F57-8557-315C0C968122", 0);
- // Create a mock AssetManager catalog that will fake load any registered asset IDs. This is necessary because during the call to
- // ParseProductDependencies, the reference node will get initialized and attempt to load any dependent assets.
- // By using this mock catalog, we can pretend to load the specific referenced assets without actually loading anything.
- UnitTest::MockLoadAssetCatalogAndHandler testAssetCatalog({ referencedAnimGraph, referencedMotionSet });
- const AZStd::string fileName = "@gemroot:EMotionFX@/Code/Tests/TestAssets/EMotionFXBuilderTestAssets/AnimGraphExample.animgraph";
- AZStd::vector<AssetBuilderSDK::ProductDependency> productDependencies;
- EMotionFXBuilder::AnimGraphBuilderWorker builderWorker;
- ASSERT_TRUE(builderWorker.ParseProductDependencies(fileName, fileName, productDependencies));
- ASSERT_TRUE(productDependencies.size() == 2);
- ASSERT_EQ(productDependencies[0].m_dependencyId, referencedAnimGraph);
- ASSERT_EQ(productDependencies[1].m_dependencyId, referencedMotionSet);
- }
- TEST_F(EMotionFXBuilderTests, TestAnimGraphAsset_NoDependency_OutputNoProductDependencies)
- {
- const AZStd::string fileName = "@gemroot:EMotionFX@/Code/Tests/TestAssets/EMotionFXBuilderTestAssets/AnimGraphExampleNoDependency.animgraph";
- AZStd::vector<AssetBuilderSDK::ProductDependency> productDependencies;
- EMotionFXBuilder::AnimGraphBuilderWorker builderWorker;
- ASSERT_TRUE(builderWorker.ParseProductDependencies(fileName, fileName, productDependencies));
- ASSERT_EQ(productDependencies.size(), 0);
- }
- TEST_F(EMotionFXBuilderTests, TestAnimGraphAsset_InvalidFilePath_OutputNoProductDependencies)
- {
- const AZStd::string fileName = "@gemroot:EMotionFX@/Code/Tests/TestAssets/EMotionFXBuilderTestAssets/InvalidPathExample.animgraph";
- AZStd::vector<AssetBuilderSDK::ProductDependency> productDependencies;
- EMotionFXBuilder::AnimGraphBuilderWorker builderWorker;
- ASSERT_FALSE(builderWorker.ParseProductDependencies(fileName, fileName, productDependencies));
- ASSERT_EQ(productDependencies.size(), 0);
- }
- TEST_F(EMotionFXBuilderTests, TestAnimGraphAsset_EmptyFile_OutputNoProductDependencies)
- {
- const AZStd::string fileName = "@gemroot:EMotionFX@/Code/Tests/TestAssets/EMotionFXBuilderTestAssets/EmptyAnimGraphExample.animgraph";
- AZStd::vector<AssetBuilderSDK::ProductDependency> productDependencies;
- EMotionFXBuilder::AnimGraphBuilderWorker builderWorker;
- AZ_TEST_START_ASSERTTEST;
- ASSERT_FALSE(builderWorker.ParseProductDependencies(fileName, fileName, productDependencies));
- AZ_TEST_STOP_ASSERTTEST(2);
- ASSERT_EQ(productDependencies.size(), 0);
- }
- TEST_F(EMotionFXBuilderTests, TestMotionSetAsset_HasReferenceNode_OutputProductDependencies)
- {
- const AZStd::string fileName = "@gemroot:EMotionFX@/Code/Tests/TestAssets/EMotionFXBuilderTestAssets/MotionSetExample.motionset";
- AssetBuilderSDK::ProductPathDependencySet productDependencies;
- EMotionFXBuilder::MotionSetBuilderWorker builderWorker;
- ASSERT_TRUE(builderWorker.ParseProductDependencies(fileName, fileName, productDependencies));
- ASSERT_THAT(productDependencies, testing::ElementsAre(
- AssetBuilderSDK::ProductPathDependency{ "animationsamples/advanced_rinlocomotion/motions/rin_forward_dive_roll.motion", AssetBuilderSDK::ProductPathDependencyType::ProductFile },
- AssetBuilderSDK::ProductPathDependency{ "animationsamples/advanced_rinlocomotion/motions/rin_come_to_stop.motion", AssetBuilderSDK::ProductPathDependencyType::ProductFile }));
- }
- TEST_F(EMotionFXBuilderTests, TestMotionSetAsset_NoDependency_OutputNoProductDependencies)
- {
- const AZStd::string fileName = "@gemroot:EMotionFX@/Code/Tests/TestAssets/EMotionFXBuilderTestAssets/MotionSetExampleNoDependency.motionset";
- AssetBuilderSDK::ProductPathDependencySet productDependencies;
- EMotionFXBuilder::MotionSetBuilderWorker builderWorker;
- ASSERT_TRUE(builderWorker.ParseProductDependencies(fileName, fileName, productDependencies));
- ASSERT_EQ(productDependencies.size(), 0);
- }
- TEST_F(EMotionFXBuilderTests, TestMotionSetAsset_InvalidFilePath_OutputNoProductDependencies)
- {
- const AZStd::string fileName = "@gemroot:EMotionFX@/Code/Tests/TestAssets/EMotionFXBuilderTestAssets/InvalidPathExample.motionset";
- AssetBuilderSDK::ProductPathDependencySet productDependencies;
- EMotionFXBuilder::MotionSetBuilderWorker builderWorker;
- ASSERT_FALSE(builderWorker.ParseProductDependencies(fileName, fileName, productDependencies));
- ASSERT_EQ(productDependencies.size(), 0);
- }
- TEST_F(EMotionFXBuilderTests, TestMotionSetAsset_EmptyFile_OutputNoProductDependencies)
- {
- const AZStd::string fileName = "@gemroot:EMotionFX@/Code/Tests/TestAssets/EMotionFXBuilderTestAssets/EmptyMotionSetExample.motionset";
- AssetBuilderSDK::ProductPathDependencySet productDependencies;
- EMotionFXBuilder::MotionSetBuilderWorker builderWorker;
- AZ_TEST_START_ASSERTTEST;
- ASSERT_FALSE(builderWorker.ParseProductDependencies(fileName, fileName, productDependencies));
- AZ_TEST_STOP_ASSERTTEST(2);
- ASSERT_EQ(productDependencies.size(), 0);
- }
- } // namespace EMotionFX
|