Files
UnrealEngineUWP/Engine/Source/Editor/StaticMeshEditor/Private/StaticMeshAutomationTests.cpp
Martin Mittring 97ee86291e UE-19859 Remove debug/show rendering features on shipping
I did the first part, lock some showflags to be 0 or 1 in SHIPPING
If this causes problems for some applications (e.g. using showflag as scalability which they shouldn't) the user needs to update the code.
or we remove the lock from that showflag.
For editor or non shipping features it's fine to use the SetSHOWFLAGNAME() calls, they become NOPS in SHIPPING.

This is a performance optimization (when  used in inner loop) and prepares for removing more

[CL 2673126 by Martin Mittring in Main branch]
2015-08-28 17:18:26 -04:00

242 lines
7.9 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "StaticMeshEditorModule.h"
#include "AutomationCommon.h"
#include "SStaticMeshEditorViewport.h"
#include "StaticMeshEditorViewportClient.h"
#include "Engine/StaticMesh.h"
namespace EditorViewButtonHelper
{
/**
* The types of buttons that will be toggled on and off, if new buttons are made that want to be added,
* all you need to do is add them to this list, and fill out the latent automation task below with how to toggle the button
*/
namespace EStaticMeshFlag
{
enum Type
{
Wireframe = 0,
Vert,
Grid,
Bounds,
Collision,
Pivot,
Normals,
Tangents,
Binormals,
UV,
Max //Do not go beyond this
};
}
/**
* The struct we will be passing into the below Latent Automation Task
*/
struct PerformStaticMeshFlagParameters
{
FStaticMeshEditorViewportClient* ViewportClient;
EStaticMeshFlag::Type CommandType;
};
static const TCHAR* GetStaticMeshFlagName(EStaticMeshFlag::Type InType)
{
switch(InType)
{
case EStaticMeshFlag::Wireframe:
return TEXT("Wireframe");
case EStaticMeshFlag::Vert:
return TEXT("Vertex");
case EStaticMeshFlag::Grid:
return TEXT("Grid");
case EStaticMeshFlag::Bounds:
return TEXT("Bounds");
case EStaticMeshFlag::Collision:
return TEXT("Collision");
case EStaticMeshFlag::Pivot:
return TEXT("Pivot");
case EStaticMeshFlag::Normals:
return TEXT("Normals");
case EStaticMeshFlag::Tangents:
return TEXT("Tangents");
case EStaticMeshFlag::Binormals:
return TEXT("Binormals");
case EStaticMeshFlag::UV:
return TEXT("UV");
default:
break;
}
return TEXT("Unknown");
}
/**
* Used for toggling a certain button on/off based on the passed in viewport client and button type.
*/
DEFINE_LATENT_AUTOMATION_COMMAND_ONE_PARAMETER(FPerformStaticMeshFlagToggle, PerformStaticMeshFlagParameters, AutomationParameters);
bool EditorViewButtonHelper::FPerformStaticMeshFlagToggle::Update()
{
switch(AutomationParameters.CommandType)
{
case EStaticMeshFlag::Wireframe:
if (AutomationParameters.ViewportClient->GetViewMode() != VMI_Wireframe)
{
AutomationParameters.ViewportClient->SetViewMode(VMI_Wireframe);
}
else
{
AutomationParameters.ViewportClient->SetViewMode(VMI_Lit);
}
break;
case EStaticMeshFlag::Vert:
if (!AutomationParameters.ViewportClient->EngineShowFlags.VertexColors)
{
AutomationParameters.ViewportClient->EngineShowFlags.SetVertexColors(true);
AutomationParameters.ViewportClient->EngineShowFlags.SetLighting(false);
}
else
{
AutomationParameters.ViewportClient->EngineShowFlags.SetVertexColors(false);
AutomationParameters.ViewportClient->EngineShowFlags.SetLighting(true);
}
break;
case EStaticMeshFlag::Grid:
AutomationParameters.ViewportClient->SetShowGrid();
break;
case EStaticMeshFlag::Bounds:
AutomationParameters.ViewportClient->EngineShowFlags.SetBounds(!AutomationParameters.ViewportClient->EngineShowFlags.Bounds);
break;
case EStaticMeshFlag::Collision:
AutomationParameters.ViewportClient->SetShowCollision();
break;
case EStaticMeshFlag::Pivot:
AutomationParameters.ViewportClient->SetShowPivot();
break;
case EStaticMeshFlag::Normals:
AutomationParameters.ViewportClient->SetShowNormals();
break;
case EStaticMeshFlag::Tangents:
AutomationParameters.ViewportClient->SetShowTangents();
break;
case EStaticMeshFlag::Binormals:
AutomationParameters.ViewportClient->SetShowBinormals();
break;
case EStaticMeshFlag::UV:
AutomationParameters.ViewportClient->SetDrawUVOverlay();
break;
default:
//Break out immediately.
break;
}
return true;
}
/**
* Close all asset editors
*/
DEFINE_LATENT_AUTOMATION_COMMAND(FCloseAllAssetEditorsCommand);
bool FCloseAllAssetEditorsCommand::Update()
{
FAssetEditorManager::Get().CloseAllAssetEditors();
return true;
}
}
/**
* Static mesh editor test
*/
IMPLEMENT_SIMPLE_AUTOMATION_TEST(FStaticMeshEditorTest, "System.Editor.Content.Static Mesh Editor Test", EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter)
/**
* Take screenshots of the SME window with each of the toolbar buttons toggled separately
*/
bool FStaticMeshEditorTest::RunTest(const FString& Parameters)
{
TArray<FString> ButtonNamesToTestFor;
FString LoadedObjectType = TEXT("EditorCylinder");
FString MeshName;
EditorViewButtonHelper::PerformStaticMeshFlagParameters AutomationParameters;
WindowScreenshotParameters WindowParameters;
//Pull from .ini the names of the buttons we want to test for
GConfig->GetString( TEXT("AutomationTesting"), TEXT("EditorViewButtonsObject"), LoadedObjectType, GEngineIni);
//Open static mesh in the editor and save out the window for the screenshots
UObject* EditorMesh = (UStaticMesh*)StaticLoadObject(UStaticMesh::StaticClass(),
NULL,
*FString::Printf(TEXT("/Engine/EditorMeshes/%s.%s"), *LoadedObjectType, *LoadedObjectType),
NULL,
LOAD_None,
NULL);
FAssetEditorManager::Get().OpenEditorForAsset(EditorMesh);
{
TArray<TSharedRef<SWindow>> AllWindows;
FSlateApplication::Get().GetAllVisibleWindowsOrdered(AllWindows);
const FText ExpectedTitle = FText::FromString(LoadedObjectType);
if (auto* Window = AllWindows.FindByPredicate([&](const TSharedRef<SWindow>& In) { return In->GetTitle().EqualTo(ExpectedTitle); }))
{
WindowParameters.CurrentWindow = *Window;
}
}
if (!WindowParameters.CurrentWindow.IsValid())
{
AddError(TEXT("Could not find static mesh editor window"));
return false;
}
//Grab the last opened Viewport (aka the asset manager)
AutomationParameters.ViewportClient = static_cast<FStaticMeshEditorViewportClient*>(GEditor->AllViewportClients[GEditor->AllViewportClients.Num() - 1]);
AutomationParameters.CommandType = EditorViewButtonHelper::EStaticMeshFlag::Wireframe; //Start it off at Wireframe because that is the first button we are attempting to press
if (AutomationParameters.ViewportClient)
{
const FString BaseFileName = TEXT("StaticMeshEditorTest");
FString TestName = FString::Printf(TEXT("%s/Base"), *BaseFileName);
//Wait for the window to load and then take the initial screen shot
ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(0.5f));
if( FAutomationTestFramework::GetInstance().IsScreenshotAllowed() )
{
AutomationCommon::GetScreenshotPath(TestName, WindowParameters.ScreenshotName, false);
ADD_LATENT_AUTOMATION_COMMAND(FTakeEditorScreenshotCommand(WindowParameters));
ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(0.1f));
}
for(auto CurrentCommandType = 0; CurrentCommandType < EditorViewButtonHelper::EStaticMeshFlag::Max; ++CurrentCommandType)
{
TestName = FString::Printf(TEXT("%s/%s"), *BaseFileName, EditorViewButtonHelper::GetStaticMeshFlagName(AutomationParameters.CommandType));
//Toggle the command for the button, take a screenshot, and then re-toggle the command for the button
ADD_LATENT_AUTOMATION_COMMAND(EditorViewButtonHelper::FPerformStaticMeshFlagToggle(AutomationParameters));
ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(0.1f));
if( FAutomationTestFramework::GetInstance().IsScreenshotAllowed() )
{
//Take the screenshot
AutomationCommon::GetScreenshotPath(TestName, WindowParameters.ScreenshotName, false);
ADD_LATENT_AUTOMATION_COMMAND(FTakeEditorScreenshotCommand(WindowParameters));
//Wait so the screenshots have a chance to save
ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(0.1f));
}
//Toggle the flag back off
ADD_LATENT_AUTOMATION_COMMAND(EditorViewButtonHelper::FPerformStaticMeshFlagToggle(AutomationParameters));
//Increment to the next enum, so we can loop through all the types
AutomationParameters.CommandType = (EditorViewButtonHelper::EStaticMeshFlag::Type)((int)AutomationParameters.CommandType + 1);
}
ADD_LATENT_AUTOMATION_COMMAND(EditorViewButtonHelper::FCloseAllAssetEditorsCommand());
}
return true;
}