ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

type_traits_test.cpp
Go to the documentation of this file.
00001 #include <algorithm>
00002 #include <vector>
00003 #include <string>
00004 
00005 #include "cppunit/cppunit_proxy.h"
00006 
00007 #if defined (_STLP_USE_NAMESPACES)
00008 using namespace std;
00009 #endif
00010 
00011 //
00012 // TestCase class
00013 //
00014 class TypeTraitsTest : public CPPUNIT_NS::TestCase
00015 {
00016   CPPUNIT_TEST_SUITE(TypeTraitsTest);
00017 #if !defined (STLPORT)
00018   CPPUNIT_IGNORE;
00019 #endif
00020   CPPUNIT_TEST(manips);
00021   CPPUNIT_TEST(integer);
00022   CPPUNIT_TEST(rational);
00023   CPPUNIT_TEST(pointer_type);
00024 #if defined (STLPORT) && !defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00025   CPPUNIT_IGNORE;
00026 #endif
00027   CPPUNIT_TEST(reference_type);
00028 #if defined (STLPORT)
00029   CPPUNIT_STOP_IGNORE;
00030 #endif
00031   CPPUNIT_TEST(both_pointer_type);
00032   CPPUNIT_TEST(ok_to_use_memcpy);
00033   CPPUNIT_TEST(ok_to_use_memmove);
00034   CPPUNIT_TEST(trivial_destructor);
00035   CPPUNIT_TEST(is_POD);
00036   CPPUNIT_TEST(stlport_class);
00037   CPPUNIT_TEST_SUITE_END();
00038 
00039 protected:
00040   void manips();
00041   void integer();
00042   void rational();
00043   void pointer_type();
00044   void reference_type();
00045   void both_pointer_type();
00046   void ok_to_use_memcpy();
00047   void ok_to_use_memmove();
00048   void trivial_destructor();
00049   void is_POD();
00050   void stlport_class();
00051 };
00052 
00053 CPPUNIT_TEST_SUITE_REGISTRATION(TypeTraitsTest);
00054 
00055 #if defined (STLPORT)
00056 
00057 #  if defined (__GNUC__) && defined (_STLP_USE_NAMESPACES)
00058 // libstdc++ sometimes exposed its own __true_type type in global
00059 // namespace resulting in an ambiguity.
00060 #    define __true_type std::__true_type
00061 #    define __false_type std::__false_type
00062 #  endif
00063 
00064 int type_to_value(__true_type)
00065 { return 1; }
00066 int type_to_value(__false_type)
00067 { return 0; }
00068 
00069 int* int_pointer;
00070 int const* int_const_pointer;
00071 int volatile* int_volatile_pointer;
00072 int const volatile* int_const_volatile_pointer;
00073 int int_val = 0;
00074 int const int_const_val = 0;
00075 int volatile int_volatile_val = 0;
00076 int & int_ref = int_val;
00077 int const& int_const_ref = int_val;
00078 int const volatile& int_const_volatile_ref = int_val;
00079 
00080 //A type that represent any type:
00081 struct any_type
00082 {
00083   //Dummy operations to forbid to compilers with intrinsic
00084   //type traits support to consider this type as a POD.
00085   any_type() : m_data(1) {}
00086   any_type(const any_type&) : m_data(2) {}
00087   any_type& operator = (const any_type&)
00088   { m_data = 3; return *this; }
00089   ~any_type() { m_data = 0; }
00090 
00091   size_t m_data;
00092 };
00093 
00094 any_type any;
00095 any_type* any_pointer;
00096 any_type const* any_const_pointer;
00097 any_type volatile* any_volatile_pointer;
00098 any_type const volatile* any_const_volatile_pointer;
00099 
00100 //A type that represent any pod type
00101 struct any_pod_type
00102 {};
00103 
00104 #  if defined (_STLP_USE_BOOST_SUPPORT)
00105 //Mandatory for compilers without without partial template specialization.
00106 BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION(any_pod_type)
00107 #  endif
00108 
00109 any_pod_type any_pod;
00110 any_pod_type* any_pod_pointer;
00111 any_pod_type const* any_pod_const_pointer;
00112 any_pod_type volatile* any_pod_volatile_pointer;
00113 any_pod_type const volatile* any_pod_const_volatile_pointer;
00114 
00115 #  if defined (_STLP_USE_NAMESPACES)
00116 namespace std {
00117 #  endif
00118   _STLP_TEMPLATE_NULL
00119   struct __type_traits<any_pod_type> {
00120     typedef __true_type has_trivial_default_constructor;
00121     typedef __true_type has_trivial_copy_constructor;
00122     typedef __true_type has_trivial_assignment_operator;
00123     typedef __true_type has_trivial_destructor;
00124     typedef __true_type is_POD_type;
00125   };
00126 #  if defined (_STLP_USE_NAMESPACES)
00127 }
00128 #  endif
00129 
00130 struct base
00131 {};
00132 struct derived : public base
00133 {};
00134 
00135 //
00136 // tests implementation
00137 //
00138 template <typename _Src, typename _Dst>
00139 int is_convertible(_Src, _Dst) {
00140 #  if !defined(__BORLANDC__)
00141   typedef typename _IsConvertible<_Src, _Dst>::_Ret _Ret;
00142 #  else
00143   enum { _Is = _IsConvertible<_Src, _Dst>::value };
00144   typedef typename __bool2type<_Is>::_Ret _Ret;
00145 #  endif
00146   return type_to_value(_Ret());
00147 }
00148 
00149 template <typename _Src, typename _Dst>
00150 int is_cv_convertible(_Src, _Dst) {
00151 #  if !defined(__BORLANDC__)
00152   typedef typename _IsCVConvertible<_Src, _Dst>::_Ret _Ret;
00153 #  else
00154   enum { _Is = _IsCVConvertible<_Src, _Dst>::value };
00155   typedef typename __bool2type<_Is>::_Ret _Ret;
00156 #  endif
00157   return type_to_value(_Ret());
00158 }
00159 #endif
00160 
00161 void TypeTraitsTest::manips()
00162 {
00163 #if defined (STLPORT)
00164   {
00165     typedef __bool2type<0>::_Ret _ZeroRet;
00166     CPPUNIT_ASSERT( type_to_value(_ZeroRet()) == 0 );
00167     typedef __bool2type<1>::_Ret _OneRet;
00168     CPPUNIT_ASSERT( type_to_value(_OneRet()) == 1 );
00169     typedef __bool2type<65456873>::_Ret _AnyRet;
00170     CPPUNIT_ASSERT( type_to_value(_AnyRet()) == 1 );
00171   }
00172 
00173   {
00174     CPPUNIT_ASSERT( __type2bool<__true_type>::_Ret == 1 );
00175     CPPUNIT_ASSERT( __type2bool<__false_type>::_Ret == 0 );
00176     CPPUNIT_ASSERT( __type2bool<any_type>::_Ret == 1 );
00177   }
00178 
00179   {
00180     typedef _Not<__true_type>::_Ret _NotTrueRet;
00181     CPPUNIT_ASSERT( type_to_value(_NotTrueRet()) == 0 );
00182     typedef _Not<__false_type>::_Ret _NotFalseRet;
00183     CPPUNIT_ASSERT( type_to_value(_NotFalseRet()) == 1 );
00184   }
00185 
00186   {
00187     typedef _Land2<__true_type, __true_type>::_Ret _TrueTrueRet;
00188     CPPUNIT_ASSERT( type_to_value(_TrueTrueRet()) == 1 );
00189     typedef _Land2<__true_type, __false_type>::_Ret _TrueFalseRet;
00190     CPPUNIT_ASSERT( type_to_value(_TrueFalseRet()) == 0 );
00191     typedef _Land2<__false_type, __true_type>::_Ret _FalseTrueRet;
00192     CPPUNIT_ASSERT( type_to_value(_FalseTrueRet()) == 0 );
00193     typedef _Land2<__false_type, __false_type>::_Ret _FalseFalseRet;
00194     CPPUNIT_ASSERT( type_to_value(_FalseFalseRet()) == 0 );
00195   }
00196 
00197   {
00198     typedef _Land3<__true_type, __true_type, __true_type>::_Ret _TrueTrueTrueRet;
00199     CPPUNIT_ASSERT( type_to_value(_TrueTrueTrueRet()) == 1 );
00200     typedef _Land3<__true_type, __true_type, __false_type>::_Ret _TrueTrueFalseRet;
00201     CPPUNIT_ASSERT( type_to_value(_TrueTrueFalseRet()) == 0 );
00202     typedef _Land3<__true_type, __false_type, __true_type>::_Ret _TrueFalseTrueRet;
00203     CPPUNIT_ASSERT( type_to_value(_TrueFalseTrueRet()) == 0 );
00204     typedef _Land3<__true_type, __false_type, __false_type>::_Ret _TrueFalseFalseRet;
00205     CPPUNIT_ASSERT( type_to_value(_TrueFalseFalseRet()) == 0 );
00206     typedef _Land3<__false_type, __true_type, __true_type>::_Ret _FalseTrueTrueRet;
00207     CPPUNIT_ASSERT( type_to_value(_FalseTrueTrueRet()) == 0 );
00208     typedef _Land3<__false_type, __true_type, __false_type>::_Ret _FalseTrueFalseRet;
00209     CPPUNIT_ASSERT( type_to_value(_FalseTrueFalseRet()) == 0 );
00210     typedef _Land3<__false_type, __false_type, __true_type>::_Ret _FalseFalseTrueRet;
00211     CPPUNIT_ASSERT( type_to_value(_FalseFalseTrueRet()) == 0 );
00212     typedef _Land3<__false_type, __false_type, __false_type>::_Ret _FalseFalseFalseRet;
00213     CPPUNIT_ASSERT( type_to_value(_FalseFalseFalseRet()) == 0 );
00214   }
00215 
00216   {
00217     typedef _Lor2<__true_type, __true_type>::_Ret _TrueTrueRet;
00218     CPPUNIT_ASSERT( type_to_value(_TrueTrueRet()) == 1 );
00219     typedef _Lor2<__true_type, __false_type>::_Ret _TrueFalseRet;
00220     CPPUNIT_ASSERT( type_to_value(_TrueFalseRet()) == 1 );
00221     typedef _Lor2<__false_type, __true_type>::_Ret _FalseTrueRet;
00222     CPPUNIT_ASSERT( type_to_value(_FalseTrueRet()) == 1 );
00223     typedef _Lor2<__false_type, __false_type>::_Ret _FalseFalseRet;
00224     CPPUNIT_ASSERT( type_to_value(_FalseFalseRet()) == 0 );
00225   }
00226 
00227   {
00228     typedef _Lor3<__true_type, __true_type, __true_type>::_Ret _TrueTrueTrueRet;
00229     CPPUNIT_ASSERT( type_to_value(_TrueTrueTrueRet()) == 1 );
00230     typedef _Lor3<__true_type, __true_type, __false_type>::_Ret _TrueTrueFalseRet;
00231     CPPUNIT_ASSERT( type_to_value(_TrueTrueFalseRet()) == 1 );
00232     typedef _Lor3<__true_type, __false_type, __true_type>::_Ret _TrueFalseTrueRet;
00233     CPPUNIT_ASSERT( type_to_value(_TrueFalseTrueRet()) == 1 );
00234     typedef _Lor3<__true_type, __false_type, __false_type>::_Ret _TrueFalseFalseRet;
00235     CPPUNIT_ASSERT( type_to_value(_TrueFalseFalseRet()) == 1 );
00236     typedef _Lor3<__false_type, __true_type, __true_type>::_Ret _FalseTrueTrueRet;
00237     CPPUNIT_ASSERT( type_to_value(_FalseTrueTrueRet()) == 1 );
00238     typedef _Lor3<__false_type, __true_type, __false_type>::_Ret _FalseTrueFalseRet;
00239     CPPUNIT_ASSERT( type_to_value(_FalseTrueFalseRet()) == 1 );
00240     typedef _Lor3<__false_type, __false_type, __true_type>::_Ret _FalseFalseTrueRet;
00241     CPPUNIT_ASSERT( type_to_value(_FalseFalseTrueRet()) == 1 );
00242     typedef _Lor3<__false_type, __false_type, __false_type>::_Ret _FalseFalseFalseRet;
00243     CPPUNIT_ASSERT( type_to_value(_FalseFalseFalseRet()) == 0 );
00244   }
00245 
00246   {
00247     typedef __select<1, __true_type, __false_type>::_Ret _SelectFirstRet;
00248     CPPUNIT_ASSERT( type_to_value(_SelectFirstRet()) == 1 );
00249     typedef __select<0, __true_type, __false_type>::_Ret _SelectSecondRet;
00250     CPPUNIT_ASSERT( type_to_value(_SelectSecondRet()) == 0 );
00251 #  if defined (__BORLANDC__)
00252     typedef __selectT<__true_type, __true_type, __false_type>::_Ret _SelectFirstRet;
00253     CPPUNIT_ASSERT( type_to_value(_SelectFirstRet()) == 1 );
00254     typedef __selectT<__false_type, __true_type, __false_type>::_Ret _SelectSecondRet;
00255     CPPUNIT_ASSERT( type_to_value(_SelectSecondRet()) == 0 );
00256 #  endif
00257   }
00258 
00259   {
00260     base b;
00261     derived d;
00262     const derived cd = d;
00263     base *pb = &b;
00264     derived *pd = &d;
00265     derived const *pcd = pd;
00266     CPPUNIT_CHECK( is_convertible(any, b) == 0 );
00267     CPPUNIT_CHECK( is_convertible(d, b) == 1 );
00268     CPPUNIT_CHECK( is_convertible(cd, b) == 1 );
00269     // _IsCVConvertible only needs to work for pointer type:
00270     //CPPUNIT_CHECK( is_cv_convertible(d, b) == 1 );
00271     //CPPUNIT_CHECK( is_cv_convertible(cd, b) == 0 );
00272 
00273     //_IsConvertible do not need to work for pointers:
00274     //CPPUNIT_CHECK( is_convertible(pd, pb) == 1 );
00275     //CPPUNIT_CHECK( is_convertible(pcd, pb) == 1 );
00276 
00277     CPPUNIT_CHECK( is_cv_convertible(pd, pb) == 1 );
00278     CPPUNIT_CHECK( is_cv_convertible(pcd, pb) == 0 );
00279   }
00280 #endif
00281 }
00282 
00283 #if defined (STLPORT)
00284 template <typename _Type>
00285 int is_integer(_Type) {
00286   typedef typename _IsIntegral<_Type>::_Ret _Ret;
00287   return type_to_value(_Ret());
00288 }
00289 #endif
00290 
00291 void TypeTraitsTest::integer()
00292 {
00293 #if defined (STLPORT)
00294   CPPUNIT_ASSERT( is_integer(bool()) == 1 );
00295   CPPUNIT_ASSERT( is_integer(char()) == 1 );
00296   typedef signed char signed_char;
00297   CPPUNIT_ASSERT( is_integer(signed_char()) == 1 );
00298   typedef unsigned char unsigned_char;
00299   CPPUNIT_ASSERT( is_integer(unsigned_char()) == 1 );
00300 #  if defined (_STLP_HAS_WCHAR_T)
00301   CPPUNIT_ASSERT( is_integer(wchar_t()) == 1 );
00302 #  endif
00303   CPPUNIT_ASSERT( is_integer(short()) == 1 );
00304   typedef unsigned short unsigned_short;
00305   CPPUNIT_ASSERT( is_integer(unsigned_short()) == 1 );
00306   CPPUNIT_ASSERT( is_integer(int()) == 1 );
00307   typedef unsigned int unsigned_int;
00308   CPPUNIT_ASSERT( is_integer(unsigned_int()) == 1 );
00309   CPPUNIT_ASSERT( is_integer(long()) == 1 );
00310   typedef unsigned long unsigned_long;
00311   CPPUNIT_ASSERT( is_integer(unsigned_long()) == 1 );
00312 #  if defined (_STLP_LONG_LONG)
00313   typedef _STLP_LONG_LONG long_long;
00314   CPPUNIT_ASSERT( is_integer(long_long()) == 1 );
00315   typedef unsigned _STLP_LONG_LONG unsigned_long_long;
00316   CPPUNIT_ASSERT( is_integer(unsigned_long_long()) == 1 );
00317 #  endif
00318   CPPUNIT_ASSERT( is_integer(float()) == 0 );
00319   CPPUNIT_ASSERT( is_integer(double()) == 0 );
00320 #  if !defined ( _STLP_NO_LONG_DOUBLE )
00321   typedef long double long_double;
00322   CPPUNIT_ASSERT( is_integer(long_double()) == 0 );
00323 #  endif
00324   CPPUNIT_ASSERT( is_integer(any) == 0 );
00325   CPPUNIT_ASSERT( is_integer(any_pointer) == 0 );
00326 #endif
00327 }
00328 
00329 #if defined (STLPORT)
00330 template <typename _Type>
00331 int is_rational(_Type) {
00332   typedef typename _IsRational<_Type>::_Ret _Ret;
00333   return type_to_value(_Ret());
00334 }
00335 #endif
00336 
00337 void TypeTraitsTest::rational()
00338 {
00339 #if defined (STLPORT)
00340   CPPUNIT_ASSERT( is_rational(bool()) == 0 );
00341   CPPUNIT_ASSERT( is_rational(char()) == 0 );
00342   typedef signed char signed_char;
00343   CPPUNIT_ASSERT( is_rational(signed_char()) == 0 );
00344   typedef unsigned char unsigned_char;
00345   CPPUNIT_ASSERT( is_rational(unsigned_char()) == 0 );
00346 #  if defined (_STLP_HAS_WCHAR_T)
00347   CPPUNIT_ASSERT( is_rational(wchar_t()) == 0 );
00348 #  endif
00349   CPPUNIT_ASSERT( is_rational(short()) == 0 );
00350   typedef unsigned short unsigned_short;
00351   CPPUNIT_ASSERT( is_rational(unsigned_short()) == 0 );
00352   CPPUNIT_ASSERT( is_rational(int()) == 0 );
00353   typedef unsigned int unsigned_int;
00354   CPPUNIT_ASSERT( is_rational(unsigned_int()) == 0 );
00355   CPPUNIT_ASSERT( is_rational(long()) == 0 );
00356   typedef unsigned long unsigned_long;
00357   CPPUNIT_ASSERT( is_rational(unsigned_long()) == 0 );
00358 #  if defined (_STLP_LONG_LONG)
00359   typedef _STLP_LONG_LONG long_long;
00360   CPPUNIT_ASSERT( is_rational(long_long()) == 0 );
00361   typedef unsigned _STLP_LONG_LONG unsigned_long_long;
00362   CPPUNIT_ASSERT( is_rational(unsigned_long_long()) == 0 );
00363 #  endif
00364   CPPUNIT_ASSERT( is_rational(float()) == 1 );
00365   CPPUNIT_ASSERT( is_rational(double()) == 1 );
00366 #  if !defined ( _STLP_NO_LONG_DOUBLE )
00367   typedef long double long_double;
00368   CPPUNIT_ASSERT( is_rational(long_double()) == 1 );
00369 #  endif
00370   CPPUNIT_ASSERT( is_rational(any) == 0 );
00371   CPPUNIT_ASSERT( is_rational(any_pointer) == 0 );
00372 #endif
00373 }
00374 
00375 #if defined (STLPORT)
00376 template <typename _Type>
00377 int is_pointer_type(_Type) {
00378   return type_to_value(_IsPtrType<_Type>::_Ret());
00379 }
00380 #endif
00381 
00382 void TypeTraitsTest::pointer_type()
00383 {
00384 #if defined (STLPORT)
00385   CPPUNIT_ASSERT( is_pointer_type(int_val) == 0 );
00386   CPPUNIT_ASSERT( is_pointer_type(int_pointer) == 1 );
00387   CPPUNIT_ASSERT( is_pointer_type(int_const_pointer) == 1 );
00388   CPPUNIT_ASSERT( is_pointer_type(int_volatile_pointer) == 1 );
00389   CPPUNIT_ASSERT( is_pointer_type(int_const_volatile_pointer) == 1 );
00390   CPPUNIT_ASSERT( is_pointer_type(int_ref) == 0 );
00391   CPPUNIT_ASSERT( is_pointer_type(int_const_ref) == 0 );
00392   CPPUNIT_ASSERT( is_pointer_type(any) == 0 );
00393   CPPUNIT_ASSERT( is_pointer_type(any_pointer) == 1 );
00394 #endif
00395 }
00396 
00397 void TypeTraitsTest::reference_type()
00398 {
00399 #if defined (STLPORT) && defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00400   CPPUNIT_ASSERT( type_to_value(_IsRefType<int>::_Ret()) == 0 );
00401   CPPUNIT_ASSERT( type_to_value(_IsRefType<int*>::_Ret()) == 0 );
00402   CPPUNIT_ASSERT( type_to_value(_IsRefType<int&>::_Ret()) == 1 );
00403   CPPUNIT_ASSERT( type_to_value(_IsRefType<int const&>::_Ret()) == 1 );
00404   CPPUNIT_ASSERT( type_to_value(_IsRefType<int const volatile&>::_Ret()) == 1 );
00405 
00406   CPPUNIT_ASSERT( type_to_value(_IsOKToSwap(int_pointer, int_pointer, __true_type(), __true_type())._Answer()) == 1 );
00407   CPPUNIT_ASSERT( type_to_value(_IsOKToSwap(int_pointer, int_pointer, __false_type(), __false_type())._Answer()) == 0 );
00408 #endif
00409 }
00410 
00411 #if defined (STLPORT)
00412 template <typename _Tp1, typename _Tp2>
00413 int are_both_pointer_type (_Tp1, _Tp2) {
00414   return type_to_value(_BothPtrType<_Tp1, _Tp2>::_Answer());
00415 }
00416 #endif
00417 
00418 void TypeTraitsTest::both_pointer_type()
00419 {
00420 #if defined (STLPORT)
00421   CPPUNIT_CHECK( are_both_pointer_type(int_val, int_val) == 0 );
00422   CPPUNIT_CHECK( are_both_pointer_type(int_pointer, int_pointer) == 1 );
00423   CPPUNIT_CHECK( are_both_pointer_type(int_const_pointer, int_const_pointer) == 1 );
00424   CPPUNIT_CHECK( are_both_pointer_type(int_volatile_pointer, int_volatile_pointer) == 1 );
00425   CPPUNIT_CHECK( are_both_pointer_type(int_const_volatile_pointer, int_const_volatile_pointer) == 1 );
00426   CPPUNIT_CHECK( are_both_pointer_type(int_ref, int_ref) == 0 );
00427   CPPUNIT_CHECK( are_both_pointer_type(int_const_ref, int_const_ref) == 0 );
00428   CPPUNIT_CHECK( are_both_pointer_type(any, any) == 0 );
00429   CPPUNIT_CHECK( are_both_pointer_type(any_pointer, any_pointer) == 1 );
00430 #endif
00431 }
00432 
00433 #if defined (STLPORT)
00434 template <typename _Tp1, typename _Tp2>
00435 int is_ok_to_use_memcpy(_Tp1 val1, _Tp2 val2) {
00436   return type_to_value(_UseTrivialCopy(val1, val2)._Answer());
00437 }
00438 #endif
00439 
00440 void TypeTraitsTest::ok_to_use_memcpy()
00441 {
00442 #if defined (STLPORT) && !defined (_STLP_DONT_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS)
00443   CPPUNIT_CHECK( is_ok_to_use_memcpy(int_pointer, int_pointer) == 1 );
00444   CPPUNIT_CHECK( is_ok_to_use_memcpy(int_const_pointer, int_pointer) == 1 );
00445   CPPUNIT_CHECK( is_ok_to_use_memcpy(int_pointer, int_volatile_pointer) == 0 );
00446   CPPUNIT_CHECK( is_ok_to_use_memcpy(int_pointer, int_const_volatile_pointer) == 0 );
00447   CPPUNIT_CHECK( is_ok_to_use_memcpy(int_const_pointer, int_const_pointer) == 0 );
00448   CPPUNIT_CHECK( is_ok_to_use_memcpy(int_const_pointer, int_volatile_pointer) == 0 );
00449   CPPUNIT_CHECK( is_ok_to_use_memcpy(int_const_pointer, int_const_volatile_pointer) == 0 );
00450   CPPUNIT_CHECK( is_ok_to_use_memcpy(int_const_volatile_pointer, int_const_volatile_pointer) == 0 );
00451   CPPUNIT_CHECK( is_ok_to_use_memcpy(int_pointer, any_pointer) == 0 );
00452   CPPUNIT_CHECK( is_ok_to_use_memcpy(any_pointer, int_pointer) == 0 );
00453   CPPUNIT_CHECK( is_ok_to_use_memcpy(any_pointer, any_pointer) == 0 );
00454   CPPUNIT_CHECK( is_ok_to_use_memcpy(any_pointer, any_const_pointer) == 0 );
00455   CPPUNIT_CHECK( is_ok_to_use_memcpy(any_pod_pointer, int_pointer) == 0 );
00456   CPPUNIT_CHECK( is_ok_to_use_memcpy(any_pod_pointer, any_pod_pointer) == 1 );
00457   CPPUNIT_CHECK( is_ok_to_use_memcpy(any_pod_pointer, any_pod_const_pointer) == 0 );
00458   vector<float> **pvf = 0;
00459   vector<int> **pvi = 0;
00460   CPPUNIT_CHECK( is_ok_to_use_memcpy(pvf, pvi) == 0 );
00461   CPPUNIT_CHECK( is_ok_to_use_memcpy(pvi, pvf) == 0 );
00462 #endif
00463 }
00464 
00465 #if defined (STLPORT)
00466 template <typename _Tp1, typename _Tp2>
00467 int is_ok_to_use_memmove(_Tp1 val1, _Tp2 val2) {
00468   return type_to_value(_UseTrivialUCopy(val1, val2)._Answer());
00469 }
00470 #endif
00471 
00472 void TypeTraitsTest::ok_to_use_memmove()
00473 {
00474 #if defined (STLPORT) && !defined (_STLP_DONT_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS)
00475   CPPUNIT_CHECK( is_ok_to_use_memmove(int_pointer, int_pointer) == 1 );
00476   CPPUNIT_CHECK( is_ok_to_use_memmove(int_const_pointer, int_pointer) == 1 );
00477   CPPUNIT_CHECK( is_ok_to_use_memmove(int_pointer, int_volatile_pointer) == 0 );
00478   CPPUNIT_CHECK( is_ok_to_use_memmove(int_pointer, int_const_volatile_pointer) == 0 );
00479   CPPUNIT_CHECK( is_ok_to_use_memmove(int_const_pointer, int_const_pointer) == 0 );
00480   CPPUNIT_CHECK( is_ok_to_use_memmove(int_const_pointer, int_volatile_pointer) == 0 );
00481   CPPUNIT_CHECK( is_ok_to_use_memmove(int_const_pointer, int_const_volatile_pointer) == 0 );
00482   CPPUNIT_CHECK( is_ok_to_use_memmove(int_const_volatile_pointer, int_const_volatile_pointer) == 0 );
00483   CPPUNIT_CHECK( is_ok_to_use_memmove(int_pointer, any_pointer) == 0 );
00484   CPPUNIT_CHECK( is_ok_to_use_memmove(any_pointer, int_pointer) == 0 );
00485   CPPUNIT_CHECK( is_ok_to_use_memmove(any_pointer, any_pointer) == 0 );
00486   CPPUNIT_CHECK( is_ok_to_use_memmove(any_pointer, any_const_pointer) == 0 );
00487   CPPUNIT_CHECK( is_ok_to_use_memmove(any_pod_pointer, int_pointer) == 0 );
00488   CPPUNIT_CHECK( is_ok_to_use_memmove(any_pod_pointer, any_pod_pointer) == 1 );
00489   CPPUNIT_CHECK( is_ok_to_use_memmove(any_pod_pointer, any_pod_const_pointer) == 0 );
00490 #endif
00491 }
00492 
00493 #if defined (STLPORT)
00494 template <typename _Tp>
00495 int has_trivial_destructor(_Tp) {
00496   typedef typename __type_traits<_Tp>::has_trivial_destructor _TrivialDestructor;
00497   return type_to_value(_TrivialDestructor());
00498 }
00499 
00500 struct DestructorMonitor
00501 {
00502   ~DestructorMonitor()
00503   { ++nb_destructor_call; }
00504 
00505   static size_t nb_destructor_call;
00506 };
00507 
00508 size_t DestructorMonitor::nb_destructor_call = 0;
00509 
00510 #  if defined (_STLP_USE_NAMESPACES)
00511 namespace std {
00512 #  endif
00513   _STLP_TEMPLATE_NULL
00514   struct __type_traits<DestructorMonitor> {
00515     typedef __true_type has_trivial_default_constructor;
00516     typedef __true_type has_trivial_copy_constructor;
00517     typedef __true_type has_trivial_assignment_operator;
00518     typedef __true_type has_trivial_destructor;
00519     typedef __true_type is_POD_type;
00520   };
00521 #  if defined (_STLP_USE_NAMESPACES)
00522 }
00523 #  endif
00524 #endif
00525 
00526 void TypeTraitsTest::trivial_destructor()
00527 {
00528 #if defined (STLPORT)
00529   CPPUNIT_CHECK( has_trivial_destructor(int_pointer) == 1 );
00530   CPPUNIT_CHECK( has_trivial_destructor(int_const_pointer) == 1 );
00531   CPPUNIT_CHECK( has_trivial_destructor(int_volatile_pointer) == 1 );
00532   CPPUNIT_CHECK( has_trivial_destructor(int_const_volatile_pointer) == 1 );
00533   CPPUNIT_CHECK( has_trivial_destructor(any_pointer) == 1 );
00534   CPPUNIT_CHECK( has_trivial_destructor(any) == 0 );
00535   CPPUNIT_CHECK( has_trivial_destructor(any_pointer) == 1 );
00536   CPPUNIT_CHECK( has_trivial_destructor(any_pod) == 1 );
00537   CPPUNIT_CHECK( has_trivial_destructor(string()) == 0 );
00538 
00539   //Check of the meta information impact in a container implementation
00540   {
00541     vector<DestructorMonitor> v(10);
00542     DestructorMonitor::nb_destructor_call = 0;
00543   }
00544   CPPUNIT_CHECK( DestructorMonitor::nb_destructor_call == 0 );
00545 #endif
00546 }
00547 
00548 #if defined (STLPORT)
00549 template <typename _Tp>
00550 int is_POD_type(_Tp) {
00551   typedef typename __type_traits<_Tp>::is_POD_type _IsPODType;
00552   return type_to_value(_IsPODType());
00553 }
00554 #endif
00555 
00556 void TypeTraitsTest::is_POD()
00557 {
00558 #if defined (STLPORT)
00559   CPPUNIT_CHECK( is_POD_type(int_pointer) == 1 );
00560   CPPUNIT_CHECK( is_POD_type(int_const_pointer) == 1 );
00561   CPPUNIT_CHECK( is_POD_type(int_volatile_pointer) == 1 );
00562   CPPUNIT_CHECK( is_POD_type(int_const_volatile_pointer) == 1 );
00563   CPPUNIT_CHECK( is_POD_type(any_pointer) == 1 );
00564   CPPUNIT_CHECK( is_POD_type(any) == 0 );
00565   CPPUNIT_CHECK( is_POD_type(any_pointer) == 1 );
00566   CPPUNIT_CHECK( is_POD_type(any_pod) == 1 );
00567   CPPUNIT_CHECK( is_POD_type(string()) == 0 );
00568 #endif
00569 }
00570 
00571 #if defined (STLPORT)
00572 template <typename _Tp>
00573 int is_stlport_class(_Tp) {
00574   typedef _IsSTLportClass<_Tp> _STLportClass;
00575 #    if !defined (__BORLANDC__)
00576   typedef typename _STLportClass::_Ret _Is;
00577 #    else
00578   typedef typename __bool2type<_STLportClass::_Is>::_Ret _Is;
00579 #    endif
00580   return type_to_value(_Is());
00581 }
00582 #endif
00583 
00584 void TypeTraitsTest::stlport_class()
00585 {
00586 #if defined (STLPORT)
00587   CPPUNIT_CHECK( is_stlport_class(allocator<char>()) == 1 );
00588 #  if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
00589   CPPUNIT_CHECK( is_stlport_class(string()) == 1 );
00590 #  endif
00591   CPPUNIT_CHECK( is_stlport_class(any) == 0 );
00592 #endif
00593 }

Generated on Sun May 27 2012 04:35:53 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.