/* * 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 #include #include #include #include #include #include #include #include #include using namespace ScriptCanvasTests; using namespace TestNodes; TEST_F(ScriptCanvasTestFixture, CoreNodeFunction_OwningGraphCheck) { using namespace ScriptCanvas; ScriptCanvas::Graph* graph = CreateGraph(); ConfigurableUnitTestNode* groupedNode = CreateConfigurableNode(); EXPECT_EQ(graph, groupedNode->GetGraph()); } TEST_F(ScriptCanvasTestFixture, AddRemoveSlotNotifications) { RegisterComponentDescriptor(); using namespace ScriptCanvas; AZStd::unique_ptr numberAddEntity = AZStd::make_unique("numberAddEntity"); auto numberAddNode = numberAddEntity->CreateComponent(); numberAddEntity->Init(); ScriptUnitTestNodeNotificationHandler nodeNotifications(numberAddNode->GetEntityId()); SlotId testSlotId = numberAddNode->AddSlot("test"); EXPECT_EQ(1U, nodeNotifications.GetSlotsAdded()); numberAddNode->RemoveSlot(testSlotId); EXPECT_EQ(1U, nodeNotifications.GetSlotsRemoved()); testSlotId = numberAddNode->AddSlot("duplicate"); EXPECT_EQ(2U, nodeNotifications.GetSlotsAdded()); // This should not signal the NodeNotification::OnSlotAdded event as the slot already exist on the node SlotId duplicateSlotId = numberAddNode->AddSlot("duplicate"); EXPECT_EQ(2U, nodeNotifications.GetSlotsAdded()); EXPECT_EQ(testSlotId, duplicateSlotId); numberAddNode->RemoveSlot(testSlotId); EXPECT_EQ(2U, nodeNotifications.GetSlotsRemoved()); // This should not signal the NodeNotification::OnSlotRemoved event as the slot no longer exist on the node numberAddNode->RemoveSlot(testSlotId, false); EXPECT_EQ(2U, nodeNotifications.GetSlotsRemoved()); numberAddEntity.reset(); } TEST_F(ScriptCanvasTestFixture, InsertSlot_Basic) { using namespace ScriptCanvas; ScriptCanvas::Graph* graph = CreateGraph(); ConfigurableUnitTestNode* basicNode = CreateConfigurableNode(); SlotId firstSlotAdded; SlotId secondSlotAdded; SlotId thirdSlotAdded; { DataSlotConfiguration slotConfiguration; slotConfiguration.m_name = "A"; slotConfiguration.SetDefaultValue(0); slotConfiguration.SetConnectionType(ConnectionType::Input); Slot* slot = basicNode->AddTestingSlot(slotConfiguration); firstSlotAdded = slot->GetId(); } { DataSlotConfiguration slotConfiguration; slotConfiguration.m_name = "C"; slotConfiguration.SetDefaultValue(2); slotConfiguration.SetConnectionType(ConnectionType::Input); Slot* slot = basicNode->AddTestingSlot(slotConfiguration); secondSlotAdded = slot->GetId(); } { DataSlotConfiguration slotConfiguration; slotConfiguration.m_name = "B"; slotConfiguration.SetDefaultValue(1); slotConfiguration.SetConnectionType(ConnectionType::Input); auto index = basicNode->FindSlotIndex(secondSlotAdded); EXPECT_EQ(index, 1); Slot* slot = basicNode->InsertTestingSlot(index, slotConfiguration); thirdSlotAdded = slot->GetId(); } { AZStd::vector< const Slot* > slotList = basicNode->GetAllSlots(); EXPECT_EQ(slotList.size(), 3); { const Slot* firstSlot = slotList[0]; EXPECT_EQ(firstSlot->GetId(), firstSlotAdded); EXPECT_EQ(firstSlot->GetName(), "A"); EXPECT_FLOAT_EQ(static_cast((*firstSlot->FindDatum()->GetAs())), 0.0f); } { const Slot* secondSlot = slotList[1]; EXPECT_EQ(secondSlot->GetId(), thirdSlotAdded); EXPECT_EQ(secondSlot->GetName(), "B"); EXPECT_FLOAT_EQ(static_cast((*secondSlot->FindDatum()->GetAs())), 1.0f); } { const Slot* thirdSlot = slotList[2]; EXPECT_EQ(thirdSlot->GetId(), secondSlotAdded); EXPECT_EQ(thirdSlot->GetName(), "C"); EXPECT_FLOAT_EQ(static_cast((*thirdSlot->FindDatum()->GetAs())), 2.0f); } } graph->Activate(); { AZStd::vector< const Slot* > slotList = basicNode->GetAllSlots(); EXPECT_EQ(slotList.size(), 3); { const Slot* firstSlot = slotList[0]; EXPECT_EQ(firstSlot->GetId(), firstSlotAdded); EXPECT_EQ(firstSlot->GetName(), "A"); EXPECT_FLOAT_EQ(static_cast((*firstSlot->FindDatum()->GetAs())), 0.0f); } { const Slot* secondSlot = slotList[1]; EXPECT_EQ(secondSlot->GetId(), thirdSlotAdded); EXPECT_EQ(secondSlot->GetName(), "B"); EXPECT_FLOAT_EQ(static_cast((*secondSlot->FindDatum()->GetAs())), 1.0f); } { const Slot* thirdSlot = slotList[2]; EXPECT_EQ(thirdSlot->GetId(), secondSlotAdded); EXPECT_EQ(thirdSlot->GetName(), "C"); EXPECT_FLOAT_EQ(static_cast((*thirdSlot->FindDatum()->GetAs())), 2.0f); } } graph->Deactivate(); { const AZStd::vector< const Slot* > slotList = basicNode->GetAllSlots(); EXPECT_EQ(slotList.size(), 3); { const Slot* firstSlot = slotList[0]; EXPECT_EQ(firstSlot->GetId(), firstSlotAdded); EXPECT_EQ(firstSlot->GetName(), "A"); EXPECT_FLOAT_EQ(static_cast((*firstSlot->FindDatum()->GetAs())), 0.0f); } { const Slot* secondSlot = slotList[1]; EXPECT_EQ(secondSlot->GetId(), thirdSlotAdded); EXPECT_EQ(secondSlot->GetName(), "B"); EXPECT_FLOAT_EQ(static_cast((*secondSlot->FindDatum()->GetAs())), 1.0f); } { const Slot* thirdSlot = slotList[2]; EXPECT_EQ(thirdSlot->GetId(), secondSlotAdded); EXPECT_EQ(thirdSlot->GetName(), "C"); EXPECT_FLOAT_EQ(static_cast((*thirdSlot->FindDatum()->GetAs())), 2.0f); } } } TEST_F(ScriptCanvasTestFixture, InsertSlot_FrontPadded) { using namespace ScriptCanvas; ScriptCanvas::Graph* graph = CreateGraph(); ConfigurableUnitTestNode* basicNode = CreateConfigurableNode(); basicNode->AddTestingSlot(ExecutionSlotConfiguration("Input", ConnectionType::Input)); basicNode->AddTestingSlot(ExecutionSlotConfiguration("Input-1", ConnectionType::Input)); basicNode->AddTestingSlot(ExecutionSlotConfiguration("Input-2", ConnectionType::Input)); basicNode->AddTestingSlot(ExecutionSlotConfiguration("Input-3", ConnectionType::Input)); SlotId firstSlotAdded; SlotId secondSlotAdded; SlotId thirdSlotAdded; { DataSlotConfiguration slotConfiguration; slotConfiguration.m_name = "A"; slotConfiguration.SetDefaultValue(0); slotConfiguration.SetConnectionType(ConnectionType::Input); Slot* slot = basicNode->AddTestingSlot(slotConfiguration); firstSlotAdded = slot->GetId(); } { DataSlotConfiguration slotConfiguration; slotConfiguration.m_name = "C"; slotConfiguration.SetDefaultValue(2); slotConfiguration.SetConnectionType(ConnectionType::Input); Slot* slot = basicNode->AddTestingSlot(slotConfiguration); secondSlotAdded = slot->GetId(); } { DataSlotConfiguration slotConfiguration; slotConfiguration.m_name = "B"; slotConfiguration.SetDefaultValue(1); slotConfiguration.SetConnectionType(ConnectionType::Input); auto index = basicNode->FindSlotIndex(secondSlotAdded); Slot* slot = basicNode->InsertTestingSlot(index, slotConfiguration); thirdSlotAdded = slot->GetId(); } { AZStd::vector< const Slot* > slotList = basicNode->FindSlotsByDescriptor(SlotDescriptors::DataIn()); EXPECT_EQ(slotList.size(), 3); { const Slot* firstSlot = slotList[0]; EXPECT_EQ(firstSlot->GetId(), firstSlotAdded); EXPECT_EQ(firstSlot->GetName(), "A"); EXPECT_FLOAT_EQ(static_cast((*firstSlot->FindDatum()->GetAs())), 0.0f); } { const Slot* secondSlot = slotList[1]; EXPECT_EQ(secondSlot->GetId(), thirdSlotAdded); EXPECT_EQ(secondSlot->GetName(), "B"); EXPECT_FLOAT_EQ(static_cast((*secondSlot->FindDatum()->GetAs())), 1.0f); } { const Slot* thirdSlot = slotList[2]; EXPECT_EQ(thirdSlot->GetId(), secondSlotAdded); EXPECT_EQ(thirdSlot->GetName(), "C"); EXPECT_FLOAT_EQ(static_cast((*thirdSlot->FindDatum()->GetAs())), 2.0f); } } graph->Activate(); { AZStd::vector< const Slot* > slotList = basicNode->FindSlotsByDescriptor(SlotDescriptors::DataIn()); EXPECT_EQ(slotList.size(), 3); { const Slot* firstSlot = slotList[0]; EXPECT_EQ(firstSlot->GetId(), firstSlotAdded); EXPECT_EQ(firstSlot->GetName(), "A"); EXPECT_FLOAT_EQ(static_cast((*firstSlot->FindDatum()->GetAs())), 0.0f); } { const Slot* secondSlot = slotList[1]; EXPECT_EQ(secondSlot->GetId(), thirdSlotAdded); EXPECT_EQ(secondSlot->GetName(), "B"); EXPECT_FLOAT_EQ(static_cast((*secondSlot->FindDatum()->GetAs())), 1.0f); } { const Slot* thirdSlot = slotList[2]; EXPECT_EQ(thirdSlot->GetId(), secondSlotAdded); EXPECT_EQ(thirdSlot->GetName(), "C"); EXPECT_FLOAT_EQ(static_cast((*thirdSlot->FindDatum()->GetAs())), 2.0f); } } graph->Deactivate(); { AZStd::vector< const Slot* > slotList = basicNode->FindSlotsByDescriptor(SlotDescriptors::DataIn()); EXPECT_EQ(slotList.size(), 3); { const Slot* firstSlot = slotList[0]; EXPECT_EQ(firstSlot->GetId(), firstSlotAdded); EXPECT_EQ(firstSlot->GetName(), "A"); EXPECT_FLOAT_EQ(static_cast((*firstSlot->FindDatum()->GetAs())), 0.0f); } { const Slot* secondSlot = slotList[1]; EXPECT_EQ(secondSlot->GetId(), thirdSlotAdded); EXPECT_EQ(secondSlot->GetName(), "B"); EXPECT_FLOAT_EQ(static_cast((*secondSlot->FindDatum()->GetAs())), 1.0f); } { const Slot* thirdSlot = slotList[2]; EXPECT_EQ(thirdSlot->GetId(), secondSlotAdded); EXPECT_EQ(thirdSlot->GetName(), "C"); EXPECT_FLOAT_EQ(static_cast((*thirdSlot->FindDatum()->GetAs())), 2.0f); } } } TEST_F(ScriptCanvasTestFixture, ValueTypes) { using namespace ScriptCanvas; Datum number0(Datum(0)); int number0Value = *number0.GetAs(); Datum number1(Datum(1)); int number1Value = *number1.GetAs(); Datum numberFloat(Datum(2.f)); float numberFloatValue = *numberFloat.GetAs(); Datum numberDouble(Datum(3.0)); double numberDoubleValue = *numberDouble.GetAs(); Datum numberHex(Datum(0xff)); /*int numberHexValue =*/ *numberHex.GetAs(); Datum numberPi(Datum(3.14f)); float numberPiValue = *numberPi.GetAs(); Datum numberSigned(Datum(-100)); /*int numberSignedValue =*/ *numberSigned.GetAs(); Datum numberUnsigned(Datum(100u)); /*unsigned int numberUnsignedValue =*/ *numberUnsigned.GetAs(); Datum numberDoublePi(Datum(6.28)); double numberDoublePiValue = *numberDoublePi.GetAs(); EXPECT_EQ(number0Value, 0); EXPECT_EQ(number1Value, 1); EXPECT_TRUE(AZ::IsClose(numberFloatValue, 2.f, std::numeric_limits::epsilon())); EXPECT_TRUE(AZ::IsClose(numberDoubleValue, 3.0, std::numeric_limits::epsilon())); EXPECT_NE(number0Value, number1Value); SC_EXPECT_FLOAT_EQ(numberPiValue, 3.14f); EXPECT_NE(number0Value, numberPiValue); EXPECT_NE(numberPiValue, numberDoublePiValue); Datum boolTrue(Datum(true)); EXPECT_TRUE(*boolTrue.GetAs()); Datum boolFalse(Datum(false)); EXPECT_FALSE(*boolFalse.GetAs()); boolFalse = boolTrue; EXPECT_TRUE(*boolFalse.GetAs()); Datum boolFalse2(Datum(false)); boolTrue = boolFalse2; EXPECT_FALSE(*boolTrue.GetAs()); { const int k_count(10000); AZStd::vector objects; for (int i = 0; i < k_count; ++i) { objects.push_back(Datum("Vector3", Datum::eOriginality::Original)); } } GTEST_SUCCEED(); } namespace { using namespace ScriptCanvas; using namespace ScriptCanvas::Nodes; bool GraphHasVectorWithValue(const ScriptCanvas::Graph& graph, const AZ::Vector3& vector) { for (auto nodeId : graph.GetNodes()) { AZ::Entity* entity{}; AZ::ComponentApplicationBus::BroadcastResult(entity, &AZ::ComponentApplicationRequests::FindEntity, nodeId); if (entity) { if (auto node = AZ::EntityUtils::FindFirstDerivedComponent(entity)) { if (auto candidate = node->GetInput_UNIT_TEST("Set")) { if (*candidate == vector) { return true; } } } } } return false; } } TEST_F(ScriptCanvasTestFixture, Contracts) { using namespace ScriptCanvas; RegisterComponentDescriptor(); ////////////////////////////////////////////////////////////////////////// // Make the graph. ScriptCanvas::Graph* graph = nullptr; SystemRequestBus::BroadcastResult(graph, &SystemRequests::MakeGraph); EXPECT_TRUE(graph != nullptr); graph->GetEntity()->Init(); const ScriptCanvasId& graphUniqueId = graph->GetScriptCanvasId(); // Make the nodes. // Start AZ::Entity* startEntity{ aznew AZ::Entity("Start") }; startEntity->Init(); AZ::EntityId startNode{ startEntity->GetId() }; SystemRequestBus::Broadcast(&SystemRequests::CreateNodeOnEntity, startNode, graphUniqueId, ScriptCanvas::Nodes::Core::Start::TYPEINFO_Uuid()); // ContractNode 0 AZ::Entity* contract0Entity{ aznew AZ::Entity("Contract 0") }; contract0Entity->Init(); AZ::EntityId contract0Node{ contract0Entity->GetId() }; SystemRequestBus::Broadcast(&SystemRequests::CreateNodeOnEntity, contract0Node, graphUniqueId, ContractNode::TYPEINFO_Uuid()); // ContractNode 1 AZ::Entity* contract1Entity{ aznew AZ::Entity("Contract 1") }; contract1Entity->Init(); AZ::EntityId contract1Node{ contract1Entity->GetId() }; SystemRequestBus::Broadcast(&SystemRequests::CreateNodeOnEntity, contract1Node, graphUniqueId, ContractNode::TYPEINFO_Uuid()); // invalid { ScriptCanvasEditor::ScopedOutputSuppression suppressOutput; EXPECT_FALSE(graph->Connect(startNode, AZ::EntityUtils::FindFirstDerivedComponent(startEntity)->GetSlotId("Out"), contract0Node, AZ::EntityUtils::FindFirstDerivedComponent(contract0Entity)->GetSlotId("Out"))); EXPECT_FALSE(graph->Connect(startNode, AZ::EntityUtils::FindFirstDerivedComponent(startEntity)->GetSlotId("In"), contract0Node, AZ::EntityUtils::FindFirstDerivedComponent(contract0Entity)->GetSlotId("In"))); EXPECT_FALSE(graph->Connect(startNode, AZ::EntityUtils::FindFirstDerivedComponent(startEntity)->GetSlotId("In"), contract0Node, AZ::EntityUtils::FindFirstDerivedComponent(contract0Entity)->GetSlotId("Get String"))); EXPECT_FALSE(graph->Connect(startNode, AZ::EntityUtils::FindFirstDerivedComponent(startEntity)->GetSlotId("Out"), contract0Node, AZ::EntityUtils::FindFirstDerivedComponent(contract0Entity)->GetSlotId("Get String"))); EXPECT_FALSE(graph->Connect(startNode, AZ::EntityUtils::FindFirstDerivedComponent(startEntity)->GetSlotId("In"), contract0Node, AZ::EntityUtils::FindFirstDerivedComponent(contract0Entity)->GetSlotId("Set String"))); EXPECT_FALSE(graph->Connect(startNode, AZ::EntityUtils::FindFirstDerivedComponent(startEntity)->GetSlotId("Out"), contract0Node, AZ::EntityUtils::FindFirstDerivedComponent(contract0Entity)->GetSlotId("Set String"))); EXPECT_FALSE(graph->Connect(contract0Node, AZ::EntityUtils::FindFirstDerivedComponent(contract0Entity)->GetSlotId("Set String"), contract1Node, AZ::EntityUtils::FindFirstDerivedComponent(contract1Entity)->GetSlotId("Set String"))); EXPECT_FALSE(graph->Connect(contract0Node, AZ::EntityUtils::FindFirstDerivedComponent(contract0Entity)->GetSlotId("Set String"), contract1Node, AZ::EntityUtils::FindFirstDerivedComponent(contract1Entity)->GetSlotId("Set Number"))); EXPECT_FALSE(graph->Connect(contract0Node, AZ::EntityUtils::FindFirstDerivedComponent(contract0Entity)->GetSlotId("Get String"), contract1Node, AZ::EntityUtils::FindFirstDerivedComponent(contract1Entity)->GetSlotId("Set Number"))); EXPECT_FALSE(graph->Connect(contract0Node, AZ::EntityUtils::FindFirstDerivedComponent(contract0Entity)->GetSlotId("Set String"), contract1Node, AZ::EntityUtils::FindFirstDerivedComponent(contract1Entity)->GetSlotId("Set String"))); EXPECT_FALSE(graph->Connect(contract0Node, AZ::EntityUtils::FindFirstDerivedComponent(contract0Entity)->GetSlotId("Out"), contract0Node, AZ::EntityUtils::FindFirstDerivedComponent(contract0Entity)->GetSlotId("In"))); } // valid EXPECT_TRUE(graph->Connect(startNode, AZ::EntityUtils::FindFirstDerivedComponent(startEntity)->GetSlotId("Out"), contract0Node, AZ::EntityUtils::FindFirstDerivedComponent(contract0Entity)->GetSlotId("In"))); EXPECT_TRUE(graph->Connect(contract0Node, AZ::EntityUtils::FindFirstDerivedComponent(contract0Entity)->GetSlotId("Set String"), contract1Node, AZ::EntityUtils::FindFirstDerivedComponent(contract1Entity)->GetSlotId("Get String"))); EXPECT_TRUE(graph->Connect(contract0Node, AZ::EntityUtils::FindFirstDerivedComponent(contract0Entity)->GetSlotId("In"), contract1Node, AZ::EntityUtils::FindFirstDerivedComponent(contract1Entity)->GetSlotId("Out"))); EXPECT_TRUE(graph->Connect(contract0Node, AZ::EntityUtils::FindFirstDerivedComponent(contract0Entity)->GetSlotId("Set Number"), contract1Node, AZ::EntityUtils::FindFirstDerivedComponent(contract1Entity)->GetSlotId("Get Number"))); // Execute it graph->GetEntity()->Activate(); ReportErrors(graph); graph->GetEntity()->Deactivate(); delete graph->GetEntity(); } // // TEST_F(ScriptCanvasTestFixture, BinaryOperationTest) // { // // using namespace ScriptCanvas::Nodes; // using namespace ScriptCanvas::Nodes::Comparison; // // TestBehaviorContextObject::Reflect(m_serializeContext); // TestBehaviorContextObject::Reflect(m_behaviorContext); // // BinaryOpTest(1, 1, true); // BinaryOpTest(1, 0, false); // BinaryOpTest(0, 1, false); // BinaryOpTest(0, 0, true); // // BinaryOpTest(1, 1, false); // BinaryOpTest(1, 0, true); // BinaryOpTest(0, 1, true); // BinaryOpTest(0, 0, false); // // BinaryOpTest(1, 1, false); // BinaryOpTest(1, 0, true); // BinaryOpTest(0, 1, false); // BinaryOpTest(0, 0, false); // // BinaryOpTest(1, 1, true); // BinaryOpTest(1, 0, true); // BinaryOpTest(0, 1, false); // BinaryOpTest(0, 0, true); // // BinaryOpTest(1, 1, false); // BinaryOpTest(1, 0, false); // BinaryOpTest(0, 1, true); // BinaryOpTest(0, 0, false); // // BinaryOpTest(1, 1, true); // BinaryOpTest(1, 0, false); // BinaryOpTest(0, 1, true); // BinaryOpTest(0, 0, true); // // BinaryOpTest(true, true, true); // BinaryOpTest(true, false, false); // BinaryOpTest(false, true, false); // BinaryOpTest(false, false, true); // // BinaryOpTest(true, true, false); // BinaryOpTest(true, false, true); // BinaryOpTest(false, true, true); // BinaryOpTest(false, false, false); // // AZStd::string string0("a string"); // AZStd::string string1("b string"); // // BinaryOpTest(string1, string1, true); // BinaryOpTest(string1, string0, false); // BinaryOpTest(string0, string1, false); // BinaryOpTest(string0, string0, true); // // BinaryOpTest(string1, string1, false); // BinaryOpTest(string1, string0, true); // BinaryOpTest(string0, string1, true); // BinaryOpTest(string0, string0, false); // // BinaryOpTest(string1, string1, false); // BinaryOpTest(string1, string0, true); // BinaryOpTest(string0, string1, false); // BinaryOpTest(string0, string0, false); // // BinaryOpTest(string1, string1, true); // BinaryOpTest(string1, string0, true); // BinaryOpTest(string0, string1, false); // BinaryOpTest(string0, string0, true); // // BinaryOpTest(string1, string1, false); // BinaryOpTest(string1, string0, false); // BinaryOpTest(string0, string1, true); // BinaryOpTest(string0, string0, false); // // BinaryOpTest(string1, string1, true); // BinaryOpTest(string1, string0, false); // BinaryOpTest(string0, string1, true); // BinaryOpTest(string0, string0, true); // // const AZ::Vector3 vectorOne(1.0f, 1.0f, 1.0f); // const AZ::Vector3 vectorZero(0.0f, 0.0f, 0.0f); // // BinaryOpTest(vectorOne, vectorOne, true); // BinaryOpTest(vectorOne, vectorZero, false); // BinaryOpTest(vectorZero, vectorOne, false); // BinaryOpTest(vectorZero, vectorZero, true); // // BinaryOpTest(vectorOne, vectorOne, false); // BinaryOpTest(vectorOne, vectorZero, true); // BinaryOpTest(vectorZero, vectorOne, true); // BinaryOpTest(vectorZero, vectorZero, false); // // const TestBehaviorContextObject zero(0); // const TestBehaviorContextObject one(1); // const TestBehaviorContextObject otherOne(1); // // BinaryOpTest(one, one, true); // BinaryOpTest(one, zero, false); // BinaryOpTest(zero, one, false); // BinaryOpTest(zero, zero, true); // // BinaryOpTest(one, one, false); // BinaryOpTest(one, zero, true); // BinaryOpTest(zero, one, true); // BinaryOpTest(zero, zero, false); // // BinaryOpTest(one, one, false); // BinaryOpTest(one, zero, true); // BinaryOpTest(zero, one, false); // BinaryOpTest(zero, zero, false); // // BinaryOpTest(one, one, true); // BinaryOpTest(one, zero, true); // BinaryOpTest(zero, one, false); // BinaryOpTest(zero, zero, true); // // BinaryOpTest(one, one, false); // BinaryOpTest(one, zero, false); // BinaryOpTest(zero, one, true); // BinaryOpTest(zero, zero, false); // // BinaryOpTest(one, one, true); // BinaryOpTest(one, zero, false); // BinaryOpTest(zero, one, true); // BinaryOpTest(zero, zero, true); // // BinaryOpTest(one, otherOne, true); // BinaryOpTest(otherOne, one, true); // // BinaryOpTest(one, otherOne, false); // BinaryOpTest(otherOne, one, false); // // BinaryOpTest(one, otherOne, false); // BinaryOpTest(otherOne, one, false); // // BinaryOpTest(one, otherOne, true); // BinaryOpTest(otherOne, one, true); // // BinaryOpTest(one, otherOne, false); // BinaryOpTest(otherOne, one, false); // // BinaryOpTest(one, otherOne, true); // BinaryOpTest(otherOne, one, true); // // // force failures, to verify crash proofiness // BinaryOpTest(one, zero, false, true); // BinaryOpTest(one, zero, true, true); // BinaryOpTest(one, zero, true, true); // BinaryOpTest(one, zero, true, true); // BinaryOpTest(one, zero, false, true); // BinaryOpTest(one, zero, false, true); // // m_serializeContext->EnableRemoveReflection(); // m_behaviorContext->EnableRemoveReflection(); // TestBehaviorContextObject::Reflect(m_serializeContext); // TestBehaviorContextObject::Reflect(m_behaviorContext); // m_serializeContext->DisableRemoveReflection(); // m_behaviorContext->DisableRemoveReflection(); // } TEST_F(ScriptCanvasTestFixture, EntityRefTest) { using namespace ScriptCanvas; using namespace ScriptCanvas::Nodes; // Fake "world" entities AZ::Entity first("First"); first.CreateComponent(); first.Init(); first.Activate(); AZ::Entity second("Second"); second.CreateComponent(); second.Init(); second.Activate(); // Script Canvas ScriptCanvas::Graph ScriptCanvas::Graph* graph = nullptr; SystemRequestBus::BroadcastResult(graph, &SystemRequests::MakeGraph); EXPECT_TRUE(graph != nullptr); m_entityContext.AddEntity(first.GetId()); m_entityContext.AddEntity(second.GetId()); m_entityContext.AddEntity(graph->GetEntityId()); graph->GetEntity()->SetName("ScriptCanvas::Graph Owner Entity"); graph->GetEntity()->CreateComponent(); graph->GetEntity()->Init(); const ScriptCanvasId& graphUniqueId = graph->GetScriptCanvasId(); AZ::EntityId startID; CreateTestNode(graphUniqueId, startID); // EntityRef node to some specific entity #1 AZ::EntityId selfEntityIdNode; auto selfEntityRef = CreateTestNode(graphUniqueId, selfEntityIdNode); selfEntityRef->SetEntityRef(first.GetId()); // EntityRef node to some specific entity #2 AZ::EntityId otherEntityIdNode; auto otherEntityRef = CreateTestNode(graphUniqueId, otherEntityIdNode); otherEntityRef->SetEntityRef(second.GetId()); // Explicitly set an EntityRef node with this graph's entity Id. AZ::EntityId graphEntityIdNode; auto graphEntityRef = CreateTestNode(graphUniqueId, graphEntityIdNode); graphEntityRef->SetEntityRef(graph->GetEntity()->GetId()); // First test: directly set an entity Id on the EntityID: 0 slot AZ::EntityId eventAid; ScriptCanvas::Nodes::Core::Method* nodeA = CreateTestNode(graphUniqueId, eventAid); nodeA->InitializeEvent({ {} }, "EntityRefTestEventBus", "TestEvent"); if (auto entityId = nodeA->ModInput_UNIT_TEST("EntityID: 0")) { *entityId = first.GetId(); } // Second test: Will connect the slot to an EntityRef node AZ::EntityId eventBid; ScriptCanvas::Nodes::Core::Method* nodeB = CreateTestNode(graphUniqueId, eventBid); nodeB->InitializeEvent({ {} }, "EntityRefTestEventBus", "TestEvent"); // Third test: Set the slot's EntityId: 0 to SelfReferenceId, this should result in the same Id as graph->GetEntityId() AZ::EntityId eventCid; ScriptCanvas::Nodes::Core::Method* nodeC = CreateTestNode(graphUniqueId, eventCid); nodeC->InitializeEvent({ {} }, "EntityRefTestEventBus", "TestEvent"); if (auto entityId = nodeC->ModInput_UNIT_TEST("EntityID: 0")) { *entityId = ScriptCanvas::GraphOwnerId; } // True AZ::EntityId trueNodeId; CreateDataNode(graphUniqueId, true, trueNodeId); // False AZ::EntityId falseNodeId; CreateDataNode(graphUniqueId, false, falseNodeId); // Start -> TestEvent // O EntityId: 0 (not connected, it was set directly on the slot) // EntityRef: first -O EntityId: 1 // False -O Boolean: 2 EXPECT_TRUE(Connect(*graph, startID, "Out", eventAid, "In")); EXPECT_TRUE(Connect(*graph, eventAid, "EntityID: 1", selfEntityIdNode, "Get")); EXPECT_TRUE(Connect(*graph, eventAid, "Boolean: 2", falseNodeId, "Get")); // Start -> TestEvent // EntityRef: second -O EntityId: 0 // EntityRef: second -O EntityId: 1 // False -O Boolean: 2 EXPECT_TRUE(Connect(*graph, startID, "Out", eventBid, "In")); EXPECT_TRUE(Connect(*graph, eventBid, "EntityID: 0", otherEntityIdNode, "Get")); EXPECT_TRUE(Connect(*graph, eventBid, "EntityID: 1", otherEntityIdNode, "Get")); EXPECT_TRUE(Connect(*graph, eventBid, "Boolean: 2", falseNodeId, "Get")); // Start -> TestEvent // -O EntityId: 0 (not connected, slot is set to SelfReferenceId) // graphEntityIdNode -O EntityId: 1 // True -O Boolean: 2 EXPECT_TRUE(Connect(*graph, startID, "Out", eventCid, "In")); EXPECT_TRUE(Connect(*graph, eventCid, "EntityID: 1", graphEntityIdNode, "Get")); EXPECT_TRUE(Connect(*graph, eventCid, "Boolean: 2", trueNodeId, "Get")); // Execute the graph { ScriptCanvasEditor::ScopedOutputSuppression suppressOutput; graph->GetEntity()->Activate(); } ReportErrors(graph); delete graph->GetEntity(); } const int k_executionCount = 998; TEST_F(ScriptCanvasTestFixture, ExecutionLength) { using namespace ScriptCanvas; ScriptCanvas::Graph* graph(nullptr); SystemRequestBus::BroadcastResult(graph, &SystemRequests::MakeGraph); EXPECT_TRUE(graph != nullptr); graph->GetEntity()->Init(); const ScriptCanvasId& graphUniqueId = graph->GetScriptCanvasId(); AZ::EntityId startID; CreateTestNode(graphUniqueId, startID); AZ::EntityId previousID = startID; for (int i = 0; i < k_executionCount; ++i) { AZ::EntityId printNodeID; TestResult* printNode = CreateTestNode(graphUniqueId, printNodeID); printNode->SetInput_UNIT_TEST("Value", i); EXPECT_TRUE(Connect(*graph, previousID, "Out", printNodeID, "In")); previousID = printNodeID; } AZ::Entity* graphEntity = graph->GetEntity(); { ScriptCanvasEditor::ScopedOutputSuppression suppressOutput; graphEntity->Activate(); } ReportErrors(graph); graphEntity->Deactivate(); delete graphEntity; } TEST_F(ScriptCanvasTestFixture, While) { RunUnitTestGraph("LY_SC_UnitTest_While", ExecutionMode::Interpreted); } TEST_F(ScriptCanvasTestFixture, WhileBreak) { RunUnitTestGraph("LY_SC_UnitTest_WhileBreak", ExecutionMode::Interpreted); }