2016-07-14 00:48:53 +02:00
|
|
|
/** @file
|
|
|
|
* @author Edouard DUPIN
|
2016-07-14 23:58:54 +02:00
|
|
|
* @copyright 2016, Edouard DUPIN, all right reserved
|
2017-01-05 21:28:23 +01:00
|
|
|
* @license MPL v2.0 (see license file)
|
2016-07-14 00:48:53 +02:00
|
|
|
*/
|
|
|
|
|
2017-09-07 23:38:26 +02:00
|
|
|
#include <etest/etest.hpp>
|
2016-09-30 22:28:36 +02:00
|
|
|
#include <ememory/memory.hpp>
|
|
|
|
#include "main.hpp"
|
2016-07-14 00:48:53 +02:00
|
|
|
|
2016-07-20 21:43:14 +02:00
|
|
|
namespace testESFT {
|
|
|
|
class TestClassBase : public ememory::EnableSharedFromThis<TestClassBase> {
|
|
|
|
public:
|
|
|
|
TestClassBase() {
|
|
|
|
EMEMORY_INFO("create TestClassBase");
|
|
|
|
}
|
|
|
|
~TestClassBase() {
|
|
|
|
EMEMORY_INFO("delete TestClassBase");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class TestClass : public testESFT::TestClassBase {
|
|
|
|
public:
|
|
|
|
TestClass() {
|
|
|
|
EMEMORY_INFO("create TestClass");
|
|
|
|
}
|
|
|
|
~TestClass() {
|
|
|
|
EMEMORY_INFO("delete TestClass");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2016-07-14 00:48:53 +02:00
|
|
|
|
2016-07-20 21:43:14 +02:00
|
|
|
TEST(TestEnableSharedFromThis, testClassBase) {
|
|
|
|
ememory::SharedPtr<testESFT::TestClassBase> data = ememory::makeShared<testESFT::TestClassBase>();
|
|
|
|
EXPECT_EQ(data.useCount(), 1);
|
|
|
|
ememory::WeakPtr<testESFT::TestClassBase> dataWeak = data;
|
|
|
|
EXPECT_EQ(data.useCount(), 1);
|
|
|
|
EXPECT_EQ(dataWeak.useCount(), 1);
|
|
|
|
data.reset();
|
|
|
|
EXPECT_EQ(data.useCount(), 0);
|
|
|
|
EXPECT_EQ(dataWeak.useCount(), 0);
|
|
|
|
}
|
2016-07-14 00:48:53 +02:00
|
|
|
|
2016-07-20 21:43:14 +02:00
|
|
|
TEST(TestEnableSharedFromThis, testClass) {
|
|
|
|
ememory::SharedPtr<testESFT::TestClass> data = ememory::makeShared<testESFT::TestClass>();
|
2016-07-14 00:48:53 +02:00
|
|
|
EXPECT_EQ(data.useCount(), 1);
|
2016-07-20 21:43:14 +02:00
|
|
|
ememory::WeakPtr<testESFT::TestClass> dataWeak = data;
|
2016-07-14 00:48:53 +02:00
|
|
|
EXPECT_EQ(data.useCount(), 1);
|
|
|
|
EXPECT_EQ(dataWeak.useCount(), 1);
|
|
|
|
data.reset();
|
|
|
|
EXPECT_EQ(data.useCount(), 0);
|
|
|
|
EXPECT_EQ(dataWeak.useCount(), 0);
|
|
|
|
}
|