MultiThreadSchedulerTests.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 <EMotionFX/Source/Actor.h>
  9. #include <EMotionFX/Source/ActorInstance.h>
  10. #include <EMotionFX/Source/ActorUpdateScheduler.h>
  11. #include <EMotionFX/Source/EMotionFXManager.h>
  12. #include <EMotionFX/Source/ActorManager.h>
  13. #include <EMotionFX/Source/MultiThreadScheduler.h>
  14. #include <Tests/SystemComponentFixture.h>
  15. #include <Tests/TestAssetCode/JackActor.h>
  16. #include <Tests/TestAssetCode/ActorFactory.h>
  17. namespace EMotionFX
  18. {
  19. // This turned into an assert and is now being catched in the actual code. Skip this test, as we don't test and return at runtime anymore.
  20. TEST_F(SystemComponentFixture, DISABLED_InsertActorInstanceTwice)
  21. {
  22. ActorUpdateScheduler* baseScheduler = GetEMotionFX().GetActorManager()->GetScheduler();
  23. ASSERT_EQ(baseScheduler->GetType(), MultiThreadScheduler::TYPE_ID) << "Expected multi thread scheduler.";
  24. MultiThreadScheduler* scheduler = static_cast<MultiThreadScheduler*>(baseScheduler);
  25. // Create the actor (internally creates an actor instance for the static AABB calculation and removes it again).
  26. AZStd::unique_ptr<JackNoMeshesActor> actor = ActorFactory::CreateAndInit<JackNoMeshesActor>();
  27. EXPECT_EQ(scheduler->GetNumScheduleSteps(), 0)
  28. << "Expected an empty scheduler as the temporarily created actor instance got destroyed again.";
  29. // Create an actor instance and make sure it is in the scheduler.
  30. ActorInstance* actorInstance = ActorInstance::Create(actor.get());
  31. EXPECT_EQ(scheduler->GetNumScheduleSteps(), 1) << "The actor instance should be part of the scheduler.";
  32. EXPECT_EQ(scheduler->GetScheduleStep(0).m_actorInstances.size(), 1) << "The step should hold exactly one actor instance.";
  33. EXPECT_EQ(scheduler->GetScheduleStep(0).m_actorInstances[0], actorInstance) << "The actor instance should be part of the step.";
  34. // Insert the actor instance manually again and make sure there is no duplicate.
  35. scheduler->RecursiveInsertActorInstance(actorInstance);
  36. EXPECT_EQ(scheduler->GetNumScheduleSteps(), 1) << "The actor instance should be part of the scheduler.";
  37. EXPECT_EQ(scheduler->GetScheduleStep(0).m_actorInstances.size(), 1) << "The step should hold exactly one actor instance.";
  38. EXPECT_EQ(scheduler->GetScheduleStep(0).m_actorInstances[0], actorInstance) << "The actor instance should be part of the step.";
  39. actorInstance->Destroy();
  40. }
  41. } // namespace EMotionFX