TEST(GTestImmutable, TestUseCount) { { GTestImmutable::CPtr p = GTestImmutable::create(); ASSERT_EQ(1, p.use_count()); ASSERT_EQ(1, GTestImmutable::count); GTestImmutable::CPtr p2 = GTestImmutable::create(); ASSERT_EQ(1, p2.use_count()); ASSERT_EQ(2, GTestImmutable::count); p = p2; ASSERT_EQ(2, p.use_count()); ASSERT_EQ(2, p2.use_count()); ASSERT_EQ(1, GTestImmutable::count); } ASSERT_EQ(0, GTestImmutable::count); }
TEST(GTestImmutable, TestUseCount) { { GTestImmutable::CPtr p = GTestImmutable::create(); ASSERT_EQ(1, p.use_count()); ASSERT_EQ(1, GTestImmutable::count); GTestImmutable::CPtr p2 = GTestImmutable::create(); ASSERT_EQ(1, p2.use_count()); ASSERT_EQ(2, GTestImmutable::count); p = p2; ASSERT_EQ(2, p.use_count()); ASSERT_EQ(2, p2.use_count()); ASSERT_EQ(1, GTestImmutable::count); GTestImmutable::CPtr p3 = LIBJ_STATIC_CPTR_CAST(GTestImmutable)((&(*p))->self()); ASSERT_EQ(3, p.use_count()); ASSERT_EQ(3, p2.use_count()); ASSERT_EQ(3, p3.use_count()); ASSERT_EQ(1, GTestImmutable::count); } ASSERT_EQ(0, GTestImmutable::count); }