Skip to content

Commit 35726fd

Browse files
committed
Added Test module
1 parent 6508229 commit 35726fd

7 files changed

Lines changed: 236 additions & 0 deletions

File tree

AttributesExtension.uplugin

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@
4343
"XboxOne",
4444
"Switch"
4545
]
46+
},
47+
{
48+
"Name" : "AttributesTest",
49+
"Type" : "Developer",
50+
"LoadingPhase" : "PreDefault",
51+
"WhitelistPlatforms": [
52+
"Win64",
53+
"Win32",
54+
"Linux",
55+
"Mac"
56+
]
4657
}
4758
]
4859
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2015-2019 Piperift. All Rights Reserved.
2+
3+
using UnrealBuildTool;
4+
using System.IO;
5+
6+
namespace UnrealBuildTool.Rules
7+
{
8+
public class AttributesTest : ModuleRules {
9+
public AttributesTest(ReadOnlyTargetRules Target) : base(Target)
10+
{
11+
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
12+
bEnforceIWYU = true;
13+
14+
PublicDependencyModuleNames.AddRange(new string[]
15+
{
16+
"Core",
17+
"Engine",
18+
"CoreUObject",
19+
"Attributes"
20+
});
21+
22+
PrivateDependencyModuleNames.AddRange(new string[]
23+
{
24+
});
25+
}
26+
}
27+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2015-2019 Piperift. All Rights Reserved.
2+
3+
#include "TestHelpers.h"
4+
#include "FloatAttr.h"
5+
#include "Int32Attr.h"
6+
7+
namespace
8+
{
9+
constexpr uint32 Flags_Product = EAutomationTestFlags::ApplicationContextMask | EAutomationTestFlags::ProductFilter;
10+
constexpr uint32 Flags_Smoke = EAutomationTestFlags::ApplicationContextMask | EAutomationTestFlags::ProductFilter;
11+
}
12+
13+
#define BASE_SPEC FAESpec
14+
15+
TESTSPEC(FFloatAttributesSpec, "AttributesExtension.Float", Flags_Smoke)
16+
void FFloatAttributesSpec::Define()
17+
{
18+
It("Attributes can be instantiated empty", [this]()
19+
{
20+
FFloatAttr Attr;
21+
TestTrue(TEXT("Base Value is set"), Attr.GetBaseValue() == 0.0f);
22+
TestTrue(TEXT("Value is set"), Attr == 0.0f);
23+
});
24+
25+
It("Attributes can be instantiated with a base value", [this]()
26+
{
27+
FFloatAttr Attr { 5.f };
28+
TestTrue(TEXT("Base Value is set"), Attr.GetBaseValue() == 5.0f);
29+
TestTrue(TEXT("Base Value is set"), Attr == 5.0f);
30+
});
31+
}
32+
33+
TESTSPEC(FInt32AttributesSpec, "AttributesExtension.Int32", Flags_Smoke)
34+
void FInt32AttributesSpec::Define()
35+
{
36+
It("Attributes can be instantiated empty", [this]()
37+
{
38+
FInt32Attr Attr;
39+
TestTrue(TEXT("Base Value is set"), Attr.GetBaseValue() == 0);
40+
TestTrue(TEXT("Value is set"), Attr == 0);
41+
});
42+
43+
It("Attributes can be instantiated with a base value", [this]()
44+
{
45+
FInt32Attr Attr{ 5 };
46+
TestTrue(TEXT("Base Value is set"), Attr.GetBaseValue() == 5);
47+
TestTrue(TEXT("Base Value is set"), Attr == 5);
48+
});
49+
}
50+
51+
TESTSPEC(FModifiersSpec, "AttributesExtension.Modifiers", Flags_Product)
52+
void FModifiersSpec::Define()
53+
{
54+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Copyright 2015-2019 Piperift. All Rights Reserved.
2+
3+
#include "AttributesTest.h"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2015-2019 Piperift. All Rights Reserved.
2+
3+
#include "TestHelpers.h"
4+
5+
#include <Engine/Engine.h>
6+
#include <Engine/LocalPlayer.h>
7+
#include <GameFramework/Actor.h>
8+
#include <GameFramework/PlayerController.h>
9+
#include <GameFramework/WorldSettings.h>
10+
#include <EngineUtils.h>
11+
12+
13+
UWorld* FAESpec::GetTestWorld() const
14+
{
15+
#if WITH_EDITOR
16+
const TIndirectArray<FWorldContext>& WorldContexts = GEngine->GetWorldContexts();
17+
for (const FWorldContext& Context : WorldContexts)
18+
{
19+
if (Context.World() != nullptr)
20+
{
21+
if (Context.WorldType == EWorldType::PIE /*&& Context.PIEInstance == 0*/)
22+
{
23+
return Context.World();
24+
}
25+
26+
if (Context.WorldType == EWorldType::Game)
27+
{
28+
return Context.World();
29+
}
30+
}
31+
}
32+
#endif
33+
34+
UWorld* TestWorld = GWorld;
35+
if (GIsEditor)
36+
{
37+
UE_LOG(LogTemp, Warning, TEXT("AttributesExtension Test using GWorld. Not correct for PIE"));
38+
}
39+
40+
return TestWorld;
41+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2015-2019 Piperift. All Rights Reserved.
2+
3+
#pragma once
4+
5+
#include <Modules/ModuleManager.h>
6+
7+
8+
class FAttributesTest : public IModuleInterface
9+
{
10+
public:
11+
12+
virtual void StartupModule() override {}
13+
virtual void ShutdownModule() override {}
14+
15+
static inline FAttributesTest& Get() {
16+
return FModuleManager::LoadModuleChecked<FAttributesTest>("AttributesTest");
17+
}
18+
19+
static inline bool IsAvailable() {
20+
return FModuleManager::Get().IsModuleLoaded("AttributesTest");
21+
}
22+
};
23+
24+
IMPLEMENT_MODULE(FAttributesTest, AttributesTest);

Source/Test/Public/TestHelpers.h

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2015-2019 Piperift. All Rights Reserved.
2+
3+
#pragma once
4+
5+
#include <CoreMinimal.h>
6+
#include <Misc/AutomationTest.h>
7+
#include <Engine/World.h>
8+
9+
10+
class FAESpec : public FAutomationSpecBase
11+
{
12+
public:
13+
14+
FAESpec(const FString& InName, const bool bInComplexTask)
15+
: FAutomationSpecBase(InName, bInComplexTask)
16+
{}
17+
18+
protected:
19+
20+
void TestNotImplemented()
21+
{
22+
AddWarning("Test not implemented.");
23+
}
24+
25+
UWorld* GetTestWorld() const;
26+
};
27+
28+
29+
#define BASE_SPEC FAESpec
30+
31+
#define BEGIN_TESTSPEC_PRIVATE( TClass, PrettyName, TFlags, FileName, LineNumber ) \
32+
class TClass : public BASE_SPEC \
33+
{ \
34+
using Super = BASE_SPEC; \
35+
public: \
36+
TClass( const FString& InName ) \
37+
: Super( InName, false ) { \
38+
static_assert((TFlags)&EAutomationTestFlags::ApplicationContextMask, "AutomationTest has no application flag. It shouldn't run. See AutomationTest.h."); \
39+
static_assert( (((TFlags)&EAutomationTestFlags::FilterMask) == EAutomationTestFlags::SmokeFilter) || \
40+
(((TFlags)&EAutomationTestFlags::FilterMask) == EAutomationTestFlags::EngineFilter) || \
41+
(((TFlags)&EAutomationTestFlags::FilterMask) == EAutomationTestFlags::ProductFilter) || \
42+
(((TFlags)&EAutomationTestFlags::FilterMask) == EAutomationTestFlags::PerfFilter) || \
43+
(((TFlags)&EAutomationTestFlags::FilterMask) == EAutomationTestFlags::StressFilter) || \
44+
(((TFlags)&EAutomationTestFlags::FilterMask) == EAutomationTestFlags::NegativeFilter), \
45+
"All AutomationTests must have exactly 1 filter type specified. See AutomationTest.h."); \
46+
} \
47+
virtual uint32 GetTestFlags() const override { return TFlags; } \
48+
using Super::GetTestSourceFileName; \
49+
virtual FString GetTestSourceFileName() const override { return FileName; } \
50+
using Super::GetTestSourceFileLine; \
51+
virtual int32 GetTestSourceFileLine() const override { return LineNumber; } \
52+
protected: \
53+
virtual FString GetBeautifiedTestName() const override { return PrettyName; } \
54+
virtual void Define() override;
55+
56+
57+
#if WITH_AUTOMATION_WORKER
58+
#define TESTSPEC( TClass, PrettyName, TFlags ) \
59+
BEGIN_TESTSPEC_PRIVATE(TClass, PrettyName, TFlags, __FILE__, __LINE__) \
60+
};\
61+
namespace\
62+
{\
63+
TClass TClass##AutomationSpecInstance( TEXT(#TClass) );\
64+
}
65+
66+
#define BEGIN_TESTSPEC( TClass, PrettyName, TFlags ) \
67+
BEGIN_TESTSPEC_PRIVATE(TClass, PrettyName, TFlags, __FILE__, __LINE__)
68+
69+
#define END_TESTSPEC( TClass ) \
70+
};\
71+
namespace\
72+
{\
73+
TClass TClass##AutomationSpecInstance( TEXT(#TClass) );\
74+
}
75+
#endif
76+

0 commit comments

Comments
 (0)