EMotionFXBuilderTests.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "EMotionFXBuilderFixture.h"
  9. #include <EMotionFX/Pipeline/EMotionFXBuilder/AnimGraphBuilderWorker.h>
  10. #include <EMotionFX/Pipeline/EMotionFXBuilder/MotionSetBuilderWorker.h>
  11. #include <AzTest/AzTest.h>
  12. #include <AzCore/Asset/AssetManager.h>
  13. #include <AzCore/Asset/AssetSerializer.h>
  14. #include <AzCore/Component/ComponentApplication.h>
  15. #include <AzCore/std/containers/vector.h>
  16. #include <AzCore/std/string/string.h>
  17. #include <AzCore/UnitTest/UnitTest.h>
  18. #include <AzFramework/IO/LocalFileIO.h>
  19. #include <Tests/Asset/MockLoadAssetCatalogAndHandler.h>
  20. namespace EMotionFX
  21. {
  22. class EMotionFXBuilderTests
  23. : public EMotionFXBuilderFixture
  24. {
  25. protected:
  26. void SetUp() override
  27. {
  28. EMotionFXBuilderFixture::SetUp();
  29. }
  30. void TearDown() override
  31. {
  32. AZ::Data::AssetManager::Instance().PrepareShutDown();
  33. EMotionFXBuilderFixture::TearDown();
  34. }
  35. };
  36. TEST_F(EMotionFXBuilderTests, TestAnimGraphAsset_HasReferenceNode_OutputProductDependencies)
  37. {
  38. AZ::Data::AssetId referencedAnimGraph("96025290-BCC9-5382-AFC0-8B47CEF63018", 0);
  39. AZ::Data::AssetId referencedMotionSet("6455D020-F4CE-5F57-8557-315C0C968122", 0);
  40. // Create a mock AssetManager catalog that will fake load any registered asset IDs. This is necessary because during the call to
  41. // ParseProductDependencies, the reference node will get initialized and attempt to load any dependent assets.
  42. // By using this mock catalog, we can pretend to load the specific referenced assets without actually loading anything.
  43. UnitTest::MockLoadAssetCatalogAndHandler testAssetCatalog({ referencedAnimGraph, referencedMotionSet });
  44. const AZStd::string fileName = "@gemroot:EMotionFX@/Code/Tests/TestAssets/EMotionFXBuilderTestAssets/AnimGraphExample.animgraph";
  45. AZStd::vector<AssetBuilderSDK::ProductDependency> productDependencies;
  46. EMotionFXBuilder::AnimGraphBuilderWorker builderWorker;
  47. ASSERT_TRUE(builderWorker.ParseProductDependencies(fileName, fileName, productDependencies));
  48. ASSERT_TRUE(productDependencies.size() == 2);
  49. ASSERT_EQ(productDependencies[0].m_dependencyId, referencedAnimGraph);
  50. ASSERT_EQ(productDependencies[1].m_dependencyId, referencedMotionSet);
  51. }
  52. TEST_F(EMotionFXBuilderTests, TestAnimGraphAsset_NoDependency_OutputNoProductDependencies)
  53. {
  54. const AZStd::string fileName = "@gemroot:EMotionFX@/Code/Tests/TestAssets/EMotionFXBuilderTestAssets/AnimGraphExampleNoDependency.animgraph";
  55. AZStd::vector<AssetBuilderSDK::ProductDependency> productDependencies;
  56. EMotionFXBuilder::AnimGraphBuilderWorker builderWorker;
  57. ASSERT_TRUE(builderWorker.ParseProductDependencies(fileName, fileName, productDependencies));
  58. ASSERT_EQ(productDependencies.size(), 0);
  59. }
  60. TEST_F(EMotionFXBuilderTests, TestAnimGraphAsset_InvalidFilePath_OutputNoProductDependencies)
  61. {
  62. const AZStd::string fileName = "@gemroot:EMotionFX@/Code/Tests/TestAssets/EMotionFXBuilderTestAssets/InvalidPathExample.animgraph";
  63. AZStd::vector<AssetBuilderSDK::ProductDependency> productDependencies;
  64. EMotionFXBuilder::AnimGraphBuilderWorker builderWorker;
  65. ASSERT_FALSE(builderWorker.ParseProductDependencies(fileName, fileName, productDependencies));
  66. ASSERT_EQ(productDependencies.size(), 0);
  67. }
  68. TEST_F(EMotionFXBuilderTests, TestAnimGraphAsset_EmptyFile_OutputNoProductDependencies)
  69. {
  70. const AZStd::string fileName = "@gemroot:EMotionFX@/Code/Tests/TestAssets/EMotionFXBuilderTestAssets/EmptyAnimGraphExample.animgraph";
  71. AZStd::vector<AssetBuilderSDK::ProductDependency> productDependencies;
  72. EMotionFXBuilder::AnimGraphBuilderWorker builderWorker;
  73. AZ_TEST_START_ASSERTTEST;
  74. ASSERT_FALSE(builderWorker.ParseProductDependencies(fileName, fileName, productDependencies));
  75. AZ_TEST_STOP_ASSERTTEST(2);
  76. ASSERT_EQ(productDependencies.size(), 0);
  77. }
  78. TEST_F(EMotionFXBuilderTests, TestMotionSetAsset_HasReferenceNode_OutputProductDependencies)
  79. {
  80. const AZStd::string fileName = "@gemroot:EMotionFX@/Code/Tests/TestAssets/EMotionFXBuilderTestAssets/MotionSetExample.motionset";
  81. AssetBuilderSDK::ProductPathDependencySet productDependencies;
  82. EMotionFXBuilder::MotionSetBuilderWorker builderWorker;
  83. ASSERT_TRUE(builderWorker.ParseProductDependencies(fileName, fileName, productDependencies));
  84. ASSERT_THAT(productDependencies, testing::ElementsAre(
  85. AssetBuilderSDK::ProductPathDependency{ "animationsamples/advanced_rinlocomotion/motions/rin_forward_dive_roll.motion", AssetBuilderSDK::ProductPathDependencyType::ProductFile },
  86. AssetBuilderSDK::ProductPathDependency{ "animationsamples/advanced_rinlocomotion/motions/rin_come_to_stop.motion", AssetBuilderSDK::ProductPathDependencyType::ProductFile }));
  87. }
  88. TEST_F(EMotionFXBuilderTests, TestMotionSetAsset_NoDependency_OutputNoProductDependencies)
  89. {
  90. const AZStd::string fileName = "@gemroot:EMotionFX@/Code/Tests/TestAssets/EMotionFXBuilderTestAssets/MotionSetExampleNoDependency.motionset";
  91. AssetBuilderSDK::ProductPathDependencySet productDependencies;
  92. EMotionFXBuilder::MotionSetBuilderWorker builderWorker;
  93. ASSERT_TRUE(builderWorker.ParseProductDependencies(fileName, fileName, productDependencies));
  94. ASSERT_EQ(productDependencies.size(), 0);
  95. }
  96. TEST_F(EMotionFXBuilderTests, TestMotionSetAsset_InvalidFilePath_OutputNoProductDependencies)
  97. {
  98. const AZStd::string fileName = "@gemroot:EMotionFX@/Code/Tests/TestAssets/EMotionFXBuilderTestAssets/InvalidPathExample.motionset";
  99. AssetBuilderSDK::ProductPathDependencySet productDependencies;
  100. EMotionFXBuilder::MotionSetBuilderWorker builderWorker;
  101. ASSERT_FALSE(builderWorker.ParseProductDependencies(fileName, fileName, productDependencies));
  102. ASSERT_EQ(productDependencies.size(), 0);
  103. }
  104. TEST_F(EMotionFXBuilderTests, TestMotionSetAsset_EmptyFile_OutputNoProductDependencies)
  105. {
  106. const AZStd::string fileName = "@gemroot:EMotionFX@/Code/Tests/TestAssets/EMotionFXBuilderTestAssets/EmptyMotionSetExample.motionset";
  107. AssetBuilderSDK::ProductPathDependencySet productDependencies;
  108. EMotionFXBuilder::MotionSetBuilderWorker builderWorker;
  109. AZ_TEST_START_ASSERTTEST;
  110. ASSERT_FALSE(builderWorker.ParseProductDependencies(fileName, fileName, productDependencies));
  111. AZ_TEST_STOP_ASSERTTEST(2);
  112. ASSERT_EQ(productDependencies.size(), 0);
  113. }
  114. } // namespace EMotionFX