]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright (C) 2003, Fernando Luis Cacciola Carballal. |
2 | // | |
3 | // Distributed under the Boost Software License, Version 1.0. (See | |
4 | // accompanying file LICENSE_1_0.txt or copy at | |
5 | // http://www.boost.org/LICENSE_1_0.txt) | |
6 | // | |
7 | // | |
8 | #include<iostream> | |
9 | #include<iomanip> | |
10 | #include<string> | |
11 | #include<typeinfo> | |
12 | #include<vector> | |
13 | #include<algorithm> | |
14 | ||
15 | #include <boost/cstdint.hpp> | |
16 | #include <boost/utility.hpp> | |
17 | #include <boost/preprocessor/cat.hpp> | |
18 | ||
19 | #include <boost/numeric/conversion/conversion_traits.hpp> | |
20 | #include <boost/numeric/conversion/int_float_mixture.hpp> | |
21 | #include <boost/numeric/conversion/sign_mixture.hpp> | |
22 | #include <boost/numeric/conversion/udt_builtin_mixture.hpp> | |
23 | #include <boost/numeric/conversion/is_subranged.hpp> | |
24 | ||
20effc67 | 25 | #ifdef BOOST_BORLANDC |
7c673cae FG |
26 | #pragma hdrstop |
27 | #endif | |
28 | ||
29 | #include "test_helpers.cpp" | |
30 | #include "test_helpers2.cpp" | |
31 | ||
32 | using namespace std ; | |
33 | using namespace boost ; | |
34 | using namespace numeric; | |
35 | using namespace MyUDT ; | |
36 | ||
37 | // These helpers are used by generate_expected_traits<T,S>. | |
38 | // Unlike the similar helpers in the implementation, they are specialized by extension. | |
39 | // | |
40 | template<class T, class S> struct my_is_subranged ; | |
41 | template<class T, class S> struct my_is_trivial ; | |
42 | template<class T, class S> struct my_int_float_mixture ; | |
43 | template<class T, class S> struct my_sign_mixture ; | |
44 | template<class T, class S> struct my_udt_builtin_mixture ; | |
45 | ||
46 | // This macro is used to define the properties of each conversion between | |
47 | // the builtin arithmetric types | |
48 | // | |
49 | // It defines the specialization of the helper traits used by 'generate_expected_traits' | |
50 | // | |
51 | #define DEFINE_CONVERSION(Target,Source,Trivial,Mixture,SignMixture,UdtMixture,SubRanged) \ | |
52 | \ | |
53 | template<> struct my_is_subranged<Target,Source> \ | |
54 | { typedef mpl::bool_< (SubRanged) > type ; } ; \ | |
55 | \ | |
56 | template<> struct my_is_trivial<Target,Source> \ | |
57 | { typedef mpl::bool_< (Trivial) > type ; } ; \ | |
58 | \ | |
59 | template<> struct my_int_float_mixture<Target,Source> \ | |
60 | { typedef mpl::integral_c<boost::numeric::int_float_mixture_enum, (Mixture) > type ; } ; \ | |
61 | \ | |
62 | template<> struct my_sign_mixture<Target,Source> \ | |
63 | { typedef mpl::integral_c<boost::numeric::sign_mixture_enum, (SignMixture) > type ; } ; \ | |
64 | \ | |
65 | template<> struct my_udt_builtin_mixture<Target,Source> \ | |
66 | { typedef mpl::integral_c<boost::numeric::udt_builtin_mixture_enum, (UdtMixture) > type ; } | |
67 | ||
68 | ||
69 | #define cSubRanged true | |
70 | #define cTrivial true | |
71 | ||
72 | // The following test assumes a specific relation between the sizes of the types being used; | |
73 | // therefore, use specific fixed-width types instead built-in types directly. | |
74 | ||
75 | // NOTE --> TARGET,SOURCE | |
76 | // | |
77 | DEFINE_CONVERSION(boost::uint8_t , boost::uint8_t, cTrivial, integral_to_integral, unsigned_to_unsigned, builtin_to_builtin, !cSubRanged ); | |
78 | DEFINE_CONVERSION(boost::int8_t , boost::uint8_t, !cTrivial, integral_to_integral, unsigned_to_signed , builtin_to_builtin, cSubRanged ); | |
79 | DEFINE_CONVERSION(boost::uint16_t , boost::uint8_t, !cTrivial, integral_to_integral, unsigned_to_unsigned, builtin_to_builtin, !cSubRanged ); | |
80 | DEFINE_CONVERSION(boost::int16_t , boost::uint8_t, !cTrivial, integral_to_integral, unsigned_to_signed , builtin_to_builtin, !cSubRanged ); | |
81 | DEFINE_CONVERSION(boost::uint32_t , boost::uint8_t, !cTrivial, integral_to_integral, unsigned_to_unsigned, builtin_to_builtin, !cSubRanged ); | |
82 | DEFINE_CONVERSION(boost::int32_t , boost::uint8_t, !cTrivial, integral_to_integral, unsigned_to_signed , builtin_to_builtin, !cSubRanged ); | |
83 | DEFINE_CONVERSION(float , boost::uint8_t, !cTrivial, integral_to_float , unsigned_to_signed , builtin_to_builtin, !cSubRanged ); | |
84 | DEFINE_CONVERSION(double , boost::uint8_t, !cTrivial, integral_to_float , unsigned_to_signed , builtin_to_builtin, !cSubRanged ); | |
85 | DEFINE_CONVERSION(long double , boost::uint8_t, !cTrivial, integral_to_float , unsigned_to_signed , builtin_to_builtin, !cSubRanged ); | |
86 | DEFINE_CONVERSION(MyInt , boost::uint8_t, !cTrivial, integral_to_integral, unsigned_to_signed , builtin_to_udt , !cSubRanged ); | |
87 | DEFINE_CONVERSION(MyFloat , boost::uint8_t, !cTrivial, integral_to_float , unsigned_to_signed , builtin_to_udt , !cSubRanged ); | |
88 | ||
89 | DEFINE_CONVERSION(boost::uint8_t , boost::int8_t, !cTrivial, integral_to_integral, signed_to_unsigned, builtin_to_builtin, cSubRanged ); | |
90 | DEFINE_CONVERSION(boost::int8_t , boost::int8_t, cTrivial, integral_to_integral, signed_to_signed , builtin_to_builtin, !cSubRanged ); | |
91 | DEFINE_CONVERSION(boost::uint16_t , boost::int8_t, !cTrivial, integral_to_integral, signed_to_unsigned, builtin_to_builtin, cSubRanged ); | |
92 | DEFINE_CONVERSION(boost::int16_t , boost::int8_t, !cTrivial, integral_to_integral, signed_to_signed , builtin_to_builtin, !cSubRanged ); | |
93 | DEFINE_CONVERSION(boost::uint32_t , boost::int8_t, !cTrivial, integral_to_integral, signed_to_unsigned, builtin_to_builtin, cSubRanged ); | |
94 | DEFINE_CONVERSION(boost::int32_t , boost::int8_t, !cTrivial, integral_to_integral, signed_to_signed , builtin_to_builtin, !cSubRanged ); | |
95 | DEFINE_CONVERSION(float , boost::int8_t, !cTrivial, integral_to_float , signed_to_signed , builtin_to_builtin, !cSubRanged ); | |
96 | DEFINE_CONVERSION(double , boost::int8_t, !cTrivial, integral_to_float , signed_to_signed , builtin_to_builtin, !cSubRanged ); | |
97 | DEFINE_CONVERSION(long double , boost::int8_t, !cTrivial, integral_to_float , signed_to_signed , builtin_to_builtin, !cSubRanged ); | |
98 | DEFINE_CONVERSION(MyInt , boost::int8_t, !cTrivial, integral_to_integral, signed_to_signed , builtin_to_udt , !cSubRanged ); | |
99 | DEFINE_CONVERSION(MyFloat , boost::int8_t, !cTrivial, integral_to_float , signed_to_signed , builtin_to_udt , !cSubRanged ); | |
100 | ||
101 | DEFINE_CONVERSION(boost::uint8_t , boost::uint16_t, !cTrivial, integral_to_integral, unsigned_to_unsigned, builtin_to_builtin, cSubRanged ); | |
102 | DEFINE_CONVERSION(boost::int8_t , boost::uint16_t, !cTrivial, integral_to_integral, unsigned_to_signed , builtin_to_builtin, cSubRanged ); | |
103 | DEFINE_CONVERSION(boost::uint16_t , boost::uint16_t, cTrivial, integral_to_integral, unsigned_to_unsigned, builtin_to_builtin, !cSubRanged ); | |
104 | DEFINE_CONVERSION(boost::int16_t , boost::uint16_t, !cTrivial, integral_to_integral, unsigned_to_signed , builtin_to_builtin, cSubRanged ); | |
105 | DEFINE_CONVERSION(boost::uint32_t , boost::uint16_t, !cTrivial, integral_to_integral, unsigned_to_unsigned, builtin_to_builtin, !cSubRanged ); | |
106 | DEFINE_CONVERSION(boost::int32_t , boost::uint16_t, !cTrivial, integral_to_integral, unsigned_to_signed , builtin_to_builtin, !cSubRanged ); | |
107 | DEFINE_CONVERSION(float , boost::uint16_t, !cTrivial, integral_to_float , unsigned_to_signed , builtin_to_builtin, !cSubRanged ); | |
108 | DEFINE_CONVERSION(double , boost::uint16_t, !cTrivial, integral_to_float , unsigned_to_signed , builtin_to_builtin, !cSubRanged ); | |
109 | DEFINE_CONVERSION(long double , boost::uint16_t, !cTrivial, integral_to_float , unsigned_to_signed , builtin_to_builtin, !cSubRanged ); | |
110 | DEFINE_CONVERSION(MyInt , boost::uint16_t, !cTrivial, integral_to_integral, unsigned_to_signed , builtin_to_udt , !cSubRanged ); | |
111 | DEFINE_CONVERSION(MyFloat , boost::uint16_t, !cTrivial, integral_to_float , unsigned_to_signed , builtin_to_udt , !cSubRanged ); | |
112 | ||
113 | DEFINE_CONVERSION(boost::uint8_t , boost::int16_t, !cTrivial, integral_to_integral, signed_to_unsigned, builtin_to_builtin, cSubRanged ); | |
114 | DEFINE_CONVERSION(boost::int8_t , boost::int16_t, !cTrivial, integral_to_integral, signed_to_signed , builtin_to_builtin, cSubRanged ); | |
115 | DEFINE_CONVERSION(boost::uint16_t , boost::int16_t, !cTrivial, integral_to_integral, signed_to_unsigned, builtin_to_builtin, cSubRanged ); | |
116 | DEFINE_CONVERSION(boost::int16_t , boost::int16_t, cTrivial, integral_to_integral, signed_to_signed , builtin_to_builtin, !cSubRanged ); | |
117 | DEFINE_CONVERSION(boost::uint32_t , boost::int16_t, !cTrivial, integral_to_integral, signed_to_unsigned, builtin_to_builtin, cSubRanged ); | |
118 | DEFINE_CONVERSION(boost::int32_t , boost::int16_t, !cTrivial, integral_to_integral, signed_to_signed , builtin_to_builtin, !cSubRanged ); | |
119 | DEFINE_CONVERSION(float , boost::int16_t, !cTrivial, integral_to_float , signed_to_signed , builtin_to_builtin, !cSubRanged ); | |
120 | DEFINE_CONVERSION(double , boost::int16_t, !cTrivial, integral_to_float , signed_to_signed , builtin_to_builtin, !cSubRanged ); | |
121 | DEFINE_CONVERSION(long double , boost::int16_t, !cTrivial, integral_to_float , signed_to_signed , builtin_to_builtin, !cSubRanged ); | |
122 | DEFINE_CONVERSION(MyInt , boost::int16_t, !cTrivial, integral_to_integral, signed_to_signed , builtin_to_udt , !cSubRanged ); | |
123 | DEFINE_CONVERSION(MyFloat , boost::int16_t, !cTrivial, integral_to_float , signed_to_signed , builtin_to_udt , !cSubRanged ); | |
124 | ||
125 | DEFINE_CONVERSION(boost::uint8_t , boost::uint32_t, !cTrivial, integral_to_integral, unsigned_to_unsigned, builtin_to_builtin, cSubRanged ); | |
126 | DEFINE_CONVERSION(boost::int8_t , boost::uint32_t, !cTrivial, integral_to_integral, unsigned_to_signed , builtin_to_builtin, cSubRanged ); | |
127 | DEFINE_CONVERSION(boost::uint16_t , boost::uint32_t, !cTrivial, integral_to_integral, unsigned_to_unsigned, builtin_to_builtin, cSubRanged ); | |
128 | DEFINE_CONVERSION(boost::int16_t , boost::uint32_t, !cTrivial, integral_to_integral, unsigned_to_signed , builtin_to_builtin, cSubRanged ); | |
129 | DEFINE_CONVERSION(boost::uint32_t , boost::uint32_t, cTrivial, integral_to_integral, unsigned_to_unsigned, builtin_to_builtin, !cSubRanged ); | |
130 | DEFINE_CONVERSION(boost::int32_t , boost::uint32_t, !cTrivial, integral_to_integral, unsigned_to_signed , builtin_to_builtin, cSubRanged ); | |
131 | DEFINE_CONVERSION(float , boost::uint32_t, !cTrivial, integral_to_float , unsigned_to_signed , builtin_to_builtin, !cSubRanged ); | |
132 | DEFINE_CONVERSION(double , boost::uint32_t, !cTrivial, integral_to_float , unsigned_to_signed , builtin_to_builtin, !cSubRanged ); | |
133 | DEFINE_CONVERSION(long double , boost::uint32_t, !cTrivial, integral_to_float , unsigned_to_signed , builtin_to_builtin, !cSubRanged ); | |
134 | DEFINE_CONVERSION(MyInt , boost::uint32_t, !cTrivial, integral_to_integral, unsigned_to_signed , builtin_to_udt , !cSubRanged ); | |
135 | DEFINE_CONVERSION(MyFloat , boost::uint32_t, !cTrivial, integral_to_float , unsigned_to_signed , builtin_to_udt , !cSubRanged ); | |
136 | ||
137 | DEFINE_CONVERSION(boost::uint8_t , boost::int32_t, !cTrivial, integral_to_integral, signed_to_unsigned, builtin_to_builtin, cSubRanged ); | |
138 | DEFINE_CONVERSION(boost::int8_t , boost::int32_t, !cTrivial, integral_to_integral, signed_to_signed , builtin_to_builtin, cSubRanged ); | |
139 | DEFINE_CONVERSION(boost::uint16_t , boost::int32_t, !cTrivial, integral_to_integral, signed_to_unsigned, builtin_to_builtin, cSubRanged ); | |
140 | DEFINE_CONVERSION(boost::int16_t , boost::int32_t, !cTrivial, integral_to_integral, signed_to_signed , builtin_to_builtin, cSubRanged ); | |
141 | DEFINE_CONVERSION(boost::uint32_t , boost::int32_t, !cTrivial, integral_to_integral, signed_to_unsigned, builtin_to_builtin, cSubRanged ); | |
142 | DEFINE_CONVERSION(boost::int32_t , boost::int32_t, cTrivial, integral_to_integral, signed_to_signed , builtin_to_builtin, !cSubRanged ); | |
143 | DEFINE_CONVERSION(float , boost::int32_t, !cTrivial, integral_to_float , signed_to_signed , builtin_to_builtin, !cSubRanged ); | |
144 | DEFINE_CONVERSION(double , boost::int32_t, !cTrivial, integral_to_float , signed_to_signed , builtin_to_builtin, !cSubRanged ); | |
145 | DEFINE_CONVERSION(long double , boost::int32_t, !cTrivial, integral_to_float , signed_to_signed , builtin_to_builtin, !cSubRanged ); | |
146 | DEFINE_CONVERSION(MyInt , boost::int32_t, !cTrivial, integral_to_integral, signed_to_signed , builtin_to_udt , !cSubRanged ); | |
147 | DEFINE_CONVERSION(MyFloat , boost::int32_t, !cTrivial, integral_to_float , signed_to_signed , builtin_to_udt , !cSubRanged ); | |
148 | ||
149 | DEFINE_CONVERSION(boost::uint8_t , float, !cTrivial, float_to_integral, signed_to_unsigned, builtin_to_builtin, cSubRanged ); | |
150 | DEFINE_CONVERSION(boost::int8_t , float, !cTrivial, float_to_integral, signed_to_signed , builtin_to_builtin, cSubRanged ); | |
151 | DEFINE_CONVERSION(boost::uint16_t , float, !cTrivial, float_to_integral, signed_to_unsigned, builtin_to_builtin, cSubRanged ); | |
152 | DEFINE_CONVERSION(boost::int16_t , float, !cTrivial, float_to_integral, signed_to_signed , builtin_to_builtin, cSubRanged ); | |
153 | DEFINE_CONVERSION(boost::uint32_t , float, !cTrivial, float_to_integral, signed_to_unsigned, builtin_to_builtin, cSubRanged ); | |
154 | DEFINE_CONVERSION(boost::int32_t , float, !cTrivial, float_to_integral, signed_to_signed , builtin_to_builtin, cSubRanged ); | |
155 | DEFINE_CONVERSION(float , float, cTrivial, float_to_float , signed_to_signed , builtin_to_builtin, !cSubRanged ); | |
156 | DEFINE_CONVERSION(double , float, !cTrivial, float_to_float , signed_to_signed , builtin_to_builtin, ( sizeof(float) > sizeof(double) ) ); | |
157 | DEFINE_CONVERSION(long double , float, !cTrivial, float_to_float , signed_to_signed , builtin_to_builtin, ( sizeof(float) > sizeof(long double) ) ); | |
158 | DEFINE_CONVERSION(MyInt , float, !cTrivial, float_to_integral, signed_to_signed , builtin_to_udt , !cSubRanged ); | |
159 | DEFINE_CONVERSION(MyFloat , float, !cTrivial, float_to_float , signed_to_signed , builtin_to_udt , !cSubRanged ); | |
160 | ||
161 | DEFINE_CONVERSION(boost::uint8_t , double, !cTrivial, float_to_integral, signed_to_unsigned, builtin_to_builtin, cSubRanged ); | |
162 | DEFINE_CONVERSION(boost::int8_t , double, !cTrivial, float_to_integral, signed_to_signed , builtin_to_builtin, cSubRanged ); | |
163 | DEFINE_CONVERSION(boost::uint16_t , double, !cTrivial, float_to_integral, signed_to_unsigned, builtin_to_builtin, cSubRanged ); | |
164 | DEFINE_CONVERSION(boost::int16_t , double, !cTrivial, float_to_integral, signed_to_signed , builtin_to_builtin, cSubRanged ); | |
165 | DEFINE_CONVERSION(boost::uint32_t , double, !cTrivial, float_to_integral, signed_to_unsigned, builtin_to_builtin, cSubRanged ); | |
166 | DEFINE_CONVERSION(boost::int32_t , double, !cTrivial, float_to_integral, signed_to_signed , builtin_to_builtin, cSubRanged ); | |
167 | DEFINE_CONVERSION(float , double, !cTrivial, float_to_float , signed_to_signed , builtin_to_builtin, ( sizeof(double) > sizeof(float) ) ); | |
168 | DEFINE_CONVERSION(double , double, cTrivial, float_to_float , signed_to_signed , builtin_to_builtin, !cSubRanged ); | |
169 | DEFINE_CONVERSION(long double , double, !cTrivial, float_to_float , signed_to_signed , builtin_to_builtin, ( sizeof(double) > sizeof(long double) ) ); | |
170 | DEFINE_CONVERSION(MyInt , double, !cTrivial, float_to_integral, signed_to_signed , builtin_to_udt , !cSubRanged ); | |
171 | DEFINE_CONVERSION(MyFloat , double, !cTrivial, float_to_float , signed_to_signed , builtin_to_udt , !cSubRanged ); | |
172 | ||
173 | DEFINE_CONVERSION(boost::uint8_t , long double, !cTrivial, float_to_integral, signed_to_unsigned, builtin_to_builtin, cSubRanged ); | |
174 | DEFINE_CONVERSION(boost::int8_t , long double, !cTrivial, float_to_integral, signed_to_signed , builtin_to_builtin, cSubRanged ); | |
175 | DEFINE_CONVERSION(boost::uint16_t , long double, !cTrivial, float_to_integral, signed_to_unsigned, builtin_to_builtin, cSubRanged ); | |
176 | DEFINE_CONVERSION(boost::int16_t , long double, !cTrivial, float_to_integral, signed_to_signed , builtin_to_builtin, cSubRanged ); | |
177 | DEFINE_CONVERSION(boost::uint32_t , long double, !cTrivial, float_to_integral, signed_to_unsigned, builtin_to_builtin, cSubRanged ); | |
178 | DEFINE_CONVERSION(boost::int32_t , long double, !cTrivial, float_to_integral, signed_to_signed , builtin_to_builtin, cSubRanged ); | |
179 | DEFINE_CONVERSION(float , long double, !cTrivial, float_to_float , signed_to_signed , builtin_to_builtin, ( sizeof(long double) > sizeof(float) ) ); | |
180 | DEFINE_CONVERSION(double , long double, !cTrivial, float_to_float , signed_to_signed , builtin_to_builtin, ( sizeof(long double) > sizeof(double) ) ); | |
181 | DEFINE_CONVERSION(long double , long double, cTrivial, float_to_float , signed_to_signed , builtin_to_builtin, !cSubRanged ); | |
182 | DEFINE_CONVERSION(MyInt , long double, !cTrivial, float_to_integral, signed_to_signed , builtin_to_udt , !cSubRanged ); | |
183 | DEFINE_CONVERSION(MyFloat , long double, !cTrivial, float_to_float , signed_to_signed , builtin_to_udt , !cSubRanged ); | |
184 | ||
185 | DEFINE_CONVERSION(boost::uint8_t , MyInt, !cTrivial, integral_to_integral, signed_to_unsigned, udt_to_builtin , cSubRanged ); | |
186 | DEFINE_CONVERSION(boost::int8_t , MyInt, !cTrivial, integral_to_integral, signed_to_signed , udt_to_builtin , cSubRanged ); | |
187 | DEFINE_CONVERSION(boost::uint16_t , MyInt, !cTrivial, integral_to_integral, signed_to_unsigned, udt_to_builtin , cSubRanged ); | |
188 | DEFINE_CONVERSION(boost::int16_t , MyInt, !cTrivial, integral_to_integral, signed_to_signed , udt_to_builtin , cSubRanged ); | |
189 | DEFINE_CONVERSION(boost::uint32_t , MyInt, !cTrivial, integral_to_integral, signed_to_unsigned, udt_to_builtin , cSubRanged ); | |
190 | DEFINE_CONVERSION(boost::int32_t , MyInt, !cTrivial, integral_to_integral, signed_to_signed , udt_to_builtin , cSubRanged ); | |
191 | DEFINE_CONVERSION(float , MyInt, !cTrivial, integral_to_float , signed_to_signed , udt_to_builtin , cSubRanged ); | |
192 | DEFINE_CONVERSION(double , MyInt, !cTrivial, integral_to_float , signed_to_signed , udt_to_builtin , cSubRanged ); | |
193 | DEFINE_CONVERSION(long double , MyInt, !cTrivial, integral_to_float , signed_to_signed , udt_to_builtin , cSubRanged ); | |
194 | DEFINE_CONVERSION(MyInt , MyInt, cTrivial, integral_to_integral, signed_to_signed , udt_to_udt ,!cSubRanged ); | |
195 | DEFINE_CONVERSION(MyFloat , MyInt, !cTrivial, integral_to_float , signed_to_signed , udt_to_udt ,!cSubRanged ); | |
196 | ||
197 | DEFINE_CONVERSION(boost::uint8_t , MyFloat, !cTrivial, float_to_integral, signed_to_unsigned, udt_to_builtin , cSubRanged ); | |
198 | DEFINE_CONVERSION(boost::int8_t , MyFloat, !cTrivial, float_to_integral, signed_to_signed , udt_to_builtin , cSubRanged ); | |
199 | DEFINE_CONVERSION(boost::uint16_t , MyFloat, !cTrivial, float_to_integral, signed_to_unsigned, udt_to_builtin , cSubRanged ); | |
200 | DEFINE_CONVERSION(boost::int16_t , MyFloat, !cTrivial, float_to_integral, signed_to_signed , udt_to_builtin , cSubRanged ); | |
201 | DEFINE_CONVERSION(boost::uint32_t , MyFloat, !cTrivial, float_to_integral, signed_to_unsigned, udt_to_builtin , cSubRanged ); | |
202 | DEFINE_CONVERSION(boost::int32_t , MyFloat, !cTrivial, float_to_integral, signed_to_signed , udt_to_builtin , cSubRanged ); | |
203 | DEFINE_CONVERSION(float , MyFloat, !cTrivial, float_to_float , signed_to_signed , udt_to_builtin , cSubRanged ); | |
204 | DEFINE_CONVERSION(double , MyFloat, !cTrivial, float_to_float , signed_to_signed , udt_to_builtin , cSubRanged ); | |
205 | DEFINE_CONVERSION(long double , MyFloat, !cTrivial, float_to_float , signed_to_signed , udt_to_builtin , cSubRanged ); | |
206 | DEFINE_CONVERSION(MyInt , MyFloat, !cTrivial, float_to_integral, signed_to_signed , udt_to_udt ,!cSubRanged ); | |
207 | DEFINE_CONVERSION(MyFloat , MyFloat, cTrivial, float_to_float , signed_to_signed , udt_to_udt ,!cSubRanged ); | |
208 | ||
209 | // | |
210 | // The test is performed by comparing each field of | |
211 | // boost::numeric::conversion_traits<T,S> | |
212 | // with the fields of | |
213 | // expected_traits<T,S> | |
214 | // which is a traits class constructed explicitely for each combination | |
215 | // of the built-in arithmetic types. | |
216 | // | |
217 | template<class T, | |
218 | class S, | |
219 | class Supertype, | |
220 | class Subtype, | |
221 | class Subranged, | |
222 | class Trivial | |
223 | > | |
224 | struct expected_traits | |
225 | { | |
226 | typedef typename my_int_float_mixture <T,S>::type int_float_mixture ; | |
227 | typedef typename my_sign_mixture <T,S>::type sign_mixture ; | |
228 | typedef typename my_udt_builtin_mixture <T,S>::type udt_builtin_mixture ; | |
229 | ||
230 | typedef Subranged subranged ; | |
231 | typedef Trivial trivial ; | |
232 | typedef Supertype supertype ; | |
233 | typedef Subtype subtype ; | |
234 | } ; | |
235 | ||
236 | // This is used by the test engine to generate a expected_traits from T and S. | |
237 | // | |
238 | template<class T, class S> | |
239 | struct generate_expected_traits | |
240 | { | |
241 | typedef expected_traits<T, S, T, S, mpl::false_, mpl::true_ > trivial ; | |
242 | typedef expected_traits<T, S, S, T, mpl::true_ , mpl::false_ > subranged ; | |
243 | typedef expected_traits<T, S, T, S, mpl::false_, mpl::false_ > non_subranged ; | |
244 | ||
245 | typedef typename my_is_subranged<T,S>::type IsSubranged ; | |
246 | typedef typename my_is_trivial <T,S>::type IsTrivial ; | |
247 | ||
248 | typedef typename mpl::if_<IsSubranged,subranged,non_subranged>::type non_trivial ; | |
249 | ||
250 | typedef typename mpl::if_<IsTrivial,trivial,non_trivial>::type type ; | |
251 | } ; | |
252 | ||
253 | // This macro generates the code that compares a non-type field | |
254 | // in boost::numeric::conversion_traits<> with its corresponding field | |
255 | // in expected_traits<> | |
256 | // | |
257 | ||
258 | #define TEST_VALUE_FIELD(Name) \ | |
259 | typedef typename traits::Name BOOST_PP_CAT(t,Name) ; \ | |
260 | typedef typename expected::Name BOOST_PP_CAT(x,Name) ; \ | |
261 | BOOST_CHECK_MESSAGE ( ( BOOST_PP_CAT(t,Name)::value == BOOST_PP_CAT(x,Name)::value ) , \ | |
262 | "conversion_traits<" << typeid(T).name() << "," << typeid(S).name() \ | |
263 | << ">::" << #Name << " = " << to_string(BOOST_PP_CAT(t,Name)::value) \ | |
264 | << ". Expected: " << to_string(BOOST_PP_CAT(x,Name)::value) \ | |
265 | ) ; | |
266 | ||
267 | // This macro generates the code that compares a type field | |
268 | // in numeric::conversion_traits<> with its corresponding field | |
269 | // in expected_traits<> | |
270 | // | |
271 | #define TEST_TYPE_FIELD(Name) \ | |
272 | typedef typename traits::Name BOOST_PP_CAT(t,Name) ; \ | |
273 | typedef typename expected::Name BOOST_PP_CAT(x,Name) ; \ | |
274 | BOOST_CHECK_MESSAGE ( ( typeid(BOOST_PP_CAT(t,Name)) == typeid(BOOST_PP_CAT(x,Name)) ) , \ | |
275 | "conversion_traits<" << typeid(T).name() << "," << typeid(S).name() \ | |
276 | << ">::" << #Name << " = " << typeid(BOOST_PP_CAT(t,Name)).name() \ | |
277 | << ". Expected: " << typeid(BOOST_PP_CAT(x,Name)).name() \ | |
278 | ) ; | |
279 | ||
280 | // | |
281 | // Test core. | |
282 | // Compares each field of boost::numeric::conversion_traits<T,S> | |
283 | // with the corresponding field of expected_traits<T,S> | |
284 | // | |
285 | template<class T, class S> | |
286 | void test_traits_base( MATCH_FNTPL_ARG(T), MATCH_FNTPL_ARG(S) ) | |
287 | { | |
288 | typedef boost::numeric::conversion_traits<T,S> traits ; | |
289 | typedef typename generate_expected_traits<T,S>::type expected ; | |
290 | ||
291 | TEST_VALUE_FIELD(int_float_mixture) ; | |
292 | TEST_VALUE_FIELD(sign_mixture) ; | |
293 | TEST_VALUE_FIELD(udt_builtin_mixture) ; | |
294 | TEST_VALUE_FIELD(subranged) ; | |
295 | TEST_VALUE_FIELD(trivial) ; | |
296 | TEST_TYPE_FIELD (supertype) ; | |
297 | TEST_TYPE_FIELD (subtype) ; | |
298 | } | |
299 | ||
300 | ||
301 | template<class S> | |
302 | void test_traits_from( MATCH_FNTPL_ARG(S) ) | |
303 | { | |
304 | test_traits_base( SET_FNTPL_ARG(boost::uint8_t) ,SET_FNTPL_ARG(S) ); | |
305 | test_traits_base( SET_FNTPL_ARG(boost::int8_t) ,SET_FNTPL_ARG(S) ); | |
306 | test_traits_base( SET_FNTPL_ARG(boost::uint16_t) ,SET_FNTPL_ARG(S) ); | |
307 | test_traits_base( SET_FNTPL_ARG(boost::int16_t) ,SET_FNTPL_ARG(S) ); | |
308 | test_traits_base( SET_FNTPL_ARG(boost::uint32_t) ,SET_FNTPL_ARG(S) ); | |
309 | test_traits_base( SET_FNTPL_ARG(boost::int32_t) ,SET_FNTPL_ARG(S) ); | |
310 | test_traits_base( SET_FNTPL_ARG(float) ,SET_FNTPL_ARG(S) ); | |
311 | test_traits_base( SET_FNTPL_ARG(double) ,SET_FNTPL_ARG(S) ); | |
312 | test_traits_base( SET_FNTPL_ARG(long double) ,SET_FNTPL_ARG(S) ); | |
313 | test_traits_base( SET_FNTPL_ARG(MyInt) ,SET_FNTPL_ARG(S) ); | |
314 | test_traits_base( SET_FNTPL_ARG(MyFloat) ,SET_FNTPL_ARG(S) ); | |
315 | } | |
316 | ||
317 | void test_traits() | |
318 | { | |
319 | test_traits_from( SET_FNTPL_ARG(boost::uint8_t) ); | |
320 | test_traits_from( SET_FNTPL_ARG(boost::int8_t) ); | |
321 | test_traits_from( SET_FNTPL_ARG(boost::uint16_t) ); | |
322 | test_traits_from( SET_FNTPL_ARG(boost::int16_t) ); | |
323 | test_traits_from( SET_FNTPL_ARG(boost::uint32_t) ); | |
324 | test_traits_from( SET_FNTPL_ARG(boost::int32_t) ); | |
325 | test_traits_from( SET_FNTPL_ARG(float) ); | |
326 | test_traits_from( SET_FNTPL_ARG(double) ); | |
327 | test_traits_from( SET_FNTPL_ARG(long double) ); | |
328 | test_traits_from( SET_FNTPL_ARG(MyInt) ); | |
329 | test_traits_from( SET_FNTPL_ARG(MyFloat) ); | |
330 | } | |
331 | ||
332 | int test_main( int, char * []) | |
333 | { | |
334 | std::cout << std::setprecision( std::numeric_limits<long double>::digits10 ) ; | |
335 | ||
336 | test_traits(); | |
337 | ||
338 | return 0; | |
339 | } | |
340 | //--------------------------------------------------------------------------- | |
341 |