ExpressionEngineTestFixture.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #pragma once
  9. #include <AzCore/UnitTest/TestTypes.h>
  10. #include <gtest/gtest-param-test.h>
  11. #include <ExpressionEvaluation/ExpressionEngine.h>
  12. #include <ExpressionEvaluationSystemComponent.h>
  13. #include <ExpressionEngine/Utils.h>
  14. namespace ExpressionEvaluation
  15. {
  16. class ExpressionEngineTestFixture
  17. : public UnitTest::LeakDetectionFixture
  18. {
  19. public:
  20. void SetUp() override
  21. {
  22. UnitTest::LeakDetectionFixture::SetUp();
  23. // Faking the setup to avoid needing to re-implement these features somewhere else.
  24. m_systemComponent = aznew ExpressionEvaluationSystemComponent();
  25. m_systemComponent->Init();
  26. m_systemComponent->Activate();
  27. }
  28. void TearDown() override
  29. {
  30. m_systemComponent->Deactivate();
  31. delete m_systemComponent;
  32. UnitTest::LeakDetectionFixture::TearDown();
  33. }
  34. template<typename T>
  35. void ConfirmResult(const ExpressionResult& result, const T& knownValue)
  36. {
  37. EXPECT_FALSE(result.type().IsNull());
  38. EXPECT_EQ(result.type(), azrtti_typeid<T>());
  39. T resultValue = Utils::GetAnyValue<T>(result);
  40. EXPECT_EQ(resultValue, knownValue);
  41. }
  42. void ConfirmFailure(const ExpressionResult& result)
  43. {
  44. EXPECT_TRUE(result.type().IsNull());
  45. }
  46. template<typename T>
  47. void PushPrimitive(ExpressionTree& expressionTree, const T& primitiveValue)
  48. {
  49. ExpressionToken token;
  50. if (AZStd::is_same<T, double>::value)
  51. {
  52. token.m_parserId = Interfaces::NumericPrimitives;
  53. }
  54. else if (AZStd::is_same<T, bool>())
  55. {
  56. token.m_parserId = Interfaces::BooleanPrimitives;
  57. }
  58. token.m_information = Primitive::GetPrimitiveElement(primitiveValue);
  59. expressionTree.PushElement(AZStd::move(token));
  60. }
  61. void PushOperator(ExpressionTree& expressionTree, ExpressionParserId parserId, ElementInformation&& elementInformation)
  62. {
  63. ExpressionToken expressionToken;
  64. expressionToken.m_parserId = parserId;
  65. expressionToken.m_information = AZStd::move(elementInformation);
  66. expressionTree.PushElement(AZStd::move(expressionToken));
  67. }
  68. ExpressionEvaluationRequests* GetExpressionEvaluationRequests()
  69. {
  70. return m_systemComponent;
  71. }
  72. AZStd::unordered_set<ExpressionParserId> MathOnlyOperatorRestrictions() const
  73. {
  74. return {
  75. Interfaces::NumericPrimitives,
  76. Interfaces::MathOperators
  77. };
  78. }
  79. private:
  80. ExpressionEvaluationSystemComponent* m_systemComponent;
  81. };
  82. }