BehaviorContextFixture.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #pragma once
  9. #include <AzCore/UnitTest/TestTypes.h>
  10. #include <AzCore/RTTI/BehaviorContext.h>
  11. #include <AzCore/Interface/Interface.h>
  12. namespace UnitTest
  13. {
  14. // Basic fixture for managing a BehaviorContext
  15. class BehaviorContextFixture
  16. : public LeakDetectionFixture
  17. , public AZ::ComponentApplicationBus::Handler
  18. {
  19. public:
  20. void SetUp() override
  21. {
  22. LeakDetectionFixture::SetUp();
  23. m_behaviorContext = aznew AZ::BehaviorContext();
  24. AZ::ComponentApplicationBus::Handler::BusConnect();
  25. AZ::Interface<AZ::ComponentApplicationRequests>::Register(this);
  26. }
  27. void TearDown() override
  28. {
  29. AZ::Interface<AZ::ComponentApplicationRequests>::Unregister(this);
  30. AZ::ComponentApplicationBus::Handler::BusDisconnect();
  31. // Just destroy everything before we complete the tear down.
  32. delete m_behaviorContext;
  33. m_behaviorContext = nullptr;
  34. LeakDetectionFixture::TearDown();
  35. }
  36. // ComponentApplicationBus
  37. AZ::ComponentApplication* GetApplication() override { return nullptr; }
  38. void RegisterComponentDescriptor(const AZ::ComponentDescriptor*) override {}
  39. void UnregisterComponentDescriptor(const AZ::ComponentDescriptor*) override {}
  40. void RegisterEntityAddedEventHandler(AZ::EntityAddedEvent::Handler&) override {}
  41. void RegisterEntityRemovedEventHandler(AZ::EntityRemovedEvent::Handler&) override {}
  42. void RegisterEntityActivatedEventHandler(AZ::EntityActivatedEvent::Handler&) override {}
  43. void RegisterEntityDeactivatedEventHandler(AZ::EntityDeactivatedEvent::Handler&) override {}
  44. void SignalEntityActivated(AZ::Entity*) override {}
  45. void SignalEntityDeactivated(AZ::Entity*) override {}
  46. bool AddEntity(AZ::Entity*) override { return true; }
  47. bool RemoveEntity(AZ::Entity*) override { return true; }
  48. bool DeleteEntity(const AZ::EntityId&) override { return true; }
  49. AZ::Entity* FindEntity(const AZ::EntityId&) override { return nullptr; }
  50. AZ::SerializeContext* GetSerializeContext() override { return nullptr; }
  51. AZ::BehaviorContext* GetBehaviorContext() override { return m_behaviorContext; }
  52. AZ::JsonRegistrationContext* GetJsonRegistrationContext() override { return nullptr; }
  53. const char* GetEngineRoot() const override { return nullptr; }
  54. const char* GetExecutableFolder() const override { return nullptr; }
  55. void EnumerateEntities(const EntityCallback& /*callback*/) override {}
  56. void QueryApplicationType(AZ::ApplicationTypeQuery& /*appType*/) const override {}
  57. ////
  58. protected:
  59. AZ::BehaviorContext* m_behaviorContext;
  60. };
  61. }