Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,109 @@
/*
* 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 <AzCore/EBus/IEventScheduler.h>
#include <AzCore/EBus/EventSchedulerSystemComponent.h>
#include <AzCore/EBus/ScheduledEvent.h>
#include <AzCore/Interface/Interface.h>
#include <AzCore/Console/LoggerSystemComponent.h>
#include <AzCore/Time/TimeSystemComponent.h>
#include <AzCore/Name/NameDictionary.h>
#include <AzCore/UnitTest/TestTypes.h>
namespace UnitTest
{
class ScheduledEventTests
: public AllocatorsFixture
{
public:
void SetUp() override
{
SetupAllocator();
AZ::NameDictionary::Create();
m_loggerComponent = new AZ::LoggerSystemComponent;
m_timeComponent = new AZ::TimeSystemComponent;
m_eventSchedulerComponent = new AZ::EventSchedulerSystemComponent;
m_testEvent = new AZ::ScheduledEvent([this] { TestBasicEvent(); }, AZ::Name("UnitTestEvent fire once event"));
m_testRequeue = new AZ::ScheduledEvent([this] { TestAutoRequeuedEvent(); }, AZ::Name("UnitTestEvent auto Requeue"));
}
void TearDown() override
{
delete m_testEvent;
delete m_testRequeue;
delete m_eventSchedulerComponent;
delete m_timeComponent;
delete m_loggerComponent;
AZ::NameDictionary::Destroy();
TeardownAllocator();
}
void TestBasicEvent()
{
++m_basicEventTriggerCount;
}
void TestAutoRequeuedEvent()
{
++m_requeuedEventTriggerCount;
}
uint32_t m_basicEventTriggerCount = 0;
uint32_t m_requeuedEventTriggerCount = 0;
AZ::ScheduledEvent* m_testEvent = nullptr;
AZ::ScheduledEvent* m_testRequeue = nullptr;
AZ::LoggerSystemComponent* m_loggerComponent = nullptr;
AZ::TimeSystemComponent* m_timeComponent = nullptr;
AZ::EventSchedulerSystemComponent* m_eventSchedulerComponent = nullptr;
};
TEST_F(ScheduledEventTests, TestFireOnce)
{
m_testEvent->Enqueue(AZ::TimeMs(100));
constexpr AZ::TimeMs TotalIterationTimeMs = AZ::TimeMs{ 1050 };
const AZ::TimeMs startTimeMs = AZ::GetElapsedTimeMs();
for (;;)
{
AZStd::this_thread::sleep_for(AZStd::chrono::milliseconds(25));
m_eventSchedulerComponent->OnTick(0.0f, AZ::ScriptTimePoint());
if (AZ::GetElapsedTimeMs() - startTimeMs > TotalIterationTimeMs)
{
break;
}
}
EXPECT_EQ(m_basicEventTriggerCount, 1);
}
TEST_F(ScheduledEventTests, TestRequeue)
{
m_testRequeue->Enqueue(AZ::TimeMs(200), true);
constexpr AZ::TimeMs TotalIterationTimeMs = AZ::TimeMs{ 1050 };
const AZ::TimeMs startTimeMs = AZ::GetElapsedTimeMs();
for (;;)
{
AZStd::this_thread::sleep_for(AZStd::chrono::milliseconds(25));
m_eventSchedulerComponent->OnTick(0.0f, AZ::ScriptTimePoint());
if (AZ::GetElapsedTimeMs() - startTimeMs > TotalIterationTimeMs)
{
break;
}
}
// Use EXPECT_GT in case the OS oversleeps long enough to cause unexpected extra timer pops
EXPECT_GT(m_requeuedEventTriggerCount, 1);
}
}