/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #pragma once #include #include #include #include #include namespace ExpressionEvaluation { class ExpressionEngineTestFixture : public UnitTest::AllocatorsFixture { public: void SetUp() override { UnitTest::AllocatorsFixture::SetUp(); // Faking the setup to avoid needing to re-implement these features somewhere else. m_systemComponent = aznew ExpressionEvaluationSystemComponent(); m_systemComponent->Init(); m_systemComponent->Activate(); } void TearDown() override { m_systemComponent->Deactivate(); delete m_systemComponent; UnitTest::AllocatorsFixture::TearDown(); } template void ConfirmResult(const ExpressionResult& result, const T& knownValue) { EXPECT_FALSE(result.type().IsNull()); EXPECT_EQ(result.type(), azrtti_typeid()); T resultValue = Utils::GetAnyValue(result); EXPECT_EQ(resultValue, knownValue); } void ConfirmFailure(const ExpressionResult& result) { EXPECT_TRUE(result.type().IsNull()); } template void PushPrimitive(ExpressionTree& expressionTree, const T& primitiveValue) { ExpressionToken token; if (AZStd::is_same::value) { token.m_parserId = Interfaces::NumericPrimitives; } else if (AZStd::is_same()) { token.m_parserId = Interfaces::BooleanPrimitives; } token.m_information = Primitive::GetPrimitiveElement(primitiveValue); expressionTree.PushElement(AZStd::move(token)); } void PushOperator(ExpressionTree& expressionTree, ExpressionParserId parserId, ElementInformation&& elementInformation) { ExpressionToken expressionToken; expressionToken.m_parserId = parserId; expressionToken.m_information = AZStd::move(elementInformation); expressionTree.PushElement(AZStd::move(expressionToken)); } ExpressionEvaluationRequests* ExpressionEvaluationRequests() { return m_systemComponent; } AZStd::unordered_set MathOnlyOperatorRestrictions() const { return { Interfaces::NumericPrimitives, Interfaces::MathOperators }; } private: ExpressionEvaluationSystemComponent* m_systemComponent; }; }