1// Copyright 2020 Peter Dimov
2// Distributed under the Boost Software License, Version 1.0.
3// https://www.boost.org/LICENSE_1_0.txt
4
5#include <boost/describe/bases.hpp>
6#include <boost/describe/class.hpp>
7#include <boost/core/lightweight_test.hpp>
8#include <boost/core/lightweight_test_trait.hpp>
9
10#if defined(_MSC_VER) && _MSC_VER < 1900
11# pragma warning(disable: 4510) // default constructor could not be generated
12# pragma warning(disable: 4610) // struct can never be instantiated
13#endif
14
15struct X
16{
17};
18
19BOOST_DESCRIBE_STRUCT(X, (), ())
20
21struct X1
22{
23};
24
25struct X2
26{
27};
28
29struct X3
30{
31};
32
33struct V1
34{
35 V1(int);
36};
37
38struct V2
39{
40 V2(int);
41};
42
43struct V3
44{
45 V3(int);
46};
47
48struct Y: public X1, protected X2, private X3, public virtual V1, protected virtual V2, private virtual V3
49{
50};
51
52BOOST_DESCRIBE_STRUCT(Y, (X1, X2, X3, V1, V2, V3), ())
53
54#if !defined(BOOST_DESCRIBE_CXX14)
55
56#include <boost/config/pragma_message.hpp>
57
58BOOST_PRAGMA_MESSAGE("Skipping test because C++14 is not available")
59int main() {}
60
61#else
62
63#include <boost/mp11.hpp>
64
65int main()
66{
67 using namespace boost::describe;
68 using namespace boost::mp11;
69
70 {
71 using L = describe_bases<X, mod_any_access>;
72
73 BOOST_TEST_EQ( mp_size<L>::value, 0 );
74 }
75
76 {
77 using L = describe_bases<X, mod_public>;
78
79 BOOST_TEST_EQ( mp_size<L>::value, 0 );
80 }
81
82 {
83 using L = describe_bases<X, mod_protected>;
84
85 BOOST_TEST_EQ( mp_size<L>::value, 0 );
86 }
87
88 {
89 using L = describe_bases<X, mod_private>;
90
91 BOOST_TEST_EQ( mp_size<L>::value, 0 );
92 }
93
94 {
95 using L = describe_bases<Y, mod_any_access>;
96
97 BOOST_TEST_EQ( mp_size<L>::value, 6 );
98
99 BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 0>::type, X1 );
100 BOOST_TEST_EQ( (mp_at_c<L, 0>::modifiers), mod_public );
101
102 BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 1>::type, X2 );
103 BOOST_TEST_EQ( (mp_at_c<L, 1>::modifiers), mod_protected );
104
105 BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 2>::type, X3 );
106 BOOST_TEST_EQ( (mp_at_c<L, 2>::modifiers), mod_private );
107
108 BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 3>::type, V1 );
109 BOOST_TEST_EQ( (mp_at_c<L, 3>::modifiers), mod_public | mod_virtual );
110
111 BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 4>::type, V2 );
112 BOOST_TEST_EQ( (mp_at_c<L, 4>::modifiers), mod_protected | mod_virtual );
113
114 BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 5>::type, V3 );
115 BOOST_TEST_EQ( (mp_at_c<L, 5>::modifiers), mod_private | mod_virtual );
116 }
117
118 {
119 using L = describe_bases<Y, mod_public>;
120
121 BOOST_TEST_EQ( mp_size<L>::value, 2 );
122
123 BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 0>::type, X1 );
124 BOOST_TEST_EQ( (mp_at_c<L, 0>::modifiers), mod_public );
125
126 BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 1>::type, V1 );
127 BOOST_TEST_EQ( (mp_at_c<L, 1>::modifiers), mod_public | mod_virtual );
128 }
129
130 {
131 using L = describe_bases<Y, mod_protected>;
132
133 BOOST_TEST_EQ( mp_size<L>::value, 2 );
134
135 BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 0>::type, X2 );
136 BOOST_TEST_EQ( (mp_at_c<L, 0>::modifiers), mod_protected );
137
138 BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 1>::type, V2 );
139 BOOST_TEST_EQ( (mp_at_c<L, 1>::modifiers), mod_protected | mod_virtual );
140 }
141
142 {
143 using L = describe_bases<Y, mod_private>;
144
145 BOOST_TEST_EQ( mp_size<L>::value, 2 );
146
147 BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 0>::type, X3 );
148 BOOST_TEST_EQ( (mp_at_c<L, 0>::modifiers), mod_private );
149
150 BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 1>::type, V3 );
151 BOOST_TEST_EQ( (mp_at_c<L, 1>::modifiers), mod_private | mod_virtual );
152 }
153
154 return boost::report_errors();
155}
156
157#endif // !defined(BOOST_DESCRIBE_CXX14)
158

source code of boost/libs/describe/test/bases_test.cpp