MotionSetLoadEscalation.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 <AzCore/Asset/AssetDataStream.h>
  9. #include <AzCore/std/smart_ptr/make_shared.h>
  10. #include <Tests/SystemComponentFixture.h>
  11. #include <Source/Integration/Assets/MotionSetAsset.h>
  12. #include <AzFramework/Asset/AssetSystemBus.h>
  13. #include <UI/PropertyEditor/PropertyManagerComponent.h>
  14. namespace EMotionFX
  15. {
  16. struct RegisterHandler
  17. : AzToolsFramework::PropertyTypeRegistrationMessages::Bus::Handler
  18. {
  19. RegisterHandler()
  20. {
  21. BusConnect();
  22. }
  23. ~RegisterHandler()
  24. {
  25. BusDisconnect();
  26. for(auto* handler : m_handlers)
  27. {
  28. delete handler;
  29. }
  30. }
  31. void RegisterPropertyType(AzToolsFramework::PropertyHandlerBase* pHandler) override
  32. {
  33. m_handlers.insert(pHandler);
  34. }
  35. void UnregisterPropertyType(AzToolsFramework::PropertyHandlerBase* pHandler) override
  36. {
  37. m_handlers.erase(pHandler);
  38. }
  39. AzToolsFramework::PropertyHandlerBase* ResolvePropertyHandler([[maybe_unused]] AZ::u32 handlerName, [[maybe_unused]] const AZ::Uuid& handlerType) override
  40. {
  41. return {};
  42. }
  43. AZStd::unordered_set<AzToolsFramework::PropertyHandlerBase*> m_handlers{};
  44. };
  45. struct MotionSetFixture
  46. : ComponentFixture<
  47. AZ::AssetManagerComponent,
  48. AZ::JobManagerComponent,
  49. AZ::StreamerComponent,
  50. AzFramework::AssetCatalogComponent,
  51. AzToolsFramework::Components::PropertyManagerComponent,
  52. EMotionFX::Integration::SystemComponent
  53. >
  54. {
  55. };
  56. struct MockAssetSystemRequests
  57. : AzFramework::AssetSystemRequestBus::Handler
  58. {
  59. MockAssetSystemRequests()
  60. {
  61. BusConnect();
  62. }
  63. ~MockAssetSystemRequests() override
  64. {
  65. BusDisconnect();
  66. }
  67. MOCK_METHOD1(CompileAssetSync, AzFramework::AssetSystem::AssetStatus(const AZStd::string& assetPath));
  68. MOCK_METHOD1(EscalateAssetBySearchTerm, bool(AZStd::string_view searchTerm));
  69. MOCK_METHOD1(EscalateAssetByUuid, bool (const AZ::Uuid&));
  70. MOCK_METHOD1(CompileAssetSync_FlushIO, AzFramework::AssetSystem::AssetStatus (const AZStd::string&));
  71. MOCK_METHOD1(CompileAssetSyncById, AzFramework::AssetSystem::AssetStatus (const AZ::Data::AssetId&));
  72. MOCK_METHOD1(CompileAssetSyncById_FlushIO, AzFramework::AssetSystem::AssetStatus (const AZ::Data::AssetId&));
  73. MOCK_METHOD4(ConfigureSocketConnection, bool (const AZStd::string&, const AZStd::string&, const AZStd::string&, const AZStd::string&));
  74. MOCK_METHOD1(Connect, bool (const char*));
  75. MOCK_METHOD2(ConnectWithTimeout, bool (const char*, AZStd::chrono::duration<float>));
  76. MOCK_METHOD0(Disconnect, bool ());
  77. MOCK_METHOD0(GetAssetProcessorPingTimeMilliseconds, float ());
  78. MOCK_METHOD1(GetAssetStatus, AzFramework::AssetSystem::AssetStatus (const AZStd::string&));
  79. MOCK_METHOD1(GetAssetStatus_FlushIO, AzFramework::AssetSystem::AssetStatus (const AZStd::string&));
  80. MOCK_METHOD2(GetAssetStatusSearchType, AzFramework::AssetSystem::AssetStatus(const AZStd::string&, int));
  81. MOCK_METHOD2(GetAssetStatusSearchType_FlushIO, AzFramework::AssetSystem::AssetStatus(const AZStd::string&, int));
  82. MOCK_METHOD1(GetAssetStatusById, AzFramework::AssetSystem::AssetStatus (const AZ::Data::AssetId&));
  83. MOCK_METHOD1(GetAssetStatusById_FlushIO, AzFramework::AssetSystem::AssetStatus (const AZ::Data::AssetId&));
  84. MOCK_METHOD3(GetUnresolvedProductReferences, void (AZ::Data::AssetId, AZ::u32&, AZ::u32&));
  85. MOCK_METHOD0(SaveCatalog, bool ());
  86. MOCK_METHOD1(SetAssetProcessorIP, void (const AZStd::string&));
  87. MOCK_METHOD1(SetAssetProcessorPort, void (AZ::u16));
  88. MOCK_METHOD1(SetBranchToken, void (const AZStd::string&));
  89. MOCK_METHOD1(SetProjectName, void (const AZStd::string&));
  90. MOCK_METHOD0(ShowAssetProcessor, void());
  91. MOCK_METHOD1(UpdateSourceControlStatus, void (bool));
  92. MOCK_METHOD1(ShowInAssetProcessor, void(const AZStd::string&));
  93. MOCK_METHOD1(WaitUntilAssetProcessorReady, bool(AZStd::chrono::duration<float>));
  94. MOCK_METHOD1(WaitUntilAssetProcessorConnected, bool(AZStd::chrono::duration<float>));
  95. MOCK_METHOD1(WaitUntilAssetProcessorDisconnected, bool(AZStd::chrono::duration<float>));
  96. MOCK_METHOD0(AssetProcessorIsReady, bool());
  97. MOCK_METHOD0(ConnectedWithAssetProcessor, bool());
  98. MOCK_METHOD0(DisconnectedWithAssetProcessor, bool());
  99. MOCK_METHOD0(NegotiationWithAssetProcessorFailed, bool());
  100. MOCK_METHOD0(StartDisconnectingAssetProcessor, void());
  101. MOCK_METHOD1(EstablishAssetProcessorConnection, bool(const AzFramework::AssetSystem::ConnectionSettings&));
  102. MOCK_METHOD3(AppendAssetToPrioritySet, bool (const AZStd::string&, const AZ::Uuid&, uint32_t));
  103. MOCK_METHOD3(AppendAssetsToPrioritySet, bool (const AZStd::string&, const AZStd::vector<AZ::Uuid>&, uint32_t));
  104. MOCK_METHOD2(RemoveAssetFromPrioritySet, bool (const AZStd::string&, const AZ::Uuid&));
  105. MOCK_METHOD2(RemoveAssetsFromPrioritySet, bool (const AZStd::string&, const AZStd::vector<AZ::Uuid>&));
  106. };
  107. TEST_F(MotionSetFixture, MeshLoadTest)
  108. {
  109. using testing::_;
  110. const AZStd::string fileName = "@gemroot:EMotionFX@/Code/Tests/TestAssets/EMotionFXBuilderTestAssets/MotionSetExample.motionset";
  111. MockAssetSystemRequests assetSystem;
  112. EXPECT_CALL(assetSystem, CompileAssetSync(_))
  113. .Times(2)
  114. .WillRepeatedly(testing::Return(AzFramework::AssetSystem::AssetStatus_Queued));
  115. EXPECT_CALL(assetSystem, EscalateAssetBySearchTerm(_))
  116. .Times(2)
  117. .WillRepeatedly(testing::Return(false));
  118. auto* handler = static_cast<Integration::MotionSetAssetHandler*>(AZ::Data::AssetManager::Instance().GetHandler(azrtti_typeid<Integration::MotionSetAsset>()));
  119. AZ::Data::AssetPtr assetPointer = handler->CreateAsset(AZ::Data::AssetId(AZ::Uuid::CreateRandom(), 0), AZ::Data::AssetType::CreateRandom());
  120. AZ::Data::Asset<AZ::Data::AssetData> asset(assetPointer, AZ::Data::AssetLoadBehavior::NoLoad);
  121. AZ::u64 fileLength = 0;
  122. AZ::IO::FileIOBase::GetInstance()->Size(fileName.c_str(), fileLength);
  123. AZStd::shared_ptr<AZ::Data::AssetDataStream> stream = AZStd::make_shared<AZ::Data::AssetDataStream>();
  124. stream->Open(fileName, 0, fileLength);
  125. stream->BlockUntilLoadComplete();
  126. handler->LoadAssetData(asset, stream, &AZ::Data::AssetFilterNoAssetLoading);
  127. handler->OnInitAsset(asset);
  128. }
  129. } // end namespace EMotionFX