1// Copyright 2018 The Fuchsia Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include <fbl/type_info.h> 6 7#include <unittest/unittest.h> 8 9namespace test { 10 11struct Struct { 12 int a; 13 int b; 14}; 15 16struct StructWithVTable { 17 int a; 18 int b; 19 20 virtual int Sum() { 21 return a + b; 22 } 23}; 24 25struct IncompleteType; 26 27} // namespace test 28 29namespace { 30 31bool type_info_test() { 32 BEGIN_TEST; 33 34 EXPECT_STR_EQ(fbl::TypeInfo<int>::Name(), "int"); 35 EXPECT_STR_EQ(fbl::TypeInfo<double>::Name(), "double"); 36 EXPECT_STR_EQ(fbl::TypeInfo<test::Struct>::Name(), "test::Struct"); 37 EXPECT_STR_EQ(fbl::TypeInfo<test::StructWithVTable>::Name(), "test::StructWithVTable"); 38 EXPECT_STR_EQ(fbl::TypeInfo<test::IncompleteType>::Name(), "test::IncompleteType"); 39 40 // Lambdas are printed differently between GCC and Clang. Just test that this 41 // expression compiles. 42 auto lambda = [](int a, int b) { return a + b; }; 43 EXPECT_STR_NE(fbl::TypeInfo<decltype(lambda)>::Name(), ""); 44 45 char array[10]; 46 EXPECT_STR_EQ(fbl::TypeInfo<decltype(array)>::Name(), "char [10]"); 47 48 char(&array_reference)[10] = array; 49 EXPECT_STR_EQ(fbl::TypeInfo<decltype(array_reference)>::Name(), "char (&)[10]"); 50 51 END_TEST; 52} 53 54} // anonymous namespace 55 56BEGIN_TEST_CASE(type_info_tests) 57RUN_NAMED_TEST("type info test", type_info_test) 58END_TEST_CASE(type_info_tests); 59