// Copyright 2014 The Chromium OS Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include #include #include namespace brillo { // Tests using tags from the __PRETTY_FUNCTION__ don't work when using RTTI // to get the type name. #ifndef USE_RTTI_FOR_TYPE_TAGS TEST(TypeTags, GetTypeTag) { EXPECT_STREQ("const char *brillo::GetTypeTag() [T = int]", GetTypeTag()); EXPECT_STREQ("const char *brillo::GetTypeTag() [T = std::__1::map, " "std::__1::allocator >, brillo::Any, std::__1::less<" "std::__1::basic_string, " "std::__1::allocator > >, std::__1::allocator, std::__1::allocator >, brillo::Any> > >]", GetTypeTag()); EXPECT_STREQ("const char *brillo::GetTypeTag() [T = int []]", GetTypeTag()); } #endif // USE_RTTI_FOR_TYPE_TAGS TEST(TypeDecoration, UndecorateTypeName) { EXPECT_EQ("int", UndecorateTypeName("i")); EXPECT_EQ("char const* brillo::GetTypeTag()", UndecorateTypeName("_ZN6brillo10GetTypeTagIyEEPKcv")); EXPECT_EQ("std::__1::to_string(int)", UndecorateTypeName("_ZNSt3__19to_stringEi")); } #ifndef USE_RTTI_FOR_TYPE_TAGS TEST(TypeDecoration, GetUndecoratedTypeNameForTag) { EXPECT_EQ("int", GetUndecoratedTypeNameForTag( "const char *brillo::GetTypeTag() [T = int]")); EXPECT_EQ("int []", GetUndecoratedTypeNameForTag( "const char *brillo::GetTypeTag() [T = int []]")); EXPECT_EQ("foo::bar()", GetUndecoratedTypeNameForTag( "const char *brillo::GetTypeTag() [T = foo::bar()]")); } TEST(TypeDecoration, GetUndecoratedTypeName) { EXPECT_EQ("int", GetUndecoratedTypeName()); EXPECT_EQ("int *", GetUndecoratedTypeName()); EXPECT_EQ("const int *", GetUndecoratedTypeName()); EXPECT_EQ("int []", GetUndecoratedTypeName()); EXPECT_EQ("bool", GetUndecoratedTypeName()); EXPECT_EQ("char", GetUndecoratedTypeName()); EXPECT_EQ("float", GetUndecoratedTypeName()); EXPECT_EQ("double", GetUndecoratedTypeName()); EXPECT_EQ("long", GetUndecoratedTypeName()); EXPECT_EQ("std::__1::map, " "std::__1::allocator > >", (GetUndecoratedTypeName>())); } #endif // USE_RTTI_FOR_TYPE_TAGS } // namespace brillo