Files
UnrealEngineUWP/Engine/Source/Developer/LowLevelTestsRunner/Private/CheckScope.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

90 lines
1.5 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "LowLevelTestsRunner/CheckScope.h"
#include "Containers/StringConv.h"
#include "CoreGlobals.h"
#include "Misc/OutputDeviceError.h"
namespace UE::LowLevelTests
{
class FCheckScopeOutputDeviceError : public FOutputDeviceError
{
public:
FCheckScopeOutputDeviceError(FOutputDeviceError* Error, const ANSICHAR* Msg)
: DeviceError(Error)
, ExpectedMsg(Msg)
, Count(0)
{
}
virtual void HandleError() override
{
if (DeviceError)
{
DeviceError->HandleError();
}
}
void Serialize(const TCHAR* V, ELogVerbosity::Type Verbosity, const FName& Category) override
{
if (ExpectedMsg)
{
auto Str = StringCast<TCHAR>(ExpectedMsg);
auto Found = FPlatformString::Strstr(V, Str.Get());
if (Found)
{
++Count;
}
}
else
{
++Count;
}
}
void SetDeviceError(FOutputDeviceError* Error)
{
DeviceError = Error;
}
FOutputDeviceError* GetDeviceError() const
{
return DeviceError;
}
int GetCount() { return Count; }
private:
FOutputDeviceError* DeviceError;
const ANSICHAR* ExpectedMsg;
int Count;
};
FCheckScope::FCheckScope(const ANSICHAR* Msg)
: DeviceError(new FCheckScopeOutputDeviceError(GError, Msg))
, bIgnoreDebugger(GIgnoreDebugger)
{
GIgnoreDebugger = true;
GError = DeviceError;
}
FCheckScope::FCheckScope()
: FCheckScope(nullptr)
{
}
FCheckScope::~FCheckScope()
{
GIgnoreDebugger = bIgnoreDebugger;
GError = DeviceError->GetDeviceError();
delete DeviceError;
}
int
FCheckScope::GetCount()
{
return DeviceError->GetCount();
}
}