Files
Bigfoot/Bigfoot/Tests/Utils/Caster.cpp
Romain BOULLARD f3a1c7ec36
Some checks failed
Bigfoot / build-and-test (Debug, ON) (push) Successful in 25s
Bigfoot / build-and-test (RelWithDebInfo, OFF) (push) Successful in 27s
Bigfoot / build-and-test (RelWithDebInfo, ON) (push) Successful in 25s
Bigfoot / build-and-test (Release, OFF) (push) Successful in 20s
Bigfoot / build-and-test (Release, ON) (push) Has been cancelled
Bigfoot / build-and-test (Debug, OFF) (push) Successful in 26s
Update compilation
2026-01-28 14:28:07 +01:00

103 lines
2.2 KiB
C++

/*********************************************************************
* \file Caster.cpp
*
* \author Romain BOULLARD
* \date October 2025
*********************************************************************/
#include <Utils/Caster.hpp>
#include <gtest/gtest.h>
namespace Bigfoot
{
class Parent
{
public:
Parent(const std::uint32_t p_value):
m_value(p_value)
{
}
virtual ~Parent() = default;
std::uint32_t GetParentValue() const
{
return m_value;
}
virtual std::uint32_t GetChildValue() const = 0;
private:
std::uint32_t m_value;
};
/****************************************************************************************/
class ChildA final: public Parent
{
public:
ChildA(const std::uint32_t p_value):
Parent(28),
m_value(p_value)
{
}
~ChildA() override = default;
std::uint32_t GetChildValue() const override
{
return m_value;
}
private:
std::uint32_t m_value;
};
/****************************************************************************************/
class ChildB final: public Parent
{
public:
ChildB(const std::uint32_t p_value):
Parent(34),
m_value(p_value)
{
}
~ChildB() override = default;
std::uint32_t GetChildValue() const override
{
return m_value;
}
private:
std::uint32_t m_value;
};
/****************************************************************************************/
class CasterFixture: public ::testing::Test
{
protected:
std::unique_ptr<Parent> m_a = std::make_unique<ChildA>(42);
ChildB m_b {12};
};
/****************************************************************************************/
TEST_F(CasterFixture, ObjectCast)
{
EXPECT_EQ(m_a->GetParentValue(), 28);
EXPECT_EQ(m_a->GetChildValue(), 42);
const ChildA* child = BIGFOOT_OBJECT_CAST(ChildA, m_a.get());
EXPECT_EQ(child->GetParentValue(), 28);
EXPECT_EQ(child->GetChildValue(), 42);
EXPECT_EQ(m_b.GetParentValue(), 34);
EXPECT_EQ(m_b.GetChildValue(), 12);
const Parent& parent = BIGFOOT_OBJECT_CAST(Parent, m_b);
EXPECT_EQ(parent.GetParentValue(), 34);
}
} // namespace Bigfoot