Skip to content

Commit

Permalink
Added Test module
Browse files Browse the repository at this point in the history
  • Loading branch information
muit committed Oct 19, 2019
1 parent 6508229 commit 35726fd
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 0 deletions.
11 changes: 11 additions & 0 deletions AttributesExtension.uplugin
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@
"XboxOne",
"Switch"
]
},
{
"Name" : "AttributesTest",
"Type" : "Developer",
"LoadingPhase" : "PreDefault",
"WhitelistPlatforms": [
"Win64",
"Win32",
"Linux",
"Mac"
]
}
]
}
27 changes: 27 additions & 0 deletions Source/Test/AttributesTest.Build.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2015-2019 Piperift. All Rights Reserved.

using UnrealBuildTool;
using System.IO;

namespace UnrealBuildTool.Rules
{
public class AttributesTest : ModuleRules {
public AttributesTest(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
bEnforceIWYU = true;

PublicDependencyModuleNames.AddRange(new string[]
{
"Core",
"Engine",
"CoreUObject",
"Attributes"
});

PrivateDependencyModuleNames.AddRange(new string[]
{
});
}
}
}
54 changes: 54 additions & 0 deletions Source/Test/Private/Attributes.spec.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2015-2019 Piperift. All Rights Reserved.

#include "TestHelpers.h"
#include "FloatAttr.h"
#include "Int32Attr.h"

namespace
{
constexpr uint32 Flags_Product = EAutomationTestFlags::ApplicationContextMask | EAutomationTestFlags::ProductFilter;
constexpr uint32 Flags_Smoke = EAutomationTestFlags::ApplicationContextMask | EAutomationTestFlags::ProductFilter;
}

#define BASE_SPEC FAESpec

TESTSPEC(FFloatAttributesSpec, "AttributesExtension.Float", Flags_Smoke)
void FFloatAttributesSpec::Define()
{
It("Attributes can be instantiated empty", [this]()
{
FFloatAttr Attr;
TestTrue(TEXT("Base Value is set"), Attr.GetBaseValue() == 0.0f);
TestTrue(TEXT("Value is set"), Attr == 0.0f);
});

It("Attributes can be instantiated with a base value", [this]()
{
FFloatAttr Attr { 5.f };
TestTrue(TEXT("Base Value is set"), Attr.GetBaseValue() == 5.0f);
TestTrue(TEXT("Base Value is set"), Attr == 5.0f);
});
}

TESTSPEC(FInt32AttributesSpec, "AttributesExtension.Int32", Flags_Smoke)
void FInt32AttributesSpec::Define()
{
It("Attributes can be instantiated empty", [this]()
{
FInt32Attr Attr;
TestTrue(TEXT("Base Value is set"), Attr.GetBaseValue() == 0);
TestTrue(TEXT("Value is set"), Attr == 0);
});

It("Attributes can be instantiated with a base value", [this]()
{
FInt32Attr Attr{ 5 };
TestTrue(TEXT("Base Value is set"), Attr.GetBaseValue() == 5);
TestTrue(TEXT("Base Value is set"), Attr == 5);
});
}

TESTSPEC(FModifiersSpec, "AttributesExtension.Modifiers", Flags_Product)
void FModifiersSpec::Define()
{
}
3 changes: 3 additions & 0 deletions Source/Test/Private/AttributesTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Copyright 2015-2019 Piperift. All Rights Reserved.

#include "AttributesTest.h"
41 changes: 41 additions & 0 deletions Source/Test/Private/TestHelpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2015-2019 Piperift. All Rights Reserved.

#include "TestHelpers.h"

#include <Engine/Engine.h>
#include <Engine/LocalPlayer.h>
#include <GameFramework/Actor.h>
#include <GameFramework/PlayerController.h>
#include <GameFramework/WorldSettings.h>
#include <EngineUtils.h>


