AWSGameLiftClientSystemComponentTest.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. * its licensors.
  4. *
  5. * For complete copyright and license terms please see the LICENSE at the root of this
  6. * distribution (the "License"). All use of this software is governed by the License,
  7. * or, if provided, by the license below or the license accompanying this file. Do not
  8. * remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. *
  11. */
  12. #include <AzCore/Component/ComponentApplication.h>
  13. #include <AzCore/Serialization/EditContext.h>
  14. #include <AzCore/Serialization/SerializeContext.h>
  15. #include <AzCore/std/smart_ptr/unique_ptr.h>
  16. #include <AWSGameLiftClientFixture.h>
  17. #include <AWSGameLiftClientManager.h>
  18. #include <AWSGameLiftClientSystemComponent.h>
  19. #include <aws/gamelift/GameLiftClient.h>
  20. using namespace AWSGameLift;
  21. class AWSGameLiftClientManagerMock
  22. : public AWSGameLiftClientManager
  23. {
  24. public:
  25. AWSGameLiftClientManagerMock() = default;
  26. ~AWSGameLiftClientManagerMock() = default;
  27. MOCK_METHOD0(ActivateManager, void());
  28. MOCK_METHOD0(DeactivateManager, void());
  29. };
  30. class TestAWSGameLiftClientSystemComponent
  31. : public AWSGameLiftClientSystemComponent
  32. {
  33. public:
  34. TestAWSGameLiftClientSystemComponent()
  35. {
  36. m_gameliftClientManagerMockPtr = nullptr;
  37. }
  38. ~TestAWSGameLiftClientSystemComponent()
  39. {
  40. m_gameliftClientManagerMockPtr = nullptr;
  41. }
  42. void SetUpMockManager()
  43. {
  44. AZStd::unique_ptr<AWSGameLiftClientManagerMock> gameliftClientManagerMock = AZStd::make_unique<AWSGameLiftClientManagerMock>();
  45. m_gameliftClientManagerMockPtr = gameliftClientManagerMock.get();
  46. SetGameLiftClientManager(AZStd::move(gameliftClientManagerMock));
  47. }
  48. AWSGameLiftClientManagerMock* m_gameliftClientManagerMockPtr;
  49. };
  50. class AWSCoreSystemComponentMock
  51. : public AZ::Component
  52. {
  53. public:
  54. AZ_COMPONENT(AWSCoreSystemComponentMock, "{52DB1342-30C6-412F-B7CC-B23F8B0629EA}");
  55. static void Reflect(AZ::ReflectContext* context)
  56. {
  57. AZ_UNUSED(context);
  58. }
  59. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  60. {
  61. provided.push_back(AZ_CRC_CE("AWSCoreService"));
  62. }
  63. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  64. {
  65. AZ_UNUSED(incompatible);
  66. }
  67. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  68. {
  69. AZ_UNUSED(required);
  70. }
  71. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  72. {
  73. AZ_UNUSED(dependent);
  74. }
  75. AWSCoreSystemComponentMock() = default;
  76. ~AWSCoreSystemComponentMock() = default;
  77. void Init() override {}
  78. void Activate() override {}
  79. void Deactivate() override {}
  80. };
  81. class AWSGameLiftClientSystemComponentTest
  82. : public AWSGameLiftClientFixture
  83. {
  84. protected:
  85. AZStd::unique_ptr<AZ::SerializeContext> m_serializeContext;
  86. AZStd::unique_ptr<AZ::BehaviorContext> m_behaviorContext;
  87. AZStd::unique_ptr<AZ::ComponentDescriptor> m_coreComponentDescriptor;
  88. AZStd::unique_ptr<AZ::ComponentDescriptor> m_gameliftClientComponentDescriptor;
  89. void SetUp() override
  90. {
  91. AWSGameLiftClientFixture::SetUp();
  92. m_serializeContext = AZStd::make_unique<AZ::SerializeContext>();
  93. m_serializeContext->CreateEditContext();
  94. m_behaviorContext = AZStd::make_unique<AZ::BehaviorContext>();
  95. m_coreComponentDescriptor.reset(AWSCoreSystemComponentMock::CreateDescriptor());
  96. m_gameliftClientComponentDescriptor.reset(TestAWSGameLiftClientSystemComponent::CreateDescriptor());
  97. m_gameliftClientComponentDescriptor->Reflect(m_serializeContext.get());
  98. m_gameliftClientComponentDescriptor->Reflect(m_behaviorContext.get());
  99. m_entity = aznew AZ::Entity();
  100. m_coreSystemComponent = AZStd::make_unique<AWSCoreSystemComponentMock>();
  101. m_entity->AddComponent(m_coreSystemComponent.get());
  102. m_gameliftClientSystemComponent = AZStd::make_unique<TestAWSGameLiftClientSystemComponent>();
  103. m_gameliftClientSystemComponent->SetUpMockManager();
  104. m_entity->AddComponent(m_gameliftClientSystemComponent.get());
  105. }
  106. void TearDown() override
  107. {
  108. m_entity->RemoveComponent(m_gameliftClientSystemComponent.get());
  109. m_gameliftClientSystemComponent.reset();
  110. m_entity->RemoveComponent(m_coreSystemComponent.get());
  111. m_coreSystemComponent.reset();
  112. delete m_entity;
  113. m_entity = nullptr;
  114. m_gameliftClientComponentDescriptor.reset();
  115. m_coreComponentDescriptor.reset();
  116. m_behaviorContext.reset();
  117. m_serializeContext.reset();
  118. AWSGameLiftClientFixture::TearDown();
  119. }
  120. public:
  121. AZStd::unique_ptr<AWSCoreSystemComponentMock> m_coreSystemComponent;
  122. AZStd::unique_ptr<TestAWSGameLiftClientSystemComponent> m_gameliftClientSystemComponent;
  123. AZ::Entity* m_entity;
  124. };
  125. TEST_F(AWSGameLiftClientSystemComponentTest, ActivateDeactivate_Call_GameLiftClientManagerGetsInvoked)
  126. {
  127. m_entity->Init();
  128. EXPECT_CALL(*(m_gameliftClientSystemComponent->m_gameliftClientManagerMockPtr), ActivateManager()).Times(1);
  129. m_entity->Activate();
  130. EXPECT_CALL(*(m_gameliftClientSystemComponent->m_gameliftClientManagerMockPtr), DeactivateManager()).Times(1);
  131. m_entity->Deactivate();
  132. }