Files
UnrealEngineUWP/Engine/Source/Developer/LowLevelTestsRunner/Private/EnsureScope.cpp
joe pribele 1366bc3f93 [Core] added support to lowlevel tests validating that ensure and check are executed
added  a tls for an ensure handler callback to let the reporting log of ensures to be overridden

the following macros are supported in lowlevel tests
REQUIRE_ENSURE
CHECK_ENSURE
REQUIRE_CHECK

#rb devin.doucette
#preflight 634827c457048bdb82b43ffe

[CL 22505260 by joe pribele in ue5-main branch]
2022-10-13 11:24:15 -04:00

42 lines
828 B
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "LowLevelTestsRunner/EnsureScope.h"
#include "Containers/StringConv.h"
namespace UE::LowLevelTests
{
FEnsureScope::FEnsureScope()
: FEnsureScope([](const FEnsureHandlerArgs&) { return true; })
{
}
FEnsureScope::FEnsureScope(const ANSICHAR* ExpectedMsg)
: FEnsureScope([ExpectedMsg](const FEnsureHandlerArgs& Args)
{
return FPlatformString::Stricmp(ExpectedMsg, Args.Message) == 0;
})
{
}
FEnsureScope::FEnsureScope(TFunction<bool(const FEnsureHandlerArgs& Args)> EnsureFunc)
: Count(0)
{
OldHandler = SetEnsureHandler([this, EnsureFunc](const FEnsureHandlerArgs& Args) -> bool
{
bool Handled = EnsureFunc(Args);
if (Handled)
{
++Count;
}
return Handled;
});
}
FEnsureScope::~FEnsureScope()
{
SetEnsureHandler(OldHandler);
}
}