name_of_test.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE (name_of test)
2 #include "boost/test/unit_test.hpp"
3 
4 #include "cetlib/name_of.h"
5 
6 using cet::name_of;
7 
8 struct sometype;
9 
10 BOOST_AUTO_TEST_SUITE(name_of_test)
11 
12 BOOST_AUTO_TEST_CASE(unknown_type_test)
13 {
14  BOOST_TEST(name_of<sometype>::is() == "unknown-type");
15  BOOST_TEST(name_of<sometype*>::is() == "ptr-to_unknown-type");
16  BOOST_TEST(name_of<sometype&>::is() == "ref-to_unknown-type");
17  BOOST_TEST(name_of<sometype[1]>::is() == "array[1]-of_unknown-type");
18 }
19 
20 BOOST_AUTO_TEST_CASE(fundamental_types_test)
21 {
22  // signed ints:
23  BOOST_TEST(name_of<int>::is() == "int");
24  BOOST_TEST(name_of<long>::is() == "long");
25  BOOST_TEST(name_of<long long>::is() == "llong");
26  BOOST_TEST(name_of<short>::is() == "short");
27  BOOST_TEST(name_of<signed char>::is() == "schar");
28 
29  // unsigned ints:
30  BOOST_TEST(name_of<unsigned char>::is() == "uchar");
31  BOOST_TEST(name_of<unsigned int>::is() == "uint");
32  BOOST_TEST(name_of<unsigned long>::is() == "ulong");
33  BOOST_TEST(name_of<unsigned long long>::is() == "ullong");
34  BOOST_TEST(name_of<unsigned short>::is() == "ushort");
35 
36  // floating:
37  BOOST_TEST(name_of<double>::is() == "double");
38  BOOST_TEST(name_of<float>::is() == "float");
39  BOOST_TEST(name_of<long double>::is() == "ldouble");
40 
41  // other:
42  BOOST_TEST(name_of<bool>::is() == "bool");
43  BOOST_TEST(name_of<char>::is() == "char");
44  BOOST_TEST(name_of<void>::is() == "void");
45 }
46 
47 BOOST_AUTO_TEST_CASE(cv_types_test)
48 {
49  // const:
50  BOOST_TEST(name_of<int const>::is() == "c_int");
51  BOOST_TEST(name_of<long const>::is() == "c_long");
52  BOOST_TEST(name_of<long long const>::is() == "c_llong");
53  BOOST_TEST(name_of<short const>::is() == "c_short");
54  BOOST_TEST(name_of<signed char const>::is() == "c_schar");
55 
56  // volatile:
57  BOOST_TEST(name_of<unsigned char volatile>::is() == "v_uchar");
58  BOOST_TEST(name_of<unsigned int volatile>::is() == "v_uint");
59  BOOST_TEST(name_of<unsigned long volatile>::is() == "v_ulong");
60  BOOST_TEST(name_of<unsigned long long volatile>::is() == "v_ullong");
61  BOOST_TEST(name_of<unsigned short volatile>::is() == "v_ushort");
62 
63  // const-volatile:
64  BOOST_TEST(name_of<double const volatile>::is() == "c-v_double");
65  BOOST_TEST(name_of<float const volatile>::is() == "c-v_float");
66  BOOST_TEST(name_of<long double const volatile>::is() == "c-v_ldouble");
67  BOOST_TEST(name_of<bool const volatile>::is() == "c-v_bool");
68  BOOST_TEST(name_of<char const volatile>::is() == "c-v_char");
69  BOOST_TEST(name_of<void const volatile>::is() == "c-v_void");
70 }
71 
72 BOOST_AUTO_TEST_CASE(array_types_test)
73 {
74  BOOST_TEST(name_of<sometype[1]>::is() == "array[1]-of_unknown-type");
75  BOOST_TEST(name_of<int[9]>::is() == "array[9]-of_int");
76  BOOST_TEST(name_of<int * [9]>::is() == "array[9]-of_ptr-to_int");
77  BOOST_TEST(name_of<int const * [9]>::is() == "array[9]-of_ptr-to_c_int");
78 }
79 
80 BOOST_AUTO_TEST_CASE(library_types_test)
81 {
82  BOOST_TEST(name_of<std::nullptr_t>::is() == "std::nullptr_t");
83  BOOST_TEST(name_of<std::string>::is() == "std::string");
84  BOOST_TEST(name_of<std::istream>::is() == "std::istream");
85  BOOST_TEST(name_of<std::ostream>::is() == "std::ostream");
86 }
87 
88 BOOST_AUTO_TEST_SUITE_END()
std::string name_of()
Definition: Printer.h:61
BOOST_AUTO_TEST_CASE(unknown_type_test)
Definition: name_of_test.cc:12