Files
Seele/test/Engine/EngineTest.cpp
T

119 lines
2.4 KiB
C++
Raw Normal View History

#include "EngineTest.h"
#include "MinimalEngine.h"
2021-11-05 00:01:12 +01:00
#define BOOST_TEST_MODULE SeeleEngine
#include <boost/test/unit_test.hpp>
2022-03-26 12:55:04 +01:00
//#include <vld.h>
using namespace Seele;
2022-03-26 12:55:04 +01:00
Seele::GlobalFixture::~GlobalFixture()
{
2022-04-15 23:45:44 +02:00
//getGlobalThreadPool().waitIdle();
2022-03-26 12:55:04 +01:00
}
2021-03-31 12:18:16 +02:00
BOOST_TEST_GLOBAL_FIXTURE(GlobalFixture);
BOOST_AUTO_TEST_SUITE(RefPtr)
struct TestStruct
{
2022-03-26 12:55:04 +01:00
TestStruct()
: data(10)
{
}
virtual ~TestStruct()
{
data = 15;
}
uint32 data;
};
2021-11-05 00:01:12 +01:00
struct DeclStruct;
BOOST_AUTO_TEST_CASE(basic_refcount)
{
2022-03-26 12:55:04 +01:00
{
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-05 00:01:12 +01:00
struct DeclStruct
{
2022-03-26 12:55:04 +01:00
~DeclStruct()
{
data = 10;
}
uint32 data = 20;
2021-11-05 00:01:12 +01:00
};
2020-03-09 12:30:07 +01:00
struct DerivedStruct : public TestStruct
{
2022-03-26 12:55:04 +01:00
DerivedStruct()
:data2(20)
{
2020-03-09 12:30:07 +01:00
2022-03-26 12:55:04 +01:00
}
~DerivedStruct()
{
data2 = 30;
}
uint32 data2;
2020-03-09 12:30:07 +01:00
};
BOOST_AUTO_TEST_CASE(inheritance_cast)
{
2022-03-26 12:55:04 +01:00
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>();
BOOST_REQUIRE_EQUAL(backCast->data, 10);
BOOST_REQUIRE_EQUAL(backCast->data2, 20);
}
BOOST_REQUIRE_EQUAL(backCast->data, 10);
BOOST_REQUIRE_EQUAL(backCast->data2, 20);
2020-03-09 12:30:07 +01:00
}
BOOST_AUTO_TEST_CASE(unique_ptr)
{
2022-03-26 12:55:04 +01:00
Seele::UniquePtr<TestStruct> uptr = new TestStruct();
Seele::UniquePtr<TestStruct> uptr2 = std::move(uptr);
BOOST_REQUIRE_EQUAL(uptr2->data, 10);
BOOST_REQUIRE_EQUAL(uptr.isValid(), false);
}
2021-12-02 13:00:03 +01:00
struct ThisReference
{
2022-03-26 12:55:04 +01:00
ThisReference()
{
}
~ThisReference()
{
data = 12;
}
Seele::RefPtr<ThisReference> getRef()
{
return this;
}
uint32 data = 1;
2021-12-02 13:00:03 +01:00
};
BOOST_AUTO_TEST_CASE(this_reference)
{
2022-03-26 12:55:04 +01:00
Seele::RefPtr<ThisReference> ptr2;
{
Seele::RefPtr<ThisReference> ptr = new ThisReference();
BOOST_REQUIRE_EQUAL(ptr->data, 1);
ptr2 = ptr->getRef();
BOOST_REQUIRE_EQUAL(ptr2->data, 1);
ptr2->data = 5;
BOOST_REQUIRE_EQUAL(ptr->data, 5);
}
BOOST_REQUIRE_EQUAL(ptr2->data, 5);
2021-12-02 13:00:03 +01:00
}
BOOST_AUTO_TEST_SUITE_END()