65 lines
1.6 KiB
C++
65 lines
1.6 KiB
C++
#include "KylinSmartPointer.h"
|
|
#include "SharedPointer.h"
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
using namespace Kylin;
|
|
|
|
class SmartPointerTest {
|
|
public:
|
|
class TestObject {
|
|
public:
|
|
TestObject(bool &status) : m_status(status) {}
|
|
~TestObject() { m_status = false; }
|
|
bool &m_status;
|
|
};
|
|
|
|
bool status = true;
|
|
};
|
|
|
|
BOOST_FIXTURE_TEST_CASE(exampleOne, SmartPointerTest) {
|
|
{ Kylin::SmartPointer<TestObject> pointer(new TestObject(status)); }
|
|
BOOST_CHECK_EQUAL(status, false);
|
|
}
|
|
|
|
BOOST_FIXTURE_TEST_CASE(Move, SmartPointerTest) {
|
|
{
|
|
SmartPointer<TestObject> pointer(new TestObject(status));
|
|
auto p1 = std::move(pointer);
|
|
BOOST_CHECK_EQUAL(pointer.isNull(), true);
|
|
}
|
|
BOOST_CHECK_EQUAL(status, false);
|
|
}
|
|
|
|
class SharedPointerTest {
|
|
public:
|
|
class TestObject {
|
|
public:
|
|
TestObject(bool &status) : m_status(status) {}
|
|
~TestObject() { m_status = false; }
|
|
bool &m_status;
|
|
};
|
|
|
|
bool status = true;
|
|
};
|
|
|
|
BOOST_FIXTURE_TEST_CASE(example1, SharedPointerTest) {
|
|
{ SharedPointer<TestObject> pointer(new TestObject(status)); }
|
|
BOOST_CHECK_EQUAL(status, false);
|
|
}
|
|
|
|
BOOST_FIXTURE_TEST_CASE(Count, SharedPointerTest) {
|
|
{
|
|
SharedPointer<TestObject> pointer(new TestObject(status));
|
|
{ auto p1 = pointer; }
|
|
BOOST_CHECK_EQUAL(status, true);
|
|
}
|
|
|
|
BOOST_CHECK_EQUAL(status, false);
|
|
}
|
|
|
|
BOOST_FIXTURE_TEST_CASE(Equal, SharedPointerTest) {
|
|
SharedPointer<TestObject> pointer(new TestObject(status));
|
|
auto p1 = pointer;
|
|
BOOST_TEST((pointer == p1));
|
|
}
|