22 TEST(OwnPtrTest, SamePointer)
27 EXPECT_TRUE(own == a);
28 EXPECT_TRUE(a == own);
30 EXPECT_FALSE(own != a);
31 EXPECT_FALSE(a != own);
33 EXPECT_EQ(a, own.
get());
36 TEST(OwnPtrTest, MoveOwnership)
42 EXPECT_EQ(own2.
get(), a);
43 EXPECT_EQ(own.
get(),
nullptr);
54 TEST(OwnPtrTest, DeleteOutOfScope)
62 EXPECT_EQ(deleted, 1U);
65 TEST(OwnPtrTest, DeleteOutOfScopeAfterMove)
72 own = std::move(own2);
76 EXPECT_EQ(deleted, 0U);
81 EXPECT_EQ(deleted, 1U);
86 int foo() {
return 42; }
89 TEST(OwnPtrTest, CallMethod)
92 EXPECT_EQ(own->foo(), 42);
93 EXPECT_EQ((*own).foo(), 42);
103 TEST(OwnPtrTest, MoveToConstructor)
109 EXPECT_EQ(0U, deleted);
111 EXPECT_EQ(0U, deleted);
113 EXPECT_EQ(1U, deleted);
126 EXPECT_EQ(0U, deleted);
129 EXPECT_EQ(0U, deleted);
131 EXPECT_EQ(1U, deleted);
133 EXPECT_EQ(2U, deleted);
136 TEST(OwnPtrTest, ReplacePointer)
138 unsigned int deleted1 = 0;
139 unsigned int deleted2 = 0;
142 EXPECT_EQ(0U, deleted1);
145 EXPECT_EQ(1U, deleted1);
147 EXPECT_EQ(0U, deleted2);
149 EXPECT_EQ(1U, deleted2);
152 TEST(OwnPtrTest, ReplaceWithRawPointer)
154 unsigned int deleted1 = 0;
157 EXPECT_EQ(0U, deleted1);
160 EXPECT_EQ(1U, deleted1);
166 int *a =
new int{42};
172 EXPECT_TRUE((
bool) own1);
193 own_a = std::move(own_b);
194 EXPECT_EQ(b, own_a.
get());
195 EXPECT_EQ(42, own_a->
_a);
static AP_HAL::OwnPtr< TestDeleted > create_test_deleted(unsigned int &deleted)
AP_HAL::OwnPtr< TestDeleted > _v
TestDeleted(unsigned int &d)
TEST(OwnPtrTest, SamePointer)
TestDestructor(AP_HAL::OwnPtr< TestDeleted > v)