Added network prefab processor test
This commit is contained in:
@@ -59,6 +59,26 @@ ly_add_target(
|
||||
)
|
||||
|
||||
if (PAL_TRAIT_BUILD_HOST_TOOLS)
|
||||
ly_add_target(
|
||||
NAME Multiplayer.Tools.Static STATIC
|
||||
NAMESPACE Gem
|
||||
FILES_CMAKE
|
||||
multiplayer_tools_files.cmake
|
||||
COMPILE_DEFINITIONS
|
||||
PUBLIC
|
||||
MULTIPLAYER_TOOLS
|
||||
INCLUDE_DIRECTORIES
|
||||
PRIVATE
|
||||
.
|
||||
Source
|
||||
${pal_source_dir}
|
||||
PUBLIC
|
||||
Include
|
||||
BUILD_DEPENDENCIES
|
||||
PUBLIC
|
||||
AZ::AzToolsFramework
|
||||
Gem::Multiplayer.Static
|
||||
)
|
||||
|
||||
ly_add_target(
|
||||
NAME Multiplayer.Tools MODULE
|
||||
@@ -74,8 +94,7 @@ if (PAL_TRAIT_BUILD_HOST_TOOLS)
|
||||
Include
|
||||
BUILD_DEPENDENCIES
|
||||
PRIVATE
|
||||
AZ::AzToolsFramework
|
||||
Gem::Multiplayer.Static
|
||||
Gem::Multiplayer.Tools.Static
|
||||
)
|
||||
|
||||
ly_add_target(
|
||||
@@ -145,6 +164,30 @@ if (PAL_TRAIT_BUILD_TESTS_SUPPORTED)
|
||||
ly_add_googletest(
|
||||
NAME Gem::Multiplayer.Tests
|
||||
)
|
||||
|
||||
if (PAL_TRAIT_BUILD_HOST_TOOLS)
|
||||
ly_add_target(
|
||||
NAME Multiplayer.Tools.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
|
||||
NAMESPACE Gem
|
||||
FILES_CMAKE
|
||||
multiplayer_tools_tests_files.cmake
|
||||
INCLUDE_DIRECTORIES
|
||||
PRIVATE
|
||||
Tests
|
||||
Source
|
||||
.
|
||||
BUILD_DEPENDENCIES
|
||||
PRIVATE
|
||||
AZ::AzTest
|
||||
AZ::AzTestShared
|
||||
AZ::AzToolsFrameworkTestCommon
|
||||
Gem::Multiplayer.Tools.Static
|
||||
)
|
||||
ly_add_googletest(
|
||||
NAME Gem::Multiplayer.Tools.Tests
|
||||
)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
ly_add_target(
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/UnitTest/UnitTest.h>
|
||||
#include <AzQtComponents/Utilities/QtPluginPaths.h>
|
||||
#include <AzTest/AzTest.h>
|
||||
#include <AzTest/GemTestEnvironment.h>
|
||||
#include <QApplication>
|
||||
#include <Source/Components/NetBindComponent.h>
|
||||
#include <Source/Pipeline/NetBindMarkerComponent.h>
|
||||
#include <Source/Pipeline/NetworkSpawnableHolderComponent.h>
|
||||
#include <UnitTest/ToolsTestApplication.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
class MultiplayerToolsTestEnvironment : public AZ::Test::GemTestEnvironment
|
||||
{
|
||||
AZ::ComponentApplication* CreateApplicationInstance() override
|
||||
{
|
||||
return aznew UnitTest::ToolsTestApplication("MultiplayerToolsTest");
|
||||
}
|
||||
|
||||
void AddGemsAndComponents() override
|
||||
{
|
||||
AZStd::vector<AZ::ComponentDescriptor*> descriptors({
|
||||
NetBindComponent::CreateDescriptor(),
|
||||
NetBindMarkerComponent::CreateDescriptor(),
|
||||
NetworkSpawnableHolderComponent::CreateDescriptor()
|
||||
});
|
||||
|
||||
AddComponentDescriptors(descriptors);
|
||||
}
|
||||
};
|
||||
} // namespace UnitTest
|
||||
|
||||
// Required to support running integration tests with Qt
|
||||
AZTEST_EXPORT int AZ_UNIT_TEST_HOOK_NAME(int argc, char** argv)
|
||||
{
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
AzQtComponents::PrepareQtPaths();
|
||||
QApplication app(argc, argv);
|
||||
AZ::Test::printUnusedParametersWarning(argc, argv);
|
||||
AZ::Test::addTestEnvironments({new Multiplayer::MultiplayerToolsTestEnvironment});
|
||||
int result = RUN_ALL_TESTS();
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzFramework/Components/TransformComponent.h>
|
||||
#include <AzFramework/Spawnable/Spawnable.h>
|
||||
#include <AzToolsFramework/Prefab/PrefabSystemComponentInterface.h>
|
||||
#include <AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h>
|
||||
#include <Prefab/PrefabDomTypes.h>
|
||||
#include <Prefab/Spawnable/PrefabProcessorContext.h>
|
||||
#include <Source/Components/NetBindComponent.h>
|
||||
#include <Source/Pipeline/NetworkPrefabProcessor.h>
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
class PrefabProcessingTestFixture : public ::testing::Test
|
||||
{
|
||||
public:
|
||||
static void ConvertEntitiesToPrefab(const AZStd::vector<AZ::Entity*>& entities, AzToolsFramework::Prefab::PrefabDom& prefabDom)
|
||||
{
|
||||
auto* prefabSystem = AZ::Interface<AzToolsFramework::Prefab::PrefabSystemComponentInterface>::Get();
|
||||
AZStd::unique_ptr<AzToolsFramework::Prefab::Instance> sourceInstance(prefabSystem->CreatePrefab(entities, {}, "test/path"));
|
||||
ASSERT_TRUE(sourceInstance);
|
||||
|
||||
auto& prefabTemplateDom = prefabSystem->FindTemplateDom(sourceInstance->GetTemplateId());
|
||||
prefabDom.CopyFrom(prefabTemplateDom, prefabDom.GetAllocator());
|
||||
}
|
||||
|
||||
static AZ::Entity* CreateSourceEntity(const char* name, bool networked, const AZ::Transform& tm, AZ::Entity* parent = nullptr)
|
||||
{
|
||||
AZ::Entity* entity = aznew AZ::Entity(name);
|
||||
auto* transformComponent = entity->CreateComponent<AzFramework::TransformComponent>();
|
||||
|
||||
if (parent)
|
||||
{
|
||||
transformComponent->SetParent(parent->GetId());
|
||||
transformComponent->SetLocalTM(tm);
|
||||
}
|
||||
else
|
||||
{
|
||||
transformComponent->SetWorldTM(tm);
|
||||
}
|
||||
|
||||
if(networked)
|
||||
{
|
||||
entity->CreateComponent<Multiplayer::NetBindComponent>();
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(PrefabProcessingTestFixture, NetworkPrefabProcessor_ProcessPrefabTwoEntities_NetEntityGoesToNetSpawnable)
|
||||
{
|
||||
using AzToolsFramework::Prefab::PrefabConversionUtils::PrefabProcessorContext;
|
||||
|
||||
AZStd::vector<AZ::Entity*> entities;
|
||||
|
||||
const AZStd::string staticEntityName = "static_floor";
|
||||
entities.emplace_back(CreateSourceEntity(staticEntityName.c_str(), false, AZ::Transform::CreateIdentity()));
|
||||
|
||||
const AZStd::string netEntityName = "networked_entity";
|
||||
entities.emplace_back(CreateSourceEntity(netEntityName.c_str(), true, AZ::Transform::CreateIdentity()));
|
||||
|
||||
AzToolsFramework::Prefab::PrefabDom prefabDom;
|
||||
ConvertEntitiesToPrefab(entities, prefabDom);
|
||||
|
||||
const AZStd::string prefabName = "testPrefab";
|
||||
PrefabProcessorContext prefabProcessorContext{AZ::Uuid::CreateRandom()};
|
||||
prefabProcessorContext.AddPrefab(prefabName, AZStd::move(prefabDom));
|
||||
|
||||
Multiplayer::NetworkPrefabProcessor processor;
|
||||
processor.Process(prefabProcessorContext);
|
||||
|
||||
EXPECT_TRUE(prefabProcessorContext.HasCompletedSuccessfully());
|
||||
|
||||
const auto& processedObjects = prefabProcessorContext.GetProcessedObjects();
|
||||
EXPECT_EQ(processedObjects.size(), 1);
|
||||
|
||||
const AZ::Data::AssetData& spawnableAsset = processedObjects[0].GetAsset();
|
||||
EXPECT_EQ(prefabName + ".network.spawnable", processedObjects[0].GetId());
|
||||
EXPECT_EQ(spawnableAsset.GetType(), azrtti_typeid<AzFramework::Spawnable>());
|
||||
|
||||
const AzFramework::Spawnable* netSpawnable = azrtti_cast<const AzFramework::Spawnable*>(&spawnableAsset);
|
||||
const AzFramework::Spawnable::EntityList& entityList = netSpawnable->GetEntities();
|
||||
auto countEntityCallback = [](const auto& name)
|
||||
{
|
||||
return [name](const auto& entity)
|
||||
{
|
||||
return entity->GetName() == name;
|
||||
};
|
||||
};
|
||||
|
||||
EXPECT_EQ(0, AZStd::count_if(entityList.begin(), entityList.end(), countEntityCallback(staticEntityName)));
|
||||
EXPECT_EQ(1, AZStd::count_if(entityList.begin(), entityList.end(), countEntityCallback(netEntityName)));
|
||||
}
|
||||
|
||||
} // namespace UnitTest
|
||||
@@ -0,0 +1,15 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
set(FILES
|
||||
Tests/MainTools.cpp
|
||||
Tests/PrefabProcessingTests.cpp
|
||||
)
|
||||
Reference in New Issue
Block a user