5#if WITH_AUTOMATION_TESTS
7#include "CoreMinimal.h"
8#include "Engine/Blueprint.h"
9#include "Tests/AutomationCommon.h"
10#include "Blueprint/WidgetBlueprintLibrary.h"
11#include "Blueprint/WidgetTree.h"
12#include "Blueprint/UserWidget.h"
18template <
typename Type1,
typename Type2>
23 float Tolerance = KINDA_SMALL_NUMBER;
26#define ENUM_LOOP_START(TYPE, EnumElem) \
27 for (int32 Index = 0; Index < StaticEnum<TYPE>()->NumEnums() - 1; ++Index) \
29 const auto EnumElem = static_cast<TYPE>(StaticEnum<TYPE>()->GetValueByIndex(Index));
30#define ENUM_LOOP_END }
32template <
typename EnumType,
typename FunctionType>
33void ForEach(FunctionType&& Function)
35 const UEnum* Enum = StaticEnum<EnumType>();
36 for (int32 i = 0; i < Enum->NumEnums(); ++i)
38 Function(
static_cast<EnumType
>(Enum->GetValueByIndex(i)));
43T* CreateBlueprint(UWorld* World,
const FString& Name,
const FTransform& Transform = FTransform::Identity)
45 const UBlueprint* Blueprint = LoadObject<UBlueprint>(
nullptr, *Name);
46 return (World && Blueprint) ? World->SpawnActor<T>(Blueprint->GeneratedClass, Transform) :
nullptr;
50T* CreateBlueprintDeferred(UWorld* World,
const FString& Name,
const FTransform& Transform = FTransform::Identity)
52 const UBlueprint* Blueprint = LoadObject<UBlueprint>(
nullptr, *Name);
53 return (World && Blueprint) ? World->SpawnActorDeferred<T>(Blueprint->GeneratedClass, Transform) :
nullptr;
59 LevelScope(
const FString& MapName) { AutomationOpenMap(MapName); }
60 ~LevelScope() { ADD_LATENT_AUTOMATION_COMMAND(FExitGameCommand); }
63UWorld* GetTestGameWorld();
65void CallFuncByNameWithParams(UObject* Object,
const FString& FuncName,
const TArray<FString>& Params);
67class FTPSUntilLatentCommand :
public IAutomationLatentCommand
70 FTPSUntilLatentCommand(TFunction<
void()> InCallback, TFunction<
void()> InTimeoutCallback,
float InTimeout = 5.0f);
71 virtual bool Update()
override;
74 TFunction<void()> Callback;
75 TFunction<void()> TimeoutCallback;
79int32 GetActionBindingIndexByName(UInputComponent* InputComp,
const FString& ActionName, EInputEvent InputEvent);
80int32 GetAxisBindingIndexByName(UInputComponent* InputComp,
const FString& AxisName);
82FString GetTestDataDir();
87 TArray<UUserWidget*> Widgets;
88 UWidgetBlueprintLibrary::GetAllWidgetsOfClass(GetTestGameWorld(), Widgets, T::StaticClass(),
false);
89 return Widgets.Num() != 0 ? Cast<T>(Widgets[0]) : nullptr;
92UWidget* FindWidgetByName(
const UUserWidget* Widget,
const FName& WidgetName);
94void DoInputAction(UInputComponent* InputComponent,
const FString& ActionName,
const FKey& Key);
95void JumpPressed(UInputComponent* InputComponent);
96void PausePressed(UInputComponent* InputComponent);
98class FTakeScreenshotLatentCommand :
public IAutomationLatentCommand
101 FTakeScreenshotLatentCommand(
const FString& InScreenshotName);
102 virtual ~FTakeScreenshotLatentCommand();
105 const FString ScreenshotName;
106 bool ScreenshotRequested{
false};
107 bool CommandCompleted{
false};
109 virtual void OnScreenshotTakenAndCompared();
112class FTakeGameScreenshotLatentCommand :
public FTakeScreenshotLatentCommand
115 FTakeGameScreenshotLatentCommand(
const FString& InScreenshotName);
117 virtual bool Update()
override;
120class FTakeUIScreenshotLatentCommand :
public FTakeScreenshotLatentCommand
123 FTakeUIScreenshotLatentCommand(
const FString& InScreenshotName);
124 virtual bool Update()
override;
127 bool ScreenshotSetupDone{
false};
129 virtual void OnScreenshotTakenAndCompared()
override;
130 void SetBufferVisualization(
const FName& VisualizeBuffer);
133void SpecCloseLevel(UWorld* World);
135template <
class ObjectClass,
class PropertyClass>
136PropertyClass GetPropertyValueByName(ObjectClass* Obj,
const FString& PropName)
138 if (!Obj)
return PropertyClass();
139 for (TFieldIterator<FProperty> PropIt(Obj->StaticClass()); PropIt; ++PropIt)
141 const FProperty* Property = *PropIt;
142 if (Property && Property->GetName().Equals(PropName))
144 return *Property->ContainerPtrToValuePtr<PropertyClass>(Obj);
147 return PropertyClass();