UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TestHelpers.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
5#include "HAL/PlatformTime.h"
8
10{
11 template<typename T1, typename T2>
12 inline bool TestEqual(const FString& Description, T1 Expression, T2 Expected, FAutomationSpecBase* This)
13 {
14 This->TestEqual(Description, Expression, Expected);
15 return Expression == Expected;
16 }
17
18 template<typename T1, typename T2>
19 inline bool TestNotEqual(const FString& Description, T1 Expression, T2 Expected, FAutomationSpecBase* This)
20 {
21 This->TestNotEqual(Description, Expression, Expected);
22 return Expression != Expected;
23 }
24
25 template<typename T>
26 inline bool TestNull(const FString& Description, T Expression, FAutomationSpecBase* This)
27 {
28 This->TestNull(Description, Expression);
29 return Expression == nullptr;
30 }
31
32 template<typename T>
33 inline bool TestNotNull(const FString& Description, T Expression, FAutomationSpecBase* This)
34 {
35 This->TestNotNull(Description, Expression);
36 return Expression != nullptr;
37 }
38
39 inline bool WaitUntilTrue(const TFunction<bool()>& Pred, const TFunction<bool()>& TestResult, double TimeoutSeconds)
40 {
42 while (!Pred() && FPlatformTime::Seconds() < TimeoutEnd)
43 {
44 FPlatformProcess::Sleep(0);
45 }
46 return TestResult();
47 }
48}
49
50#if WITH_DEV_AUTOMATION_TESTS
51
52#define _TEST_EQUAL(text, expression, expected) \
53 BuildPatchTestHelpers::TestEqual(text, expression, expected, this)
54
55#define _TEST_NOT_EQUAL(text, expression, expected) \
56 BuildPatchTestHelpers::TestNotEqual(text, expression, expected, this)
57
58#define _TEST_NULL(text, expression) \
59 BuildPatchTestHelpers::TestNull(text, expression, this)
60
61#define _TEST_NOT_NULL(text, expression) \
62 BuildPatchTestHelpers::TestNotNull(text, expression, this)
63
64#define TEST_EQUAL(expression, expected) \
65 _TEST_EQUAL(TEXT(#expression), expression, expected)
66
67#define TEST_NOT_EQUAL(expression, expected) \
68 _TEST_NOT_EQUAL(TEXT(#expression), expression, expected)
69
70#define TEST_TRUE(expression) \
71 TEST_EQUAL(expression, true)
72
73#define TEST_FALSE(expression) \
74 TEST_EQUAL(expression, false)
75
76#define TEST_NULL(expression) \
77 _TEST_NULL(TEXT(#expression), expression)
78
79#define TEST_NOT_NULL(expression) \
80 _TEST_NOT_NULL(TEXT(#expression), expression)
81
82#define TEST_BECOMES_TRUE(expression, timeout) \
83 BuildPatchTestHelpers::WaitUntilTrue([this](){ return expression; }, [this](){ return TEST_EQUAL(expression, true); }, timeout)
84
85#define MOCK_FUNC_NOT_IMPLEMENTED(funcname) \
86 UE_LOG(LogBuildPatchServices, Error, TEXT(funcname) TEXT(": Called but there is no implementation."))
87
88#define ARRAY(Type, ...) TArray<Type>({ __VA_ARGS__ })
89#define ARRAYU64(...) ARRAY(uint64, __VA_ARGS__)
90
91template<typename ElementType>
93{
94 return (LHS.Num() == RHS.Num())
95 && (LHS.Difference(RHS).Num() == 0)
96 && (RHS.Difference(LHS).Num() == 0);
97}
98
99#endif //WITH_DEV_AUTOMATION_TESTS
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition AutomationTest.h:2888
Definition AndroidPlatformMisc.h:14
Definition TestHelpers.h:10
bool WaitUntilTrue(const TFunction< bool()> &Pred, const TFunction< bool()> &TestResult, double TimeoutSeconds)
Definition TestHelpers.h:39
bool TestNull(const FString &Description, T Expression, FAutomationSpecBase *This)
Definition TestHelpers.h:26
bool TestNotNull(const FString &Description, T Expression, FAutomationSpecBase *This)
Definition TestHelpers.h:33
bool TestNotEqual(const FString &Description, T1 Expression, T2 Expected, FAutomationSpecBase *This)
Definition TestHelpers.h:19
bool TestEqual(const FString &Description, T1 Expression, T2 Expected, FAutomationSpecBase *This)
Definition TestHelpers.h:12
static double Seconds()
Definition AndroidPlatformTime.h:20