2022-10-13 11:24:15 -04:00
|
|
|
// 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)
|
|
|
|
|
{
|
2022-12-07 13:40:53 -05:00
|
|
|
#if DO_ENSURE
|
2022-10-13 11:24:15 -04:00
|
|
|
OldHandler = SetEnsureHandler([this, EnsureFunc](const FEnsureHandlerArgs& Args) -> bool
|
|
|
|
|
{
|
|
|
|
|
bool Handled = EnsureFunc(Args);
|
|
|
|
|
if (Handled)
|
|
|
|
|
{
|
|
|
|
|
++Count;
|
|
|
|
|
}
|
|
|
|
|
return Handled;
|
|
|
|
|
});
|
2022-12-07 13:40:53 -05:00
|
|
|
#endif
|
2022-10-13 11:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FEnsureScope::~FEnsureScope()
|
|
|
|
|
{
|
2022-12-07 13:40:53 -05:00
|
|
|
#if DO_ENSURE
|
2022-10-13 11:24:15 -04:00
|
|
|
SetEnsureHandler(OldHandler);
|
2022-12-07 13:40:53 -05:00
|
|
|
#endif
|
2022-10-13 11:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|