/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include #include #include #include #include #include #include #include namespace UnitTest { class AWSGameLiftServerSystemComponentTest : public AWSGameLiftServerFixture { public: void SetUp() override { AWSGameLiftServerFixture::SetUp(); m_serializeContext = AZStd::make_unique(); m_serializeContext->CreateEditContext(); m_behaviorContext = AZStd::make_unique(); m_componentDescriptor.reset(AWSGameLift::AWSGameLiftServerSystemComponent::CreateDescriptor()); m_componentDescriptor->Reflect(m_serializeContext.get()); m_componentDescriptor->Reflect(m_behaviorContext.get()); m_entity = aznew AZ::Entity(); m_AWSGameLiftServerSystemsComponent = aznew NiceMock(); m_entity->AddComponent(m_AWSGameLiftServerSystemsComponent); // Set up the file IO and alias m_localFileIO = aznew AZ::IO::LocalFileIO(); m_priorFileIO = AZ::IO::FileIOBase::GetInstance(); AZ::IO::FileIOBase::SetInstance(nullptr); AZ::IO::FileIOBase::SetInstance(m_localFileIO); m_localFileIO->SetAlias("@log@", AZ_TRAIT_TEST_ROOT_FOLDER); } void TearDown() override { AZ::IO::FileIOBase::SetInstance(nullptr); delete m_localFileIO; AZ::IO::FileIOBase::SetInstance(m_priorFileIO); m_entity->RemoveComponent(m_AWSGameLiftServerSystemsComponent); delete m_AWSGameLiftServerSystemsComponent; delete m_entity; m_componentDescriptor.reset(); m_behaviorContext.reset(); m_serializeContext.reset(); AWSGameLiftServerFixture::TearDown(); } AZStd::unique_ptr m_componentDescriptor; AZStd::unique_ptr m_serializeContext; AZStd::unique_ptr m_behaviorContext; AZ::Entity* m_entity; NiceMock* m_AWSGameLiftServerSystemsComponent; AZ::IO::FileIOBase* m_priorFileIO; AZ::IO::FileIOBase* m_localFileIO; }; TEST_F(AWSGameLiftServerSystemComponentTest, ActivateDeactivateComponent_ExecuteInOrder_Success) { testing::Sequence s1, s2; EXPECT_CALL(*m_AWSGameLiftServerSystemsComponent, Init()).Times(1).InSequence(s1); EXPECT_CALL(*m_AWSGameLiftServerSystemsComponent, Activate()).Times(1).InSequence(s1); EXPECT_CALL(*m_AWSGameLiftServerSystemsComponent, Deactivate()).Times(1).InSequence(s2); // activate component m_entity->Init(); m_entity->Activate(); // deactivate component m_entity->Deactivate(); } } // namespace UnitTest