31
|
1 |
#include <algorithm>
|
|
2 |
#include <vector>
|
|
3 |
#include <string>
|
|
4 |
|
|
5 |
#include "cppunit/cppunit_proxy.h"
|
|
6 |
|
|
7 |
#if defined (_STLP_USE_NAMESPACES)
|
|
8 |
using namespace std;
|
|
9 |
#endif
|
|
10 |
|
|
11 |
//
|
|
12 |
// TestCase class
|
|
13 |
//
|
|
14 |
class TypeTraitsTest : public CPPUNIT_NS::TestCase
|
|
15 |
{
|
|
16 |
CPPUNIT_TEST_SUITE(TypeTraitsTest);
|
|
17 |
#if !defined (STLPORT)
|
|
18 |
CPPUNIT_IGNORE;
|
|
19 |
#endif
|
|
20 |
CPPUNIT_TEST(manips);
|
|
21 |
CPPUNIT_TEST(integer);
|
|
22 |
CPPUNIT_TEST(rational);
|
|
23 |
CPPUNIT_TEST(pointer_type);
|
|
24 |
#if defined (STLPORT) && !defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
|
25 |
CPPUNIT_IGNORE;
|
|
26 |
#endif
|
|
27 |
CPPUNIT_TEST(reference_type);
|
|
28 |
#if defined (STLPORT)
|
|
29 |
CPPUNIT_STOP_IGNORE;
|
|
30 |
#endif
|
|
31 |
CPPUNIT_TEST(both_pointer_type);
|
|
32 |
CPPUNIT_TEST(ok_to_use_memcpy);
|
|
33 |
CPPUNIT_TEST(ok_to_use_memmove);
|
|
34 |
CPPUNIT_TEST(trivial_destructor);
|
|
35 |
CPPUNIT_TEST(is_POD);
|
|
36 |
CPPUNIT_TEST(stlport_class);
|
|
37 |
CPPUNIT_TEST_SUITE_END();
|
|
38 |
|
|
39 |
protected:
|
|
40 |
void manips();
|
|
41 |
void integer();
|
|
42 |
void rational();
|
|
43 |
void pointer_type();
|
|
44 |
void reference_type();
|
|
45 |
void both_pointer_type();
|
|
46 |
void ok_to_use_memcpy();
|
|
47 |
void ok_to_use_memmove();
|
|
48 |
void trivial_destructor();
|
|
49 |
void is_POD();
|
|
50 |
void stlport_class();
|
|
51 |
};
|
|
52 |
|
|
53 |
CPPUNIT_TEST_SUITE_REGISTRATION(TypeTraitsTest);
|
|
54 |
|
|
55 |
#if defined (STLPORT)
|
|
56 |
|
|
57 |
# if defined (__GNUC__) && defined (_STLP_USE_NAMESPACES)
|
|
58 |
// libstdc++ sometimes exposed its own __true_type type in global
|
|
59 |
// namespace resulting in an ambiguity.
|
|
60 |
# define __true_type std::__true_type
|
|
61 |
# define __false_type std::__false_type
|
|
62 |
# endif
|
|
63 |
|
|
64 |
int type_to_value(__true_type)
|
|
65 |
{ return 1; }
|
|
66 |
int type_to_value(__false_type)
|
|
67 |
{ return 0; }
|
|
68 |
|
|
69 |
int* int_pointer;
|
|
70 |
int const* int_const_pointer;
|
|
71 |
int volatile* int_volatile_pointer;
|
|
72 |
int const volatile* int_const_volatile_pointer;
|
|
73 |
int int_val = 0;
|
|
74 |
int const int_const_val = 0;
|
|
75 |
int volatile int_volatile_val = 0;
|
|
76 |
int & int_ref = int_val;
|
|
77 |
int const& int_const_ref = int_val;
|
|
78 |
int const volatile& int_const_volatile_ref = int_val;
|
|
79 |
|
|
80 |
//A type that represent any type:
|
|
81 |
struct any_type
|
|
82 |
{
|
|
83 |
//Dummy operations to forbid to compilers with intrinsic
|
|
84 |
//type traits support to consider this type as a POD.
|
|
85 |
any_type() : m_data(1) {}
|
|
86 |
any_type(const any_type&) : m_data(2) {}
|
|
87 |
any_type& operator = (const any_type&)
|
|
88 |
{ m_data = 3; return *this; }
|
|
89 |
~any_type() { m_data = 0; }
|
|
90 |
|
|
91 |
size_t m_data;
|
|
92 |
};
|
|
93 |
|
|
94 |
any_type any;
|
|
95 |
any_type* any_pointer;
|
|
96 |
any_type const* any_const_pointer;
|
|
97 |
any_type volatile* any_volatile_pointer;
|
|
98 |
any_type const volatile* any_const_volatile_pointer;
|
|
99 |
|
|
100 |
//A type that represent any pod type
|
|
101 |
struct any_pod_type
|
|
102 |
{};
|
|
103 |
|
|
104 |
# if defined (_STLP_USE_BOOST_SUPPORT)
|
|
105 |
//Mandatory for compilers without without partial template specialization.
|
|
106 |
BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION(any_pod_type)
|
|
107 |
# endif
|
|
108 |
|
|
109 |
any_pod_type any_pod;
|
|
110 |
any_pod_type* any_pod_pointer;
|
|
111 |
any_pod_type const* any_pod_const_pointer;
|
|
112 |
any_pod_type volatile* any_pod_volatile_pointer;
|
|
113 |
any_pod_type const volatile* any_pod_const_volatile_pointer;
|
|
114 |
|
|
115 |
namespace std {
|
|
116 |
_STLP_TEMPLATE_NULL
|
|
117 |
struct __type_traits<any_pod_type> {
|
|
118 |
typedef __true_type has_trivial_default_constructor;
|
|
119 |
typedef __true_type has_trivial_copy_constructor;
|
|
120 |
typedef __true_type has_trivial_assignment_operator;
|
|
121 |
typedef __true_type has_trivial_destructor;
|
|
122 |
typedef __true_type is_POD_type;
|
|
123 |
};
|
|
124 |
}
|
|
125 |
|
|
126 |
struct base
|
|
127 |
{};
|
|
128 |
struct derived : public base
|
|
129 |
{};
|
|
130 |
|
|
131 |
//
|
|
132 |
// tests implementation
|
|
133 |
//
|
|
134 |
template <typename _Tp1, typename _Tp2>
|
|
135 |
int are_same_uncv_types(_Tp1, _Tp2) {
|
|
136 |
typedef typename _AreSameUnCVTypes<_Tp1, _Tp2>::_Ret _Ret;
|
|
137 |
return type_to_value(_Ret());
|
|
138 |
}
|
|
139 |
|
|
140 |
template <typename _Src, typename _Dst>
|
|
141 |
int is_convertible(_Src, _Dst) {
|
|
142 |
# if !defined(__BORLANDC__)
|
|
143 |
typedef typename _IsConvertible<_Src, _Dst>::_Ret _Ret;
|
|
144 |
# else
|
|
145 |
enum { _Is = _IsConvertible<_Src, _Dst>::value };
|
|
146 |
typedef typename __bool2type<_Is>::_Ret _Ret;
|
|
147 |
# endif
|
|
148 |
return type_to_value(_Ret());
|
|
149 |
}
|
|
150 |
|
|
151 |
template <typename _Src, typename _Dst>
|
|
152 |
int is_cv_convertible(_Src, _Dst) {
|
|
153 |
# if !defined(__BORLANDC__)
|
|
154 |
typedef typename _IsCVConvertible<_Src, _Dst>::_Ret _Ret;
|
|
155 |
# else
|
|
156 |
enum { _Is = _IsCVConvertible<_Src, _Dst>::value };
|
|
157 |
typedef typename __bool2type<_Is>::_Ret _Ret;
|
|
158 |
# endif
|
|
159 |
return type_to_value(_Ret());
|
|
160 |
}
|
|
161 |
#endif
|
|
162 |
|
|
163 |
void TypeTraitsTest::manips()
|
|
164 |
{
|
|
165 |
#if defined (STLPORT)
|
|
166 |
{
|
|
167 |
typedef __bool2type<0>::_Ret _ZeroRet;
|
|
168 |
CPPUNIT_ASSERT( type_to_value(_ZeroRet()) == 0 );
|
|
169 |
typedef __bool2type<1>::_Ret _OneRet;
|
|
170 |
CPPUNIT_ASSERT( type_to_value(_OneRet()) == 1 );
|
|
171 |
typedef __bool2type<65456873>::_Ret _AnyRet;
|
|
172 |
CPPUNIT_ASSERT( type_to_value(_AnyRet()) == 1 );
|
|
173 |
}
|
|
174 |
|
|
175 |
{
|
|
176 |
CPPUNIT_ASSERT( __type2bool<__true_type>::_Ret == 1 );
|
|
177 |
CPPUNIT_ASSERT( __type2bool<__false_type>::_Ret == 0 );
|
|
178 |
CPPUNIT_ASSERT( __type2bool<any_type>::_Ret == 1 );
|
|
179 |
}
|
|
180 |
|
|
181 |
{
|
|
182 |
typedef _Not<__true_type>::_Ret _NotTrueRet;
|
|
183 |
CPPUNIT_ASSERT( type_to_value(_NotTrueRet()) == 0 );
|
|
184 |
typedef _Not<__false_type>::_Ret _NotFalseRet;
|
|
185 |
CPPUNIT_ASSERT( type_to_value(_NotFalseRet()) == 1 );
|
|
186 |
}
|
|
187 |
|
|
188 |
{
|
|
189 |
typedef _Land2<__true_type, __true_type>::_Ret _TrueTrueRet;
|
|
190 |
CPPUNIT_ASSERT( type_to_value(_TrueTrueRet()) == 1 );
|
|
191 |
typedef _Land2<__true_type, __false_type>::_Ret _TrueFalseRet;
|
|
192 |
CPPUNIT_ASSERT( type_to_value(_TrueFalseRet()) == 0 );
|
|
193 |
typedef _Land2<__false_type, __true_type>::_Ret _FalseTrueRet;
|
|
194 |
CPPUNIT_ASSERT( type_to_value(_FalseTrueRet()) == 0 );
|
|
195 |
typedef _Land2<__false_type, __false_type>::_Ret _FalseFalseRet;
|
|
196 |
CPPUNIT_ASSERT( type_to_value(_FalseFalseRet()) == 0 );
|
|
197 |
}
|
|
198 |
|
|
199 |
{
|
|
200 |
typedef _Land3<__true_type, __true_type, __true_type>::_Ret _TrueTrueTrueRet;
|
|
201 |
CPPUNIT_ASSERT( type_to_value(_TrueTrueTrueRet()) == 1 );
|
|
202 |
typedef _Land3<__true_type, __true_type, __false_type>::_Ret _TrueTrueFalseRet;
|
|
203 |
CPPUNIT_ASSERT( type_to_value(_TrueTrueFalseRet()) == 0 );
|
|
204 |
typedef _Land3<__true_type, __false_type, __true_type>::_Ret _TrueFalseTrueRet;
|
|
205 |
CPPUNIT_ASSERT( type_to_value(_TrueFalseTrueRet()) == 0 );
|
|
206 |
typedef _Land3<__true_type, __false_type, __false_type>::_Ret _TrueFalseFalseRet;
|
|
207 |
CPPUNIT_ASSERT( type_to_value(_TrueFalseFalseRet()) == 0 );
|
|
208 |
typedef _Land3<__false_type, __true_type, __true_type>::_Ret _FalseTrueTrueRet;
|
|
209 |
CPPUNIT_ASSERT( type_to_value(_FalseTrueTrueRet()) == 0 );
|
|
210 |
typedef _Land3<__false_type, __true_type, __false_type>::_Ret _FalseTrueFalseRet;
|
|
211 |
CPPUNIT_ASSERT( type_to_value(_FalseTrueFalseRet()) == 0 );
|
|
212 |
typedef _Land3<__false_type, __false_type, __true_type>::_Ret _FalseFalseTrueRet;
|
|
213 |
CPPUNIT_ASSERT( type_to_value(_FalseFalseTrueRet()) == 0 );
|
|
214 |
typedef _Land3<__false_type, __false_type, __false_type>::_Ret _FalseFalseFalseRet;
|
|
215 |
CPPUNIT_ASSERT( type_to_value(_FalseFalseFalseRet()) == 0 );
|
|
216 |
}
|
|
217 |
|
|
218 |
{
|
|
219 |
typedef _Lor2<__true_type, __true_type>::_Ret _TrueTrueRet;
|
|
220 |
CPPUNIT_ASSERT( type_to_value(_TrueTrueRet()) == 1 );
|
|
221 |
typedef _Lor2<__true_type, __false_type>::_Ret _TrueFalseRet;
|
|
222 |
CPPUNIT_ASSERT( type_to_value(_TrueFalseRet()) == 1 );
|
|
223 |
typedef _Lor2<__false_type, __true_type>::_Ret _FalseTrueRet;
|
|
224 |
CPPUNIT_ASSERT( type_to_value(_FalseTrueRet()) == 1 );
|
|
225 |
typedef _Lor2<__false_type, __false_type>::_Ret _FalseFalseRet;
|
|
226 |
CPPUNIT_ASSERT( type_to_value(_FalseFalseRet()) == 0 );
|
|
227 |
}
|
|
228 |
|
|
229 |
{
|
|
230 |
typedef _Lor3<__true_type, __true_type, __true_type>::_Ret _TrueTrueTrueRet;
|
|
231 |
CPPUNIT_ASSERT( type_to_value(_TrueTrueTrueRet()) == 1 );
|
|
232 |
typedef _Lor3<__true_type, __true_type, __false_type>::_Ret _TrueTrueFalseRet;
|
|
233 |
CPPUNIT_ASSERT( type_to_value(_TrueTrueFalseRet()) == 1 );
|
|
234 |
typedef _Lor3<__true_type, __false_type, __true_type>::_Ret _TrueFalseTrueRet;
|
|
235 |
CPPUNIT_ASSERT( type_to_value(_TrueFalseTrueRet()) == 1 );
|
|
236 |
typedef _Lor3<__true_type, __false_type, __false_type>::_Ret _TrueFalseFalseRet;
|
|
237 |
CPPUNIT_ASSERT( type_to_value(_TrueFalseFalseRet()) == 1 );
|
|
238 |
typedef _Lor3<__false_type, __true_type, __true_type>::_Ret _FalseTrueTrueRet;
|
|
239 |
CPPUNIT_ASSERT( type_to_value(_FalseTrueTrueRet()) == 1 );
|
|
240 |
typedef _Lor3<__false_type, __true_type, __false_type>::_Ret _FalseTrueFalseRet;
|
|
241 |
CPPUNIT_ASSERT( type_to_value(_FalseTrueFalseRet()) == 1 );
|
|
242 |
typedef _Lor3<__false_type, __false_type, __true_type>::_Ret _FalseFalseTrueRet;
|
|
243 |
CPPUNIT_ASSERT( type_to_value(_FalseFalseTrueRet()) == 1 );
|
|
244 |
typedef _Lor3<__false_type, __false_type, __false_type>::_Ret _FalseFalseFalseRet;
|
|
245 |
CPPUNIT_ASSERT( type_to_value(_FalseFalseFalseRet()) == 0 );
|
|
246 |
}
|
|
247 |
|
|
248 |
{
|
|
249 |
# if !defined (__BORLANDC__)
|
|
250 |
typedef __select<1, __true_type, __false_type>::_Ret _SelectFirstRet;
|
|
251 |
CPPUNIT_ASSERT( type_to_value(_SelectFirstRet()) == 1 );
|
|
252 |
typedef __select<0, __true_type, __false_type>::_Ret _SelectSecondRet;
|
|
253 |
CPPUNIT_ASSERT( type_to_value(_SelectSecondRet()) == 0 );
|
|
254 |
# else
|
|
255 |
typedef __selectT<__true_type(), __true_type, __false_type>::_Ret _SelectFirstRet;
|
|
256 |
CPPUNIT_ASSERT( type_to_value(_SelectFirstRet()) == 1 );
|
|
257 |
typedef __selectT<__false_type(), __true_type, __false_type>::_Ret _SelectSecondRet;
|
|
258 |
CPPUNIT_ASSERT( type_to_value(_SelectSecondRet()) == 0 );
|
|
259 |
# endif
|
|
260 |
}
|
|
261 |
|
|
262 |
{
|
|
263 |
CPPUNIT_ASSERT( are_same_uncv_types(int_val, int_val) == 1 );
|
|
264 |
CPPUNIT_ASSERT( are_same_uncv_types(int_val, int_const_val) == 1 );
|
|
265 |
CPPUNIT_ASSERT( are_same_uncv_types(int_val, int_volatile_val) == 1 );
|
|
266 |
CPPUNIT_ASSERT( are_same_uncv_types(int_const_val, int_val) == 1 );
|
|
267 |
CPPUNIT_ASSERT( are_same_uncv_types(int_volatile_val, int_val) == 1 );
|
|
268 |
CPPUNIT_ASSERT( are_same_uncv_types(int_val, int_pointer) == 0 );
|
|
269 |
CPPUNIT_ASSERT( are_same_uncv_types(int_pointer, int_val) == 0 );
|
|
270 |
CPPUNIT_ASSERT( are_same_uncv_types(int_pointer, int_pointer) == 1 );
|
|
271 |
CPPUNIT_ASSERT( are_same_uncv_types(int_pointer, int_const_pointer) == 0 );
|
|
272 |
CPPUNIT_ASSERT( are_same_uncv_types(int_pointer, int_const_volatile_pointer) == 0 );
|
|
273 |
CPPUNIT_ASSERT( are_same_uncv_types(int_const_pointer, int_const_pointer) == 1 );
|
|
274 |
CPPUNIT_ASSERT( are_same_uncv_types(int_const_pointer, int_const_volatile_pointer) == 0 );
|
|
275 |
CPPUNIT_ASSERT( are_same_uncv_types(any, any) == 1 );
|
|
276 |
CPPUNIT_ASSERT( are_same_uncv_types(any, any_pointer) == 0 );
|
|
277 |
CPPUNIT_ASSERT( are_same_uncv_types(any_pointer, any_pointer) == 1 );
|
|
278 |
CPPUNIT_ASSERT( are_same_uncv_types(any_const_pointer, any_const_pointer) == 1 );
|
|
279 |
CPPUNIT_ASSERT( are_same_uncv_types(any_const_volatile_pointer, any_const_volatile_pointer) == 1 );
|
|
280 |
}
|
|
281 |
|
|
282 |
{
|
|
283 |
base b;
|
|
284 |
derived d;
|
|
285 |
const derived cd = d;
|
|
286 |
base *pb = &b;
|
|
287 |
derived *pd = &d;
|
|
288 |
derived const *pcd = pd;
|
|
289 |
CPPUNIT_CHECK( is_convertible(any, b) == 0 );
|
|
290 |
CPPUNIT_CHECK( is_convertible(d, b) == 1 );
|
|
291 |
CPPUNIT_CHECK( is_convertible(cd, b) == 1 );
|
|
292 |
// _IsCVConvertible only needs to work for pointer type:
|
|
293 |
//CPPUNIT_CHECK( is_cv_convertible(d, b) == 1 );
|
|
294 |
//CPPUNIT_CHECK( is_cv_convertible(cd, b) == 0 );
|
|
295 |
|
|
296 |
//_IsConvertible do not need to work for pointers:
|
|
297 |
//CPPUNIT_CHECK( is_convertible(pd, pb) == 1 );
|
|
298 |
//CPPUNIT_CHECK( is_convertible(pcd, pb) == 1 );
|
|
299 |
|
|
300 |
CPPUNIT_CHECK( is_cv_convertible(pd, pb) == 1 );
|
|
301 |
CPPUNIT_CHECK( is_cv_convertible(pcd, pb) == 0 );
|
|
302 |
}
|
|
303 |
#endif
|
|
304 |
}
|
|
305 |
|
|
306 |
#if defined (STLPORT)
|
|
307 |
template <typename _Type>
|
|
308 |
int is_integer(_Type) {
|
|
309 |
typedef typename _IsIntegral<_Type>::_Ret _Ret;
|
|
310 |
return type_to_value(_Ret());
|
|
311 |
}
|
|
312 |
#endif
|
|
313 |
|
|
314 |
void TypeTraitsTest::integer()
|
|
315 |
{
|
|
316 |
#if defined (STLPORT)
|
|
317 |
CPPUNIT_ASSERT( is_integer(bool()) == 1 );
|
|
318 |
CPPUNIT_ASSERT( is_integer(char()) == 1 );
|
|
319 |
typedef signed char signed_char;
|
|
320 |
CPPUNIT_ASSERT( is_integer(signed_char()) == 1 );
|
|
321 |
typedef unsigned char unsigned_char;
|
|
322 |
CPPUNIT_ASSERT( is_integer(unsigned_char()) == 1 );
|
|
323 |
# if defined (_STLP_HAS_WCHAR_T)
|
|
324 |
CPPUNIT_ASSERT( is_integer(wchar_t()) == 1 );
|
|
325 |
# endif
|
|
326 |
CPPUNIT_ASSERT( is_integer(short()) == 1 );
|
|
327 |
typedef unsigned short unsigned_short;
|
|
328 |
CPPUNIT_ASSERT( is_integer(unsigned_short()) == 1 );
|
|
329 |
CPPUNIT_ASSERT( is_integer(int()) == 1 );
|
|
330 |
typedef unsigned int unsigned_int;
|
|
331 |
CPPUNIT_ASSERT( is_integer(unsigned_int()) == 1 );
|
|
332 |
CPPUNIT_ASSERT( is_integer(long()) == 1 );
|
|
333 |
typedef unsigned long unsigned_long;
|
|
334 |
CPPUNIT_ASSERT( is_integer(unsigned_long()) == 1 );
|
|
335 |
# if defined (_STLP_LONG_LONG)
|
|
336 |
typedef _STLP_LONG_LONG long_long;
|
|
337 |
CPPUNIT_ASSERT( is_integer(long_long()) == 1 );
|
|
338 |
typedef unsigned _STLP_LONG_LONG unsigned_long_long;
|
|
339 |
CPPUNIT_ASSERT( is_integer(unsigned_long_long()) == 1 );
|
|
340 |
# endif
|
|
341 |
CPPUNIT_ASSERT( is_integer(float()) == 0 );
|
|
342 |
CPPUNIT_ASSERT( is_integer(double()) == 0 );
|
|
343 |
# if !defined ( _STLP_NO_LONG_DOUBLE )
|
|
344 |
typedef long double long_double;
|
|
345 |
CPPUNIT_ASSERT( is_integer(long_double()) == 0 );
|
|
346 |
# endif
|
|
347 |
CPPUNIT_ASSERT( is_integer(any) == 0 );
|
|
348 |
CPPUNIT_ASSERT( is_integer(any_pointer) == 0 );
|
|
349 |
#endif
|
|
350 |
}
|
|
351 |
|
|
352 |
#if defined (STLPORT)
|
|
353 |
template <typename _Type>
|
|
354 |
int is_rational(_Type) {
|
|
355 |
typedef typename _IsRational<_Type>::_Ret _Ret;
|
|
356 |
return type_to_value(_Ret());
|
|
357 |
}
|
|
358 |
#endif
|
|
359 |
|
|
360 |
void TypeTraitsTest::rational()
|
|
361 |
{
|
|
362 |
#if defined (STLPORT)
|
|
363 |
CPPUNIT_ASSERT( is_rational(bool()) == 0 );
|
|
364 |
CPPUNIT_ASSERT( is_rational(char()) == 0 );
|
|
365 |
typedef signed char signed_char;
|
|
366 |
CPPUNIT_ASSERT( is_rational(signed_char()) == 0 );
|
|
367 |
typedef unsigned char unsigned_char;
|
|
368 |
CPPUNIT_ASSERT( is_rational(unsigned_char()) == 0 );
|
|
369 |
# if defined (_STLP_HAS_WCHAR_T)
|
|
370 |
CPPUNIT_ASSERT( is_rational(wchar_t()) == 0 );
|
|
371 |
# endif
|
|
372 |
CPPUNIT_ASSERT( is_rational(short()) == 0 );
|
|
373 |
typedef unsigned short unsigned_short;
|
|
374 |
CPPUNIT_ASSERT( is_rational(unsigned_short()) == 0 );
|
|
375 |
CPPUNIT_ASSERT( is_rational(int()) == 0 );
|
|
376 |
typedef unsigned int unsigned_int;
|
|
377 |
CPPUNIT_ASSERT( is_rational(unsigned_int()) == 0 );
|
|
378 |
CPPUNIT_ASSERT( is_rational(long()) == 0 );
|
|
379 |
typedef unsigned long unsigned_long;
|
|
380 |
CPPUNIT_ASSERT( is_rational(unsigned_long()) == 0 );
|
|
381 |
# if defined (_STLP_LONG_LONG)
|
|
382 |
typedef _STLP_LONG_LONG long_long;
|
|
383 |
CPPUNIT_ASSERT( is_rational(long_long()) == 0 );
|
|
384 |
typedef unsigned _STLP_LONG_LONG unsigned_long_long;
|
|
385 |
CPPUNIT_ASSERT( is_rational(unsigned_long_long()) == 0 );
|
|
386 |
# endif
|
|
387 |
CPPUNIT_ASSERT( is_rational(float()) == 1 );
|
|
388 |
CPPUNIT_ASSERT( is_rational(double()) == 1 );
|
|
389 |
# if !defined ( _STLP_NO_LONG_DOUBLE )
|
|
390 |
typedef long double long_double;
|
|
391 |
CPPUNIT_ASSERT( is_rational(long_double()) == 1 );
|
|
392 |
# endif
|
|
393 |
CPPUNIT_ASSERT( is_rational(any) == 0 );
|
|
394 |
CPPUNIT_ASSERT( is_rational(any_pointer) == 0 );
|
|
395 |
#endif
|
|
396 |
}
|
|
397 |
|
|
398 |
#if defined (STLPORT)
|
|
399 |
template <typename _Type>
|
|
400 |
int is_pointer_type(_Type) {
|
|
401 |
return type_to_value(_IsPtrType<_Type>::_Ret());
|
|
402 |
}
|
|
403 |
#endif
|
|
404 |
|
|
405 |
void TypeTraitsTest::pointer_type()
|
|
406 |
{
|
|
407 |
#if defined (STLPORT)
|
|
408 |
CPPUNIT_ASSERT( is_pointer_type(int_val) == 0 );
|
|
409 |
CPPUNIT_ASSERT( is_pointer_type(int_pointer) == 1 );
|
|
410 |
CPPUNIT_ASSERT( is_pointer_type(int_const_pointer) == 1 );
|
|
411 |
CPPUNIT_ASSERT( is_pointer_type(int_volatile_pointer) == 1 );
|
|
412 |
CPPUNIT_ASSERT( is_pointer_type(int_const_volatile_pointer) == 1 );
|
|
413 |
CPPUNIT_ASSERT( is_pointer_type(int_ref) == 0 );
|
|
414 |
CPPUNIT_ASSERT( is_pointer_type(int_const_ref) == 0 );
|
|
415 |
CPPUNIT_ASSERT( is_pointer_type(any) == 0 );
|
|
416 |
CPPUNIT_ASSERT( is_pointer_type(any_pointer) == 1 );
|
|
417 |
#endif
|
|
418 |
}
|
|
419 |
|
|
420 |
void TypeTraitsTest::reference_type()
|
|
421 |
{
|
|
422 |
#if defined (STLPORT) && defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
|
423 |
CPPUNIT_ASSERT( type_to_value(_IsRefType<int>::_Ret()) == 0 );
|
|
424 |
CPPUNIT_ASSERT( type_to_value(_IsRefType<int*>::_Ret()) == 0 );
|
|
425 |
CPPUNIT_ASSERT( type_to_value(_IsRefType<int&>::_Ret()) == 1 );
|
|
426 |
CPPUNIT_ASSERT( type_to_value(_IsRefType<int const&>::_Ret()) == 1 );
|
|
427 |
CPPUNIT_ASSERT( type_to_value(_IsRefType<int const volatile&>::_Ret()) == 1 );
|
|
428 |
|
|
429 |
CPPUNIT_ASSERT( type_to_value(_IsOKToSwap(int_pointer, int_pointer, __true_type(), __true_type())._Answer()) == 1 );
|
|
430 |
CPPUNIT_ASSERT( type_to_value(_IsOKToSwap(int_pointer, int_pointer, __false_type(), __false_type())._Answer()) == 0 );
|
|
431 |
#endif
|
|
432 |
}
|
|
433 |
|
|
434 |
#if defined (STLPORT)
|
|
435 |
template <typename _Tp1, typename _Tp2>
|
|
436 |
int are_both_pointer_type (_Tp1, _Tp2) {
|
|
437 |
return type_to_value(_BothPtrType<_Tp1, _Tp2>::_Answer());
|
|
438 |
}
|
|
439 |
#endif
|
|
440 |
|
|
441 |
void TypeTraitsTest::both_pointer_type()
|
|
442 |
{
|
|
443 |
#if defined (STLPORT)
|
|
444 |
CPPUNIT_ASSERT( are_both_pointer_type(int_val, int_val) == 0 );
|
|
445 |
CPPUNIT_ASSERT( are_both_pointer_type(int_pointer, int_pointer) == 1 );
|
|
446 |
CPPUNIT_ASSERT( are_both_pointer_type(int_const_pointer, int_const_pointer) == 1 );
|
|
447 |
CPPUNIT_ASSERT( are_both_pointer_type(int_volatile_pointer, int_volatile_pointer) == 1 );
|
|
448 |
CPPUNIT_ASSERT( are_both_pointer_type(int_const_volatile_pointer, int_const_volatile_pointer) == 1 );
|
|
449 |
CPPUNIT_ASSERT( are_both_pointer_type(int_ref, int_ref) == 0 );
|
|
450 |
CPPUNIT_ASSERT( are_both_pointer_type(int_const_ref, int_const_ref) == 0 );
|
|
451 |
CPPUNIT_ASSERT( are_both_pointer_type(any, any) == 0 );
|
|
452 |
CPPUNIT_ASSERT( are_both_pointer_type(any_pointer, any_pointer) == 1 );
|
|
453 |
#endif
|
|
454 |
}
|
|
455 |
|
|
456 |
#if defined (STLPORT)
|
|
457 |
template <typename _Tp1, typename _Tp2>
|
|
458 |
int is_ok_to_use_memcpy(_Tp1 val1, _Tp2 val2) {
|
|
459 |
return type_to_value(_UseTrivialCopy(val1, val2)._Answer());
|
|
460 |
}
|
|
461 |
#endif
|
|
462 |
|
|
463 |
void TypeTraitsTest::ok_to_use_memcpy()
|
|
464 |
{
|
|
465 |
#if defined (STLPORT)
|
|
466 |
CPPUNIT_ASSERT( is_ok_to_use_memcpy(int_pointer, int_pointer) == 1 );
|
|
467 |
CPPUNIT_ASSERT( is_ok_to_use_memcpy(int_const_pointer, int_pointer) == 1 );
|
|
468 |
CPPUNIT_ASSERT( is_ok_to_use_memcpy(int_pointer, int_volatile_pointer) == 1 );
|
|
469 |
CPPUNIT_ASSERT( is_ok_to_use_memcpy(int_pointer, int_const_volatile_pointer) == 1 );
|
|
470 |
CPPUNIT_ASSERT( is_ok_to_use_memcpy(int_const_pointer, int_const_pointer) == 1 );
|
|
471 |
CPPUNIT_ASSERT( is_ok_to_use_memcpy(int_const_pointer, int_volatile_pointer) == 1 );
|
|
472 |
CPPUNIT_ASSERT( is_ok_to_use_memcpy(int_const_pointer, int_const_volatile_pointer) == 1 );
|
|
473 |
CPPUNIT_ASSERT( is_ok_to_use_memcpy(int_const_volatile_pointer, int_const_volatile_pointer) == 1 );
|
|
474 |
CPPUNIT_ASSERT( is_ok_to_use_memcpy(int_pointer, any_pointer) == 0 );
|
|
475 |
CPPUNIT_ASSERT( is_ok_to_use_memcpy(any_pointer, int_pointer) == 0 );
|
|
476 |
CPPUNIT_ASSERT( is_ok_to_use_memcpy(any_pointer, any_pointer) == 0 );
|
|
477 |
CPPUNIT_ASSERT( is_ok_to_use_memcpy(any_pointer, any_const_pointer) == 0 );
|
|
478 |
CPPUNIT_ASSERT( is_ok_to_use_memcpy(any_pod_pointer, int_pointer) == 0 );
|
|
479 |
CPPUNIT_ASSERT( is_ok_to_use_memcpy(any_pod_pointer, any_pod_pointer) == 1 );
|
|
480 |
CPPUNIT_ASSERT( is_ok_to_use_memcpy(any_pod_pointer, any_pod_const_pointer) == 1 );
|
|
481 |
vector<float> **pvf = 0;
|
|
482 |
vector<int> **pvi = 0;
|
|
483 |
CPPUNIT_ASSERT( is_ok_to_use_memcpy(pvf, pvi) == 0 );
|
|
484 |
CPPUNIT_ASSERT( is_ok_to_use_memcpy(pvi, pvf) == 0 );
|
|
485 |
#endif
|
|
486 |
}
|
|
487 |
|
|
488 |
#if defined (STLPORT)
|
|
489 |
template <typename _Tp1, typename _Tp2>
|
|
490 |
int is_ok_to_use_memmove(_Tp1 val1, _Tp2 val2) {
|
|
491 |
return type_to_value(_UseTrivialUCopy(val1, val2)._Answer());
|
|
492 |
}
|
|
493 |
#endif
|
|
494 |
|
|
495 |
void TypeTraitsTest::ok_to_use_memmove()
|
|
496 |
{
|
|
497 |
#if defined (STLPORT)
|
|
498 |
CPPUNIT_ASSERT( is_ok_to_use_memmove(int_pointer, int_pointer) == 1 );
|
|
499 |
CPPUNIT_ASSERT( is_ok_to_use_memmove(int_const_pointer, int_pointer) == 1 );
|
|
500 |
CPPUNIT_ASSERT( is_ok_to_use_memmove(int_pointer, int_volatile_pointer) == 1 );
|
|
501 |
CPPUNIT_ASSERT( is_ok_to_use_memmove(int_pointer, int_const_volatile_pointer) == 1 );
|
|
502 |
CPPUNIT_ASSERT( is_ok_to_use_memmove(int_const_pointer, int_const_pointer) == 1 );
|
|
503 |
CPPUNIT_ASSERT( is_ok_to_use_memmove(int_const_pointer, int_volatile_pointer) == 1 );
|
|
504 |
CPPUNIT_ASSERT( is_ok_to_use_memmove(int_const_pointer, int_const_volatile_pointer) == 1 );
|
|
505 |
CPPUNIT_ASSERT( is_ok_to_use_memmove(int_const_volatile_pointer, int_const_volatile_pointer) == 1 );
|
|
506 |
CPPUNIT_ASSERT( is_ok_to_use_memmove(int_pointer, any_pointer) == 0 );
|
|
507 |
CPPUNIT_ASSERT( is_ok_to_use_memmove(any_pointer, int_pointer) == 0 );
|
|
508 |
CPPUNIT_ASSERT( is_ok_to_use_memmove(any_pointer, any_pointer) == 0 );
|
|
509 |
CPPUNIT_ASSERT( is_ok_to_use_memmove(any_pointer, any_const_pointer) == 0 );
|
|
510 |
CPPUNIT_ASSERT( is_ok_to_use_memmove(any_pod_pointer, int_pointer) == 0 );
|
|
511 |
CPPUNIT_ASSERT( is_ok_to_use_memmove(any_pod_pointer, any_pod_pointer) == 1 );
|
|
512 |
CPPUNIT_ASSERT( is_ok_to_use_memmove(any_pod_pointer, any_pod_const_pointer) == 1 );
|
|
513 |
#endif
|
|
514 |
}
|
|
515 |
|
|
516 |
#if defined (STLPORT)
|
|
517 |
template <typename _Tp>
|
|
518 |
int has_trivial_destructor(_Tp) {
|
|
519 |
typedef typename __type_traits<_Tp>::has_trivial_destructor _TrivialDestructor;
|
|
520 |
return type_to_value(_TrivialDestructor());
|
|
521 |
}
|
|
522 |
|
|
523 |
struct DestructorMonitor
|
|
524 |
{
|
|
525 |
~DestructorMonitor()
|
|
526 |
{ ++nb_destructor_call; }
|
|
527 |
|
|
528 |
static size_t nb_destructor_call;
|
|
529 |
};
|
|
530 |
|
|
531 |
size_t DestructorMonitor::nb_destructor_call = 0;
|
|
532 |
|
|
533 |
namespace std {
|
|
534 |
_STLP_TEMPLATE_NULL
|
|
535 |
struct __type_traits<DestructorMonitor> {
|
|
536 |
typedef __true_type has_trivial_default_constructor;
|
|
537 |
typedef __true_type has_trivial_copy_constructor;
|
|
538 |
typedef __true_type has_trivial_assignment_operator;
|
|
539 |
typedef __true_type has_trivial_destructor;
|
|
540 |
typedef __true_type is_POD_type;
|
|
541 |
};
|
|
542 |
}
|
|
543 |
#endif
|
|
544 |
|
|
545 |
void TypeTraitsTest::trivial_destructor()
|
|
546 |
{
|
|
547 |
#if defined (STLPORT)
|
|
548 |
CPPUNIT_ASSERT( has_trivial_destructor(int_pointer) == 1 );
|
|
549 |
CPPUNIT_ASSERT( has_trivial_destructor(int_const_pointer) == 1 );
|
|
550 |
CPPUNIT_ASSERT( has_trivial_destructor(int_volatile_pointer) == 1 );
|
|
551 |
CPPUNIT_ASSERT( has_trivial_destructor(int_const_volatile_pointer) == 1 );
|
|
552 |
CPPUNIT_ASSERT( has_trivial_destructor(any_pointer) == 1 );
|
|
553 |
CPPUNIT_ASSERT( has_trivial_destructor(any) == 0 );
|
|
554 |
CPPUNIT_ASSERT( has_trivial_destructor(any_pointer) == 1 );
|
|
555 |
CPPUNIT_ASSERT( has_trivial_destructor(any_pod) == 1 );
|
|
556 |
CPPUNIT_ASSERT( has_trivial_destructor(string()) == 0 );
|
|
557 |
|
|
558 |
//Check of the meta information impact in a container implementation
|
|
559 |
{
|
|
560 |
vector<DestructorMonitor> v(10);
|
|
561 |
DestructorMonitor::nb_destructor_call = 0;
|
|
562 |
}
|
|
563 |
CPPUNIT_ASSERT( DestructorMonitor::nb_destructor_call == 0 );
|
|
564 |
#endif
|
|
565 |
}
|
|
566 |
|
|
567 |
#if defined (STLPORT)
|
|
568 |
template <typename _Tp>
|
|
569 |
int is_POD_type(_Tp) {
|
|
570 |
typedef typename __type_traits<_Tp>::is_POD_type _IsPODType;
|
|
571 |
return type_to_value(_IsPODType());
|
|
572 |
}
|
|
573 |
#endif
|
|
574 |
|
|
575 |
void TypeTraitsTest::is_POD()
|
|
576 |
{
|
|
577 |
#if defined (STLPORT)
|
|
578 |
CPPUNIT_ASSERT( is_POD_type(int_pointer) == 1 );
|
|
579 |
CPPUNIT_ASSERT( is_POD_type(int_const_pointer) == 1 );
|
|
580 |
CPPUNIT_ASSERT( is_POD_type(int_volatile_pointer) == 1 );
|
|
581 |
CPPUNIT_ASSERT( is_POD_type(int_const_volatile_pointer) == 1 );
|
|
582 |
CPPUNIT_ASSERT( is_POD_type(any_pointer) == 1 );
|
|
583 |
CPPUNIT_ASSERT( is_POD_type(any) == 0 );
|
|
584 |
CPPUNIT_ASSERT( is_POD_type(any_pointer) == 1 );
|
|
585 |
CPPUNIT_ASSERT( is_POD_type(any_pod) == 1 );
|
|
586 |
CPPUNIT_ASSERT( is_POD_type(string()) == 0 );
|
|
587 |
#endif
|
|
588 |
}
|
|
589 |
|
|
590 |
#if defined (STLPORT)
|
|
591 |
template <typename _Tp>
|
|
592 |
int is_stlport_class(_Tp) {
|
|
593 |
typedef _IsSTLportClass<_Tp> _STLportClass;
|
|
594 |
# if !defined (__BORLANDC__)
|
|
595 |
typedef typename _STLportClass::_Ret _Is;
|
|
596 |
# else
|
|
597 |
typedef typename __bool2type<_STLportClass::_Is>::_Ret _Is;
|
|
598 |
# endif
|
|
599 |
return type_to_value(_Is());
|
|
600 |
}
|
|
601 |
#endif
|
|
602 |
|
|
603 |
void TypeTraitsTest::stlport_class()
|
|
604 |
{
|
|
605 |
#if defined (STLPORT)
|
|
606 |
CPPUNIT_ASSERT( is_stlport_class(allocator<char>()) == 1 );
|
|
607 |
# if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
|
|
608 |
CPPUNIT_ASSERT( is_stlport_class(string()) == 1 );
|
|
609 |
# endif
|
|
610 |
CPPUNIT_ASSERT( is_stlport_class(any) == 0 );
|
|
611 |
#endif
|
|
612 |
}
|