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
|
2016-07-14 00:48:53 +02:00
|
|
|
* @license APACHE v2.0 (see license file)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <ememory/memory.h>
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
|
|
|
|
class testClass : public ememory::EnableSharedFromThis<testClass> {
|
|
|
|
public:
|
|
|
|
testClass() {
|
|
|
|
EMEMORY_INFO("create TestClass");
|
|
|
|
}
|
|
|
|
~testClass() {
|
|
|
|
EMEMORY_INFO("delete TestClass");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TestEnableSharedFromThis, base) {
|
|
|
|
ememory::SharedPtr<testClass> data = ememory::makeShared<testClass>();
|
|
|
|
EXPECT_EQ(data.useCount(), 1);
|
|
|
|
ememory::WeakPtr<testClass> dataWeak = data;
|
|
|
|
EXPECT_EQ(data.useCount(), 1);
|
|
|
|
EXPECT_EQ(dataWeak.useCount(), 1);
|
|
|
|
data.reset();
|
|
|
|
EXPECT_EQ(data.useCount(), 0);
|
|
|
|
EXPECT_EQ(dataWeak.useCount(), 0);
|
|
|
|
}
|