AWSScriptBehaviorsComponentTest.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/Component/ComponentApplication.h>
  9. #include <AzCore/Serialization/EditContext.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. #include <ScriptCanvas/AWSScriptBehaviorsComponent.h>
  12. #include <TestFramework/AWSCoreFixture.h>
  13. using namespace AWSCore;
  14. class AWSScriptBehaviorsComponentTest
  15. : public AWSCoreFixture
  16. {
  17. public:
  18. void SetUp() override
  19. {
  20. AWSCoreFixture::SetUpFixture();
  21. m_serializeContext = AZStd::make_unique<AZ::SerializeContext>();
  22. m_serializeContext->CreateEditContext();
  23. m_behaviorContext = AZStd::make_unique<AZ::BehaviorContext>();
  24. m_entity = AZStd::make_unique<AZ::Entity>();
  25. m_scriptBehaviorsComponent.reset(m_entity->CreateComponent<AWSScriptBehaviorsComponent>());
  26. }
  27. void TearDown() override
  28. {
  29. m_entity->RemoveComponent(m_scriptBehaviorsComponent.get());
  30. m_scriptBehaviorsComponent.reset();
  31. m_entity.reset();
  32. m_componentDescriptor.reset();
  33. m_behaviorContext.reset();
  34. m_serializeContext.reset();
  35. AWSCoreFixture::TearDownFixture();
  36. }
  37. protected:
  38. AZStd::unique_ptr<AZ::SerializeContext> m_serializeContext;
  39. AZStd::unique_ptr<AZ::BehaviorContext> m_behaviorContext;
  40. AZStd::unique_ptr<AZ::ComponentDescriptor> m_componentDescriptor;
  41. AZStd::unique_ptr<AWSScriptBehaviorsComponent> m_scriptBehaviorsComponent;
  42. AZStd::unique_ptr<AZ::Entity> m_entity;
  43. };
  44. TEST_F(AWSScriptBehaviorsComponentTest, Reflect)
  45. {
  46. int oldEBusNum = static_cast<int>(m_behaviorContext->m_ebuses.size());
  47. m_componentDescriptor.reset(AWSScriptBehaviorsComponent::CreateDescriptor());
  48. m_componentDescriptor->Reflect(m_serializeContext.get());
  49. m_componentDescriptor->Reflect(m_behaviorContext.get());
  50. EXPECT_TRUE(m_behaviorContext->m_ebuses.size() - oldEBusNum == 3);
  51. }