2014-12-07 19:09:38 -05:00
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
2014-03-14 14:13:41 -04:00
# include "FunctionalTestingPrivatePCH.h"
2014-06-25 05:47:19 -04:00
# include "Engine/World.h"
2014-03-14 14:13:41 -04:00
DEFINE_LOG_CATEGORY ( LogFunctionalTest ) ;
void FFuncTestManager : : SetScript ( class UFunctionalTestingManager * NewScript )
{
TestScript = NewScript ;
}
bool FFuncTestManager : : IsRunning ( ) const
{
return TestScript . IsValid ( ) & & TestScript - > IsRunning ( ) ;
}
2014-12-10 09:17:33 -05:00
bool FFuncTestManager : : IsFinished ( ) const
{
2015-10-06 15:59:09 -04:00
return ( ! TestScript . IsValid ( ) | | TestScript - > IsFinished ( ) ) ;
2014-12-10 09:17:33 -05:00
}
2014-03-14 14:13:41 -04:00
void FFuncTestManager : : SetLooping ( const bool bLoop )
{
if ( TestScript . IsValid ( ) )
{
TestScript - > SetLooped ( bLoop ) ;
}
}
void FFuncTestManager : : RunAllTestsOnMap ( bool bClearLog , bool bRunLooped )
{
2015-10-06 15:59:09 -04:00
UWorld * TestWorld = NULL ;
# if WITH_EDITOR
const TIndirectArray < FWorldContext > & WorldContexts = GEngine - > GetWorldContexts ( ) ;
for ( const FWorldContext & Context : WorldContexts )
2014-03-14 14:13:41 -04:00
{
2015-10-06 15:59:09 -04:00
if ( ( Context . WorldType = = EWorldType : : PIE ) & & ( Context . World ( ) ! = NULL ) )
{
TestWorld = Context . World ( ) ;
}
}
# endif
if ( ! TestWorld )
{
TestWorld = GWorld ;
UE_LOG ( LogFunctionalTest , Warning , TEXT ( " Functional Test using GWorld. Not correct for PIE " ) ) ;
}
if ( TestWorld )
{
if ( UFunctionalTestingManager : : RunAllFunctionalTests ( TestWorld , bClearLog , bRunLooped ) = = false )
{
UE_LOG ( LogFunctionalTest , Error , TEXT ( " No functional testing script on map. " ) ) ;
}
2014-03-14 14:13:41 -04:00
}
}
//////////////////////////////////////////////////////////////////////////
// Exec
//////////////////////////////////////////////////////////////////////////
static bool FuncTestExec ( UWorld * InWorld , const TCHAR * Command , FOutputDevice & Ar )
{
if ( FParse : : Command ( & Command , TEXT ( " ftest " ) ) )
{
if ( FParse : : Command ( & Command , TEXT ( " start " ) ) )
{
const bool bLooped = FParse : : Command ( & Command , TEXT ( " loop " ) ) ;
2015-10-06 15:59:09 -04:00
//instead of allowing straight use of the functional test framework, this should go through the automation framework and kick off one of the Editor/Client functional tests
//FFunctionalTestingModule::Get()->RunAllTestsOnMap(/*bClearLog=*/true, bLooped);
FString TestName = InWorld - > GetName ( ) ;
FString AutomationString = FString : : Printf ( TEXT ( " Automation RunTests FunctionalTesting.%s " ) , * TestName ) ;
GEngine - > Exec ( InWorld , * AutomationString ) ;
2014-03-14 14:13:41 -04:00
}
return true ;
}
return false ;
}
FStaticSelfRegisteringExec FuncTestExecRegistration ( FuncTestExec ) ;