//===------ unittests/ExtensibleRTTITest.cpp - Extensible RTTI Tests ------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "llvm/Support/ExtensibleRTTI.h" #include "llvm/Support/Casting.h" #include "gtest/gtest.h" using namespace llvm; namespace { class MyBaseType : public RTTIExtends { public: static char ID; }; class MyDerivedType : public RTTIExtends { public: static char ID; }; class MyOtherDerivedType : public RTTIExtends { public: static char ID; }; class MyDeeperDerivedType : public RTTIExtends { public: static char ID; }; char MyBaseType::ID = 0; char MyDerivedType::ID = 0; char MyOtherDerivedType::ID = 0; char MyDeeperDerivedType::ID = 0; TEST(ExtensibleRTTI, isa) { MyBaseType B; MyDerivedType D; MyDeeperDerivedType DD; EXPECT_TRUE(isa(B)); EXPECT_FALSE(isa(B)); EXPECT_FALSE(isa(B)); EXPECT_FALSE(isa(B)); EXPECT_TRUE(isa(D)); EXPECT_TRUE(isa(D)); EXPECT_FALSE(isa(D)); EXPECT_FALSE(isa(D)); EXPECT_TRUE(isa(DD)); EXPECT_TRUE(isa(DD)); EXPECT_FALSE(isa(DD)); EXPECT_TRUE(isa(DD)); } TEST(ExtensibleRTTI, cast) { MyDerivedType D; MyBaseType &BD = D; cast(D); cast(BD); cast(BD); } TEST(ExtensibleRTTI, dyn_cast) { MyBaseType B; MyDerivedType D; MyBaseType &BD = D; EXPECT_EQ(dyn_cast(&B), nullptr); EXPECT_EQ(dyn_cast(&D), &D); EXPECT_EQ(dyn_cast(&BD), &BD); EXPECT_EQ(dyn_cast(&BD), &D); } } // namespace