1f9b284de2
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> # Conflicts: # Code/Editor/Plugins/ComponentEntityEditorPlugin/ComponentEntityEditorPlugin_precompiled.h # Code/Editor/Plugins/EditorCommon/EditorCommon_precompiled.h # Code/Editor/Plugins/EditorCommon/stdafx.cpp # Code/Editor/Plugins/FFMPEGPlugin/FFMPEGPlugin_precompiled.h # Code/Editor/Plugins/PerforcePlugin/PerforcePlugin_precompiled.h # Code/Editor/Plugins/ProjectSettingsTool/ProjectSettingsTool_precompiled.h # Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFramework_precompiled.h # Code/Tools/AssetProcessor/native/precompiled.h # Code/Tools/Standalone/StandaloneTools_precompiled.h # Gems/AssetMemoryAnalyzer/Code/Source/AssetMemoryAnalyzer_precompiled.h # Gems/Atom/Asset/ImageProcessingAtom/Code/Source/ImageProcessing_precompiled.h # Gems/Atom/RHI/DX12/Code/Source/RHI/Atom_RHI_DX12_precompiled.h # Gems/Atom/RHI/Metal/Code/Include/Platform/Mac/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Include/Platform/iOS/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Source/Atom_RHI_Metal_precompiled.h # Gems/Atom/RHI/Metal/Code/atom_rhi_metal_common_files.cmake # Gems/Atom/RHI/Null/Code/Source/Atom_RHI_Null_precompiled.h # Gems/Atom/RHI/Null/Code/atom_rhi_null_common_files.cmake # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Android/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Linux/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Mac/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Windows/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Source/Atom_RHI_Vulkan_precompiled.h # Gems/Atom/RHI/Vulkan/Code/Source/RHI/SwapChain.cpp # Gems/Atom/RHI/Vulkan/Code/atom_rhi_vulkan_common_files.cmake # Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont_precompiled.h # Gems/Blast/Code/Source/StdAfx.cpp # Gems/Camera/Code/Source/Camera_precompiled.h # Gems/EMotionFX/Code/Source/EMotionFX_precompiled.h # Gems/FastNoise/Code/Source/FastNoise_precompiled.h # Gems/Gestures/Code/Source/Gestures_precompiled.h # Gems/GradientSignal/Code/Source/GradientSignal_precompiled.h # Gems/GraphCanvas/Code/precompiled.h # Gems/ImGui/Code/Source/ImGui_precompiled.h # Gems/InAppPurchases/Code/Source/InAppPurchases_precompiled.h # Gems/LmbrCentral/Code/Source/LmbrCentral_precompiled.h # Gems/LmbrCentral/Code/Tests/ShapeGeometryUtilTest.cpp # Gems/LyShine/Code/Editor/UiCanvasEditor_precompiled.h # Gems/LyShine/Code/Source/Animation/LyShine_precompiled.h # Gems/LyShine/Code/Source/LyShine_precompiled.h # Gems/LyShineExamples/Code/Source/LyShineExamples_precompiled.h # Gems/Maestro/Code/Source/Cinematics/Maestro_precompiled.h # Gems/Maestro/Code/Source/Maestro_precompiled.h # Gems/MessagePopup/Code/Source/MessagePopup_precompiled.h # Gems/Metastream/Code/Source/Metastream_precompiled.h # Gems/Microphone/Code/Source/Microphone_precompiled.h # Gems/Multiplayer/Code/Source/Multiplayer_precompiled.h # Gems/PhysX/Code/NumericalMethods/Source/NumericalMethods_precompiled.h # Gems/PhysX/Code/Source/PhysXUnsupported_precompiled.h # Gems/PhysX/Code/Source/PhysX_precompiled.h # Gems/PhysX/Code/physx_unsupported_files.cmake # Gems/PhysXDebug/Code/Source/PhysXDebugUnsupported_precompiled.h # Gems/PhysXDebug/Code/Source/PhysXDebug_precompiled.h # Gems/ScriptCanvas/Code/Editor/precompiled.h # Gems/ScriptCanvas/Code/Source/precompiled.h # Gems/ScriptCanvasDeveloper/Code/Source/precompiled.h # Gems/ScriptCanvasPhysics/Code/Source/ScriptCanvasPhysics_precompiled.h # Gems/ScriptEvents/Code/Source/precompiled.h # Gems/ScriptEvents/Code/Tests/Editor/EditorTests.cpp # Gems/ScriptedEntityTweener/Code/Source/ScriptedEntityTweener_precompiled.h # Gems/SliceFavorites/Code/Source/SliceFavorites_precompiled.h # Gems/StartingPointCamera/Code/Source/StartingPointCamera_precompiled.h # Gems/StartingPointInput/Code/Source/StartingPointInput_precompiled.h # Gems/StartingPointMovement/Code/Source/StartingPointMovement_precompiled.h # Gems/SurfaceData/Code/Source/SurfaceData_precompiled.h # Gems/TextureAtlas/Code/Source/TextureAtlas_precompiled.h # Gems/TickBusOrderViewer/Code/Source/TickBusOrderViewer_precompiled.h # Gems/Twitch/Code/Source/Twitch_precompiled.h # Gems/VirtualGamepad/Code/Source/VirtualGamepad_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBoxUnsupported_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBox_precompiled.h
173 lines
6.8 KiB
C++
173 lines
6.8 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
#include <AzCore/UnitTest/TestTypes.h>
|
|
#include <AzCore/std/smart_ptr/make_shared.h>
|
|
#include <AzFramework/Physics/Common/PhysicsSceneQueries.h>
|
|
#include <AzFramework/Physics/SystemBus.h>
|
|
|
|
#include <Blast/BlastSystemBus.h>
|
|
#include <Mocks/BlastMocks.h>
|
|
|
|
#include <NvBlastExtPxManager.h>
|
|
|
|
using testing::_;
|
|
using testing::Eq;
|
|
using testing::Ref;
|
|
using testing::Return;
|
|
using testing::ReturnRef;
|
|
using testing::StrictMock;
|
|
|
|
namespace Blast
|
|
{
|
|
class BlastFamilyTest
|
|
: public testing::Test
|
|
, public FastScopedAllocatorsBase
|
|
{
|
|
protected:
|
|
void SetUp() override
|
|
{
|
|
NvBlastActorDesc actorDesc{1, nullptr, 1, nullptr};
|
|
|
|
m_fakeActorFactory = AZStd::make_shared<FakeActorFactory>(3);
|
|
m_fakeEntityProvider = AZStd::make_shared<FakeEntityProvider>(3);
|
|
m_mockPxAsset = AZStd::make_unique<FakeExtPxAsset>(actorDesc);
|
|
m_asset = AZStd::make_unique<BlastAsset>(m_mockPxAsset.get());
|
|
m_blastMaterial = AZStd::make_unique<BlastMaterial>(BlastMaterialConfiguration());
|
|
|
|
m_systemHandler = AZStd::make_shared<MockBlastSystemBusHandler>();
|
|
m_mockTkFramework = AZStd::make_unique<MockTkFramework>();
|
|
m_mockTkFamily = AZStd::make_unique<MockTkFamily>();
|
|
m_mockTkAsset = AZStd::make_unique<MockTkAsset>();
|
|
m_mockListener = AZStd::make_unique<MockBlastListener>();
|
|
}
|
|
|
|
void TearDown() override
|
|
{
|
|
m_fakeActorFactory = nullptr;
|
|
m_systemHandler = nullptr;
|
|
}
|
|
|
|
AZStd::shared_ptr<FakeActorFactory> m_fakeActorFactory;
|
|
AZStd::shared_ptr<FakeEntityProvider> m_fakeEntityProvider;
|
|
AZStd::unique_ptr<FakeExtPxAsset> m_mockPxAsset;
|
|
AZStd::unique_ptr<BlastAsset> m_asset;
|
|
AZStd::unique_ptr<BlastMaterial> m_blastMaterial;
|
|
|
|
AZStd::shared_ptr<MockBlastSystemBusHandler> m_systemHandler;
|
|
AZStd::unique_ptr<MockTkFramework> m_mockTkFramework;
|
|
AZStd::unique_ptr<MockTkFamily> m_mockTkFamily;
|
|
AZStd::unique_ptr<MockTkAsset> m_mockTkAsset;
|
|
AZStd::unique_ptr<MockBlastListener> m_mockListener;
|
|
};
|
|
|
|
TEST_F(BlastFamilyTest, FamilySpawnsAndDespawns_SUITE_sandbox)
|
|
{
|
|
AZStd::unique_ptr<BlastFamily> blastFamily;
|
|
BlastActorConfiguration blastActorConfiguration;
|
|
|
|
// BlastFamily::Create expectations
|
|
{
|
|
EXPECT_CALL(*m_systemHandler, GetTkFramework()).Times(1).WillOnce(Return(m_mockTkFramework.get()));
|
|
EXPECT_CALL(*m_mockPxAsset, getTkAsset()).Times(1).WillOnce(testing::ReturnRef(*m_mockTkAsset.get()));
|
|
EXPECT_CALL(*m_mockTkFramework, createActor(_))
|
|
.Times(1)
|
|
.WillOnce(Return(&m_fakeActorFactory->m_mockActors[0]->GetTkActor()));
|
|
EXPECT_CALL(*m_fakeActorFactory->m_mockActors[0]->m_tkActor, getFamily())
|
|
.Times(1)
|
|
.WillOnce(ReturnRef(*m_mockTkFamily.get()));
|
|
EXPECT_CALL(*m_fakeActorFactory, CalculateComponents(_))
|
|
.Times(3)
|
|
.WillRepeatedly(Return(AZStd::vector<AZ::Uuid>()));
|
|
|
|
BlastFamilyDesc familyDesc
|
|
{*m_asset,
|
|
m_mockListener.get(),
|
|
nullptr,
|
|
Physics::MaterialId(),
|
|
*m_blastMaterial,
|
|
m_fakeActorFactory,
|
|
m_fakeEntityProvider,
|
|
blastActorConfiguration};
|
|
|
|
blastFamily = BlastFamily::Create(familyDesc);
|
|
}
|
|
|
|
// BlastFamily::Spawn expectations
|
|
{
|
|
int actorCount = 1;
|
|
EXPECT_CALL(*m_mockTkFamily, getActorCount()).Times(1).WillOnce(Return(actorCount));
|
|
EXPECT_CALL(*m_mockTkFamily, getActors(_, Eq(actorCount), _))
|
|
.Times(1)
|
|
.WillOnce(testing::Invoke(
|
|
[this](auto buffer, auto actorCount, auto indexStart)
|
|
{
|
|
buffer[indexStart] = m_fakeActorFactory->m_mockActors[0]->m_tkActor.get();
|
|
return actorCount;
|
|
}));
|
|
EXPECT_CALL(*m_mockListener, OnActorCreated(Ref(*blastFamily), Ref(*m_fakeActorFactory->m_mockActors[0])))
|
|
.Times(1);
|
|
EXPECT_CALL(*m_mockTkFamily, addListener(_)).Times(1);
|
|
EXPECT_CALL(
|
|
*m_fakeActorFactory,
|
|
CalculateVisibleChunks(
|
|
Ref<BlastFamily&>(*blastFamily),
|
|
Ref<Nv::Blast::TkActor&>(*m_fakeActorFactory->m_mockActors[0]->m_tkActor)))
|
|
.Times(1);
|
|
EXPECT_CALL(
|
|
*m_fakeActorFactory,
|
|
CalculateIsStatic(Ref(*blastFamily), Ref(*m_fakeActorFactory->m_mockActors[0]->m_tkActor), _))
|
|
.Times(1)
|
|
.WillOnce(Return(false));
|
|
EXPECT_CALL(
|
|
*m_fakeActorFactory, CalculateIsLeafChunk(Ref(*m_fakeActorFactory->m_mockActors[0]->m_tkActor), _))
|
|
.Times(1)
|
|
.WillOnce(Return(false));
|
|
|
|
AZ::Transform transform = AZ::Transform::CreateIdentity();
|
|
blastFamily->Spawn(transform);
|
|
}
|
|
|
|
// BlastFamily::HandleEvents
|
|
{
|
|
Nv::Blast::TkSplitEvent splitEvent;
|
|
AZStd::vector<Nv::Blast::TkActor*> children(2);
|
|
children[0] = m_fakeActorFactory->m_mockActors[1]->m_tkActor.get();
|
|
children[1] = m_fakeActorFactory->m_mockActors[2]->m_tkActor.get();
|
|
splitEvent.children = children.data();
|
|
splitEvent.numChildren = 2;
|
|
splitEvent.parentData = {
|
|
m_mockTkFamily.get(), reinterpret_cast<void*>(m_fakeActorFactory->m_mockActors[0]), 0};
|
|
Nv::Blast::TkEvent tkEvent;
|
|
tkEvent.type = Nv::Blast::TkEvent::Split;
|
|
tkEvent.payload = reinterpret_cast<void*>(&splitEvent);
|
|
|
|
EXPECT_CALL(*m_fakeActorFactory, CalculateVisibleChunks(Ref<BlastFamily&>(*blastFamily), _)).Times(2);
|
|
EXPECT_CALL(*m_fakeActorFactory, CalculateIsStatic(Ref(*blastFamily), _, _))
|
|
.Times(2)
|
|
.WillRepeatedly(Return(false));
|
|
EXPECT_CALL(*m_fakeActorFactory, CalculateIsLeafChunk(_, _)).Times(2).WillRepeatedly(Return(false));
|
|
|
|
EXPECT_CALL(*m_mockListener, OnActorDestroyed(_, _)).Times(1);
|
|
EXPECT_CALL(*m_mockListener, OnActorCreated(_, _)).Times(2);
|
|
|
|
blastFamily->HandleEvents(&tkEvent, 1);
|
|
}
|
|
|
|
// BlastFamily::~BlastFamily
|
|
{
|
|
EXPECT_CALL(*m_mockTkFamily, removeListener(_)).Times(1);
|
|
EXPECT_CALL(*m_mockListener, OnActorDestroyed(_, _)).Times(2);
|
|
|
|
blastFamily.reset();
|
|
}
|
|
}
|
|
} // namespace Blast
|