2014-03-14 14:13:41 -04:00
|
|
|
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "FunctionalTestingPrivatePCH.h"
|
|
|
|
|
|
|
|
|
|
#define LOCTEXT_NAMESPACE "FunctionalTesting"
|
|
|
|
|
|
2014-04-23 19:29:53 -04:00
|
|
|
//struct FFuncTestingTickHelper : FTickableGameObject
|
|
|
|
|
//{
|
|
|
|
|
// class UFunctionalTestingManager* Manager;
|
|
|
|
|
//
|
|
|
|
|
// FFuncTestingTickHelper() : Manager(NULL) {}
|
|
|
|
|
// virtual void Tick(float DeltaTime);
|
|
|
|
|
// virtual bool IsTickable() const { return Owner && !((AActor*)Owner)->IsPendingKillPending(); }
|
|
|
|
|
// virtual bool IsTickableInEditor() const { return true; }
|
|
|
|
|
// virtual TStatId GetStatId() const ;
|
|
|
|
|
//};
|
|
|
|
|
//
|
|
|
|
|
////----------------------------------------------------------------------//
|
|
|
|
|
////
|
|
|
|
|
////----------------------------------------------------------------------//
|
|
|
|
|
//void FFuncTestingTickHelper::Tick(float DeltaTime)
|
|
|
|
|
//{
|
|
|
|
|
// if (Manager->IsPendingKill() == false)
|
|
|
|
|
// {
|
|
|
|
|
// Manager->TickMe(DeltaTime);
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
//
|
|
|
|
|
//TStatId FFuncTestingTickHelper::GetStatId() const
|
|
|
|
|
//{
|
|
|
|
|
// RETURN_QUICK_DECLARE_CYCLE_STAT(FRecastTickHelper, STATGROUP_Tickables);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------//
|
|
|
|
|
//
|
|
|
|
|
//----------------------------------------------------------------------//
|
2014-03-14 14:13:41 -04:00
|
|
|
UFunctionalTestingManager::UFunctionalTestingManager( const class FPostConstructInitializeProperties& PCIP )
|
|
|
|
|
: Super(PCIP)
|
2014-04-23 19:29:53 -04:00
|
|
|
, bIsRunning(false)
|
|
|
|
|
, bLooped(false)
|
|
|
|
|
, bWaitForNavigationBuildFinish(false)
|
|
|
|
|
, bInitialDelayApplied(false)
|
|
|
|
|
, CurrentIteration(INDEX_NONE)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UFunctionalTestingManager::SetUpTests()
|
|
|
|
|
{
|
|
|
|
|
OnSetupTests.Broadcast();
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 19:29:53 -04:00
|
|
|
bool UFunctionalTestingManager::RunAllFunctionalTests(UObject* WorldContext, bool bNewLog, bool bRunLooped, bool bInWaitForNavigationBuildFinish)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-04-23 19:29:53 -04:00
|
|
|
UFunctionalTestingManager* Manager = GetManager(WorldContext);
|
|
|
|
|
|
|
|
|
|
if (Manager->bIsRunning)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
UE_LOG(LogFunctionalTest, Warning, TEXT("Functional tests are already running, aborting."));
|
2014-04-23 19:29:53 -04:00
|
|
|
return true;
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FMessageLog FunctionalTestingLog("FunctionalTestingLog");
|
|
|
|
|
FunctionalTestingLog.Open();
|
|
|
|
|
if (bNewLog)
|
|
|
|
|
{
|
|
|
|
|
FunctionalTestingLog.NewPage(LOCTEXT("NewLogLabel", "Functional Test"));
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 19:29:53 -04:00
|
|
|
Manager->bLooped = bRunLooped;
|
|
|
|
|
Manager->bWaitForNavigationBuildFinish = bInWaitForNavigationBuildFinish;
|
|
|
|
|
Manager->CurrentIteration = 0;
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2014-04-30 17:34:38 -04:00
|
|
|
for (TActorIterator<AFunctionalTest> It(GWorld); It; ++It)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-04-30 17:34:38 -04:00
|
|
|
AFunctionalTest* Test = (*It);
|
2014-04-23 19:29:53 -04:00
|
|
|
if (Test != NULL && Test->bIsEnabled == true)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-04-23 19:29:53 -04:00
|
|
|
Manager->AllTests.Add(Test);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 19:29:53 -04:00
|
|
|
if (Manager->AllTests.Num() > 0)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-04-23 19:29:53 -04:00
|
|
|
Manager->SetUpTests();
|
|
|
|
|
Manager->TestsLeft = Manager->AllTests;
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2014-04-23 19:29:53 -04:00
|
|
|
Manager->TriggerFirstValidTest();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Manager->bIsRunning == false)
|
|
|
|
|
{
|
|
|
|
|
FunctionalTestingLog.Info(LOCTEXT("NoTestsDefined", "No tests defined on map or . DONE."));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if WITH_EDITOR
|
|
|
|
|
FEditorDelegates::EndPIE.AddUObject(Manager, &UFunctionalTestingManager::OnEndPIE);
|
|
|
|
|
#endif // WITH_EDITOR
|
|
|
|
|
Manager->AddToRoot();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UFunctionalTestingManager::OnEndPIE(const bool bIsSimulating)
|
|
|
|
|
{
|
|
|
|
|
RemoveFromRoot();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UFunctionalTestingManager::TriggerFirstValidTest()
|
|
|
|
|
{
|
|
|
|
|
UWorld* World = GEngine->GetWorldFromContextObject(GetOuter());
|
|
|
|
|
bIsRunning = World != NULL && World->GetNavigationSystem() != NULL;
|
|
|
|
|
|
|
|
|
|
if (bInitialDelayApplied == true && (bWaitForNavigationBuildFinish == false || UNavigationSystem::IsNavigationBeingBuilt(World) == false))
|
|
|
|
|
{
|
2014-03-14 14:13:41 -04:00
|
|
|
bIsRunning = RunFirstValidTest();
|
|
|
|
|
}
|
2014-04-23 19:29:53 -04:00
|
|
|
else
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-04-23 19:29:53 -04:00
|
|
|
bInitialDelayApplied = true;
|
|
|
|
|
static const float WaitingTime = 0.25f;
|
|
|
|
|
World->GetTimerManager().SetTimer(this, &UFunctionalTestingManager::TriggerFirstValidTest, WaitingTime);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 19:29:53 -04:00
|
|
|
UFunctionalTestingManager* UFunctionalTestingManager::GetManager(UObject* WorldContext)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-04-23 19:29:53 -04:00
|
|
|
UFunctionalTestingManager* Manager = FFunctionalTestingModule::Get()->GetCurrentScript();
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2014-04-23 19:29:53 -04:00
|
|
|
if (Manager == NULL)
|
|
|
|
|
{
|
|
|
|
|
UObject* Outer = WorldContext ? WorldContext : (UObject*)GetTransientPackage();
|
|
|
|
|
Manager = NewObject<UFunctionalTestingManager>(Outer);
|
|
|
|
|
FFunctionalTestingModule::Get()->SetScript(Manager);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Manager;
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UFunctionalTestingManager::OnTestDone(AFunctionalTest* FTest)
|
|
|
|
|
{
|
|
|
|
|
// add a delay
|
|
|
|
|
FSimpleDelegateGraphTask::CreateAndDispatchWhenReady(
|
|
|
|
|
FSimpleDelegateGraphTask::FDelegate::CreateUObject(this, &UFunctionalTestingManager::NotifyTestDone, FTest)
|
|
|
|
|
, TEXT("Requesting to build next tile if necessary")
|
|
|
|
|
, NULL
|
|
|
|
|
, ENamedThreads::GameThread
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UFunctionalTestingManager::NotifyTestDone(AFunctionalTest* FTest)
|
|
|
|
|
{
|
|
|
|
|
FMessageLog FunctionalTestingLog("FunctionalTestingLog");
|
|
|
|
|
|
2014-04-23 19:29:53 -04:00
|
|
|
if (FTest->WantsToRunAgain() == false)
|
|
|
|
|
{
|
|
|
|
|
TestsLeft.RemoveSingle(FTest);
|
|
|
|
|
FTest->CleanUp();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (TestsLeft.Num() > 0)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
bIsRunning = RunFirstValidTest();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bIsRunning = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bIsRunning == false)
|
|
|
|
|
{
|
|
|
|
|
if (bLooped == true)
|
|
|
|
|
{
|
|
|
|
|
++CurrentIteration;
|
|
|
|
|
TestsLeft = AllTests;
|
|
|
|
|
FFormatNamedArguments Arguments;
|
|
|
|
|
Arguments.Add(TEXT("IterationIndex"), CurrentIteration);
|
|
|
|
|
FunctionalTestingLog.Info( FText::Format(LOCTEXT("StartingIteration", "----- Starting iteration {IterationIndex} -----"), Arguments) );
|
|
|
|
|
bIsRunning = RunFirstValidTest();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FunctionalTestingLog.Info( LOCTEXT("TestDone", "DONE.") );
|
2014-04-23 19:29:53 -04:00
|
|
|
RemoveFromRoot();
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool UFunctionalTestingManager::RunFirstValidTest()
|
|
|
|
|
{
|
|
|
|
|
for (int32 Index = 0; Index < TestsLeft.Num(); ++Index)
|
|
|
|
|
{
|
2014-04-23 19:29:53 -04:00
|
|
|
bool bRemove = TestsLeft[Index] == NULL;
|
|
|
|
|
if (TestsLeft[Index] != NULL)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-04-23 19:29:53 -04:00
|
|
|
ensure(TestsLeft[Index]->bIsEnabled);
|
2014-03-14 14:13:41 -04:00
|
|
|
TestsLeft[Index]->TestFinishedObserver = FFunctionalTestDoneSignature::CreateUObject(this, &UFunctionalTestingManager::OnTestDone);
|
2014-04-23 19:29:53 -04:00
|
|
|
if (TestsLeft[Index]->StartTest())
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bRemove = true;
|
|
|
|
|
}
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
2014-04-23 19:29:53 -04:00
|
|
|
|
|
|
|
|
if (bRemove)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
TestsLeft.RemoveAtSwap(Index, 1, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 19:29:53 -04:00
|
|
|
void UFunctionalTestingManager::TickMe(float DeltaTime)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
#undef LOCTEXT_NAMESPACE
|