/* * 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 "precompiled.h" #include #include #include #include #include #include #include #include #include #include "ScriptCanvas/Asset/RuntimeAsset.h" struct MockAsset : public AZ::Data::AssetData { AZ_RTTI(MockAsset, "{D1E5A5DA-89D3-4B1F-8194-3E84CA6991DF}", AZ::Data::AssetData); static void Reflect(AZ::ReflectContext* reflection) { AZ::SerializeContext* serializeContext = azrtti_cast(reflection); if (serializeContext) { serializeContext->Class() ->Field("value", &MockAsset::m_value); } } int m_value = 0; }; struct MockAssetRefComponent : public AZ::Component { AZ_COMPONENT(MockAssetRefComponent, "{EE1F3C90-2301-483D-AE28-9381BBFE18FB}"); static void Reflect(AZ::ReflectContext* reflection) { AZ::SerializeContext* serializeContext = azrtti_cast(reflection); if (serializeContext) { serializeContext->Class() ->Field("asset", &MockAssetRefComponent::m_asset); } } void Activate() override {} void Deactivate() override {} AZ::Data::Asset m_asset; }; class ScriptCanvasBuilderTests : public UnitTest::AllocatorsFixture , public AZ::ComponentApplicationBus::Handler { protected: ////////////////////////////////////////////////////////////////////////// // ComponentApplicationMessages AZ::ComponentApplication* GetApplication() override { return nullptr; } void RegisterComponentDescriptor(const AZ::ComponentDescriptor*) override { } void UnregisterComponentDescriptor(const AZ::ComponentDescriptor*) override { } bool AddEntity(AZ::Entity*) override { return true; } bool RemoveEntity(AZ::Entity*) override { return true; } bool DeleteEntity(const AZ::EntityId&) override { return true; } AZ::Entity* FindEntity(const AZ::EntityId&) override { return nullptr; } AZ::SerializeContext* GetSerializeContext() override { return m_serializeContext; } AZ::BehaviorContext* GetBehaviorContext() override { return nullptr; } AZ::JsonRegistrationContext* GetJsonRegistrationContext() override { return nullptr; } const char* GetExecutableFolder() const override { return nullptr; } const char* GetBinFolder() const { return nullptr; } const char* GetAppRoot() override { return nullptr; } AZ::Debug::DrillerManager* GetDrillerManager() override { return nullptr; } void EnumerateEntities(const AZ::ComponentApplicationRequests::EntityCallback& /*callback*/) override {} ////////////////////////////////////////////////////////////////////////// void SetUp() override { UnitTest::AllocatorsFixture::SetUp(); AZ::AllocatorInstance::Create(); AZ::AllocatorInstance::Create(); m_serializeContext = aznew AZ::SerializeContext(true, true); AZ::ComponentApplicationBus::Handler::BusConnect(); m_mockAssetDescriptor = MockAssetRefComponent::CreateDescriptor(); MockAssetRefComponent::Reflect(m_serializeContext); MockAsset::Reflect(m_serializeContext); ScriptCanvas::RuntimeData::Reflect(m_serializeContext); ScriptCanvas::GraphData::Reflect(m_serializeContext); ScriptCanvas::VariableData::Reflect(m_serializeContext); AZ::Entity::Reflect(m_serializeContext); AZ::Data::AssetManager::Descriptor desc; AZ::Data::AssetManager::Create(desc); AZ::Data::AssetManager::Instance().RegisterHandler(aznew AzFramework::GenericAssetHandler("Mock Asset", "Other", "mockasset"), AZ::AzTypeInfo::Uuid()); AZ::Data::AssetManager::Instance().RegisterHandler(aznew AzFramework::GenericAssetHandler("ScriptCanvas::RuntimeAsset", "Other", "mockasset"), azrtti_typeid()); } void TearDown() override { AZ::ComponentApplicationBus::Handler::BusDisconnect(); AZ::Data::AssetManager::Destroy(); delete m_mockAssetDescriptor; delete m_serializeContext; AZ::AllocatorInstance::Destroy(); AZ::AllocatorInstance::Destroy(); UnitTest::AllocatorsFixture::TearDown(); } AZ::SerializeContext* m_serializeContext = nullptr; AZ::ComponentDescriptor* m_mockAssetDescriptor = nullptr; }; // Just test for one case to verify the call to ScriptCanvasBuilder::Worker::GatherProductDependencies works. // SerializationDependencyTests handles testing other asset reference types. TEST_F(ScriptCanvasBuilderTests, ScriptCanvasWithAssetReference_GatherProductDependencies_DependencyFound) { MockAssetRefComponent* assetComponent = aznew MockAssetRefComponent; AZ::Data::AssetId testAssetId("{CAAC5458-0738-43F6-A2BD-4E315C64BFD3}", 71); assetComponent->m_asset = AZ::Data::AssetManager::Instance().CreateAsset(testAssetId); AZ::Entity* graphEntity = aznew AZ::Entity; graphEntity->AddComponent(assetComponent); ScriptCanvas::RuntimeData runtimeData; runtimeData.m_graphData.m_nodes.emplace(graphEntity); AZ::Data::Asset runtimeAsset; runtimeAsset.Create(AZ::Uuid::CreateRandom()); runtimeAsset.Get()->SetData(runtimeData); AZStd::vector productDependencies; AssetBuilderSDK::ProductPathDependencySet productPathDependencySet; bool gatherResults = ScriptCanvasBuilder::Worker::GatherProductDependencies( *m_serializeContext, runtimeAsset, productDependencies, productPathDependencySet); ASSERT_TRUE(gatherResults); ASSERT_EQ(productDependencies.size(), 1); ASSERT_EQ(productDependencies[0].m_dependencyId, testAssetId); ASSERT_EQ(productPathDependencySet.size(), 0); }