/* * 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 #include #include #include #include #include #include #include #include #include #include namespace ScriptCanvasEditor { using namespace ScriptCanvas; inline void RunGraph(AZStd::string_view graphPath, ScriptCanvas::ExecutionMode execution, const DurationSpec& duration, Reporter& reporter) { TraceSuppressionBus::Broadcast(&TraceSuppressionRequests::SuppressPrintf, true); LoadTestGraphResult loadResult = LoadTestGraph(graphPath); TraceSuppressionBus::Broadcast(&TraceSuppressionRequests::SuppressPrintf, false); if (loadResult.m_graph) { reporter.SetGraph(loadResult.m_graph->GetScriptCanvasId(), loadResult.m_graph->GetEntityId()); loadResult.m_graphEntity->Init(); TraceSuppressionBus::Broadcast(&TraceSuppressionRequests::SuppressPrintf, true); loadResult.m_graphEntity->Activate(); // force the runtime asset state AZ::Data::AssetManagerBus::Broadcast(&AZ::Data::AssetManagerEvents::OnAssetReady, loadResult.m_asset); // force the runtime component to receive the OnAssetReady event, on which it will execute the graph AZ::Data::AssetManager::Instance().DispatchEvents(); TraceSuppressionBus::Broadcast(&TraceSuppressionRequests::SuppressPrintf, false); loadResult.m_graphEntity->Deactivate(); reporter.FinishReport(loadResult.m_graph->IsInErrorState()); loadResult.m_graphEntity.reset(); } else { reporter.FinishReport(); } } inline Reporter RunGraph(AZStd::string_view graphPath, ExecutionMode execution, const DurationSpec& duration) { Reporter reporter; RunGraph(graphPath, execution, duration, reporter); return reporter; } inline Reporter RunGraph(AZStd::string_view graphPath, const DurationSpec& duration) { return RunGraph(graphPath, ExecutionMode::Interpreted, duration); } inline Reporter RunGraph(AZStd::string_view graphPath, ExecutionMode execution) { return RunGraph(graphPath, execution, DurationSpec()); } inline LoadTestGraphResult LoadTestGraph(AZStd::string_view graphPath) { AZ::Outcome< AZ::Data::Asset, AZStd::string> assetOutcome = AZ::Failure(AZStd::string("asset creation failed")); ScriptCanvasEditor::EditorAssetConversionBus::BroadcastResult(assetOutcome, &ScriptCanvasEditor::EditorAssetConversionBusTraits::CreateRuntimeAsset, graphPath); if (assetOutcome.IsSuccess()) { LoadTestGraphResult result; result.m_asset = assetOutcome.GetValue(); result.m_graphEntity = AZStd::make_unique("Loaded Graph"); result.m_graph = result.m_graphEntity->CreateComponent(result.m_asset); return result; } return {}; } } // namespace ScriptCanvasEditor