59 lines
1.1 KiB
C++
59 lines
1.1 KiB
C++
#include <gtest/gtest.h>
|
|
#include "Types/object_ptr.hpp"
|
|
|
|
class TestClass
|
|
{
|
|
int* test_ptr_;
|
|
public:
|
|
TestClass(int* test_ptr) : test_ptr_(test_ptr)
|
|
{
|
|
*test_ptr_ = 1;
|
|
}
|
|
|
|
~TestClass()
|
|
{
|
|
*test_ptr_ = 2;
|
|
}
|
|
};
|
|
|
|
TEST(object_ptr_test, base_test)
|
|
{
|
|
int* test = new int(123);
|
|
UType::object_ptr<int> ptr(test);
|
|
EXPECT_EQ(*ptr.get(), 123);
|
|
|
|
UType::object_ptr<int> ptr2(ptr);
|
|
EXPECT_EQ(*ptr2.get(), 123);
|
|
EXPECT_EQ(ptr2.get(), ptr.get());
|
|
|
|
ptr.destroy();
|
|
EXPECT_EQ(ptr.get(), nullptr);
|
|
EXPECT_EQ(ptr2.get(), nullptr);
|
|
}
|
|
|
|
TEST(object_ptr_test, check_destry)
|
|
{
|
|
UType::object_ptr<int> ptr(new int(123)), ptr2(ptr);
|
|
|
|
ptr.destroy();
|
|
EXPECT_EQ(ptr.get(), nullptr);
|
|
EXPECT_EQ(ptr2.get(), nullptr);
|
|
}
|
|
|
|
TEST(object_ptr_test, check_destroy)
|
|
{
|
|
int* test = new int(0);
|
|
{
|
|
UType::object_ptr<TestClass> ptr(new TestClass(test));
|
|
EXPECT_EQ(*test, 1);
|
|
}
|
|
EXPECT_EQ(*test, 2);
|
|
|
|
*test = 0;
|
|
{
|
|
UType::object_ptr<TestClass> ptr(new TestClass(test));
|
|
UType::object_ptr<TestClass> ptr2(ptr);
|
|
EXPECT_EQ(*test, 1);
|
|
}
|
|
EXPECT_EQ(*test, 2);
|
|
} |