TestEnvironment.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Tests/TestEnvironment.h>
  9. #include <Source/GraphModelSystemComponent.h>
  10. namespace GraphModelIntegrationTest
  11. {
  12. // TestGraphContext
  13. TestGraphContext::TestGraphContext()
  14. : GraphModel::GraphContext("GraphModelIntegrationTest", ".nodeTest", {})
  15. {
  16. // Construct basic data types
  17. const AZ::Uuid stringTypeUuid = azrtti_typeid<AZStd::string>();
  18. const AZ::Uuid entityIdTypeUuid = azrtti_typeid<AZ::EntityId>();
  19. m_dataTypes.push_back(AZStd::make_shared<GraphModel::DataType>(TestDataTypeEnum::TestDataTypeEnum_String, stringTypeUuid, AZStd::any(AZStd::string("")), "String", "AZStd::string"));
  20. m_dataTypes.push_back(AZStd::make_shared<GraphModel::DataType>(TestDataTypeEnum::TestDataTypeEnum_EntityId, entityIdTypeUuid, AZStd::any(AZ::EntityId()), "EntityId", "AZ::EntityId"));
  21. }
  22. // TestNode
  23. void TestNode::Reflect(AZ::ReflectContext* context)
  24. {
  25. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
  26. if (serializeContext)
  27. {
  28. serializeContext->Class<TestNode, GraphModel::Node>()
  29. ->Version(0)
  30. ;
  31. }
  32. }
  33. TestNode::TestNode(GraphModel::GraphPtr graph, AZStd::shared_ptr<TestGraphContext> graphContext)
  34. : GraphModel::Node(graph)
  35. , m_graphContext(graphContext)
  36. {
  37. RegisterSlots();
  38. CreateSlotData();
  39. }
  40. const char* TestNode::GetTitle() const
  41. {
  42. return "TestNode";
  43. }
  44. void TestNode::RegisterSlots()
  45. {
  46. GraphModel::DataTypePtr stringDataType = m_graphContext->GetDataType(TestDataTypeEnum::TestDataTypeEnum_String);
  47. RegisterSlot(AZStd::make_shared<GraphModel::SlotDefinition>(
  48. GraphModel::SlotDirection::Input,
  49. GraphModel::SlotType::Data,
  50. TEST_STRING_INPUT_ID,
  51. "Test Input",
  52. "A test input slot for String data type",
  53. GraphModel::DataTypeList{ stringDataType },
  54. stringDataType->GetDefaultValue()));
  55. RegisterSlot(AZStd::make_shared<GraphModel::SlotDefinition>(
  56. GraphModel::SlotDirection::Output,
  57. GraphModel::SlotType::Data,
  58. TEST_STRING_OUTPUT_ID,
  59. "Test Output",
  60. "A test output slot for String data type",
  61. GraphModel::DataTypeList{ stringDataType } ));
  62. RegisterSlot(AZStd::make_shared<GraphModel::SlotDefinition>(
  63. GraphModel::SlotDirection::Input,
  64. GraphModel::SlotType::Event,
  65. TEST_EVENT_INPUT_ID,
  66. "Event In",
  67. "A test input event slot"));
  68. RegisterSlot(AZStd::make_shared<GraphModel::SlotDefinition>(
  69. GraphModel::SlotDirection::Output,
  70. GraphModel::SlotType::Event,
  71. TEST_EVENT_OUTPUT_ID,
  72. "Event Out",
  73. "A test output event slot"));
  74. }
  75. // ExtendableSlotsNode
  76. void ExtendableSlotsNode::Reflect(AZ::ReflectContext* context)
  77. {
  78. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
  79. if (serializeContext)
  80. {
  81. serializeContext->Class<ExtendableSlotsNode, GraphModel::Node>()
  82. ->Version(0)
  83. ;
  84. }
  85. }
  86. ExtendableSlotsNode::ExtendableSlotsNode(GraphModel::GraphPtr graph, AZStd::shared_ptr<TestGraphContext> graphContext)
  87. : GraphModel::Node(graph)
  88. , m_graphContext(graphContext)
  89. {
  90. RegisterSlots();
  91. CreateSlotData();
  92. }
  93. const char* ExtendableSlotsNode::GetTitle() const
  94. {
  95. return "ExtendableSlotsNode";
  96. }
  97. void ExtendableSlotsNode::RegisterSlots()
  98. {
  99. GraphModel::DataTypePtr stringDataType = m_graphContext->GetDataType(TestDataTypeEnum::TestDataTypeEnum_String);
  100. RegisterSlot(AZStd::make_shared<GraphModel::SlotDefinition>(
  101. GraphModel::SlotDirection::Input,
  102. GraphModel::SlotType::Data,
  103. TEST_STRING_INPUT_ID,
  104. "Test Input",
  105. "An extendable input slot for String data type",
  106. GraphModel::DataTypeList{ stringDataType },
  107. stringDataType->GetDefaultValue(),
  108. 0,
  109. 2,
  110. "Add String Input",
  111. "Add a test string input"));
  112. RegisterSlot(AZStd::make_shared<GraphModel::SlotDefinition>(
  113. GraphModel::SlotDirection::Output,
  114. GraphModel::SlotType::Data,
  115. TEST_STRING_OUTPUT_ID,
  116. "Test Output",
  117. "An extendable output slot for String data type",
  118. GraphModel::DataTypeList{ stringDataType },
  119. AZStd::any{},
  120. 1,
  121. 100,
  122. "Add String Output",
  123. "Add a test string output"));
  124. RegisterSlot(AZStd::make_shared<GraphModel::SlotDefinition>(
  125. GraphModel::SlotDirection::Input,
  126. GraphModel::SlotType::Event,
  127. TEST_EVENT_INPUT_ID,
  128. "Test Input Event",
  129. "An extendable input event",
  130. GraphModel::DataTypeList{},
  131. AZStd::any{},
  132. 1,
  133. 100,
  134. "Add Input Event",
  135. "Add a test event input"));
  136. RegisterSlot(AZStd::make_shared<GraphModel::SlotDefinition>(
  137. GraphModel::SlotDirection::Output,
  138. GraphModel::SlotType::Event,
  139. TEST_EVENT_OUTPUT_ID,
  140. "Test Output Event",
  141. "An extendable output event",
  142. GraphModel::DataTypeList{},
  143. AZStd::any{},
  144. 3,
  145. 4,
  146. "Add Output Event",
  147. "Add a test event output"));
  148. }
  149. // GraphModelTestEnvironment
  150. void GraphModelTestEnvironment::SetupEnvironment()
  151. {
  152. // Create application and descriptor
  153. m_application = aznew AZ::ComponentApplication;
  154. AZ::ComponentApplication::Descriptor appDesc;
  155. appDesc.m_useExistingAllocator = true;
  156. // Create basic system entity
  157. AZ::ComponentApplication::StartupParameters startupParams;
  158. m_systemEntity = m_application->Create(appDesc, startupParams);
  159. m_systemEntity->AddComponent(aznew AZ::AssetManagerComponent());
  160. m_systemEntity->AddComponent(aznew AZ::JobManagerComponent());
  161. m_systemEntity->AddComponent(aznew AZ::StreamerComponent());
  162. m_systemEntity->AddComponent(aznew GraphModel::GraphModelSystemComponent());
  163. // Register descriptor for the GraphModelSystemComponent
  164. m_application->RegisterComponentDescriptor(GraphModel::GraphModelSystemComponent::CreateDescriptor());
  165. // Register descriptors for our mock components
  166. m_application->RegisterComponentDescriptor(MockGraphCanvasServices::MockNodeComponent::CreateDescriptor());
  167. m_application->RegisterComponentDescriptor(MockGraphCanvasServices::MockSlotComponent::CreateDescriptor());
  168. m_application->RegisterComponentDescriptor(MockGraphCanvasServices::MockDataSlotComponent::CreateDescriptor());
  169. m_application->RegisterComponentDescriptor(MockGraphCanvasServices::MockExecutionSlotComponent::CreateDescriptor());
  170. m_application->RegisterComponentDescriptor(MockGraphCanvasServices::MockExtenderSlotComponent::CreateDescriptor());
  171. m_application->RegisterComponentDescriptor(MockGraphCanvasServices::MockGraphCanvasSystemComponent::CreateDescriptor());
  172. // Register our mock GraphCanvasSystemComponent
  173. m_systemEntity->AddComponent(aznew MockGraphCanvasServices::MockGraphCanvasSystemComponent());
  174. m_systemEntity->Init();
  175. m_systemEntity->Activate();
  176. }
  177. void GraphModelTestEnvironment::TeardownEnvironment()
  178. {
  179. delete m_application;
  180. }
  181. }