UWorld* FAESpec::GetTestWorld() const
{
#if WITH_EDITOR
const TIndirectArray<FWorldContext>& WorldContexts = GEngine->GetWorldContexts();
for (const FWorldContext& Context : WorldContexts)
{
if (Context.World() != nullptr)
{
if (Context.WorldType == EWorldType::PIE /*&& Context.PIEInstance == 0*/)
{
return Context.World();
}

if (Context.WorldType == EWorldType::Game)
{
return Context.World();
}
}
}
#endif

UWorld* TestWorld = GWorld;
if (GIsEditor)
{
UE_LOG(LogTemp, Warning, TEXT("AttributesExtension Test using GWorld. Not correct for PIE"));
}

return TestWorld;
}
24 changes: 24 additions & 0 deletions Source/Test/Public/AttributesTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2015-2019 Piperift. All Rights Reserved.

#pragma once

#include <Modules/ModuleManager.h>


class FAttributesTest : public IModuleInterface
{
public:

virtual void StartupModule() override {}
virtual void ShutdownModule() override {}

static inline FAttributesTest& Get() {
return FModuleManager::LoadModuleChecked<FAttributesTest>("AttributesTest");
}

static inline bool IsAvailable() {
return FModuleManager::Get().IsModuleLoaded("AttributesTest");
}
};

IMPLEMENT_MODULE(FAttributesTest, AttributesTest);
76 changes: 76 additions & 0 deletions Source/Test/Public/TestHelpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright 2015-2019 Piperift. All Rights Reserved.

#pragma once

#include <CoreMinimal.h>
#include <Misc/AutomationTest.h>
#include <Engine/World.h>


class FAESpec : public FAutomationSpecBase
{
public:

FAESpec(const FString& InName, const bool bInComplexTask)
: FAutomationSpecBase(InName, bInComplexTask)
{}

protected:

void TestNotImplemented()
{
AddWarning("Test not implemented.");
}

UWorld* GetTestWorld() const;
};


#define BASE_SPEC FAESpec

#define BEGIN_TESTSPEC_PRIVATE( TClass, PrettyName, TFlags, FileName, LineNumber ) \
class TClass : public BASE_SPEC \
{ \
using Super = BASE_SPEC; \
public: \
TClass( const FString& InName ) \
: Super( InName, false ) { \
static_assert((TFlags)&EAutomationTestFlags::ApplicationContextMask, "AutomationTest has no application flag. It shouldn't run. See AutomationTest.h."); \
static_assert( (((TFlags)&EAutomationTestFlags::FilterMask) == EAutomationTestFlags::SmokeFilter) || \
(((TFlags)&EAutomationTestFlags::FilterMask) == EAutomationTestFlags::EngineFilter) || \
(((TFlags)&EAutomationTestFlags::FilterMask) == EAutomationTestFlags::ProductFilter) || \
(((TFlags)&EAutomationTestFlags::FilterMask) == EAutomationTestFlags::PerfFilter) || \
(((TFlags)&EAutomationTestFlags::FilterMask) == EAutomationTestFlags::StressFilter) || \
(((TFlags)&EAutomationTestFlags::FilterMask) == EAutomationTestFlags::NegativeFilter), \
"All AutomationTests must have exactly 1 filter type specified. See AutomationTest.h."); \
} \
virtual uint32 GetTestFlags() const override { return TFlags; } \
using Super::GetTestSourceFileName; \
virtual FString GetTestSourceFileName() const override { return FileName; } \
using Super::GetTestSourceFileLine; \
virtual int32 GetTestSourceFileLine() const override { return LineNumber; } \
protected: \
virtual FString GetBeautifiedTestName() const override { return PrettyName; } \
virtual void Define() override;


#if WITH_AUTOMATION_WORKER
#define TESTSPEC( TClass, PrettyName, TFlags ) \
BEGIN_TESTSPEC_PRIVATE(TClass, PrettyName, TFlags, __FILE__, __LINE__) \
};\
namespace\
{\
TClass TClass##AutomationSpecInstance( TEXT(#TClass) );\
}

#define BEGIN_TESTSPEC( TClass, PrettyName, TFlags ) \
BEGIN_TESTSPEC_PRIVATE(TClass, PrettyName, TFlags, __FILE__, __LINE__)

#define END_TESTSPEC( TClass ) \
};\
namespace\
{\
TClass TClass##AutomationSpecInstance( TEXT(#TClass) );\
}
#endif

0 comments on commit 35726fd

Please sign in to comment.