UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AutoRTFMTesting.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "AutoRTFM.h"
6
7namespace AutoRTFM::Testing
8{
9
10// Implemented by the test framework, and called when AUTORTFM_TESTING_ASSERT() fails.
11void AssertionFailure(const char* Expression, const char* File, int Line);
12
13#define AUTORTFM_TESTING_ASSERT(Condition) \
14 do { if (!(Condition)) { AssertionFailure("AUTORTFM_TESTING_ASSERT(" #Condition ")", __FILE__, __LINE__); }} while (false)
15
16// Run the callback in a transaction like Transact, but abort program
17// execution if the result is anything other than autortfm_committed.
18// Useful for testing.
19template<typename TFunctor>
20static UE_AUTORTFM_FORCEINLINE void Commit(const TFunctor& Functor)
21{
22 const ETransactionResult Result = Transact(Functor);
23 AUTORTFM_TESTING_ASSERT(ETransactionResult::Committed == Result);
24}
25
26// Run the callback in a transaction like Transact, but abort program
27// execution if the result is anything other than abort.
28template<typename TFunctor>
29static UE_AUTORTFM_FORCEINLINE void Abort(const TFunctor& Functor)
30{
31 const ETransactionResult Result = Transact(Functor);
32 AUTORTFM_TESTING_ASSERT(ETransactionResult::Committed != Result);
33}
34
35// Force set the AutoRTFM runtime state. Used in testing. Returns the old value.
36UE_AUTORTFM_API ForTheRuntime::EAutoRTFMEnabledState ForceSetAutoRTFMRuntime(ForTheRuntime::EAutoRTFMEnabledState State);
37
39{
40 FEnabledStateResetterScoped(ForTheRuntime::EAutoRTFMEnabledState State) : Original(ForceSetAutoRTFMRuntime(State)) {}
42
43private:
44 const ForTheRuntime::EAutoRTFMEnabledState Original;
45};
46
47#undef AUTORTFM_TESTING_ASSERT
48
49} // namespace AutoRTFM::Testing
#define UE_AUTORTFM_FORCEINLINE
Definition AutoRTFMDefines.h:171
#define UE_AUTORTFM_API
Definition AutoRTFMDefines.h:156
#define AUTORTFM_TESTING_ASSERT(Condition)
Definition AutoRTFMTesting.h:13
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition API.cpp:59
UE_AUTORTFM_API ForTheRuntime::EAutoRTFMEnabledState ForceSetAutoRTFMRuntime(ForTheRuntime::EAutoRTFMEnabledState State)
Definition API.cpp:60
void AssertionFailure(const char *Expression, const char *File, int Line)
UE_STRING_CLASS Result(Forward< LhsType >(Lhs), RhsLen)
Definition String.cpp.inl:732
Definition AutoRTFMTesting.h:39
~FEnabledStateResetterScoped()
Definition AutoRTFMTesting.h:41
FEnabledStateResetterScoped(ForTheRuntime::EAutoRTFMEnabledState State)
Definition AutoRTFMTesting.h:40