BVB Source Codes

CRYENGINE Show ColorGradientManager_Test.cpp Source code

Return Download CRYENGINE: download ColorGradientManager_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. -------------------------------------------------------------------------
  6. History:
  7. - 15:05:2009   Created by Federico Rebora
  8.  
  9. *************************************************************************/
  10.  
  11. #include "Stdafx.h"
  12.  
  13. #include "ColorGradientManager.h"
  14.  
  15. #include "EngineFacade/PluggableEngineFacade.h"
  16.  
  17. #include "Testing/TestUtilities.h"
  18.  
  19. #include "Testing/MockColorGradingController.h"
  20.  
  21. #include <CryRenderer/IColorGradingController.h>
  22.  
  23. CRY_TEST_FIXTURE(ColorGradientManager_TestFixture, CryUnit::ITestFixture, GameTesting::MainTestSuite)
  24. {
  25. private:
  26.         class CMock3DEngine : public EngineFacade::CDummyEngine3DEngine
  27.         {
  28.         public:
  29.                 CMock3DEngine(EngineFacade::IEngineColorGradingController& colorGradingController)
  30.                 : m_colorGradingController(colorGradingController)
  31.                 {
  32.  
  33.                 }
  34.  
  35.                 virtual EngineFacade::IEngineColorGradingController& GetEngineColorGradingController()
  36.                 {
  37.                         return m_colorGradingController;
  38.                 }
  39.  
  40.         private:
  41.                 EngineFacade::IEngineColorGradingController& m_colorGradingController;
  42.         };
  43.  
  44. public:
  45.         ColorGradientManager_TestFixture()
  46.         : m_mock3DEngine(m_mockColorGradingController)
  47.         , m_colorGradientManager(m_engine)
  48.         {
  49.         }
  50.  
  51.         void SetUp()
  52.         {
  53.                 m_engine.Use(m_mock3DEngine);
  54.         }
  55.  
  56. protected:
  57.         GameTesting::CMockEngineColorGradingController m_mockColorGradingController;
  58.         CMock3DEngine m_mock3DEngine;
  59.         EngineFacade::CDummyPluggableEngineFacade m_engine;
  60.         Graphics::CColorGradientManager m_colorGradientManager;
  61. };
  62.  
  63.  
  64.  
  65. CRY_TEST_WITH_FIXTURE(ColorGradientManager_TestTriggeredFadingColorGradientLoadsOnUpdate, ColorGradientManager_TestFixture)
  66. {
  67.         const char* const testPath = "testPath";
  68.  
  69.         m_colorGradientManager.TriggerFadingColorGradient(testPath, 0.0f);
  70.         m_colorGradientManager.UpdateForThisFrame(0.0f);
  71.  
  72.         ASSERT_ARE_EQUAL(testPath, m_mockColorGradingController.GetPathOfLastLoadedColorChart());
  73. }
  74.  
  75. CRY_TEST_WITH_FIXTURE(ColorGradientManager_TestNothingIsLoadedIfNothingWasTriggered, ColorGradientManager_TestFixture)
  76. {
  77.         m_colorGradientManager.UpdateForThisFrame(0.0f);
  78.  
  79.         ASSERT_IS_FALSE(m_mockColorGradingController.AnyChartsWereLoaded());
  80. }
  81.  
  82. CRY_TEST_WITH_FIXTURE(ColorGradientManager_TestMoreGradientsCanBeTriggeredInOneFrame, ColorGradientManager_TestFixture)
  83. {
  84.         const char* const testPath1 = "testPath1";
  85.         m_colorGradientManager.TriggerFadingColorGradient(testPath1, 0.0f);
  86.  
  87.         const char* const testPath2 = "testPath2";
  88.         m_colorGradientManager.TriggerFadingColorGradient(testPath2, 0.0f);
  89.  
  90.         m_colorGradientManager.UpdateForThisFrame(0.0f);
  91.  
  92.         ASSERT_ARE_EQUAL(testPath1, m_mockColorGradingController.GetPathOfLoadedColorChart(0));
  93.         ASSERT_ARE_EQUAL(testPath2, m_mockColorGradingController.GetPathOfLoadedColorChart(1));
  94. }
  95.  
  96. CRY_TEST_WITH_FIXTURE(ColorGradientManager_TestGradientsAreLoadedOnlyOnce, ColorGradientManager_TestFixture)
  97. {
  98.         m_colorGradientManager.TriggerFadingColorGradient("testPath", 0.0f);
  99.  
  100.         m_colorGradientManager.UpdateForThisFrame(0.0f);
  101.         m_mockColorGradingController.ClearLoadedCharts();
  102.         m_colorGradientManager.UpdateForThisFrame(0.0f);
  103.  
  104.         ASSERT_IS_FALSE(m_mockColorGradingController.AnyChartsWereLoaded());
  105. }
  106.  
  107. CRY_TEST_WITH_FIXTURE(ColorGradientManager_TestGradientWithZeroFadingTimeIsUsedImmediatelyWithFullWeight, ColorGradientManager_TestFixture)
  108. {
  109.         const int expectedTexID = 64;
  110.         m_mockColorGradingController.SetFakeIDForLoadedTexture(expectedTexID);
  111.  
  112.         m_colorGradientManager.TriggerFadingColorGradient("testPath", 0.0f);
  113.         m_colorGradientManager.UpdateForThisFrame(0.0f);
  114.  
  115.         const SColorChartLayer& theLayerSet = m_mockColorGradingController.GetCurrentlySetLayerByIndex(0);
  116.        
  117.         const SColorChartLayer expectedColorChartLayer(expectedTexID, 1.0f);
  118.  
  119.         ASSERT_ARE_EQUAL(expectedColorChartLayer, theLayerSet);
  120. }
  121.  
  122. CRY_TEST_WITH_FIXTURE(ColorGradientManager_TestBlendWeightHalfWayThroughFadingIn, ColorGradientManager_TestFixture)
  123. {
  124.         m_colorGradientManager.TriggerFadingColorGradient("testPath", 10.0f);
  125.         m_colorGradientManager.UpdateForThisFrame(5.0f);
  126.  
  127.         const SColorChartLayer& theLayerSet = m_mockColorGradingController.GetCurrentlySetLayerByIndex(0);
  128.  
  129.         const SColorChartLayer expectedColorChartLayer(0, 0.5f);
  130.  
  131.         ASSERT_ARE_EQUAL(expectedColorChartLayer, theLayerSet);
  132. }
  133.  
  134. CRY_TEST_WITH_FIXTURE(ColorGradientManager_TestBlendWeightIsOneWhenFadingIsFinished, ColorGradientManager_TestFixture)
  135. {
  136.         m_colorGradientManager.TriggerFadingColorGradient("testPath", 5.0f);
  137.         m_colorGradientManager.UpdateForThisFrame(5.0f);
  138.  
  139.         const SColorChartLayer& theLayerSet = m_mockColorGradingController.GetCurrentlySetLayerByIndex(0);
  140.  
  141.         const SColorChartLayer expectedColorChartLayer(0, 1.0f);
  142.  
  143.         ASSERT_ARE_EQUAL(expectedColorChartLayer, theLayerSet);
  144. }
  145.  
  146. CRY_TEST_WITH_FIXTURE(ColorGradientManager_TestBlendWeightIsOneAfterFadingIsFinished, ColorGradientManager_TestFixture)
  147. {
  148.         m_colorGradientManager.TriggerFadingColorGradient("testPath", 5.0f);
  149.         m_colorGradientManager.UpdateForThisFrame(10.0f);
  150.  
  151.         const SColorChartLayer& theLayerSet = m_mockColorGradingController.GetCurrentlySetLayerByIndex(0);
  152.  
  153.         const SColorChartLayer expectedColorChartLayer(0, 1.0f);
  154.  
  155.         ASSERT_ARE_EQUAL(expectedColorChartLayer, theLayerSet);
  156. }
  157.  
  158. CRY_TEST_WITH_FIXTURE(ColorGradientManager_TestNullLayersAreNotSet, ColorGradientManager_TestFixture)
  159. {
  160.         m_colorGradientManager.UpdateForThisFrame(0.0f);
  161.  
  162.         ASSERT_IS_FALSE(m_mockColorGradingController.WasNullPointerSetOnLayers())
  163. }
  164.  
  165. CRY_TEST_WITH_FIXTURE(ColorGradientManager_TestBlendWeightIsOneAfterFadingIsFinishedInMoreUpdates, ColorGradientManager_TestFixture)
  166. {
  167.         m_colorGradientManager.TriggerFadingColorGradient("testPath", 10.0f);
  168.  
  169.         m_colorGradientManager.UpdateForThisFrame(2.0f);
  170.         m_colorGradientManager.UpdateForThisFrame(2.0f);
  171.         m_colorGradientManager.UpdateForThisFrame(2.0f);
  172.         m_colorGradientManager.UpdateForThisFrame(2.0f);
  173.         m_colorGradientManager.UpdateForThisFrame(2.0f);
  174.  
  175.         const SColorChartLayer& theLayerSet = m_mockColorGradingController.GetCurrentlySetLayerByIndex(0);
  176.  
  177.         const SColorChartLayer expectedColorChartLayer(0, 1.0f);
  178.  
  179.         ASSERT_ARE_EQUAL(expectedColorChartLayer, theLayerSet);
  180. }
  181.  
  182. CRY_TEST_WITH_FIXTURE(ColorGradientManager_TestTwoLayersSet, ColorGradientManager_TestFixture)
  183. {
  184.         m_colorGradientManager.TriggerFadingColorGradient("testPath1", 10.0f);
  185.         m_colorGradientManager.UpdateForThisFrame(10.0f);
  186.  
  187.         m_colorGradientManager.TriggerFadingColorGradient("testPath2", 10.0f);
  188.         m_colorGradientManager.UpdateForThisFrame(5.0f);
  189.  
  190.         const unsigned int numberOfLayersSet = (int) m_mockColorGradingController.GetNumberOfLayersSet();
  191.         ASSERT_ARE_EQUAL(2u, numberOfLayersSet);
  192. }
  193.  
  194. CRY_TEST_WITH_FIXTURE(ColorGradientManager_TestLayerIntroducedWhileAnotherOneWasFadingIn, ColorGradientManager_TestFixture)
  195. {
  196.         m_colorGradientManager.TriggerFadingColorGradient("testPath1", 10.0f);
  197.         m_colorGradientManager.UpdateForThisFrame(10.0f);
  198.  
  199.         const int expectedTexID = 64;
  200.         m_mockColorGradingController.SetFakeIDForLoadedTexture(expectedTexID);
  201.  
  202.         m_colorGradientManager.TriggerFadingColorGradient("testPath2", 10.0f);
  203.         m_colorGradientManager.UpdateForThisFrame(5.0f);
  204.        
  205.         const SColorChartLayer expectedFirstColorChartLayer(0, 0.5f);
  206.         ASSERT_ARE_EQUAL(expectedFirstColorChartLayer,  m_mockColorGradingController.GetCurrentlySetLayerByIndex(0));
  207.  
  208.         const SColorChartLayer expectedSecondColorChartLayer(expectedTexID, 0.5f);
  209.         ASSERT_ARE_EQUAL(expectedSecondColorChartLayer,  m_mockColorGradingController.GetCurrentlySetLayerByIndex(1));
  210. }
  211.  
  212. CRY_TEST_WITH_FIXTURE(ColorGradientManager_TestNewFadedChartStopsUpdatingPreviousOnes, ColorGradientManager_TestFixture)
  213. {
  214.         m_colorGradientManager.TriggerFadingColorGradient("", 10.0f);
  215.         m_colorGradientManager.UpdateForThisFrame(5.0f);
  216.  
  217.         m_colorGradientManager.TriggerFadingColorGradient("", 10.0f);
  218.         m_colorGradientManager.UpdateForThisFrame(5.0f);
  219.  
  220.         m_colorGradientManager.TriggerFadingColorGradient("", 10.0f);
  221.         m_colorGradientManager.UpdateForThisFrame(5.0f);
  222.  
  223.         const SColorChartLayer& firstLayerSet = m_mockColorGradingController.GetCurrentlySetLayerByIndex(0);
  224.  
  225.         ASSERT_FLOAT_ARE_EQUAL(0.125f, firstLayerSet.m_blendAmount, 0.001f);
  226. }
  227.  
  228. CRY_TEST_WITH_FIXTURE(ColorGradientManager_TestLayerWithBlendWeightOneSetsOnlyOneLayer, ColorGradientManager_TestFixture)
  229. {
  230.         m_colorGradientManager.TriggerFadingColorGradient("testPath1", 10.0f);
  231.         m_colorGradientManager.UpdateForThisFrame(0.0f);
  232.  
  233.         m_colorGradientManager.TriggerFadingColorGradient("testPath2", 0.0f);
  234.         m_colorGradientManager.UpdateForThisFrame(0.0f);
  235.  
  236.         const unsigned int numberOfLayersSet = (int) m_mockColorGradingController.GetNumberOfLayersSet();
  237.         ASSERT_ARE_EQUAL(1u, numberOfLayersSet);
  238. }
  239.  
  240. CRY_TEST_WITH_FIXTURE(ColorGradientManager_TestLayerWithBlendWeightOneRemovesOtherLayersAndIsSetCorrectly, ColorGradientManager_TestFixture)
  241. {
  242.         m_colorGradientManager.TriggerFadingColorGradient("testPath1", 10.0f);
  243.         m_colorGradientManager.UpdateForThisFrame(0.0f);
  244.  
  245.         const int expectedTexID = 64;
  246.         m_mockColorGradingController.SetFakeIDForLoadedTexture(expectedTexID);
  247.  
  248.         m_colorGradientManager.TriggerFadingColorGradient("testPath2", 0.0f);
  249.         m_colorGradientManager.UpdateForThisFrame(0.0f);
  250.  
  251.         const SColorChartLayer expectedColorChartLayer(expectedTexID, 1.0f);
  252.         ASSERT_ARE_EQUAL(expectedColorChartLayer, m_mockColorGradingController.GetCurrentlySetLayerByIndex(0));
  253. }
  254.  
  255. CRY_TEST_WITH_FIXTURE(ColorGradientManager_TestRemovedLayerUnloadsTexture, ColorGradientManager_TestFixture)
  256. {
  257.         const int expectedTexID = 64;
  258.         m_mockColorGradingController.SetFakeIDForLoadedTexture(expectedTexID);
  259.  
  260.         m_colorGradientManager.TriggerFadingColorGradient("testPath1", 10.0f);
  261.         m_colorGradientManager.UpdateForThisFrame(0.0f);
  262.  
  263.         m_colorGradientManager.TriggerFadingColorGradient("testPath2", 0.0f);
  264.         m_colorGradientManager.UpdateForThisFrame(0.0f);
  265.  
  266.         ASSERT_ARE_EQUAL(expectedTexID, m_mockColorGradingController.GetLastUnloadedTextureID());
  267. }
  268.  
  269. CRY_TEST_WITH_FIXTURE(ColorGradientManager_TestTextureIsNotUnloadedIfInUse, ColorGradientManager_TestFixture)
  270. {
  271.         m_colorGradientManager.TriggerFadingColorGradient("testPath", 10.0f);
  272.         m_colorGradientManager.UpdateForThisFrame(10.0f);
  273.  
  274.         ASSERT_ARE_EQUAL(-1, m_mockColorGradingController.GetLastUnloadedTextureID());
  275. }
  276.  
  277. CRY_TEST_WITH_FIXTURE(ColorGradientManager_TestTextureIsNotUnloadedIfDeltaIsZero, ColorGradientManager_TestFixture)
  278. {
  279.         m_colorGradientManager.TriggerFadingColorGradient("testPath", 10.0f);
  280.         m_colorGradientManager.UpdateForThisFrame(0.0f);
  281.  
  282.         ASSERT_ARE_EQUAL(-1, m_mockColorGradingController.GetLastUnloadedTextureID());
  283. }
  284.  
downloadColorGradientManager_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