2021-09-29 02:38:01 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
2022-08-12 10:47:11 -04:00
# include "MassEntityManager.h"
2021-09-30 14:28:31 -04:00
# include "MassProcessingTypes.h"
2021-09-29 02:38:01 -04:00
# include "MassEntityTestTypes.h"
# include "MassExecutor.h"
2021-10-01 13:35:13 -04:00
# define LOCTEXT_NAMESPACE "MassTest"
2021-09-29 02:38:01 -04:00
2023-01-20 10:29:35 -05:00
UE_DISABLE_OPTIMIZATION_SHIP
2021-09-29 02:38:01 -04:00
//----------------------------------------------------------------------//
// tests
//----------------------------------------------------------------------//
2021-10-07 16:54:55 -04:00
namespace FMassExecutionTest
2021-09-29 02:38:01 -04:00
{
struct FExecution_Setup : FExecutionTestBase
{
virtual bool InstantTest ( ) override
{
2022-08-12 07:56:27 -04:00
AITEST_NOT_NULL ( " EntitySubsystem needs to be created for the test to be performed " , EntityManager . Get ( ) ) ;
2021-09-29 02:38:01 -04:00
return true ;
}
} ;
2021-10-01 13:35:13 -04:00
IMPLEMENT_AI_INSTANT_TEST ( FExecution_Setup , " System.Mass.Execution.Setup " ) ;
2021-09-29 02:38:01 -04:00
struct FExecution_EmptyArray : FExecutionTestBase
{
virtual bool InstantTest ( ) override
{
2022-08-12 07:56:27 -04:00
CA_ASSUME ( EntityManager ) ; // if EntitySubsystem null InstantTest won't be called at all
2021-09-29 02:38:01 -04:00
const float DeltaSeconds = 0.f ;
2022-08-12 07:56:27 -04:00
FMassProcessingContext ProcessingContext ( * EntityManager , DeltaSeconds ) ;
2021-09-29 02:38:01 -04:00
// no test performed, let's just see if it results in errors/warnings
2021-10-01 13:35:13 -04:00
UE : : Mass : : Executor : : RunProcessorsView ( TArrayView < UMassProcessor * > ( ) , ProcessingContext ) ;
2021-09-29 02:38:01 -04:00
return true ;
}
} ;
2021-10-01 13:35:13 -04:00
IMPLEMENT_AI_INSTANT_TEST ( FExecution_EmptyArray , " System.Mass.Execution.EmptyArray " ) ;
2021-09-29 02:38:01 -04:00
struct FExecution_EmptyPipeline : FExecutionTestBase
{
virtual bool InstantTest ( ) override
{
2022-08-12 07:56:27 -04:00
CA_ASSUME ( EntityManager ) ; // if EntitySubsystem null InstantTest won't be called at all
2021-09-29 02:38:01 -04:00
const float DeltaSeconds = 0.f ;
2022-08-12 07:56:27 -04:00
FMassProcessingContext ProcessingContext ( * EntityManager , DeltaSeconds ) ;
2021-09-30 10:07:42 -04:00
FMassRuntimePipeline Pipeline ;
2021-09-29 02:38:01 -04:00
// no test performed, let's just see if it results in errors/warnings
2021-10-01 13:35:13 -04:00
UE : : Mass : : Executor : : Run ( Pipeline , ProcessingContext ) ;
2021-09-29 02:38:01 -04:00
return true ;
}
} ;
2021-10-01 13:35:13 -04:00
IMPLEMENT_AI_INSTANT_TEST ( FExecution_EmptyPipeline , " System.Mass.Execution.EmptyPipeline " ) ;
2021-09-29 02:38:01 -04:00
2021-10-01 13:35:13 -04:00
struct FExecution_InvalidProcessingContext : FExecutionTestBase
2021-09-29 02:38:01 -04:00
{
virtual bool InstantTest ( ) override
{
2022-08-12 07:56:27 -04:00
CA_ASSUME ( EntityManager ) ;
2021-09-29 02:38:01 -04:00
const float DeltaSeconds = 0.f ;
2021-10-01 13:35:13 -04:00
FMassProcessingContext ProcessingContext ;
2021-09-29 02:38:01 -04:00
// test assumption
2022-08-12 07:56:27 -04:00
AITEST_NULL ( " FMassProcessingContext \' s default constructor is expected to set FMassProcessingContext.EntitySubsystem to null " , ProcessingContext . EntityManager . Get ( ) ) ;
2021-09-29 02:38:01 -04:00
2024-07-25 13:36:25 -04:00
AITEST_SCOPED_CHECK ( TEXT ( " ProcessingContext.EntityManager is null " ) , 1 ) ;
2021-10-01 09:26:13 -04:00
// note that using RunProcessorsView is to bypass reasonable tests UE::Mass::Executor::Run(Pipeline,...) does that are
2021-09-29 02:38:01 -04:00
// reported via ensures which are not handled by the automation framework
2021-10-01 13:35:13 -04:00
UE : : Mass : : Executor : : RunProcessorsView ( TArrayView < UMassProcessor * > ( ) , ProcessingContext ) ;
2021-09-29 02:38:01 -04:00
return true ;
}
} ;
2021-10-01 13:35:13 -04:00
IMPLEMENT_AI_INSTANT_TEST ( FExecution_InvalidProcessingContext , " System.Mass.Execution.InvalidProcessingContext " ) ;
2021-09-29 02:38:01 -04:00
2021-09-30 06:19:44 -04:00
# if WITH_MASSENTITY_DEBUG
2021-09-29 02:38:01 -04:00
struct FExecution_SingleNullProcessor : FExecutionTestBase
{
virtual bool InstantTest ( ) override
{
2022-08-12 07:56:27 -04:00
CA_ASSUME ( EntityManager ) ;
2021-09-29 02:38:01 -04:00
const float DeltaSeconds = 0.f ;
2022-08-12 07:56:27 -04:00
FMassProcessingContext ProcessingContext ( EntityManager , DeltaSeconds ) ;
2021-09-30 10:07:42 -04:00
TArray < UMassProcessor * > Processors ;
2021-09-29 02:38:01 -04:00
Processors . Add ( nullptr ) ;
2024-07-25 13:36:25 -04:00
AITEST_SCOPED_CHECK ( TEXT ( " Processors contains nullptr " ) , 1 ) ;
2021-10-01 09:26:13 -04:00
// note that using RunProcessorsView is to bypass reasonable tests UE::Mass::Executor::Run(Pipeline,...) does that are
2021-09-29 02:38:01 -04:00
// reported via ensures which are not handled by the automation framework
2021-10-01 13:35:13 -04:00
UE : : Mass : : Executor : : RunProcessorsView ( Processors , ProcessingContext ) ;
2021-09-29 02:38:01 -04:00
return true ;
}
} ;
2021-10-01 13:35:13 -04:00
IMPLEMENT_AI_INSTANT_TEST ( FExecution_SingleNullProcessor , " System.Mass.Execution.SingleNullProcessor " ) ;
2021-09-29 02:38:01 -04:00
struct FExecution_SingleValidProcessor : FExecutionTestBase
{
virtual bool InstantTest ( ) override
{
2022-08-12 07:56:27 -04:00
CA_ASSUME ( EntityManager ) ;
2021-09-29 02:38:01 -04:00
const float DeltaSeconds = 0.f ;
2022-08-12 07:56:27 -04:00
FMassProcessingContext ProcessingContext ( EntityManager , DeltaSeconds ) ;
UMassTestProcessorBase * Processor = NewObject < UMassTestProcessorBase > ( ) ;
2021-09-29 02:38:01 -04:00
check ( Processor ) ;
2024-03-15 06:16:08 -04:00
// need to set up some requirements to make EntityQuery valid
Processor - > EntityQuery . AddRequirement < FTestFragment_Float > ( EMassFragmentAccess : : ReadOnly ) ;
2021-09-29 02:38:01 -04:00
2024-03-15 06:16:08 -04:00
// nothing should break. The actual result of processing is getting tested in MassProcessorTest.cpp
2021-10-01 13:35:13 -04:00
UE : : Mass : : Executor : : Run ( * Processor , ProcessingContext ) ;
2021-09-29 02:38:01 -04:00
return true ;
}
} ;
2021-10-01 13:35:13 -04:00
IMPLEMENT_AI_INSTANT_TEST ( FExecution_SingleValidProcessor , " System.Mass.Execution.SingleValidProcessor " ) ;
2021-09-29 02:38:01 -04:00
struct FExecution_MultipleNullProcessors : FExecutionTestBase
{
virtual bool InstantTest ( ) override
{
2022-08-12 07:56:27 -04:00
CA_ASSUME ( EntityManager ) ;
2021-09-29 02:38:01 -04:00
const float DeltaSeconds = 0.f ;
2022-08-12 07:56:27 -04:00
FMassProcessingContext ProcessingContext ( EntityManager , DeltaSeconds ) ;
2021-09-30 10:07:42 -04:00
TArray < UMassProcessor * > Processors ;
2021-09-29 02:38:01 -04:00
Processors . Add ( nullptr ) ;
Processors . Add ( nullptr ) ;
Processors . Add ( nullptr ) ;
2024-07-25 13:36:25 -04:00
AITEST_SCOPED_CHECK ( TEXT ( " Processors contains nullptr " ) , 1 ) ;
2021-10-01 09:26:13 -04:00
// note that using RunProcessorsView is to bypass reasonable tests UE::Mass::Executor::Run(Pipeline,...) does that are
2021-09-29 02:38:01 -04:00
// reported via ensures which are not handled by the automation framework
2021-10-01 13:35:13 -04:00
UE : : Mass : : Executor : : RunProcessorsView ( Processors , ProcessingContext ) ;
2021-09-29 02:38:01 -04:00
return true ;
}
} ;
2021-10-01 13:35:13 -04:00
IMPLEMENT_AI_INSTANT_TEST ( FExecution_MultipleNullProcessors , " System.Mass.Execution.MultipleNullProcessors " ) ;
2021-09-30 06:19:44 -04:00
# endif // WITH_MASSENTITY_DEBUG
2021-09-29 02:38:01 -04:00
struct FExecution_Sparse : FEntityTestBase
{
virtual bool InstantTest ( ) override
{
2022-08-12 07:56:27 -04:00
CA_ASSUME ( EntityManager ) ;
2021-09-29 02:38:01 -04:00
const float DeltaSeconds = 0.f ;
2022-08-12 07:56:27 -04:00
FMassProcessingContext ProcessingContext ( * EntityManager , DeltaSeconds ) ;
UMassTestProcessorBase * Processor = NewObject < UMassTestProcessorBase > ( ) ;
2021-09-29 02:38:01 -04:00
check ( Processor ) ;
2024-03-15 06:16:08 -04:00
// need to set up some requirements to make EntityQuery valid
Processor - > EntityQuery . AddRequirement < FTestFragment_Float > ( EMassFragmentAccess : : ReadOnly ) ;
2021-09-29 02:38:01 -04:00
2021-09-30 10:07:42 -04:00
FMassRuntimePipeline Pipeline ;
2021-09-29 02:38:01 -04:00
{
2021-09-30 10:07:42 -04:00
TArray < UMassProcessor * > Processors ;
2021-09-29 02:38:01 -04:00
Processors . Add ( Processor ) ;
Pipeline . SetProcessors ( MoveTemp ( Processors ) ) ;
}
2022-03-08 10:30:07 -05:00
FMassArchetypeEntityCollection EntityCollection ( FloatsArchetype ) ;
2024-03-15 06:16:08 -04:00
// nothing should break. The actual result of processing is getting tested in MassProcessorTest.cpp
2021-09-29 02:38:01 -04:00
2022-03-08 10:30:07 -05:00
UE : : Mass : : Executor : : RunSparse ( Pipeline , ProcessingContext , EntityCollection ) ;
2021-09-29 02:38:01 -04:00
return true ;
}
} ;
2021-10-01 13:35:13 -04:00
IMPLEMENT_AI_INSTANT_TEST ( FExecution_Sparse , " System.Mass.Execution.Sparse " ) ;
2021-10-07 16:54:55 -04:00
} // FMassExecutionTest
2021-09-29 02:38:01 -04:00
2023-01-20 10:29:35 -05:00
UE_ENABLE_OPTIMIZATION_SHIP
2021-09-29 02:38:01 -04:00
# undef LOCTEXT_NAMESPACE