Files
UnrealEngineUWP/Engine/Source/Developer/FunctionalTesting/Private/ScreenshotFunctionalTest.cpp
Matt Kuhlenschmidt 92eed46d3f Merging //UE4/Dev-Main to Dev-Geometry (//UE4/Dev-Geometry)
#rb none

[CL 3635882 by Matt Kuhlenschmidt in Dev-Geometry branch]
2017-09-11 10:43:35 -04:00

115 lines
3.2 KiB
C++

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
#include "ScreenshotFunctionalTest.h"
#include "Engine/GameViewportClient.h"
#include "AutomationBlueprintFunctionLibrary.h"
#include "Camera/CameraComponent.h"
#include "Camera/PlayerCameraManager.h"
#include "Kismet/GameplayStatics.h"
#include "Engine/Engine.h"
#include "EngineGlobals.h"
#include "Misc/AutomationTest.h"
AScreenshotFunctionalTest::AScreenshotFunctionalTest( const FObjectInitializer& ObjectInitializer )
: AFunctionalTest(ObjectInitializer)
, bCameraCutOnScreenshotPrep(false)
, ScreenshotOptions(EComparisonTolerance::Low)
{
ScreenshotCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
ScreenshotCamera->SetupAttachment(RootComponent);
}
void AScreenshotFunctionalTest::PrepareTest()
{
APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
if (PlayerController)
{
PlayerController->SetViewTarget(this, FViewTargetTransitionParams());
}
// It's possible the defaults for certain tolerance levels have changed, so reset them on test start.
ScreenshotOptions.SetToleranceAmounts(ScreenshotOptions.Tolerance);
Super::PrepareTest();
// Apply a camera cut if requested
if (bCameraCutOnScreenshotPrep)
{
if (PlayerController && PlayerController->PlayerCameraManager)
{
PlayerController->PlayerCameraManager->bGameCameraCutThisFrame = true;
if (ScreenshotCamera)
{
ScreenshotCamera->NotifyCameraCut();
}
}
}
}
bool AScreenshotFunctionalTest::IsReady_Implementation()
{
if ( (GetWorld()->GetTimeSeconds() - RunTime) > ScreenshotOptions.Delay )
{
return ( GFrameNumber - RunFrame ) > 5;
}
return false;
}
void AScreenshotFunctionalTest::StartTest()
{
Super::StartTest();
UAutomationBlueprintFunctionLibrary::TakeAutomationScreenshotInternal(this, GetName(), ScreenshotOptions);
FAutomationTestFramework::Get().OnScreenshotTakenAndCompared.AddUObject(this, &AScreenshotFunctionalTest::OnScreenshotTakenAndCompared);
}
void AScreenshotFunctionalTest::OnScreenshotTakenAndCompared()
{
FAutomationTestFramework::Get().OnScreenshotTakenAndCompared.RemoveAll(this);
FinishTest(EFunctionalTestResult::Succeeded, TEXT(""));
}
#if WITH_EDITOR
bool AScreenshotFunctionalTest::CanEditChange(const UProperty* InProperty) const
{
bool bIsEditable = Super::CanEditChange(InProperty);
if ( bIsEditable && InProperty )
{
const FName PropertyName = InProperty->GetFName();
if ( PropertyName == GET_MEMBER_NAME_CHECKED(FAutomationScreenshotOptions, ToleranceAmount) )
{
bIsEditable = ScreenshotOptions.Tolerance == EComparisonTolerance::Custom;
}
else if ( PropertyName == TEXT("ObservationPoint") )
{
// You can't ever observe from anywhere but the camera on the screenshot test.
bIsEditable = false;
}
}
return bIsEditable;
}
void AScreenshotFunctionalTest::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
Super::PostEditChangeProperty(PropertyChangedEvent);
if ( PropertyChangedEvent.Property )
{
const FName PropertyName = PropertyChangedEvent.Property->GetFName();
if ( PropertyName == GET_MEMBER_NAME_CHECKED(FAutomationScreenshotOptions, Tolerance) )
{
ScreenshotOptions.SetToleranceAmounts(ScreenshotOptions.Tolerance);
}
}
}
#endif