Files
Seele/test/Engine/EngineTest.cpp
T

85 lines
1.6 KiB
C++
Raw Normal View History

#include "EngineTest.h"
#include "MinimalEngine.h"
2021-11-02 19:42:00 +01:00
#define BOOST_TEST_MODULE SeeleEngine
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
using namespace Seele;
2021-03-31 12:18:16 +02:00
BOOST_TEST_GLOBAL_FIXTURE(GlobalFixture);
BOOST_AUTO_TEST_SUITE(RefPtr)
struct TestStruct
{
TestStruct()
: data(10)
{
}
2020-03-09 19:22:21 +01:00
virtual ~TestStruct()
{
2020-03-09 19:22:21 +01:00
data = 15;
}
uint32 data;
};
2021-11-02 19:42:00 +01:00
struct DeclStruct;
BOOST_AUTO_TEST_CASE(basic_refcount)
{
{
Seele::RefPtr<TestStruct> ptr = new TestStruct();
BOOST_REQUIRE_EQUAL(ptr->data, 10);
{
Seele::RefPtr<TestStruct> secondPtr = ptr;
BOOST_REQUIRE_EQUAL(secondPtr->data, 10);
BOOST_REQUIRE_EQUAL(ptr->data, 10);
}
BOOST_REQUIRE_EQUAL(ptr->data, 10);
}
2021-11-02 19:42:00 +01:00
std::shared_ptr<DeclStruct> test;
}
2021-11-02 19:42:00 +01:00
struct DeclStruct
{
~DeclStruct()
{
data = 10;
}
uint32 data = 20;
};
2020-03-09 12:30:07 +01:00
struct DerivedStruct : public TestStruct
{
2020-03-09 19:22:21 +01:00
DerivedStruct()
:data2(20)
{
2020-03-09 12:30:07 +01:00
2020-03-09 19:22:21 +01:00
}
~DerivedStruct()
{
data2 = 30;
}
uint32 data2;
2020-03-09 12:30:07 +01:00
};
BOOST_AUTO_TEST_CASE(inheritance_cast)
{
Seele::RefPtr<DerivedStruct> backCast;
{
Seele::RefPtr<DerivedStruct> derived = new DerivedStruct();
Seele::RefPtr<TestStruct> base = derived;
BOOST_REQUIRE_EQUAL(base->data, 10);
backCast = base.cast<DerivedStruct>();
2020-04-12 15:47:19 +02:00
BOOST_REQUIRE_EQUAL(backCast->data, 10);
BOOST_REQUIRE_EQUAL(backCast->data2, 20);
2020-03-09 12:30:07 +01:00
}
BOOST_REQUIRE_EQUAL(backCast->data, 10);
2020-03-09 19:22:21 +01:00
BOOST_REQUIRE_EQUAL(backCast->data2, 20);
2020-03-09 12:30:07 +01:00
}
BOOST_AUTO_TEST_CASE(unique_ptr)
{
UniquePtr<TestStruct> uptr = new TestStruct();
UniquePtr<TestStruct> uptr2 = std::move(uptr);
BOOST_REQUIRE_EQUAL(uptr2->data, 10);
BOOST_REQUIRE_EQUAL(uptr.isValid(), false);
}
BOOST_AUTO_TEST_SUITE_END()