MetaDataRuleTests.cpp 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 <Tests/InitSceneAPIFixture.h>
  9. #include <AzToolsFramework/UI/PropertyEditor/PropertyManagerComponent.h>
  10. #include <MCore/Source/ReflectionSerializer.h>
  11. #include <EMotionFX/Pipeline/SceneAPIExt/Rules/MetaDataRule.h>
  12. #include <EMotionFX/Pipeline/RCExt/Motion/MotionGroupExporter.h>
  13. #include <Integration/System/PipelineComponent.h>
  14. #include <EMotionFX/Source/TwoStringEventData.h>
  15. #include <EMotionFX/CommandSystem/Source/MetaData.h>
  16. #include <EMotionFX/Source/Motion.h>
  17. #include <EMotionFX/Source/MotionEventTable.h>
  18. #include <EMotionFX/CommandSystem/Source/CommandManager.h>
  19. namespace EMotionFX
  20. {
  21. using MetaDataRuleBaseClass = InitSceneAPIFixture<
  22. AZ::AssetManagerComponent,
  23. AZ::JobManagerComponent,
  24. AZ::StreamerComponent,
  25. AzToolsFramework::Components::PropertyManagerComponent,
  26. EMotionFX::Integration::SystemComponent,
  27. EMotionFX::Pipeline::MotionGroupExporter
  28. >;
  29. class MetaDataRuleTestsPipelineFixture
  30. : public MetaDataRuleBaseClass
  31. {
  32. public:
  33. void SetUp() override
  34. {
  35. MetaDataRuleBaseClass::SetUp();
  36. m_commandManager = AZStd::make_unique<CommandSystem::CommandManager>();
  37. }
  38. void TearDown() override
  39. {
  40. m_commandManager.reset();
  41. MetaDataRuleBaseClass::TearDown();
  42. }
  43. private:
  44. AZStd::unique_ptr<CommandSystem::CommandManager> m_commandManager;
  45. };
  46. TEST_F(MetaDataRuleTestsPipelineFixture, TestVersion1Import)
  47. {
  48. EMotionFX::Pipeline::Rule::MetaDataRule::Reflect(GetSerializeContext());
  49. const AZStd::string sourceText {
  50. "<ObjectStream version=\"3\">\n"
  51. " <Class name=\"MetaDataRule\" version=\"1\" type=\"{8D759063-7D2E-4543-8EB3-AB510A5886CF}\">\n"
  52. " <Class name=\"AZStd::string\" field=\"metaData\" value='AdjustMotion -motionID $(MOTIONID) -motionExtractionFlags 0\n"
  53. "ClearMotionEvents -motionID $(MOTIONID)\n"
  54. "CreateMotionEventTrack -motionID $(MOTIONID) -eventTrackName \"Sync\"\n"
  55. "AdjustMotionEventTrack -motionID $(MOTIONID) -eventTrackName \"Sync\" -enabled true\n"
  56. "CreateMotionEvent -motionID $(MOTIONID) -eventTrackName \"Sync\" -startTime 0.022680 -endTime 0.022680 -eventType \"RightFoot\" -parameters \"\" -mirrorType \"LeftFoot\"\n"
  57. "' type=\"{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}\"/>\n"
  58. " </Class>\n"
  59. "</ObjectStream>\n"
  60. };
  61. const Pipeline::Rule::MetaDataRule* metaDataRule = MCore::ReflectionSerializer::Deserialize<Pipeline::Rule::MetaDataRule>(sourceText);
  62. const AZStd::vector<MCore::Command*>& commands = metaDataRule->GetMetaData<const AZStd::vector<MCore::Command*>&>();
  63. EXPECT_EQ(commands.size(), 5) << "There should be 5 commands";
  64. EMotionFX::Motion* motion = aznew EMotionFX::Motion("TestMotion");
  65. CommandSystem::MetaData::ApplyMetaDataOnMotion(motion, commands);
  66. ASSERT_EQ(motion->GetEventTable()->GetNumTracks(), 1);
  67. EMotionFX::MotionEventTrack* eventTrack = motion->GetEventTable()->GetTrack(0);
  68. EXPECT_STREQ(eventTrack->GetName(), "Sync");
  69. ASSERT_EQ(eventTrack->GetNumEvents(), 1);
  70. EMotionFX::MotionEvent& event = eventTrack->GetEvent(0);
  71. const EventDataSet& eventDatas = event.GetEventDatas();
  72. ASSERT_EQ(eventDatas.size(), 1);
  73. const AZStd::shared_ptr<const TwoStringEventData> eventData = AZStd::rtti_pointer_cast<const TwoStringEventData>(eventDatas[0]);
  74. ASSERT_TRUE(eventData);
  75. EXPECT_STREQ(eventData->GetSubject().c_str(), "RightFoot");
  76. EXPECT_STREQ(eventData->GetParameters().c_str(), "");
  77. EXPECT_STREQ(eventData->GetMirrorSubject().c_str(), "LeftFoot");
  78. motion->Destroy();
  79. delete metaDataRule;
  80. }
  81. } // end namespace EMotionFX