UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
UObjectTestUtils.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
7#include "UObject/Class.h"
9
10namespace UE::CoreUObject
11{
13 template <typename UEnumType
14 UE_REQUIRES(std::is_enum_v<UEnumType> && std::is_invocable_v<decltype(&StaticEnum<UEnumType>)> && std::negation_v<std::is_integral<UEnumType>>)>
15 bool TestEqual(const FString& What, const UEnumType Actual, const UEnumType Expected, FAutomationTestBase& InTestInstance)
16 {
17 // Compare by value, but convert to string for display
18 if (Actual != Expected)
19 {
20 const UEnum* EnumType = StaticEnum<UEnumType>();
21 const FString EnumNameStr =
22#if WITH_EDITORONLY_DATA
23 EnumType->GetDisplayNameText().ToString();
24#else
25 EnumType->GetName();
26#endif
27 const FText ActualName = EnumType->GetDisplayNameTextByIndex(static_cast<int32>(Actual));
28 const FText ExpectedName = EnumType->GetDisplayNameTextByIndex(static_cast<int32>(Expected));
29
30 InTestInstance.AddError(FString::Printf(TEXT("Expected '%s' to be %s::%s, but it was %s::%s."),
31 *What,
32 *EnumNameStr, *ExpectedName.ToString(),
33 *EnumNameStr, *ActualName.ToString()),
34 1);
35
36 return false;
37 }
38
39 return true;
40 }
41
43 template <typename UEnumType
44 UE_REQUIRES(std::is_enum_v<UEnumType> && std::is_invocable_v<decltype(&StaticEnum<UEnumType>)> && std::negation_v<std::is_integral<UEnumType>>)>
45 bool TestNotEqual(const FString& What, const UEnumType Actual, const UEnumType Expected, FAutomationTestBase& InTestInstance)
46 {
47 // Compare by value, but convert to string for display
48 if (Actual == Expected)
49 {
50 const UEnum* EnumType = StaticEnum<UEnumType>();
51 const FString EnumNameStr =
52#if WITH_EDITORONLY_DATA
53 EnumType->GetDisplayNameText().ToString();
54#else
55 EnumType->GetName();
56#endif
57 const FText ActualName = EnumType->GetDisplayNameTextByIndex(static_cast<int32>(Actual));
58 const FText ExpectedName = EnumType->GetDisplayNameTextByIndex(static_cast<int32>(Expected));
59
60 InTestInstance.AddError(FString::Printf(TEXT("Expected '%s' to differ from %s::%s, but it was %s::%s."),
61 *What,
62 *EnumNameStr, *ExpectedName.ToString(),
63 *EnumNameStr, *ActualName.ToString()),
64 1);
65
66 return false;
67 }
68
69 return true;
70 }
71}
72
74{
75public:
76 FAutomationTestUObjectClassBase(const FString& InName, const bool bInComplexTask)
78 { }
79
80 virtual bool SuppressLogErrors() override { return false; }
81 virtual bool SuppressLogWarnings() override { return true; }
82 virtual bool ElevateLogWarningsToErrors() override { return false; }
83
84 template <typename UEnumType
85 UE_REQUIRES(std::is_enum_v<UEnumType> && std::is_invocable_v<decltype(&StaticEnum<UEnumType>)> && std::negation_v<std::is_integral<UEnumType>>)>
86 bool TestEqual(const TCHAR* What, const UEnumType Actual, const UEnumType Expected, const FAutomationTestBase& InTestInstance)
87 {
88 return UE::CoreUObject::TestEqual(What, Actual, Expected, *this);
89 }
90
91 template <typename UEnumType
92 UE_REQUIRES(std::is_enum_v<UEnumType> && std::is_invocable_v<decltype(&StaticEnum<UEnumType>)> && std::negation_v<std::is_integral<UEnumType>>)>
93 bool TestNotEqual(const TCHAR* What, const UEnumType Actual, const UEnumType Expected, const FAutomationTestBase& InTestInstance)
94 {
95 return UE::CoreUObject::TestNotEqual(What, Actual, Expected, *this);
96 }
97};
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UE_REQUIRES(...)
Definition Requires.h:86
Definition AutomationTest.h:1594
Definition UObjectTestUtils.h:74
bool TestNotEqual(const TCHAR *What, const UEnumType Actual, const UEnumType Expected, const FAutomationTestBase &InTestInstance)
Definition UObjectTestUtils.h:93
virtual bool SuppressLogErrors() override
Definition UObjectTestUtils.h:80
virtual bool ElevateLogWarningsToErrors() override
Definition UObjectTestUtils.h:82
virtual bool SuppressLogWarnings() override
Definition UObjectTestUtils.h:81
FAutomationTestUObjectClassBase(const FString &InName, const bool bInComplexTask)
Definition UObjectTestUtils.h:76
bool TestEqual(const TCHAR *What, const UEnumType Actual, const UEnumType Expected, const FAutomationTestBase &InTestInstance)
Definition UObjectTestUtils.h:86
Definition Text.h:385
Definition Class.h:2791
virtual COREUOBJECT_API FText GetDisplayNameTextByIndex(int32 InIndex) const
Definition Enum.cpp:861
UE_FORCEINLINE_HINT FString GetName() const
Definition UObjectBaseUtility.h:439
Definition CoreGlobals.cpp:268
bool TestNotEqual(const FString &What, const UEnumType Actual, const UEnumType Expected, FAutomationTestBase &InTestInstance)
Definition UObjectTestUtils.h:45
bool TestEqual(const FString &What, const UEnumType Actual, const UEnumType Expected, FAutomationTestBase &InTestInstance)
Definition UObjectTestUtils.h:15