You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
254 lines
8.3 KiB
C++
254 lines
8.3 KiB
C++
/*
|
|
* 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
|
|
*
|
|
*/
|
|
|
|
|
|
#include "UnitTestingReporter.h"
|
|
|
|
#include <ScriptCanvas/Execution/RuntimeComponent.h>
|
|
#include <AzTest/AzTest.h>
|
|
|
|
#define SCRIPT_CANVAS_UNIT_TEST_REPORTER_EXPECT_EQ(LHS, RHS)\
|
|
EXPECT_EQ(LHS, RHS) << report.data();
|
|
|
|
#define SCRIPT_CANVAS_UNIT_TEST_REPORTER_EXPECT_NE(LHS, RHS)\
|
|
EXPECT_NE(LHS, RHS) << report.data();
|
|
|
|
#define SCRIPT_CANVAS_UNIT_TEST_REPORTER_EXPECT_GT(LHS, RHS)\
|
|
EXPECT_GT(LHS, RHS) << report.data();
|
|
|
|
#define SCRIPT_CANVAS_UNIT_TEST_REPORTER_EXPECT_GE(LHS, RHS)\
|
|
EXPECT_GE(LHS, RHS) << report.data();
|
|
|
|
#define SCRIPT_CANVAS_UNIT_TEST_REPORTER_EXPECT_LT(LHS, RHS)\
|
|
EXPECT_LT(LHS, RHS) << report.data();
|
|
|
|
#define SCRIPT_CANVAS_UNIT_TEST_REPORTER_EXPECT_LE(LHS, RHS)\
|
|
EXPECT_LE(LHS, RHS) << report.data();
|
|
|
|
namespace ScriptCanvas
|
|
{
|
|
namespace UnitTesting
|
|
{
|
|
Reporter::Reporter()
|
|
: m_graphId{}
|
|
, m_entityId{}
|
|
{}
|
|
|
|
Reporter::Reporter(const RuntimeComponent& graph)
|
|
{
|
|
SetGraph(graph);
|
|
}
|
|
|
|
Reporter::~Reporter()
|
|
{
|
|
Reset();
|
|
}
|
|
|
|
void Reporter::Checkpoint(const Report& report)
|
|
{
|
|
if (m_isReportFinished)
|
|
return;
|
|
|
|
m_checkpoints.push_back(report);
|
|
}
|
|
|
|
const AZStd::vector<Report>& Reporter::GetCheckpoints() const
|
|
{
|
|
AZ_Assert(m_isReportFinished, "the report must be finished before evaluation");
|
|
return m_checkpoints;
|
|
}
|
|
|
|
const AZStd::vector<Report>& Reporter::GetFailure() const
|
|
{
|
|
AZ_Assert(m_isReportFinished, "the report must be finished before evaluation");
|
|
return m_failures;
|
|
}
|
|
|
|
const AZ::EntityId& Reporter::GetGraphId() const
|
|
{
|
|
return m_graphId;
|
|
}
|
|
|
|
const AZStd::vector<Report>& Reporter::GetSuccess() const
|
|
{
|
|
AZ_Assert(m_isReportFinished, "the report must be finished before evaluation");
|
|
return m_successes;
|
|
}
|
|
|
|
bool Reporter::IsActivated() const
|
|
{
|
|
return m_graphIsActivated;
|
|
}
|
|
|
|
bool Reporter::IsComplete() const
|
|
{
|
|
AZ_Assert(m_isReportFinished, "the report must be finished before evaluation");
|
|
return m_graphIsComplete;
|
|
}
|
|
|
|
bool Reporter::IsDeactivated() const
|
|
{
|
|
AZ_Assert(m_isReportFinished, "the report must be finished before evaluation");
|
|
return m_graphIsDeactivated;
|
|
}
|
|
|
|
bool Reporter::IsErrorFree() const
|
|
{
|
|
AZ_Assert(m_isReportFinished, "the report must be finished before evaluation");
|
|
return m_graphIsErrorFree;
|
|
}
|
|
|
|
bool Reporter::IsReportFinished() const
|
|
{
|
|
return m_isReportFinished;
|
|
}
|
|
|
|
void Reporter::FinishReport()
|
|
{
|
|
AZ_Assert(!m_isReportFinished, "the report is already finished");
|
|
m_isReportFinished = true;
|
|
}
|
|
|
|
void Reporter::FinishReport(const RuntimeComponent& graph)
|
|
{
|
|
AZ_Assert(!m_isReportFinished, "the report is already finished");
|
|
Bus::Handler::BusDisconnect(m_graphId);
|
|
AZ::EntityBus::Handler::BusDisconnect(m_entityId);
|
|
m_graphIsErrorFree = !graph.IsInErrorState();
|
|
m_isReportFinished = true;
|
|
}
|
|
|
|
bool Reporter::operator==(const Reporter& other) const
|
|
{
|
|
AZ_Assert(m_isReportFinished, "the report must be finished before evaluation");
|
|
return m_graphIsActivated == other.m_graphIsActivated
|
|
&& m_graphIsDeactivated == other.m_graphIsDeactivated
|
|
&& m_graphIsComplete == other.m_graphIsComplete
|
|
&& m_graphIsErrorFree == other.m_graphIsErrorFree
|
|
&& m_isReportFinished == other.m_isReportFinished
|
|
&& m_failures == other.m_failures
|
|
&& m_successes == other.m_successes;
|
|
}
|
|
|
|
void Reporter::OnEntityActivated(const AZ::EntityId& entity)
|
|
{
|
|
AZ_Assert(m_entityId == entity, "this reporter is listening to the wrong entity");
|
|
if (m_isReportFinished)
|
|
return;
|
|
|
|
m_graphIsActivated = true;
|
|
}
|
|
|
|
void Reporter::OnEntityDeactivated(const AZ::EntityId& entity)
|
|
{
|
|
AZ_Assert(m_entityId == entity, "this reporter is listening to the wrong entity");
|
|
if (m_isReportFinished)
|
|
return;
|
|
|
|
m_graphIsDeactivated = true;
|
|
}
|
|
|
|
void Reporter::Reset()
|
|
{
|
|
if (m_graphId.IsValid())
|
|
{
|
|
Bus::Handler::BusDisconnect();
|
|
}
|
|
|
|
if (m_entityId.IsValid())
|
|
{
|
|
AZ::EntityBus::Handler::BusDisconnect();
|
|
}
|
|
|
|
m_graphIsActivated = false;
|
|
m_graphIsComplete = false;
|
|
m_graphIsErrorFree = false;
|
|
m_isReportFinished = false;
|
|
m_graphId = AZ::EntityId{};
|
|
m_failures.clear();
|
|
m_failures.clear();
|
|
}
|
|
|
|
void Reporter::SetGraph(const RuntimeComponent& graph)
|
|
{
|
|
Reset();
|
|
m_graphId = graph.GetUniqueId();
|
|
m_entityId = graph.GetEntityId();
|
|
Bus::Handler::BusConnect(m_graphId);
|
|
AZ::EntityBus::Handler::BusConnect(m_entityId);
|
|
}
|
|
|
|
// Handler
|
|
void Reporter::MarkComplete(const Report& report)
|
|
{
|
|
if (m_isReportFinished)
|
|
return;
|
|
|
|
if (m_graphIsComplete)
|
|
{
|
|
AddFailure(AZStd::string::format("MarkComplete was called twice. %s", report.data()));
|
|
}
|
|
else
|
|
{
|
|
m_graphIsComplete = true;
|
|
}
|
|
}
|
|
|
|
void Reporter::AddFailure(const Report& report)
|
|
{
|
|
if (m_isReportFinished)
|
|
return;
|
|
|
|
m_failures.push_back(report);
|
|
Checkpoint(AZStd::string::format("AddFailure: %s", report.data()));
|
|
}
|
|
|
|
void Reporter::AddSuccess(const Report& report)
|
|
{
|
|
if (m_isReportFinished)
|
|
return;
|
|
|
|
m_successes.push_back(report);
|
|
Checkpoint(AZStd::string::format("AddSuccess: %s", report.data()));
|
|
}
|
|
|
|
void Reporter::ExpectFalse(const bool value, const Report& report)
|
|
{
|
|
EXPECT_FALSE(value) << report.data();
|
|
Checkpoint(AZStd::string::format("ExpectFalse: %s", report.data()));
|
|
}
|
|
|
|
void Reporter::ExpectTrue(const bool value, const Report& report)
|
|
{
|
|
EXPECT_TRUE(value) << report.data();
|
|
Checkpoint(AZStd::string::format("ExpectTrue: %s", report.data()));
|
|
}
|
|
|
|
void Reporter::ExpectEqualNumber(const Data::NumberType lhs, const Data::NumberType rhs, const Report& report)
|
|
{
|
|
EXPECT_NEAR(lhs, rhs, 0.001) << report.data();
|
|
Checkpoint(AZStd::string::format("ExpectEqualNumber: %s", report.data()));
|
|
}
|
|
|
|
void Reporter::ExpectNotEqualNumber(const Data::NumberType lhs, const Data::NumberType rhs, const Report& report)
|
|
{
|
|
EXPECT_NE(lhs, rhs) << report.data();
|
|
Checkpoint(AZStd::string::format("ExpectNotEqualNumber: %s", report.data()));
|
|
}
|
|
|
|
SCRIPT_CANVAS_UNIT_TEST_EQUALITY_OVERLOAD_IMPLEMENTATIONS(Reporter, ExpectEqual, SCRIPT_CANVAS_UNIT_TEST_REPORTER_EXPECT_EQ)
|
|
SCRIPT_CANVAS_UNIT_TEST_EQUALITY_OVERLOAD_IMPLEMENTATIONS(Reporter, ExpectNotEqual, SCRIPT_CANVAS_UNIT_TEST_REPORTER_EXPECT_NE)
|
|
SCRIPT_CANVAS_UNIT_TEST_COMPARE_OVERLOAD_IMPLEMENTATIONS(Reporter, ExpectGreaterThan, SCRIPT_CANVAS_UNIT_TEST_REPORTER_EXPECT_GT)
|
|
SCRIPT_CANVAS_UNIT_TEST_COMPARE_OVERLOAD_IMPLEMENTATIONS(Reporter, ExpectGreaterThanEqual, SCRIPT_CANVAS_UNIT_TEST_REPORTER_EXPECT_GE)
|
|
SCRIPT_CANVAS_UNIT_TEST_COMPARE_OVERLOAD_IMPLEMENTATIONS(Reporter, ExpectLessThan, SCRIPT_CANVAS_UNIT_TEST_REPORTER_EXPECT_LT)
|
|
SCRIPT_CANVAS_UNIT_TEST_COMPARE_OVERLOAD_IMPLEMENTATIONS(Reporter, ExpectLessThanEqual, SCRIPT_CANVAS_UNIT_TEST_REPORTER_EXPECT_LE)
|
|
|
|
} // namespace UnitTesting
|
|
|
|
} // namespace ScriptCanvas
|