// Aesir Interactive GmbH, (c) 2019 #include "ServiceLocator.h" #if WITH_DEV_AUTOMATION_TESTS #include "Components/ActorComponent.h" #include "Components/SceneComponent.h" static_assert(TModels::Value, "Actor component should have a static uclass"); static_assert(TModels::Value); static_assert(!TModels::Value); static_assert(TModels::Value); static_assert(TIsUInterface::Value); static_assert(TModels::Value); static_assert(!TModels::Value); static_assert(!TIsUInterface::Value); static_assert(!TIsUInterface::Value); class FServiceUser { public: USceneComponent* SceneComponent = nullptr; UActorComponent* ActorComponent = nullptr; }; BEGIN_DEFINE_SPEC(TServiceLocatorSpec, "Workshop.ServiceLocator", EAutomationTestFlags::ProductFilter | EAutomationTestFlags::ApplicationContextMask) FServiceUser ServiceUser; FServiceLocator ServiceLocator; USceneComponent* SceneComponent = nullptr; UActorComponent* ActorComponent = nullptr; END_DEFINE_SPEC(TServiceLocatorSpec) void TServiceLocatorSpec::Define() { BeforeEach([this]() { SceneComponent = NewObject(); ActorComponent = NewObject(); }); Describe("ProvideService", [this]() { It("Should work for UObjects", [this]() { TestNull("GetService()", ServiceLocator.GetService()); ServiceLocator.ProvideService(ActorComponent); TestEqual("GetService()", ServiceLocator.GetService(), ActorComponent); }); It("Should work for UInterfaces", [this]() { TestNull("GetService()", ServiceLocator.GetService().GetInterface()); ServiceLocator.ProvideService(ActorComponent); TestEqual("GetService()", ServiceLocator.GetService().GetInterface(), static_cast(ActorComponent)); }); }); Describe("GetServices", [this]() { BeforeEach([this]() { ServiceLocator.ProvideService(ActorComponent); ServiceLocator.ProvideService(SceneComponent); ServiceLocator.ProvideService(ActorComponent); }); It("Should get all the services", [this]() { auto [InjectedActorComponent, InjectedSceneComponent, InjectedInterface] = ServiceLocator.GetServices(); TestEqual(TEXT("InjectedActorComponent"), InjectedActorComponent, ActorComponent); TestEqual(TEXT("InjectedSceneComponent"), InjectedSceneComponent, SceneComponent); TestEqual(TEXT("InjectedInterface"), InjectedInterface.GetInterface(), static_cast(ActorComponent)); }); }); } #endif