BVB Source Codes

CRYENGINE Show ColorGradientNode_Test.cpp Source code

Return Download CRYENGINE: download ColorGradientNode_Test.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /*************************************************************************
  4. -------------------------------------------------------------------------
  5. History:
  6. - 12:05:2009   Created by Federico Rebora
  7. *************************************************************************/
  8.  
  9. #include "Stdafx.h"
  10.  
  11. #include "ColorGradientNode.h"
  12.  
  13. #include "Testing/MockCrySizer.h"
  14. #include "Testing/FlowGraphTesting.h"
  15.  
  16. #include "EngineFacade/EngineFacade.h"
  17. #include "EngineFacade/GameFacade.h"
  18.  
  19. CRY_TEST_FIXTURE(ColorGradientNodeTestFixture, CryUnit::ITestFixture, GameTesting::FlowGraphTestSuite)
  20. {
  21.         class CMockGameFacade : public EngineFacade::CDummyGameFacade
  22.         {
  23.         public:
  24.                 void TriggerFadingColorChart(const string& filePath, const float fadeInTimeInSeconds)
  25.                 {
  26.                         m_lastTriggeredColorChartPath = filePath;
  27.                         m_lastTriggeredFadeTime = fadeInTimeInSeconds;
  28.                 }
  29.  
  30.                 const string& GetLastTriggeredColorChartPath() const
  31.                 {
  32.                         return m_lastTriggeredColorChartPath;
  33.                 }
  34.  
  35.                 float GetLastTriggeredFadeInTime() const
  36.                 {
  37.                         return m_lastTriggeredFadeTime;
  38.                 }
  39.  
  40.         private:
  41.                 string m_lastTriggeredColorChartPath;
  42.                 float m_lastTriggeredFadeTime;
  43.         };
  44.  
  45.         ColorGradientNodeTestFixture()
  46.         {
  47.                 m_environment = IGameEnvironment::Create(
  48.                         IEngineFacadePtr(new EngineFacade::CDummyEngineFacade),
  49.                         IGameFacadePtr(new CMockGameFacade));
  50.  
  51.                 m_colorGradientNodeToTest.reset(new CFlowNode_ColorGradient(GetEnvironment(), 0));
  52.         }
  53.  
  54.         void ConfigureAndProcessEvent(IFlowNode::EFlowEvent event, const string filePath, const float fadeInTime)
  55.         {
  56.                 GameTesting::CFlowNodeTestingFacility flowNodeTester(*m_colorGradientNodeToTest, CFlowNode_ColorGradient::eInputPorts_Count);
  57.  
  58.                 flowNodeTester.SetInputByIndex(CFlowNode_ColorGradient::eInputPorts_TexturePath, filePath);
  59.                 flowNodeTester.SetInputByIndex(CFlowNode_ColorGradient::eInputPorts_TransitionTime, fadeInTime);
  60.  
  61.                 flowNodeTester.ProcessEvent(event);
  62.         }
  63.  
  64.         IGameEnvironment& GetEnvironment() const
  65.         {
  66.                 return* m_environment;
  67.         }
  68.  
  69.         EngineFacade::CDummyEngineFacade& GetEngine() const
  70.         {
  71.                 return static_cast<EngineFacade::CDummyEngineFacade&>(GetEnvironment().GetEngine());
  72.         }
  73.  
  74.         CMockGameFacade& GetGame() const
  75.         {
  76.                 return static_cast<CMockGameFacade&>(GetEnvironment().GetGame());
  77.         }
  78.  
  79.         shared_ptr<CFlowNode_ColorGradient> m_colorGradientNodeToTest;
  80.  
  81. private:
  82.        
  83.         IGameEnvironmentPtr m_environment;
  84.  
  85. };
  86.  
  87. CRY_TEST_WITH_FIXTURE(TestColorGradientNode_MemoryStatisticsAreSetCorrectly, ColorGradientNodeTestFixture)
  88. {
  89.         CMockCrySizer sizer;
  90.         m_colorGradientNodeToTest->GetMemoryStatistics(&sizer);
  91.  
  92.         ASSERT_ARE_EQUAL(sizeof(CFlowNode_ColorGradient), sizer.GetTotalSize());
  93. }
  94.  
  95. CRY_TEST_WITH_FIXTURE(TestColorGradientNode_IsSetInAdvancedCategory, ColorGradientNodeTestFixture)
  96. {
  97.         SFlowNodeConfig flowNodeConfiguration;
  98.         m_colorGradientNodeToTest->GetConfiguration(flowNodeConfiguration);
  99.  
  100.         ASSERT_ARE_EQUAL(static_cast<uint32>(EFLN_ADVANCED), flowNodeConfiguration.GetCategory());
  101. }
  102.  
  103. CRY_TEST_WITH_FIXTURE(TestColorGradientNode_SetsNoOutputs, ColorGradientNodeTestFixture)
  104. {
  105.         SFlowNodeConfig flowNodeConfiguration;
  106.         m_colorGradientNodeToTest->GetConfiguration(flowNodeConfiguration);
  107.  
  108.         const SOutputPortConfig* nullOutputPorts = 0;
  109.  
  110.         ASSERT_ARE_EQUAL(nullOutputPorts, flowNodeConfiguration.pOutputPorts);
  111. }
  112.  
  113. CRY_TEST_WITH_FIXTURE(TestColorGradientNode_SetsNodeInputs, ColorGradientNodeTestFixture)
  114. {
  115.         SFlowNodeConfig flowNodeConfiguration;
  116.         m_colorGradientNodeToTest->GetConfiguration(flowNodeConfiguration);
  117.  
  118.         const SInputPortConfig* inputPorts = CFlowNode_ColorGradient::inputPorts;
  119.         ASSERT_ARE_EQUAL(inputPorts, flowNodeConfiguration.pInputPorts);
  120. }
  121.  
  122.  
  123. CRY_TEST_WITH_FIXTURE(TestColorGradientNode_SetsTriggerInput, ColorGradientNodeTestFixture)
  124. {
  125.         SFlowNodeConfig flowNodeConfiguration;
  126.         m_colorGradientNodeToTest->GetConfiguration(flowNodeConfiguration);
  127.  
  128.         const SInputPortConfig inputToTest = InputPortConfig_Void("Trigger", _HELP(""));
  129.         ASSERT_ARE_EQUAL(inputToTest, flowNodeConfiguration.pInputPorts[CFlowNode_ColorGradient::eInputPorts_Trigger]);
  130. }
  131.  
  132.  
  133. CRY_TEST_WITH_FIXTURE(TestColorGradientNode_SetsTexturePathInput, ColorGradientNodeTestFixture)
  134. {
  135.         SFlowNodeConfig flowNodeConfiguration;
  136.         m_colorGradientNodeToTest->GetConfiguration(flowNodeConfiguration);
  137.  
  138.         const SInputPortConfig inputToTest = InputPortConfig<string>("TexturePath", _HELP(""));
  139.         ASSERT_ARE_EQUAL(inputToTest, flowNodeConfiguration.pInputPorts[CFlowNode_ColorGradient::eInputPorts_TexturePath]);
  140. }
  141.  
  142. CRY_TEST_WITH_FIXTURE(TestColorGradientNode_SetsTransitionTimeInput, ColorGradientNodeTestFixture)
  143. {
  144.         SFlowNodeConfig flowNodeConfiguration;
  145.         m_colorGradientNodeToTest->GetConfiguration(flowNodeConfiguration);
  146.  
  147.         const SInputPortConfig inputToTest = InputPortConfig<float>("TransitionTime", _HELP(""));
  148.         ASSERT_ARE_EQUAL(inputToTest, flowNodeConfiguration.pInputPorts[CFlowNode_ColorGradient::eInputPorts_TransitionTime]);
  149. }
  150.  
  151. CRY_TEST_WITH_FIXTURE(TestColorGradientNode_InputsAreNullTerminated, ColorGradientNodeTestFixture)
  152. {
  153.         SFlowNodeConfig flowNodeConfiguration;
  154.         m_colorGradientNodeToTest->GetConfiguration(flowNodeConfiguration);
  155.  
  156.         const SInputPortConfig inputToTest = {0};
  157.         ASSERT_ARE_EQUAL(inputToTest, CFlowNode_ColorGradient::inputPorts[CFlowNode_ColorGradient::eInputPorts_Count]);
  158. }
  159.  
  160. CRY_TEST_WITH_FIXTURE(TestColorGradientNode_ActivationLoadsCorrectColorChartFile1, ColorGradientNodeTestFixture)
  161. {
  162.         const string filePath("filePath1");
  163.         ConfigureAndProcessEvent(IFlowNode::eFE_Activate, filePath, 0.0f);
  164.  
  165.         const string pathOfLastLoadedColorChart = GetGame().GetLastTriggeredColorChartPath();
  166.  
  167.         ASSERT_ARE_EQUAL(filePath, pathOfLastLoadedColorChart);
  168. }
  169.  
  170. CRY_TEST_WITH_FIXTURE(TestColorGradientNode_ActivationLoadsCorrectColorChartFile2, ColorGradientNodeTestFixture)
  171. {
  172.         const string filePath("filePath2");
  173.         ConfigureAndProcessEvent(IFlowNode::eFE_Activate, filePath, 0.0f);
  174.  
  175.         const string pathOfLastLoadedColorChart = GetGame().GetLastTriggeredColorChartPath();
  176.  
  177.         ASSERT_ARE_EQUAL(filePath, pathOfLastLoadedColorChart);
  178. }
  179.  
  180. CRY_TEST_WITH_FIXTURE(TestColorGradientNode_ActivationSetsCorrectFadeInTime1, ColorGradientNodeTestFixture)
  181. {
  182.         const float expectedFadeInTime = 10.0f;
  183.  
  184.         const string filePath("");
  185.         ConfigureAndProcessEvent(IFlowNode::eFE_Activate, filePath, expectedFadeInTime);
  186.  
  187.         const float resultedFadeInTime = GetGame().GetLastTriggeredFadeInTime();
  188.  
  189.         ASSERT_ARE_EQUAL(expectedFadeInTime, resultedFadeInTime);
  190. }
  191.  
  192. CRY_TEST_WITH_FIXTURE(TestColorGradientNode_ActivationSetsCorrectFadeInTime2, ColorGradientNodeTestFixture)
  193. {
  194.         const float expectedFadeInTime = 5.0f;
  195.  
  196.         const string filePath("");
  197.         ConfigureAndProcessEvent(IFlowNode::eFE_Activate, filePath, expectedFadeInTime);
  198.  
  199.         const float resultedFadeInTime = GetGame().GetLastTriggeredFadeInTime();
  200.  
  201.         ASSERT_ARE_EQUAL(expectedFadeInTime, resultedFadeInTime);
  202. }
  203.  
  204.  
  205. CRY_TEST_WITH_FIXTURE(TestColorGradientNode_OnlyActivationEventsSetUpColorCharts, ColorGradientNodeTestFixture)
  206. {
  207.         const string filePath("filePath");
  208.  
  209.         static const uint32 numberOfNonActivationEvents = 11;
  210.         const IFlowNode::EFlowEvent nonActivationEvents[numberOfNonActivationEvents] =
  211.         {
  212.                 IFlowNode::eFE_Update,
  213.                 IFlowNode::eFE_FinalActivate,
  214.                 IFlowNode::eFE_Initialize,
  215.                 IFlowNode::eFE_FinalInitialize,
  216.                 IFlowNode::eFE_SetEntityId,
  217.                 IFlowNode::eFE_Suspend,
  218.                 IFlowNode::eFE_Resume,
  219.                 IFlowNode::eFE_ConnectInputPort,
  220.                 IFlowNode::eFE_DisconnectInputPort,
  221.                 IFlowNode::eFE_ConnectOutputPort,
  222.                 IFlowNode::eFE_DisconnectOutputPort,
  223.         };
  224.  
  225.         for (uint32 eventIndex = 0; eventIndex < numberOfNonActivationEvents; ++eventIndex)
  226.         {
  227.                 ConfigureAndProcessEvent(nonActivationEvents[eventIndex], filePath, 0.0f);
  228.  
  229.                 ASSERT_ARE_EQUAL(string(""), GetGame().GetLastTriggeredColorChartPath());
  230.         }
  231. }
  232.  
  233.  
downloadColorGradientNode_Test.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top