BuilderTestFixture.h 3.1 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/Component/ComponentApplicationBus.h>
  10. #include <AzCore/IO/Streamer/Streamer.h>
  11. #include <AzCore/IO/SystemFile.h>
  12. #include <AzCore/Serialization/Json/JsonSerialization.h>
  13. #include <AzCore/Serialization/Json/JsonSystemComponent.h>
  14. #include <AzCore/Serialization/Json/RegistrationContext.h>
  15. #include <AzCore/UnitTest/TestTypes.h>
  16. #include <AzTest/AzTest.h>
  17. namespace UnitTest
  18. {
  19. /**
  20. * Unit test fixture for setting up things commonly needed by builders' unit tests
  21. */
  22. class BuilderTestFixture
  23. : public LeakDetectionFixture
  24. // Only used to provide the serialize context for now
  25. , public AZ::ComponentApplicationBus::Handler
  26. {
  27. public:
  28. virtual void Reflect(AZ::ReflectContext* context);
  29. // ComponentApplicationMessages overrides...
  30. AZ::ComponentApplication* GetApplication() override { return nullptr; }
  31. void RegisterComponentDescriptor(const AZ::ComponentDescriptor*) override { }
  32. void UnregisterComponentDescriptor(const AZ::ComponentDescriptor*) override { }
  33. void RegisterEntityAddedEventHandler(AZ::EntityAddedEvent::Handler&) override { }
  34. void RegisterEntityRemovedEventHandler(AZ::EntityRemovedEvent::Handler&) override { }
  35. void RegisterEntityActivatedEventHandler(AZ::EntityActivatedEvent::Handler&) override { }
  36. void RegisterEntityDeactivatedEventHandler(AZ::EntityDeactivatedEvent::Handler&) override { }
  37. void SignalEntityActivated(AZ::Entity*) override { }
  38. void SignalEntityDeactivated(AZ::Entity*) override { }
  39. bool AddEntity(AZ::Entity*) override { return false; }
  40. bool RemoveEntity(AZ::Entity*) override { return false; }
  41. bool DeleteEntity(const AZ::EntityId&) override { return false; }
  42. AZ::Entity* FindEntity(const AZ::EntityId&) override { return nullptr; }
  43. AZ::BehaviorContext* GetBehaviorContext() override { return nullptr; }
  44. const char* GetEngineRoot() const override { return nullptr; }
  45. const char* GetExecutableFolder() const override { return nullptr; }
  46. void EnumerateEntities(const EntityCallback& /*callback*/) override {}
  47. void QueryApplicationType(AZ::ApplicationTypeQuery& /*appType*/) const override {}
  48. // The functions we need to implement.
  49. AZ::SerializeContext* GetSerializeContext() override;
  50. AZ::JsonRegistrationContext* GetJsonRegistrationContext() override;
  51. // LeakDetectionFixture overrides...
  52. void SetUp() override;
  53. void TearDown() override;
  54. protected:
  55. AZStd::unique_ptr<AZ::SerializeContext> m_context;
  56. char m_currentDir[AZ_MAX_PATH_LEN];
  57. // Required for json serializer
  58. AZStd::unique_ptr<AZ::JsonSystemComponent> m_jsonSystemComponent;
  59. AZStd::unique_ptr<AZ::JsonRegistrationContext> m_jsonRegistrationContext;
  60. AZStd::unique_ptr<AZ::IO::Streamer> m_streamer;
  61. };
  62. }// namespace UnitTest