Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,14 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright EntityRef 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 <AzTest/AzTest.h>
AZ_UNIT_TEST_HOOK(DEFAULT_UNIT_TEST_ENV);
@@ -0,0 +1,323 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright EntityRef 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/PlatformDef.h>
#include <AzCore/Component/ComponentApplicationBus.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include <Source/Framework/ScriptCanvasTestFixture.h>
#include <Source/Framework/ScriptCanvasTestUtilities.h>
#include <ScriptCanvas/Core/SlotConfigurationDefaults.h>
using namespace ScriptCanvasTests;
using namespace ScriptCanvasEditor;
// Asynchronous ScriptCanvas Behaviors
#if AZ_COMPILER_MSVC
#include <future>
class AsyncEvent : public AZ::EBusTraits
{
public:
//////////////////////////////////////////////////////////////////////////
// EBusTraits overrides
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
using BusIdType = AZ::EntityId;
using MutexType = AZStd::recursive_mutex;
static const bool LocklessDispatch = true;
//////////////////////////////////////////////////////////////////////////
virtual void OnAsyncEvent() = 0;
};
using AsyncEventNotificationBus = AZ::EBus<AsyncEvent>;
class LongRunningProcessSimulator3000
{
public:
static void Run(const AZ::EntityId& listener)
{
int duration = 40;
while (--duration > 0)
{
AZStd::this_thread::sleep_for(AZStd::chrono::milliseconds(10));
}
AsyncEventNotificationBus::Event(listener, &AsyncEvent::OnAsyncEvent);
}
};
class AsyncNode
: public ScriptCanvas::Node
, protected AsyncEventNotificationBus::Handler
, protected AZ::TickBus::Handler
{
public:
AZ_COMPONENT(AsyncNode, "{0A7FF6C6-878B-42EC-A8BB-4D29C4039853}", ScriptCanvas::Node);
bool IsEntryPoint() const { return true; }
AsyncNode()
: Node()
{}
static void Reflect(AZ::ReflectContext* reflection)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
if (serializeContext)
{
serializeContext->Class<AsyncNode, Node>()
->Version(1)
;
}
}
void ConfigureSlots() override
{
AddSlot(ScriptCanvas::CommonSlots::GeneralInSlot());
AddSlot(ScriptCanvas::CommonSlots::GeneralOutSlot());
}
void OnActivate() override
{
ScriptCanvasTestFixture::s_asyncOperationActive = true;
AZ::TickBus::Handler::BusConnect();
AsyncEventNotificationBus::Handler::BusConnect(GetEntityId());
std::packaged_task<void()> task([this]() { LongRunningProcessSimulator3000::Run(GetEntityId()); }); // wrap the function
m_eventThread = AZStd::make_shared<AZStd::thread>(AZStd::move(task)); // launch on a thread
}
void OnDeactivate() override
{
if (m_eventThread)
{
m_eventThread->join();
m_eventThread.reset();
}
// We've received the event, no longer need the bus connection
AsyncEventNotificationBus::Handler::BusDisconnect();
// We're done, kick it out.
SignalOutput(GetSlotId("Out"));
// Disconnect from tick bus as well
AZ::TickBus::Handler::BusDisconnect();
}
virtual void HandleAsyncEvent()
{
EXPECT_GT(m_duration, 0.f);
Shutdown();
}
void OnAsyncEvent() override
{
HandleAsyncEvent();
}
void Shutdown()
{
ScriptCanvasTestFixture::s_asyncOperationActive = false;
}
void OnTick(float deltaTime, AZ::ScriptTimePoint) override
{
AZ_TracePrintf("Debug", "Awaiting async operation: %.2f\n", m_duration);
m_duration += deltaTime;
}
protected:
AZStd::shared_ptr<AZStd::thread> m_eventThread;
private:
double m_duration = 0.f;
};
TEST_F(ScriptCanvasTestFixture, Asynchronous_Behaviors)
{
using namespace ScriptCanvas;
RegisterComponentDescriptor<AsyncNode>();
// Make the graph.
Graph* graph = nullptr;
SystemRequestBus::BroadcastResult(graph, &SystemRequests::MakeGraph);
ASSERT_TRUE(graph != nullptr);
AZ::Entity* graphEntity = graph->GetEntity();
graphEntity->Init();
const AZ::EntityId& graphEntityId = graph->GetEntityId();
const ScriptCanvasId& graphUniqueId = graph->GetScriptCanvasId();
AZ::Entity* startEntity{ aznew AZ::Entity };
startEntity->Init();
AZ::EntityId startNodeId;
Nodes::Core::Start* startNode = CreateTestNode<Nodes::Core::Start>(graphUniqueId, startNodeId);
AZ::EntityId asyncNodeId;
AsyncNode* asyncNode = CreateTestNode<AsyncNode>(graphUniqueId, asyncNodeId);
EXPECT_TRUE(Connect(*graph, startNodeId, ScriptCanvas::CommonSlots::GeneralOutSlot::GetName(), asyncNodeId, ScriptCanvas::CommonSlots::GeneralInSlot::GetName()));
{
ScopedOutputSuppression supressOutput;
graphEntity->Activate();
// Tick the TickBus while the graph entity is active
while (ScriptCanvasTestFixture::s_asyncOperationActive)
{
AZ::TickBus::ExecuteQueuedEvents();
AZStd::this_thread::sleep_for(AZStd::chrono::milliseconds(100));
AZ::TickBus::Broadcast(&AZ::TickEvents::OnTick, 0.01f, AZ::ScriptTimePoint(AZStd::chrono::system_clock::now()));
}
}
graphEntity->Deactivate();
delete graphEntity;
}
///////////////////////////////////////////////////////////////////////////////
namespace
{
// Fibonacci solver, used to compare against the graph version.
long ComputeFibonacci(int digits)
{
int a = 0;
int b = 1;
long sum = 0;
for (int i = 0; i < digits - 2; ++i)
{
sum = a + b;
a = b;
b = sum;
}
return sum;
}
}
class AsyncFibonacciComputeNode
: public AsyncNode
{
public:
AZ_COMPONENT(AsyncFibonacciComputeNode, "{B198F52D-708C-414B-BB90-DFF0462D7F03}", AsyncNode);
AsyncFibonacciComputeNode()
: AsyncNode()
{}
bool IsEntryPoint() const { return true; }
static const int k_numberOfFibonacciDigits = 64;
static void Reflect(AZ::ReflectContext* reflection)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
if (serializeContext)
{
serializeContext->Class<AsyncFibonacciComputeNode, AsyncNode>()
->Version(1)
;
}
}
void OnActivate() override
{
AZ::TickBus::Handler::BusConnect();
AsyncEventNotificationBus::Handler::BusConnect(GetEntityId());
int digits = k_numberOfFibonacciDigits;
std::promise<long> p;
m_computeFuture = p.get_future();
m_eventThread = AZStd::make_shared<AZStd::thread>([this, digits, p = AZStd::move(p)]() mutable
{
p.set_value(ComputeFibonacci(digits));
AsyncEventNotificationBus::Event(GetEntityId(), &AsyncEvent::OnAsyncEvent);
});
}
void HandleAsyncEvent() override
{
m_result = m_computeFuture.get();
EXPECT_EQ(m_result, ComputeFibonacci(k_numberOfFibonacciDigits));
}
void OnTick(float deltaTime, AZ::ScriptTimePoint) override
{
AZ_TracePrintf("Debug", "Awaiting async fib operation: %.2f\n", m_duration);
m_duration += deltaTime;
if (m_result != 0)
{
Shutdown();
}
}
private:
std::future<long> m_computeFuture;
long m_result = 0;
double m_duration = 0.f;
};
TEST_F(ScriptCanvasTestFixture, ComputeFibonacciAsyncGraphTest)
{
using namespace ScriptCanvas;
RegisterComponentDescriptor<AsyncNode>();
RegisterComponentDescriptor<AsyncFibonacciComputeNode>();
// Make the graph.
Graph* graph = nullptr;
SystemRequestBus::BroadcastResult(graph, &SystemRequests::MakeGraph);
ASSERT_NE(graph, nullptr);
AZ::Entity* graphEntity = graph->GetEntity();
graphEntity->Init();
const AZ::EntityId& graphEntityId = graph->GetEntityId();
const ScriptCanvasId& graphUniqueId = graph->GetScriptCanvasId();
AZ::EntityId startNodeId;
Nodes::Core::Start* startNode = CreateTestNode<Nodes::Core::Start>(graphUniqueId, startNodeId);
AZ::EntityId asyncNodeId;
AsyncFibonacciComputeNode* asyncNode = CreateTestNode<AsyncFibonacciComputeNode>(graphUniqueId, asyncNodeId);
EXPECT_TRUE(Connect(*graph, startNodeId, "Out", asyncNodeId, "In"));
graphEntity->Activate();
// Tick the TickBus while the graph entity is active
while (ScriptCanvasTestFixture::s_asyncOperationActive)
{
AZ::TickBus::ExecuteQueuedEvents();
AZStd::this_thread::sleep_for(AZStd::chrono::milliseconds(100));
AZ::TickBus::Broadcast(&AZ::TickEvents::OnTick, 0.01f, AZ::ScriptTimePoint(AZStd::chrono::system_clock::now()));
}
graphEntity->Deactivate();
delete graphEntity;
}
#endif // AZ_COMPILER_MSVC
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,73 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affililates or
* its licensors.
*
* For complete copyright EntityRef 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 <Source/Framework/ScriptCanvasTestFixture.h>
#include <Source/Framework/ScriptCanvasTestUtilities.h>
#include <AzCore/ScriptCanvas/ScriptCanvasAttributes.h>
#include <AzCore/RTTI/AttributeReader.h>
using namespace ScriptCanvasTests;
using namespace ScriptCanvas;
TEST_F(ScriptCanvasTestFixture, FillWithOrdinals)
{
RunUnitTestGraph("LY_SC_UnitTest_FillWithOrdinals");
}
TEST_F(ScriptCanvasTestFixture, AZStdArray)
{
// Enable when BE2.0 goes to main
//RunUnitTestGraph("LY_SC_UnitTest_AZStdArray");
}
/*
TEST_F(ScriptCanvasTestFixture, ForEachNested)
{
RunUnitTestGraph("LY_SC_UnitTest_ForEachNested");
}
TEST_F(ScriptCanvasTestFixture, ForEachNestedBreak)
{
RunUnitTestGraph("LY_SC_UnitTest_ForEachNestedBreak");
}
*/
TEST_F(ScriptCanvasTestFixture, ForEachNode)
{
// Enable when BE2.0 goes to main
// RunUnitTestGraph("LY_SC_UnitTest_ForEachNode");
}
/*
TEST_F(ScriptCanvasTestFixture, ForEachBreak)
{
RunUnitTestGraph("LY_SC_UnitTest_ForEachBreak");
}
*/
// TODO: needs to be recreated with new operator nodes
//TEST_F(ScriptCanvasTestFixture, VectorContainerVector3)
//{
// RunUnitTestGraph("LY_SC_UnitTest_VectorContainerVector3");
//}
TEST_F(ScriptCanvasTestFixture, MapContainerStringVec3)
{
// Enable when BE2.0 goes to main
//RunUnitTestGraph("LY_SC_UnitTest_MapContainerStringVec3");
}
TEST_F(ScriptCanvasTestFixture, SetContainerNum)
{
// Enable when BE2.0 goes to main
//RunUnitTestGraph("LY_SC_UnitTest_SetContainerNum");
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,40 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright EntityRef 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 <Source/Framework/ScriptCanvasTestFixture.h>
using namespace ScriptCanvasTests;
TEST_F(ScriptCanvasTestFixture, StringMethodCStyle2CStyle)
{
RunUnitTestGraph("LY_SC_UnitTest_StringMethodCStyle2CStyle");
}
TEST_F(ScriptCanvasTestFixture, EBusStringResultCStyle2CStyle)
{
RunUnitTestGraph("LY_SC_UnitTest_EBusStringResultCStyle2CStyle");
}
TEST_F(ScriptCanvasTestFixture, EBusStringResultCStyle2String)
{
RunUnitTestGraph("LY_SC_UnitTest_EBusStringResultCStyle2String");
}
TEST_F(ScriptCanvasTestFixture, EBusStringResultCStyle2StringView)
{
RunUnitTestGraph("LY_SC_UnitTest_EBusStringResultCStyle2StringView");
}
TEST_F(ScriptCanvasTestFixture, EBusResultNested)
{
RunUnitTestGraph("LY_SC_UnitTest_EBusResultNested");
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,57 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affililates or
* its licensors.
*
* For complete copyright EntityRef 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 <Source/Framework/ScriptCanvasTestFixture.h>
#include <Source/Framework/ScriptCanvasTestUtilities.h>
using namespace ScriptCanvasTests;
using namespace ScriptCanvas;
TEST_F(ScriptCanvasTestFixture, OutcomeFailureVE)
{
RunUnitTestGraph("LY_SC_UnitTest_OutcomeFailureVE");
}
TEST_F(ScriptCanvasTestFixture, OutcomeFailureV)
{
RunUnitTestGraph("LY_SC_UnitTest_OutcomeFailureV");
}
TEST_F(ScriptCanvasTestFixture, OutcomeFailureE)
{
RunUnitTestGraph("LY_SC_UnitTest_OutcomeFailureE");
}
TEST_F(ScriptCanvasTestFixture, OutcomeFailure)
{
RunUnitTestGraph("LY_SC_UnitTest_OutcomeFailure");
}
TEST_F(ScriptCanvasTestFixture, OutcomeSuccessVE)
{
RunUnitTestGraph("LY_SC_UnitTest_OutcomeSuccessVE");
}
TEST_F(ScriptCanvasTestFixture, OutcomeSuccessV)
{
RunUnitTestGraph("LY_SC_UnitTest_OutcomeSuccessV");
}
TEST_F(ScriptCanvasTestFixture, OutcomeSuccessE)
{
RunUnitTestGraph("LY_SC_UnitTest_OutcomeSuccessE");
}
TEST_F(ScriptCanvasTestFixture, OutcomeSuccess)
{
RunUnitTestGraph("LY_SC_UnitTest_OutcomeSuccess");
}
@@ -0,0 +1,22 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright EntityRef 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 <Source/Framework/ScriptCanvasTestFixture.h>
using namespace ScriptCanvasTests;
TEST_F(ScriptCanvasTestFixture, Regression_LY_79396)
{
// Enable when BE2.0 goes to main
//RunUnitTestGraph("LY_SC_UnitTest_LY_79396");
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,27 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affililates or
* its licensors.
*
* For complete copyright EntityRef 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 <Source/Framework/ScriptCanvasTestFixture.h>
#include <Source/Framework/ScriptCanvasTestUtilities.h>
#include <AzCore/ScriptCanvas/ScriptCanvasAttributes.h>
#include <AzCore/RTTI/AttributeReader.h>
using namespace ScriptCanvasTests;
using namespace ScriptCanvas;
TEST_F(ScriptCanvasTestFixture, StringNodes)
{
// Disabled until BE2.0 goes into main
//RunUnitTestGraph("LY_SC_UnitTest_StringNodes");
}
@@ -0,0 +1,541 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright EntityRef 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/Serialization/IdUtils.h>
#include <ScriptCanvas/Asset/RuntimeAsset.h>
#include <ScriptCanvas/Asset/RuntimeAssetHandler.h>
#include <ScriptCanvas/Execution/RuntimeComponent.h>
#include <ScriptCanvas/Variable/GraphVariableManagerComponent.h>
#include <Source/Framework/ScriptCanvasTestFixture.h>
#include <Source/Framework/ScriptCanvasTestNodes.h>
#include <Source/Framework/ScriptCanvasTestUtilities.h>
#include <Editor/Framework/ScriptCanvasReporter.h>
using namespace ScriptCanvasEditor;
#define SCRIPT_CANVAS_UNIT_TEST_META_REPORTER_EXPECT_EQ(LHS, RHS)\
if (LHS == RHS)\
++m_countEQSucceeded;\
else\
++m_countEQFailed;
#define SCRIPT_CANVAS_UNIT_TEST_META_REPORTER_EXPECT_NE(LHS, RHS)\
if (LHS != RHS)\
++m_countNESucceeded;\
else\
++m_countNEFailed;
#define SCRIPT_CANVAS_UNIT_TEST_META_REPORTER_EXPECT_GT(LHS, RHS)\
if (LHS > RHS)\
++m_countGTSucceeded;\
else\
++m_countGTFailed;
#define SCRIPT_CANVAS_UNIT_TEST_META_REPORTER_EXPECT_GE(LHS, RHS)\
if (LHS >= RHS)\
++m_countGESucceeded;\
else\
++m_countGEFailed;
#define SCRIPT_CANVAS_UNIT_TEST_META_REPORTER_EXPECT_LT(LHS, RHS)\
if (LHS < RHS)\
++m_countLTSucceeded;\
else\
++m_countLTFailed;
#define SCRIPT_CANVAS_UNIT_TEST_META_REPORTER_EXPECT_LE(LHS, RHS)\
if (LHS <= RHS)\
++m_countLESucceeded;\
else\
++m_countLEFailed;
namespace ScriptCanvas_UnitTestingCPP
{
const double k_tolerance = 0.01;
const char* k_defaultExtension = "scriptcanvas";
const char* k_unitTestDirPathRelative = "@engroot@/Gems/ScriptCanvasTesting/Assets/ScriptCanvas/UnitTests";
}
using namespace ScriptCanvasTests;
using namespace ScriptCanvas;
using namespace ScriptCanvas::UnitTesting;
using namespace ScriptCanvasEditor;
class MetaReporter
: public Reporter
{
public:
AZ_INLINE AZ::u32 GetCountEQFailed() const { return m_countEQFailed; }
AZ_INLINE AZ::u32 GetCountEQSucceeded() const { return m_countEQSucceeded; }
AZ_INLINE AZ::u32 GetCountFalseFailed() const { return m_countFalseFailed; }
AZ_INLINE AZ::u32 GetCountFalseSucceeded() const { return m_countFalseSucceeded; }
AZ_INLINE AZ::u32 GetCountGEFailed() const { return m_countGEFailed; }
AZ_INLINE AZ::u32 GetCountGESucceeded() const { return m_countGESucceeded; }
AZ_INLINE AZ::u32 GetCountGTFailed() const { return m_countGTFailed; }
AZ_INLINE AZ::u32 GetCountGTSucceeded() const { return m_countGTSucceeded; }
AZ_INLINE AZ::u32 GetCountLEFailed() const { return m_countLEFailed; }
AZ_INLINE AZ::u32 GetCountLESucceeded() const { return m_countLESucceeded; }
AZ_INLINE AZ::u32 GetCountLTFailed() const { return m_countLTFailed; }
AZ_INLINE AZ::u32 GetCountLTSucceeded() const { return m_countLTSucceeded; }
AZ_INLINE AZ::u32 GetCountNEFailed() const { return m_countNEFailed; }
AZ_INLINE AZ::u32 GetCountNESucceeded() const { return m_countNESucceeded; }
AZ_INLINE AZ::u32 GetCountTrueFailed() const { return m_countTrueFailed; }
AZ_INLINE AZ::u32 GetCountTrueSucceeded() const { return m_countTrueSucceeded; }
bool operator==(const MetaReporter& reporter) const;
void ExpectFalse(const bool value, const Report& report) override;
void ExpectTrue(const bool value, const Report& report) override;
SCRIPT_CANVAS_UNIT_TEST_EQUALITY_OVERLOAD_OVERRIDES(ExpectEqual);
SCRIPT_CANVAS_UNIT_TEST_EQUALITY_OVERLOAD_OVERRIDES(ExpectNotEqual);
SCRIPT_CANVAS_UNIT_TEST_COMPARE_OVERLOAD_OVERRIDES(ExpectGreaterThan);
SCRIPT_CANVAS_UNIT_TEST_COMPARE_OVERLOAD_OVERRIDES(ExpectGreaterThanEqual);
SCRIPT_CANVAS_UNIT_TEST_COMPARE_OVERLOAD_OVERRIDES(ExpectLessThan);
SCRIPT_CANVAS_UNIT_TEST_COMPARE_OVERLOAD_OVERRIDES(ExpectLessThanEqual);
private:
AZ::u32 m_countEQFailed = 0;
AZ::u32 m_countEQSucceeded = 0;
AZ::u32 m_countFalseFailed = 0;
AZ::u32 m_countFalseSucceeded = 0;
AZ::u32 m_countGEFailed = 0;
AZ::u32 m_countGESucceeded = 0;
AZ::u32 m_countGTFailed = 0;
AZ::u32 m_countGTSucceeded = 0;
AZ::u32 m_countLEFailed = 0;
AZ::u32 m_countLESucceeded = 0;
AZ::u32 m_countLTFailed = 0;
AZ::u32 m_countLTSucceeded = 0;
AZ::u32 m_countNEFailed = 0;
AZ::u32 m_countNESucceeded = 0;
AZ::u32 m_countTrueFailed = 0;
AZ::u32 m_countTrueSucceeded = 0;
}; // class MetaReporter
bool MetaReporter::operator==(const MetaReporter& other) const
{
return m_countEQFailed == other.m_countEQFailed
&& m_countEQSucceeded == other.m_countEQSucceeded
&& m_countFalseFailed == other.m_countFalseFailed
&& m_countFalseSucceeded == other.m_countFalseSucceeded
&& m_countGEFailed == other.m_countGEFailed
&& m_countGESucceeded == other.m_countGESucceeded
&& m_countGTFailed == other.m_countGTFailed
&& m_countGTSucceeded == other.m_countGTSucceeded
&& m_countLEFailed == other.m_countLEFailed
&& m_countLESucceeded == other.m_countLESucceeded
&& m_countLTFailed == other.m_countLTFailed
&& m_countLTSucceeded == other.m_countLTSucceeded
&& m_countNEFailed == other.m_countNEFailed
&& m_countNESucceeded == other.m_countNESucceeded
&& m_countTrueSucceeded == other.m_countTrueSucceeded
&& m_countTrueFailed == other.m_countTrueFailed
&& *static_cast<const Reporter*>(this) == *static_cast<const Reporter*>(&other);
}
// Handler
void MetaReporter::ExpectFalse(const bool value, [[maybe_unused]] const Report& report)
{
if (!value)
++m_countFalseSucceeded;
else
++m_countFalseFailed;
}
void MetaReporter::ExpectTrue(const bool value, [[maybe_unused]] const Report& report)
{
if (value)
++m_countTrueSucceeded;
else
++m_countTrueFailed;
}
void MetaReporter::ExpectEqualNumber(const Data::NumberType lhs, const Data::NumberType rhs, [[maybe_unused]] const Report& report)
{
if (AZ::IsClose(lhs, rhs, ScriptCanvas_UnitTestingCPP::k_tolerance))
++m_countEQSucceeded;
else
++m_countEQFailed;
}
void MetaReporter::ExpectNotEqualNumber(const Data::NumberType lhs, const Data::NumberType rhs, [[maybe_unused]] const Report& report)
{
if (!AZ::IsClose(lhs, rhs, ScriptCanvas_UnitTestingCPP::k_tolerance))
++m_countNESucceeded;
else
++m_countNEFailed;
}
SCRIPT_CANVAS_UNIT_TEST_EQUALITY_OVERLOAD_IMPLEMENTATIONS(MetaReporter, ExpectEqual, SCRIPT_CANVAS_UNIT_TEST_META_REPORTER_EXPECT_EQ)
SCRIPT_CANVAS_UNIT_TEST_EQUALITY_OVERLOAD_IMPLEMENTATIONS(MetaReporter, ExpectNotEqual, SCRIPT_CANVAS_UNIT_TEST_META_REPORTER_EXPECT_NE)
SCRIPT_CANVAS_UNIT_TEST_COMPARE_OVERLOAD_IMPLEMENTATIONS(MetaReporter, ExpectGreaterThan, SCRIPT_CANVAS_UNIT_TEST_META_REPORTER_EXPECT_GT)
SCRIPT_CANVAS_UNIT_TEST_COMPARE_OVERLOAD_IMPLEMENTATIONS(MetaReporter, ExpectGreaterThanEqual, SCRIPT_CANVAS_UNIT_TEST_META_REPORTER_EXPECT_GE)
SCRIPT_CANVAS_UNIT_TEST_COMPARE_OVERLOAD_IMPLEMENTATIONS(MetaReporter, ExpectLessThan, SCRIPT_CANVAS_UNIT_TEST_META_REPORTER_EXPECT_LT)
SCRIPT_CANVAS_UNIT_TEST_COMPARE_OVERLOAD_IMPLEMENTATIONS(MetaReporter, ExpectLessThanEqual, SCRIPT_CANVAS_UNIT_TEST_META_REPORTER_EXPECT_LE)
MetaReporter MetaRunUnitTestGraph(AZStd::string_view path)
{
const DurationSpec duration;
MetaReporter interpretedReporter;
const AZStd::string filePath = AZStd::string::format("%s/%s.%s", ScriptCanvas_UnitTestingCPP::k_unitTestDirPathRelative, path.data(), ScriptCanvas_UnitTestingCPP::k_defaultExtension);
ScriptCanvasEditor::RunGraph(filePath, ExecutionMode::Interpreted, duration, interpretedReporter);
/*
MetaReporter nativeReporter;
RunGraph(path, ExecutionMode::Native, duration, nativeReporter);
EXPECT_EQ(nativeReporter, interpretedReporter);
*/
EXPECT_TRUE(interpretedReporter.IsReportFinished());
return interpretedReporter;
}
//////////////////////////////////////////////////////////////////////////
// if this test doesn't pass, our fixture is broken, and our unit tests are meaningless
//////////////////////////////////////////////////////////////////////////
TEST_F(ScriptCanvasTestFixture, FixtureSanity)
{
SUCCEED();
}
//////////////////////////////////////////////////////////////////////////
// if these tests do not pass, our SC unit test framework is broken, and such tests are meaningless
//////////////////////////////////////////////////////////////////////////
TEST_F(ScriptCanvasTestFixture, AddFailure)
{
MetaReporter reporter = MetaRunUnitTestGraph("LY_SC_UnitTest_Meta_AddFailure");
if (!reporter.GetScriptCanvasId().IsValid())
{
ADD_FAILURE() << "Graph is not valid";
return;
}
EXPECT_EQ(reporter.GetFailure().size(), 3);
if (reporter.GetFailure().size() == 3)
{
EXPECT_EQ(reporter.GetFailure()[0], "zero");
EXPECT_EQ(reporter.GetFailure()[1], "one");
EXPECT_EQ(reporter.GetFailure()[2], "two");
}
EXPECT_TRUE(reporter.IsComplete());
EXPECT_TRUE(reporter.IsDeactivated());
EXPECT_TRUE(reporter.IsErrorFree());
}
TEST_F(ScriptCanvasTestFixture, AddSuccess)
{
MetaReporter reporter = MetaRunUnitTestGraph("LY_SC_UnitTest_Meta_AddSuccess");
if (!reporter.GetScriptCanvasId().IsValid())
{
ADD_FAILURE() << "Graph is not valid";
return;
}
EXPECT_EQ(reporter.GetSuccess().size(), 3);
if (reporter.GetFailure().size() == 3)
{
EXPECT_EQ(reporter.GetSuccess()[0], "zero");
EXPECT_EQ(reporter.GetSuccess()[1], "one");
EXPECT_EQ(reporter.GetSuccess()[2], "two");
}
EXPECT_TRUE(reporter.IsComplete());
EXPECT_TRUE(reporter.IsDeactivated());
EXPECT_TRUE(reporter.IsErrorFree());
}
TEST_F(ScriptCanvasTestFixture, ExpectTrueFail)
{
MetaReporter reporter = MetaRunUnitTestGraph("LY_SC_UnitTest_Meta_ExpectTrueFail");
if (!reporter.GetScriptCanvasId().IsValid())
{
ADD_FAILURE() << "Graph is not valid";
return;
}
EXPECT_EQ(reporter.GetCountTrueSucceeded(), 0);
EXPECT_EQ(reporter.GetCountTrueFailed(), 1);
EXPECT_TRUE(reporter.IsErrorFree());
}
TEST_F(ScriptCanvasTestFixture, ExpectTrueSucceed)
{
MetaReporter reporter = MetaRunUnitTestGraph("LY_SC_UnitTest_Meta_ExpectTrueSucceed");
if (!reporter.GetScriptCanvasId().IsValid())
{
ADD_FAILURE() << "Graph is not valid";
return;
}
EXPECT_EQ(reporter.GetCountTrueSucceeded(), 1);
EXPECT_EQ(reporter.GetCountTrueFailed(), 0);
EXPECT_TRUE(reporter.IsErrorFree());
}
TEST_F(ScriptCanvasTestFixture, ExpectEqualFail)
{
MetaReporter reporter = MetaRunUnitTestGraph("LY_SC_UnitTest_Meta_ExpectEqualFail");
if (!reporter.GetScriptCanvasId().IsValid())
{
ADD_FAILURE() << "Graph is not valid";
return;
}
EXPECT_EQ(reporter.GetCountEQFailed(), 1);
EXPECT_EQ(reporter.GetCountEQSucceeded(), 0);
EXPECT_TRUE(reporter.IsComplete());
EXPECT_TRUE(reporter.IsDeactivated());
EXPECT_TRUE(reporter.IsErrorFree());
}
TEST_F(ScriptCanvasTestFixture, ExpectEqualSucceed)
{
MetaReporter reporter = MetaRunUnitTestGraph("LY_SC_UnitTest_Meta_ExpectEqualSucceed");
if (!reporter.GetScriptCanvasId().IsValid())
{
ADD_FAILURE() << "Graph is not valid";
return;
}
EXPECT_EQ(reporter.GetCountEQFailed(), 0);
EXPECT_EQ(reporter.GetCountEQSucceeded(), 1);
EXPECT_TRUE(reporter.IsComplete());
EXPECT_TRUE(reporter.IsDeactivated());
EXPECT_TRUE(reporter.IsErrorFree());
}
TEST_F(ScriptCanvasTestFixture, ExpectNotEqualFail)
{
MetaReporter reporter = MetaRunUnitTestGraph("LY_SC_UnitTest_Meta_ExpectNotEqualFail");
if (!reporter.GetScriptCanvasId().IsValid())
{
ADD_FAILURE() << "Graph is not valid";
return;
}
EXPECT_EQ(reporter.GetCountNEFailed(), 1);
EXPECT_EQ(reporter.GetCountNESucceeded(), 0);
EXPECT_TRUE(reporter.IsComplete());
EXPECT_TRUE(reporter.IsDeactivated());
EXPECT_TRUE(reporter.IsErrorFree());
}
TEST_F(ScriptCanvasTestFixture, ExpectNotEqualSucceed)
{
MetaReporter reporter = MetaRunUnitTestGraph("LY_SC_UnitTest_Meta_ExpectNotEqualSucceed");
if (!reporter.GetScriptCanvasId().IsValid())
{
ADD_FAILURE() << "Graph is not valid";
return;
}
EXPECT_EQ(reporter.GetCountNEFailed(), 0);
EXPECT_EQ(reporter.GetCountNESucceeded(), 1);
EXPECT_TRUE(reporter.IsComplete());
EXPECT_TRUE(reporter.IsDeactivated());
EXPECT_TRUE(reporter.IsErrorFree());
}
TEST_F(ScriptCanvasTestFixture, MarkCompleteFail)
{
MetaReporter reporter = MetaRunUnitTestGraph("LY_SC_UnitTest_Meta_MarkCompleteFail");
if (!reporter.GetScriptCanvasId().IsValid())
{
ADD_FAILURE() << "Graph is not valid";
return;
}
EXPECT_EQ(reporter.GetCountTrueSucceeded(), 1);
EXPECT_FALSE(reporter.IsComplete());
EXPECT_TRUE(reporter.IsDeactivated());
EXPECT_TRUE(reporter.IsErrorFree());
}
TEST_F(ScriptCanvasTestFixture, MarkCompleteSucceed)
{
MetaReporter reporter = MetaRunUnitTestGraph("LY_SC_UnitTest_Meta_MarkCompleteSucceed");
if (!reporter.GetScriptCanvasId().IsValid())
{
ADD_FAILURE() << "Graph is not valid";
return;
}
EXPECT_EQ(reporter.GetCountTrueSucceeded(), 1);
EXPECT_TRUE(reporter.IsComplete());
EXPECT_TRUE(reporter.IsDeactivated());
EXPECT_TRUE(reporter.IsErrorFree());
}
TEST_F(ScriptCanvasTestFixture, ExpectGreaterThanFail)
{
MetaReporter reporter = MetaRunUnitTestGraph("LY_SC_UnitTest_Meta_ExpectGreaterThanFail");
if (!reporter.GetScriptCanvasId().IsValid())
{
ADD_FAILURE() << "Graph is not valid";
return;
}
EXPECT_EQ(reporter.GetCountGTFailed(), 1);
EXPECT_EQ(reporter.GetCountGTSucceeded(), 0);
EXPECT_TRUE(reporter.IsComplete());
EXPECT_TRUE(reporter.IsDeactivated());
EXPECT_TRUE(reporter.IsErrorFree());
}
TEST_F(ScriptCanvasTestFixture, ExpectGreaterThanSucceed)
{
MetaReporter reporter = MetaRunUnitTestGraph("LY_SC_UnitTest_Meta_ExpectGreaterThanSucceed");
if (!reporter.GetScriptCanvasId().IsValid())
{
ADD_FAILURE() << "Graph is not valid";
return;
}
EXPECT_EQ(reporter.GetCountGTFailed(), 0);
EXPECT_EQ(reporter.GetCountGTSucceeded(), 1);
EXPECT_TRUE(reporter.IsComplete());
EXPECT_TRUE(reporter.IsDeactivated());
EXPECT_TRUE(reporter.IsErrorFree());
}
TEST_F(ScriptCanvasTestFixture, ExpectGreaterThanEqualFail)
{
MetaReporter reporter = MetaRunUnitTestGraph("LY_SC_UnitTest_Meta_ExpectGreaterThanEqualFail");
if (!reporter.GetScriptCanvasId().IsValid())
{
ADD_FAILURE() << "Graph is not valid";
return;
}
EXPECT_EQ(reporter.GetCountGEFailed(), 1);
EXPECT_EQ(reporter.GetCountGESucceeded(), 0);
EXPECT_TRUE(reporter.IsComplete());
EXPECT_TRUE(reporter.IsDeactivated());
EXPECT_TRUE(reporter.IsErrorFree());
}
TEST_F(ScriptCanvasTestFixture, ExpectGreaterThanEqualSucceed)
{
MetaReporter reporter = MetaRunUnitTestGraph("LY_SC_UnitTest_Meta_ExpectGreaterThanEqualSucceed");
if (!reporter.GetScriptCanvasId().IsValid())
{
ADD_FAILURE() << "Graph is not valid";
return;
}
EXPECT_EQ(reporter.GetCountGEFailed(), 0);
EXPECT_EQ(reporter.GetCountGESucceeded(), 2);
EXPECT_TRUE(reporter.IsComplete());
EXPECT_TRUE(reporter.IsDeactivated());
EXPECT_TRUE(reporter.IsErrorFree());
}
TEST_F(ScriptCanvasTestFixture, ExpectLessThanFail)
{
MetaReporter reporter = MetaRunUnitTestGraph("LY_SC_UnitTest_Meta_ExpectLessThanFail");
if (!reporter.GetScriptCanvasId().IsValid())
{
ADD_FAILURE() << "Graph is not valid";
return;
}
EXPECT_EQ(reporter.GetCountLTFailed(), 1);
EXPECT_EQ(reporter.GetCountLTSucceeded(), 0);
EXPECT_TRUE(reporter.IsComplete());
EXPECT_TRUE(reporter.IsDeactivated());
EXPECT_TRUE(reporter.IsErrorFree());
}
TEST_F(ScriptCanvasTestFixture, ExpectLessThanSucceed)
{
MetaReporter reporter = MetaRunUnitTestGraph("LY_SC_UnitTest_Meta_ExpectLessThanSucceed");
if (!reporter.GetScriptCanvasId().IsValid())
{
ADD_FAILURE() << "Graph is not valid";
return;
}
EXPECT_EQ(reporter.GetCountLTFailed(), 0);
EXPECT_EQ(reporter.GetCountLTSucceeded(), 1);
EXPECT_TRUE(reporter.IsComplete());
EXPECT_TRUE(reporter.IsDeactivated());
EXPECT_TRUE(reporter.IsErrorFree());
}
TEST_F(ScriptCanvasTestFixture, ExpectLessThanEqualFail)
{
MetaReporter reporter = MetaRunUnitTestGraph("LY_SC_UnitTest_Meta_ExpectLessThanEqualFail");
if (!reporter.GetScriptCanvasId().IsValid())
{
ADD_FAILURE() << "Graph is not valid";
return;
}
EXPECT_EQ(reporter.GetCountLEFailed(), 1);
EXPECT_EQ(reporter.GetCountLESucceeded(), 0);
EXPECT_TRUE(reporter.IsComplete());
EXPECT_TRUE(reporter.IsDeactivated());
EXPECT_TRUE(reporter.IsErrorFree());
}
TEST_F(ScriptCanvasTestFixture, ExpectLessThanEqualSucceed)
{
MetaReporter reporter = MetaRunUnitTestGraph("LY_SC_UnitTest_Meta_ExpectLessThanEqualSucceed");
if (!reporter.GetScriptCanvasId().IsValid())
{
ADD_FAILURE() << "Graph is not valid";
return;
}
EXPECT_EQ(reporter.GetCountLEFailed(), 0);
EXPECT_EQ(reporter.GetCountLESucceeded(), 2);
EXPECT_TRUE(reporter.IsComplete());
EXPECT_TRUE(reporter.IsDeactivated());
EXPECT_TRUE(reporter.IsErrorFree());
}
@@ -0,0 +1,24 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright EntityRef 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 <Source/Framework/ScriptCanvasTestFixture.h>
#include <Source/Framework/ScriptCanvasTestUtilities.h>
using namespace ScriptCanvasTests;
using namespace ScriptCanvas;
TEST_F(ScriptCanvasTestFixture, HelloWorldInterpreted)
{
RunUnitTestGraph("LY_SC_UnitTest_HelloWorld");
}
@@ -0,0 +1,744 @@
/*
* 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 <Source/Framework/ScriptCanvasTestFixture.h>
#include <Source/Framework/ScriptCanvasTestUtilities.h>
#include <AzCore/Serialization/Utils.h>
#include <AzCore/std/string/string.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/RTTI/ReflectContext.h>
#include <ScriptCanvas/Variable/GraphVariableManagerComponent.h>
namespace ScriptCanvasTests
{
using namespace ScriptCanvasEditor;
class StringArray
{
public:
AZ_TYPE_INFO(StringArray, "{0240E221-3800-4BD3-91F3-0304F097F9A7}");
StringArray() = default;
static AZStd::string StringArrayToString(AZStd::vector<AZStd::string> inputArray, AZStd::string_view separator = " ")
{
if (inputArray.empty())
{
return "";
}
AZStd::string value;
auto currentIt = inputArray.begin();
auto lastIt = inputArray.end();
for (value = *currentIt; currentIt != lastIt; ++currentIt)
{
value += separator;
value += *currentIt;
}
return value;
}
static void Reflect(AZ::ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<StringArray>()
->Version(0)
;
}
if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->Class<StringArray>("StringArray")
->Method("StringArrayToString", &StringArray::StringArrayToString)
->Method("Equal", [](const StringArray&, const StringArray&) -> bool {return true; }, { {} })
->Attribute(AZ::Script::Attributes::Operator, AZ::Script::Attributes::OperatorType::Equal)
;
}
}
};
}
using namespace ScriptCanvasTests;
TEST_F(ScriptCanvasTestFixture, CreateVariableTest)
{
StringArray::Reflect(m_serializeContext);
StringArray::Reflect(m_behaviorContext);
TestBehaviorContextObject::Reflect(m_serializeContext);
TestBehaviorContextObject::Reflect(m_behaviorContext);
{
using namespace ScriptCanvas;
using namespace Nodes;
ScriptCanvas::ScriptCanvasId scriptCanvasId = AZ::Entity::MakeId();
AZStd::unique_ptr<AZ::Entity> propertyEntity = AZStd::make_unique<AZ::Entity>("PropertyGraph");
propertyEntity->CreateComponent<GraphVariableManagerComponent>(scriptCanvasId);
propertyEntity->Init();
propertyEntity->Activate();
auto vector3Datum1 = Datum(Data::Vector3Type(1.1f, 2.0f, 3.6f));
auto vector3Datum2 = Datum(Data::Vector3Type(0.0f, -86.654f, 134.23f));
auto vector4Datum = Datum(Data::Vector4Type(6.0f, 17.5f, -41.75f, 400.875f));
TestBehaviorContextObject testObject;
auto behaviorMatrix4x4Datum = Datum(testObject);
auto stringArrayDatum = Datum(StringArray());
AZ::Outcome<VariableId, AZStd::string> addPropertyOutcome(AZ::Failure(AZStd::string("Uninitialized")));
GraphVariableManagerRequestBus::EventResult(addPropertyOutcome, scriptCanvasId, &GraphVariableManagerRequests::AddVariable, "FirstVector3", vector3Datum1);
EXPECT_TRUE(addPropertyOutcome);
EXPECT_TRUE(addPropertyOutcome.GetValue().IsValid());
addPropertyOutcome = AZ::Failure(AZStd::string("Uninitialized"));
GraphVariableManagerRequestBus::EventResult(addPropertyOutcome, scriptCanvasId, &GraphVariableManagerRequests::AddVariable, "SecondVector3", vector3Datum2);
EXPECT_TRUE(addPropertyOutcome);
EXPECT_TRUE(addPropertyOutcome.GetValue().IsValid());
addPropertyOutcome = AZ::Failure(AZStd::string("Uninitialized"));
GraphVariableManagerRequestBus::EventResult(addPropertyOutcome, scriptCanvasId, &GraphVariableManagerRequests::AddVariable, "FirstVector4", vector4Datum);
EXPECT_TRUE(addPropertyOutcome);
EXPECT_TRUE(addPropertyOutcome.GetValue().IsValid());
addPropertyOutcome = AZ::Failure(AZStd::string("Uninitialized"));
GraphVariableManagerRequestBus::EventResult(addPropertyOutcome, scriptCanvasId, &GraphVariableManagerRequests::AddVariable, "ProjectionMatrix", behaviorMatrix4x4Datum);
EXPECT_TRUE(addPropertyOutcome);
EXPECT_TRUE(addPropertyOutcome.GetValue().IsValid());
addPropertyOutcome = AZ::Failure(AZStd::string("Uninitialized"));
GraphVariableManagerRequestBus::EventResult(addPropertyOutcome, scriptCanvasId, &GraphVariableManagerRequests::AddVariable, "My String Array", stringArrayDatum);
EXPECT_TRUE(addPropertyOutcome);
EXPECT_TRUE(addPropertyOutcome.GetValue().IsValid());
AZStd::vector<AZ::Outcome<VariableId, AZStd::string>> addVariablesOutcome;
AZStd::vector<AZStd::pair<AZStd::string_view, Datum>> datumsToAdd;
datumsToAdd.emplace_back("FirstBoolean", Datum(true));
datumsToAdd.emplace_back("FirstString", Datum(AZStd::string("Test")));
GraphVariableManagerRequestBus::EventResult(addVariablesOutcome, scriptCanvasId, &GraphVariableManagerRequests::AddVariables<decltype(datumsToAdd)::iterator>, datumsToAdd.begin(), datumsToAdd.end());
EXPECT_EQ(2, addVariablesOutcome.size());
EXPECT_TRUE(addVariablesOutcome[0]);
EXPECT_TRUE(addVariablesOutcome[0].GetValue().IsValid());
EXPECT_TRUE(addVariablesOutcome[1]);
EXPECT_TRUE(addVariablesOutcome[1].GetValue().IsValid());
propertyEntity.reset();
}
m_serializeContext->EnableRemoveReflection();
m_behaviorContext->EnableRemoveReflection();
StringArray::Reflect(m_serializeContext);
StringArray::Reflect(m_behaviorContext);
TestBehaviorContextObject::Reflect(m_serializeContext);
TestBehaviorContextObject::Reflect(m_behaviorContext);
m_serializeContext->DisableRemoveReflection();
m_behaviorContext->DisableRemoveReflection();
}
TEST_F(ScriptCanvasTestFixture, AddVariableFailTest)
{
using namespace ScriptCanvas;
using namespace Nodes;
ScriptCanvasId scriptCanvasId = AZ::Entity::MakeId();
AZStd::unique_ptr<AZ::Entity> propertyEntity = AZStd::make_unique<AZ::Entity>("PropertyGraph");
propertyEntity->CreateComponent<GraphVariableManagerComponent>(scriptCanvasId);
propertyEntity->Init();
propertyEntity->Activate();
auto vector3Datum1 = Datum(Data::Vector3Type(1.1f, 2.0f, 3.6f));
auto vector3Datum2 = Datum(Data::Vector3Type(0.0f, -86.654f, 134.23f));
const AZStd::string_view propertyName = "SameName";
AZ::Outcome<VariableId, AZStd::string> addPropertyOutcome(AZ::Failure(AZStd::string("Uninitialized")));
GraphVariableManagerRequestBus::EventResult(addPropertyOutcome, scriptCanvasId, &GraphVariableManagerRequests::AddVariable, propertyName, vector3Datum1);
EXPECT_TRUE(addPropertyOutcome);
EXPECT_TRUE(addPropertyOutcome.GetValue().IsValid());
addPropertyOutcome = AZ::Failure(AZStd::string("Uninitialized"));
GraphVariableManagerRequestBus::EventResult(addPropertyOutcome, scriptCanvasId, &GraphVariableManagerRequests::AddVariable, propertyName, vector3Datum2);
EXPECT_FALSE(addPropertyOutcome);
propertyEntity.reset();
}
TEST_F(ScriptCanvasTestFixture, RemoveVariableTest)
{
StringArray::Reflect(m_serializeContext);
StringArray::Reflect(m_behaviorContext);
TestBehaviorContextObject::Reflect(m_serializeContext);
TestBehaviorContextObject::Reflect(m_behaviorContext);
{
using namespace ScriptCanvas;
using namespace Nodes;
ScriptCanvasId scriptCanvasId = AZ::Entity::MakeId();
AZStd::unique_ptr<AZ::Entity> propertyEntity = AZStd::make_unique<AZ::Entity>("PropertyGraph");
propertyEntity->CreateComponent<GraphVariableManagerComponent>(scriptCanvasId);
propertyEntity->Init();
propertyEntity->Activate();
auto vector3Datum1 = Datum(Data::Vector3Type(1.1f, 2.0f, 3.6f));
auto vector3Datum2 = Datum(Data::Vector3Type(0.0f, -86.654f, 134.23f));
auto vector4Datum = Datum(Data::Vector4Type(6.0f, 17.5f, -41.75f, 400.875f));
TestBehaviorContextObject testObject;
auto behaviorMatrix4x4Datum = Datum(testObject);
auto stringArrayDatum = Datum(StringArray());
size_t numVariablesAdded = 0U;
AZ::Outcome<VariableId, AZStd::string> addPropertyOutcome(AZ::Failure(AZStd::string("Uninitialized")));
GraphVariableManagerRequestBus::EventResult(addPropertyOutcome, scriptCanvasId, &GraphVariableManagerRequests::AddVariable, "FirstVector3", vector3Datum1);
EXPECT_TRUE(addPropertyOutcome);
EXPECT_TRUE(addPropertyOutcome.GetValue().IsValid());
const VariableId firstVector3Id = addPropertyOutcome.GetValue();
++numVariablesAdded;
addPropertyOutcome = AZ::Failure(AZStd::string("Uninitialized"));
GraphVariableManagerRequestBus::EventResult(addPropertyOutcome, scriptCanvasId, &GraphVariableManagerRequests::AddVariable, "SecondVector3", vector3Datum2);
EXPECT_TRUE(addPropertyOutcome);
EXPECT_TRUE(addPropertyOutcome.GetValue().IsValid());
const VariableId secondVector3Id = addPropertyOutcome.GetValue();
++numVariablesAdded;
addPropertyOutcome = AZ::Failure(AZStd::string("Uninitialized"));
GraphVariableManagerRequestBus::EventResult(addPropertyOutcome, scriptCanvasId, &GraphVariableManagerRequests::AddVariable, "FirstVector4", vector4Datum);
EXPECT_TRUE(addPropertyOutcome);
EXPECT_TRUE(addPropertyOutcome.GetValue().IsValid());
const VariableId firstVector4Id = addPropertyOutcome.GetValue();
++numVariablesAdded;
addPropertyOutcome = AZ::Failure(AZStd::string("Uninitialized"));
GraphVariableManagerRequestBus::EventResult(addPropertyOutcome, scriptCanvasId, &GraphVariableManagerRequests::AddVariable, "ProjectionMatrix", behaviorMatrix4x4Datum);
EXPECT_TRUE(addPropertyOutcome);
EXPECT_TRUE(addPropertyOutcome.GetValue().IsValid());
const VariableId projectionMatrixId = addPropertyOutcome.GetValue();
++numVariablesAdded;
addPropertyOutcome = AZ::Failure(AZStd::string("Uninitialized"));
GraphVariableManagerRequestBus::EventResult(addPropertyOutcome, scriptCanvasId, &GraphVariableManagerRequests::AddVariable, "My String Array", stringArrayDatum);
EXPECT_TRUE(addPropertyOutcome);
EXPECT_TRUE(addPropertyOutcome.GetValue().IsValid());
const VariableId stringArrayId = addPropertyOutcome.GetValue();
++numVariablesAdded;
AZStd::vector<AZ::Outcome<VariableId, AZStd::string>> addVariablesOutcome;
AZStd::vector<AZStd::pair<AZStd::string_view, Datum>> datumsToAdd;
datumsToAdd.emplace_back("FirstBoolean", Datum(true));
datumsToAdd.emplace_back("FirstString", Datum(AZStd::string("Test")));
GraphVariableManagerRequestBus::EventResult(addVariablesOutcome, scriptCanvasId, &GraphVariableManagerRequests::AddVariables<decltype(datumsToAdd)::iterator>, datumsToAdd.begin(), datumsToAdd.end());
EXPECT_EQ(2, addVariablesOutcome.size());
EXPECT_TRUE(addVariablesOutcome[0]);
EXPECT_TRUE(addVariablesOutcome[0].GetValue().IsValid());
EXPECT_TRUE(addVariablesOutcome[1]);
EXPECT_TRUE(addVariablesOutcome[1].GetValue().IsValid());
numVariablesAdded += addVariablesOutcome.size();
const AZStd::unordered_map<VariableId, GraphVariable>* properties = nullptr;
GraphVariableManagerRequestBus::EventResult(properties, scriptCanvasId, &GraphVariableManagerRequests::GetVariables);
ASSERT_NE(nullptr, properties);
EXPECT_EQ(numVariablesAdded, (*properties).size());
{
// Remove Property By Id
bool removePropertyResult = false;
GraphVariableManagerRequestBus::EventResult(removePropertyResult, scriptCanvasId, &GraphVariableManagerRequests::RemoveVariable, stringArrayId);
EXPECT_TRUE(removePropertyResult);
properties = {};
GraphVariableManagerRequestBus::EventResult(properties, scriptCanvasId, &GraphVariableManagerRequests::GetVariables);
ASSERT_NE(nullptr, properties);
EXPECT_EQ(numVariablesAdded, (*properties).size() + 1);
// Attempt to remove already removed property
GraphVariableManagerRequestBus::EventResult(removePropertyResult, scriptCanvasId, &GraphVariableManagerRequests::RemoveVariable, stringArrayId);
EXPECT_FALSE(removePropertyResult);
}
{
// Remove Property by name
size_t numVariablesRemoved = 0U;
GraphVariableManagerRequestBus::EventResult(numVariablesRemoved, scriptCanvasId, &GraphVariableManagerRequests::RemoveVariableByName, "ProjectionMatrix");
EXPECT_EQ(1U, numVariablesRemoved);
properties = {};
GraphVariableManagerRequestBus::EventResult(properties, scriptCanvasId, &GraphVariableManagerRequests::GetVariables);
ASSERT_NE(nullptr, properties);
EXPECT_EQ(numVariablesAdded, (*properties).size() + 2);
// Attempt to remove property again.
GraphVariableManagerRequestBus::EventResult(numVariablesRemoved, scriptCanvasId, &GraphVariableManagerRequests::RemoveVariableByName, "ProjectionMatrix");
EXPECT_EQ(0U, numVariablesRemoved);
}
{
// Re-add removed Property
addPropertyOutcome = AZ::Failure(AZStd::string("Uninitialized"));
GraphVariableManagerRequestBus::EventResult(addPropertyOutcome, scriptCanvasId, &GraphVariableManagerRequests::AddVariable, "ProjectionMatrix", behaviorMatrix4x4Datum);
EXPECT_TRUE(addPropertyOutcome);
EXPECT_TRUE(addPropertyOutcome.GetValue().IsValid());
properties = {};
GraphVariableManagerRequestBus::EventResult(properties, scriptCanvasId, &GraphVariableManagerRequests::GetVariables);
EXPECT_EQ(numVariablesAdded, (*properties).size() + 1);
}
propertyEntity.reset();
}
m_serializeContext->EnableRemoveReflection();
m_behaviorContext->EnableRemoveReflection();
StringArray::Reflect(m_serializeContext);
StringArray::Reflect(m_behaviorContext);
TestBehaviorContextObject::Reflect(m_serializeContext);
TestBehaviorContextObject::Reflect(m_behaviorContext);
m_serializeContext->DisableRemoveReflection();
m_behaviorContext->DisableRemoveReflection();
}
TEST_F(ScriptCanvasTestFixture, FindVariableTest)
{
using namespace ScriptCanvas;
using namespace Nodes;
ScriptCanvasId scriptCanvasId = AZ::Entity::MakeId();
AZStd::unique_ptr<AZ::Entity> propertyEntity = AZStd::make_unique<AZ::Entity>("PropertyGraph");
propertyEntity->CreateComponent<GraphVariableManagerComponent>(scriptCanvasId);
propertyEntity->Init();
propertyEntity->Activate();
auto stringVariableDatum = Datum(Data::StringType("SABCDQPE"));
const AZStd::string_view propertyName = "StringProperty";
AZ::Outcome<VariableId, AZStd::string> addPropertyOutcome(AZ::Failure(AZStd::string("Uninitialized")));
GraphVariableManagerRequestBus::EventResult(addPropertyOutcome, scriptCanvasId, &GraphVariableManagerRequests::AddVariable, propertyName, stringVariableDatum);
EXPECT_TRUE(addPropertyOutcome);
EXPECT_TRUE(addPropertyOutcome.GetValue().IsValid());
const VariableId stringVariableId = addPropertyOutcome.GetValue();
GraphVariable* variableByName = nullptr;
{
// Find Property by name
GraphVariableManagerRequestBus::EventResult(variableByName, scriptCanvasId, &GraphVariableManagerRequests::FindVariable, propertyName);
ASSERT_NE(nullptr, variableByName);
EXPECT_EQ(variableByName->GetVariableId(), stringVariableId);
EXPECT_EQ(stringVariableDatum, (*variableByName->GetDatum()));
}
GraphVariable* variableById = nullptr;
{
// Find Property by id
GraphVariableManagerRequestBus::EventResult(variableById, scriptCanvasId, &GraphVariableManagerRequests::FindVariableById, stringVariableId);
ASSERT_NE(nullptr, variableById);
EXPECT_EQ(stringVariableDatum, (*variableById->GetDatum()));
}
{
// Remove Property
size_t numVariablesRemoved = false;
GraphVariableManagerRequestBus::EventResult(numVariablesRemoved, scriptCanvasId, &GraphVariableManagerRequests::RemoveVariableByName, propertyName);
EXPECT_EQ(1U, numVariablesRemoved);
}
{
// Attempt to re-lookup property
GraphVariable* propertyVariable = nullptr;
GraphVariableManagerRequestBus::EventResult(propertyVariable, scriptCanvasId, &GraphVariableManagerRequests::FindVariable, propertyName);
EXPECT_EQ(nullptr, propertyVariable);
GraphVariable* stringVariable = nullptr;
GraphVariableManagerRequestBus::EventResult(stringVariable, scriptCanvasId, &GraphVariableManagerRequests::FindVariableById, stringVariableId);
EXPECT_EQ(nullptr, stringVariable);
}
propertyEntity.reset();
}
TEST_F(ScriptCanvasTestFixture, ModifyVariableTest)
{
using namespace ScriptCanvas;
using namespace Nodes;
ScriptCanvasId scriptCanvasId = AZ::Entity::MakeId();
AZStd::unique_ptr<AZ::Entity> propertyEntity = AZStd::make_unique<AZ::Entity>("PropertyGraph");
propertyEntity->CreateComponent<GraphVariableManagerComponent>(scriptCanvasId);
propertyEntity->Init();
propertyEntity->Activate();
auto stringVariableDatum = Datum(Data::StringType("Test1"));
const AZStd::string_view propertyName = "StringProperty";
AZ::Outcome<VariableId, AZStd::string> addPropertyOutcome(AZ::Failure(AZStd::string("Uninitialized")));
GraphVariableManagerRequestBus::EventResult(addPropertyOutcome, scriptCanvasId, &GraphVariableManagerRequests::AddVariable, propertyName, stringVariableDatum);
EXPECT_TRUE(addPropertyOutcome);
EXPECT_TRUE(addPropertyOutcome.GetValue().IsValid());
const VariableId stringVariableId = addPropertyOutcome.GetValue();
GraphVariable* propertyDatum = nullptr;
GraphVariableManagerRequestBus::EventResult(propertyDatum, scriptCanvasId, &GraphVariableManagerRequests::FindVariable, propertyName);
ASSERT_NE(nullptr, propertyDatum);
// Modify the added property
AZStd::string_view modifiedString = "High Functioning S... *<silenced>";
{
ModifiableDatumView datumView;
propertyDatum->ConfigureDatumView(datumView);
ASSERT_TRUE(datumView.IsValid());
ASSERT_TRUE(datumView.GetDataType() == Data::Type::String());
datumView.SetAs(ScriptCanvas::Data::StringType(modifiedString));
}
{
// Re-lookup Property and test against modifiedString
GraphVariable* stringVariable = nullptr;
GraphVariableManagerRequestBus::EventResult(stringVariable, scriptCanvasId, &GraphVariableManagerRequests::FindVariableById, stringVariableId);
ASSERT_NE(nullptr, stringVariable);
ModifiableDatumView datumView;
stringVariable->ConfigureDatumView(datumView);
ASSERT_TRUE(datumView.IsValid());
ASSERT_TRUE(datumView.GetDataType() == Data::Type::String());
auto resultString = datumView.GetAs<Data::StringType>();
EXPECT_EQ(modifiedString, (*resultString));
}
}
TEST_F(ScriptCanvasTestFixture, SerializationTest)
{
StringArray::Reflect(m_serializeContext);
StringArray::Reflect(m_behaviorContext);
using namespace ScriptCanvas;
using namespace Nodes;
{
ScriptCanvasId scriptCanvasId = AZ::Entity::MakeId();
AZStd::unique_ptr<AZ::Entity> propertyEntity = AZStd::make_unique<AZ::Entity>("PropertyGraph");
propertyEntity->CreateComponent<GraphVariableManagerComponent>(scriptCanvasId);
propertyEntity->Init();
propertyEntity->Activate();
auto stringArrayDatum = Datum(StringArray());
AZ::Outcome<VariableId, AZStd::string> addPropertyOutcome(AZ::Failure(AZStd::string("Uninitialized")));
GraphVariableManagerRequestBus::EventResult(addPropertyOutcome, scriptCanvasId, &GraphVariableManagerRequests::AddVariable, "My String Array", stringArrayDatum);
EXPECT_TRUE(addPropertyOutcome);
EXPECT_TRUE(addPropertyOutcome.GetValue().IsValid());
GraphVariable* stringArrayVariable = nullptr;
GraphVariableManagerRequestBus::EventResult(stringArrayVariable, scriptCanvasId, &GraphVariableManagerRequests::FindVariable, "My String Array");
ASSERT_NE(nullptr, stringArrayVariable);
EXPECT_EQ(stringArrayDatum, (*stringArrayVariable->GetDatum()));
const VariableId stringArrayVariableId = stringArrayVariable->GetVariableId();
// Save Property Component Entity
AZStd::vector<AZ::u8> binaryBuffer;
AZ::IO::ByteContainerStream<decltype(binaryBuffer)> byteStream(&binaryBuffer);
const bool objectSaved = AZ::Utils::SaveObjectToStream(byteStream, AZ::DataStream::ST_BINARY, propertyEntity.get(), m_serializeContext);
EXPECT_TRUE(objectSaved);
// Delete the Property Component
propertyEntity.reset();
// Load Variable Component Entity
{
byteStream.Seek(0U, AZ::IO::GenericStream::ST_SEEK_BEGIN);
propertyEntity.reset(AZ::Utils::LoadObjectFromStream<AZ::Entity>(byteStream, m_serializeContext));
ASSERT_TRUE(propertyEntity);
propertyEntity->Init();
propertyEntity->Activate();
GraphVariableManagerComponent* component = propertyEntity->FindComponent<GraphVariableManagerComponent>();
if (component)
{
component->ConfigureScriptCanvasId(scriptCanvasId);
}
}
// Attempt to lookup the My String Array property after loading from object stream
stringArrayVariable = nullptr;
GraphVariableManagerRequestBus::EventResult(stringArrayVariable, scriptCanvasId, &GraphVariableManagerRequests::FindVariable, "My String Array");
ASSERT_NE(nullptr, stringArrayVariable);
EXPECT_EQ(stringArrayVariableId, stringArrayVariable->GetVariableId());
auto identityMatrixDatum = Datum(Data::Matrix3x3Type::CreateIdentity());
addPropertyOutcome = AZ::Failure(AZStd::string("Uninitialized"));
GraphVariableManagerRequestBus::EventResult(addPropertyOutcome, scriptCanvasId, &GraphVariableManagerRequests::AddVariable, "Super Matrix Bros", identityMatrixDatum);
EXPECT_TRUE(addPropertyOutcome);
EXPECT_TRUE(addPropertyOutcome.GetValue().IsValid());
GraphVariable* matrixVariable = nullptr;
GraphVariableManagerRequestBus::EventResult(matrixVariable, scriptCanvasId, &GraphVariableManagerRequests::FindVariableById, addPropertyOutcome.GetValue());
ASSERT_NE(nullptr, matrixVariable);
const Datum* matrix3x3Datum = matrixVariable->GetDatum();
EXPECT_EQ(identityMatrixDatum, (*matrix3x3Datum));
propertyEntity.reset();
}
m_serializeContext->EnableRemoveReflection();
m_behaviorContext->EnableRemoveReflection();
StringArray::Reflect(m_serializeContext);
StringArray::Reflect(m_behaviorContext);
m_serializeContext->DisableRemoveReflection();
m_behaviorContext->DisableRemoveReflection();
}
TEST_F(ScriptCanvasTestFixture, GetVariableNodeTest)
{
using namespace ScriptCanvas;
using namespace Nodes;
using namespace TestNodes;
AZStd::unique_ptr<AZ::Entity> graphEntity = AZStd::make_unique<AZ::Entity>("VariableGraph");
SystemRequestBus::Broadcast(&SystemRequests::CreateEngineComponentsOnEntity, graphEntity.get());
Graph* graph = AZ::EntityUtils::FindFirstDerivedComponent<Graph>(graphEntity.get());
ASSERT_NE(nullptr, graph);
AZ::EntityId graphEntityId = graphEntity->GetId();
ScriptCanvasId graphUniqueId = graph->GetScriptCanvasId();
graphEntity->Init();
Datum planeDatum(Data::PlaneType::CreateFromCoefficients(3.0f, -1.0f, 2.0f, 0.0f));
// Add in Plane Variable to Variable Component
AZStd::string_view variableName = "TestPlane";
AZ::Outcome<VariableId, AZStd::string> addVariableOutcome(AZ::Failure(AZStd::string("Uninitialized")));
GraphVariableManagerRequestBus::EventResult(addVariableOutcome, graphUniqueId, &GraphVariableManagerRequests::AddVariable, variableName, planeDatum);
EXPECT_TRUE(addVariableOutcome);
EXPECT_TRUE(addVariableOutcome.GetValue().IsValid());
const VariableId planeVariableId = addVariableOutcome.GetValue();
// Create Get Variable Node
AZ::EntityId outID;
auto startNode = CreateTestNode<Nodes::Core::Start>(graphUniqueId, outID);
auto getVariableNode = CreateTestNode<Nodes::Core::GetVariableNode>(graphUniqueId, outID);
auto getNormalNode = CreateTestNode<PlaneNodes::GetNormalNode>(graphUniqueId, outID);
auto vector3ResultNode = CreateDataNode(graphUniqueId, Data::Vector3Type::CreateZero(), outID);
auto printNode = CreateTestNode<TestResult>(graphUniqueId, outID);
auto normalResultTestResultNode = CreateTestNode<TestResult>(graphUniqueId, outID);
auto planeDistanceTestResultNode = CreateTestNode<TestResult>(graphUniqueId, outID);
// data
// This should fail to connect until the variableNode has a valid Variable associated with it
{
ScopedOutputSuppression supressOutput;
EXPECT_FALSE(graph->Connect(getVariableNode->GetEntityId(), getVariableNode->GetDataOutSlotId(), getNormalNode->GetEntityId(), getNormalNode->GetSlotId("Plane: Source")));
}
EXPECT_FALSE(getVariableNode->GetId().IsValid());
EXPECT_FALSE(getVariableNode->GetDataOutSlotId().IsValid());
getVariableNode->SetId(planeVariableId); // This associates the variable with the node and adds the input slot
auto variableDataOutSlotId = getVariableNode->GetDataOutSlotId();
EXPECT_TRUE(graph->Connect(getVariableNode->GetEntityId(), variableDataOutSlotId, getNormalNode->GetEntityId(), getNormalNode->GetSlotId("Plane: Source")));
EXPECT_TRUE(graph->Connect(getVariableNode->GetEntityId(), variableDataOutSlotId, printNode->GetEntityId(), printNode->GetSlotId("Value")));
// Connects Get Variable Node(normal: Vector3) data output slot to the TestResult Node(Set) data input slot
// Connects Get Variable Node(distance: Vector3) data output slot to the TestResult Node(Set) data input slot
auto normalDataOutSlotId = getVariableNode->GetSlotId("normal: Vector3");
EXPECT_TRUE(graph->Connect(getVariableNode->GetEntityId(), normalDataOutSlotId, normalResultTestResultNode->GetEntityId(), normalResultTestResultNode->GetSlotId("Value")));
auto distanceDataOutSlotId = getVariableNode->GetSlotId("distance: Number");
EXPECT_TRUE(graph->Connect(getVariableNode->GetEntityId(), distanceDataOutSlotId, planeDistanceTestResultNode->GetEntityId(), planeDistanceTestResultNode->GetSlotId("Value")));
EXPECT_TRUE(Connect(*graph, getNormalNode->GetEntityId(), "Result: Vector3", vector3ResultNode->GetEntityId(), "Set"));
// logic
EXPECT_TRUE(Connect(*graph, startNode->GetEntityId(), "Out", getVariableNode->GetEntityId(), "In"));
EXPECT_TRUE(Connect(*graph, getVariableNode->GetEntityId(), "Out", getNormalNode->GetEntityId(), "In"));
EXPECT_TRUE(Connect(*graph, getVariableNode->GetEntityId(), "Out", printNode->GetEntityId(), "In"));
EXPECT_TRUE(Connect(*graph, getVariableNode->GetEntityId(), "Out", normalResultTestResultNode->GetEntityId(), "In"));
EXPECT_TRUE(Connect(*graph, getVariableNode->GetEntityId(), "Out", planeDistanceTestResultNode->GetEntityId(), "In"));
// execute
{
ScopedOutputSuppression suppressOutput;
graphEntity->Activate();
}
EXPECT_FALSE(graph->IsInErrorState());
graphEntity->Deactivate();
GraphVariable* graphVariable = nullptr;
GraphVariableManagerRequestBus::EventResult(graphVariable, graphUniqueId, &GraphVariableManagerRequests::FindVariable, variableName);
ASSERT_NE(nullptr, graphVariable);
auto variablePlane = graphVariable->GetDatum()->GetAs<Data::PlaneType>();
ASSERT_NE(nullptr, variablePlane);
auto getResultPlane = GetInput_UNIT_TEST<Data::PlaneType>(printNode, "Value");
ASSERT_NE(nullptr, getResultPlane);
EXPECT_EQ(*variablePlane, *getResultPlane);
auto resultNormal = GetInput_UNIT_TEST<Data::Vector3Type>(vector3ResultNode, "Set");
ASSERT_NE(nullptr, resultNormal);
auto expectedNormal = variablePlane->GetNormal();
EXPECT_EQ(expectedNormal, *resultNormal);
auto planeNormalPropertyVector3 = GetInput_UNIT_TEST<Data::Vector3Type>(normalResultTestResultNode, "Value");
ASSERT_NE(nullptr, planeNormalPropertyVector3);
EXPECT_EQ(Data::Vector3Type(3.0f, -1.0f, 2.0f), *planeNormalPropertyVector3);
auto planeDistancePropertyNumber = GetInput_UNIT_TEST<Data::NumberType>(planeDistanceTestResultNode, "Value");
ASSERT_NE(nullptr, planeDistancePropertyNumber);
EXPECT_EQ(0.0f, *planeDistancePropertyNumber);
AZ::Entity* connectionEntity{};
EXPECT_TRUE(graph->FindConnection(connectionEntity, { getVariableNode->GetEntityId(), variableDataOutSlotId }, { getNormalNode->GetEntityId(), getNormalNode->GetSlotId("Plane: Source") }));
getVariableNode->SetId({});
EXPECT_FALSE(graph->FindConnection(connectionEntity, { getVariableNode->GetEntityId(), variableDataOutSlotId }, { getNormalNode->GetEntityId(), getNormalNode->GetSlotId("Plane: Source") }));
EXPECT_FALSE(getVariableNode->GetId().IsValid());
EXPECT_FALSE(getVariableNode->GetDataOutSlotId().IsValid());
}
TEST_F(ScriptCanvasTestFixture, SetVariableNodeTest)
{
using namespace ScriptCanvas;
using namespace Nodes;
AZStd::unique_ptr<AZ::Entity> graphEntity = AZStd::make_unique<AZ::Entity>("VariableGraph");
SystemRequestBus::Broadcast(&SystemRequests::CreateEngineComponentsOnEntity, graphEntity.get());
Graph* graph = AZ::EntityUtils::FindFirstDerivedComponent<Graph>(graphEntity.get());
ASSERT_NE(nullptr, graph);
AZ::EntityId graphEntityId = graphEntity->GetId();
ScriptCanvasId graphUniqueId = graph->GetScriptCanvasId();
graphEntity->Init();
Datum planeDatum(Data::PlaneType::CreateFromCoefficients(0.0f, 0.0f, 0.0f, 0.0f));
// Add in Plane Variable to Variable Component
AZStd::string_view varName = "TestPlane";
AZ::Outcome<VariableId, AZStd::string> addVariableOutcome(AZ::Failure(AZStd::string("Uninitialized")));
GraphVariableManagerRequestBus::EventResult(addVariableOutcome, graphUniqueId, &GraphVariableManagerRequests::AddVariable, varName, planeDatum);
EXPECT_TRUE(addVariableOutcome);
EXPECT_TRUE(addVariableOutcome.GetValue().IsValid());
const VariableId planeVariableId = addVariableOutcome.GetValue();
// Create Set Variable Node
AZ::EntityId outID;
auto startNode = CreateTestNode<Nodes::Core::Start>(graphUniqueId, outID);
auto setVariableNode = CreateTestNode<Nodes::Core::SetVariableNode>(graphUniqueId, outID);
auto fromNormalAndPointNode = CreateTestNode<PlaneNodes::FromNormalAndPointNode>(graphUniqueId, outID);
auto testPlane = Data::PlaneType::CreateFromNormalAndPoint(Data::Vector3Type(3.0f, -1.0f, 2.0f), Data::Vector3Type::CreateZero());
auto vector3NormalNode = CreateDataNode(graphUniqueId, testPlane.GetNormal(), outID);
auto vector3PointNode = CreateDataNode(graphUniqueId, Data::Vector3Type::CreateZero(), outID);
auto planeResultNode = CreateDataNode(graphUniqueId, Data::PlaneType::CreateFromNormalAndPoint(Data::Vector3Type(3.0f, -1.0f, 2.0f), Data::Vector3Type::CreateZero()), outID);
// data
EXPECT_TRUE(Connect(*graph, vector3NormalNode->GetEntityId(), "Get", fromNormalAndPointNode->GetEntityId(), "Vector3: Normal"));
EXPECT_TRUE(Connect(*graph, vector3PointNode->GetEntityId(), "Get", fromNormalAndPointNode->GetEntityId(), "Vector3: Point"));
// This should fail to connect until the SetVariableNode has a valid Variable associated with it
{
ScopedOutputSuppression suppressOutput;
EXPECT_FALSE(graph->Connect(fromNormalAndPointNode->GetEntityId(), fromNormalAndPointNode->GetSlotId("Plane: Result"), setVariableNode->GetEntityId(), setVariableNode->GetDataInSlotId()));
}
EXPECT_FALSE(setVariableNode->GetId().IsValid());
EXPECT_FALSE(setVariableNode->GetDataInSlotId().IsValid());
setVariableNode->SetId(planeVariableId); // This associates the variable with the node and adds the input slot
auto dataInputSlotId = setVariableNode->GetDataInSlotId();
EXPECT_TRUE(graph->Connect(fromNormalAndPointNode->GetEntityId(), fromNormalAndPointNode->GetSlotId("Result: Plane"), setVariableNode->GetEntityId(), dataInputSlotId));
auto dataOutputSlotId = setVariableNode->GetDataOutSlotId();
EXPECT_TRUE(graph->Connect(setVariableNode->GetEntityId(), dataOutputSlotId, planeResultNode->GetEntityId(), planeResultNode->GetSlotId("Set")));
// logic
EXPECT_TRUE(Connect(*graph, startNode->GetEntityId(), "Out", fromNormalAndPointNode->GetEntityId(), "In"));
EXPECT_TRUE(Connect(*graph, fromNormalAndPointNode->GetEntityId(), "Out", setVariableNode->GetEntityId(), "In"));
// execute
graphEntity->Activate();
EXPECT_FALSE(graph->IsInErrorState());
graphEntity->Deactivate();
AZ::Entity* connectionEntity{};
EXPECT_TRUE(graph->FindConnection(connectionEntity, { fromNormalAndPointNode->GetEntityId(), fromNormalAndPointNode->GetSlotId("Result: Plane") }, { setVariableNode->GetEntityId(), dataInputSlotId }));
setVariableNode->SetId({});
EXPECT_FALSE(graph->FindConnection(connectionEntity, { fromNormalAndPointNode->GetEntityId(), fromNormalAndPointNode->GetSlotId("Result: Plane") }, { setVariableNode->GetEntityId(), dataInputSlotId }));
EXPECT_FALSE(setVariableNode->GetId().IsValid());
EXPECT_FALSE(setVariableNode->GetDataInSlotId().IsValid());
GraphVariable* graphVariable = nullptr;
GraphVariableManagerRequestBus::EventResult(graphVariable, graphUniqueId, &GraphVariableManagerRequests::FindVariable, varName);
ASSERT_NE(nullptr, graphVariable);
// Get Variable Plane and verify that it is the same as the plane created from
auto variablePlane = graphVariable->GetDatum()->GetAs<Data::PlaneType>();
ASSERT_NE(nullptr, variablePlane);
EXPECT_EQ(testPlane, *variablePlane);
auto resultPlane = GetInput_UNIT_TEST<Data::PlaneType>(planeResultNode, "Set");
ASSERT_NE(nullptr, resultPlane);
auto expectedNormal = variablePlane->GetNormal();
EXPECT_EQ(expectedNormal, resultPlane->GetNormal());
}
TEST_F(ScriptCanvasTestFixture, Vector2AllNodes)
{
RunUnitTestGraph("LY_SC_UnitTest_Vector2_AllNodes");
}
TEST_F(ScriptCanvasTestFixture, Vector3_GetNode)
{
RunUnitTestGraph("LY_SC_UnitTest_Vector3_Variable_GetNode");
}
TEST_F(ScriptCanvasTestFixture, Vector3_SetNode)
{
RunUnitTestGraph("LY_SC_UnitTest_Vector3_Variable_SetNode");
}