Ejemplo n.º 1
0
TEST(GTestImmutable, TestInstanceOf) {
    GTestImmutable::CPtr p = GTestImmutable::create();

    ASSERT_TRUE(p->instanceof(Type<GTestImmutable>::id()));
    ASSERT_TRUE(p->instanceof(Type<Immutable>::id()));
    ASSERT_TRUE(p->instanceof(Type<Object>::id()));

    ASSERT_FALSE(p->instanceof(Type<Mutable>::id()));
}
Ejemplo n.º 2
0
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);
}
Ejemplo n.º 3
0
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);
}