Home | History | Annotate | Download | only in Support
      1 //===- TypeNameTest.cpp ---------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 #include "llvm/Support/TypeName.h"
     11 #include "llvm/Support/raw_ostream.h"
     12 #include "gtest/gtest.h"
     13 
     14 using namespace llvm;
     15 
     16 namespace {
     17 namespace N1 {
     18 struct S1 {};
     19 class C1 {};
     20 union U1 {};
     21 }
     22 
     23 TEST(TypeNameTest, Names) {
     24   struct S2 {};
     25 
     26   StringRef S1Name = getTypeName<N1::S1>();
     27   StringRef C1Name = getTypeName<N1::C1>();
     28   StringRef U1Name = getTypeName<N1::U1>();
     29   StringRef S2Name = getTypeName<S2>();
     30 
     31 #if defined(__clang__) || defined(__GNUC__) || defined(__INTEL_COMPILER) ||    \
     32     defined(_MSC_VER)
     33   EXPECT_TRUE(S1Name.endswith("::N1::S1")) << S1Name.str();
     34   EXPECT_TRUE(C1Name.endswith("::N1::C1")) << C1Name.str();
     35   EXPECT_TRUE(U1Name.endswith("::N1::U1")) << U1Name.str();
     36 #ifdef __clang__
     37   EXPECT_TRUE(S2Name.endswith("S2")) << S2Name.str();
     38 #else
     39   EXPECT_TRUE(S2Name.endswith("::S2")) << S2Name.str();
     40 #endif
     41 #else
     42   EXPECT_EQ("UNKNOWN_TYPE", S1Name);
     43   EXPECT_EQ("UNKNOWN_TYPE", C1Name);
     44   EXPECT_EQ("UNKNOWN_TYPE", U1Name);
     45   EXPECT_EQ("UNKNOWN_TYPE", S2Name);
     46 #endif
     47 }
     48 
     49 } // end anonymous namespace
     50