Sierra Toolkit Version of the Day
UnitTestDataTraits.cpp
00001 /*------------------------------------------------------------------------*/
00002 /*                 Copyright 2010 Sandia Corporation.                     */
00003 /*  Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive   */
00004 /*  license for use of this work by or on behalf of the U.S. Government.  */
00005 /*  Export of this program may require a license from the                 */
00006 /*  United States Government.                                             */
00007 /*------------------------------------------------------------------------*/
00008 
00009 
00010 #include <stddef.h>
00011 #include <stdexcept>
00012 #include <stk_util/parallel/Parallel.hpp>
00013 #include <stk_mesh/base/DataTraits.hpp>
00014 #include <stk_mesh/base/DataTraitsEnum.hpp>
00015 #include <stk_mesh/base/DataTraitsClass.hpp>
00016 
00017 #include <stk_util/unit_test_support/stk_utest_macros.hpp>
00018 
00019 namespace stk {
00020 namespace mesh {
00021 
00022 class UnitTestDataTraits {
00023 public:
00024   UnitTestDataTraits() {}
00025 
00026   void testVoid( bool );
00027   void testFundemental( bool );
00028   void testEnum( bool );
00029   void testClass( bool );
00030   void testPointer( bool );
00031 };
00032 
00033 }//namespace mesh
00034 }//namespace stk
00035 
00036 namespace {
00037 STKUNIT_UNIT_TEST(TestDataTraits, testUnit)
00038 {
00039   int mpi_rank = 0;
00040   int mpi_size = 1;
00041   
00042 #ifdef STK_HAS_MPI
00043   STKUNIT_ASSERT_EQUAL(MPI_SUCCESS, MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank) );
00044   STKUNIT_ASSERT_EQUAL(MPI_SUCCESS, MPI_Comm_size(MPI_COMM_WORLD, &mpi_size) );
00045 #endif
00046   STKUNIT_ASSERT(mpi_rank < mpi_size);
00047 
00048   bool testComm = mpi_size <= 1 ;
00049 
00050   stk::mesh::UnitTestDataTraits udt;
00051   if ( 0 == mpi_rank ) {
00052     udt.testVoid( testComm );
00053     udt.testFundemental( testComm );
00054     udt.testEnum( testComm );
00055     udt.testClass( testComm );
00056     udt.testPointer( testComm );
00057   }
00058 }
00059 
00060 }//namespace <anonymous>
00061 
00062 namespace stk {
00063 namespace mesh {
00064 //----------------------------------------------------------------------
00065 
00066 void UnitTestDataTraits::testVoid( bool testComm )
00067 {
00068   const DataTraits & traits = data_traits<void>();
00069 
00070   STKUNIT_ASSERT(       traits.type_info        == typeid(void) );
00071   STKUNIT_ASSERT_EQUAL( traits.size_of           , size_t(0) );
00072   STKUNIT_ASSERT_EQUAL( traits.alignment_of      , size_t(0) );
00073   STKUNIT_ASSERT_EQUAL( traits.stride_of         , size_t(0) );
00074   STKUNIT_ASSERT_EQUAL( traits.is_void           , true );
00075   STKUNIT_ASSERT_EQUAL( traits.is_integral       , false );
00076   STKUNIT_ASSERT_EQUAL( traits.is_floating_point , false );
00077   STKUNIT_ASSERT_EQUAL( traits.is_array          , false );
00078   STKUNIT_ASSERT_EQUAL( traits.is_pointer        , false );
00079   STKUNIT_ASSERT_EQUAL( traits.is_enum           , false );
00080   STKUNIT_ASSERT_EQUAL( traits.is_class          , false );
00081   STKUNIT_ASSERT_EQUAL( traits.is_pod            , false );
00082   STKUNIT_ASSERT_EQUAL( traits.is_signed         , false );
00083   STKUNIT_ASSERT_EQUAL( traits.is_unsigned       , false );
00084 
00085   STKUNIT_ASSERT( ! traits.remove_pointer   );
00086   STKUNIT_ASSERT( traits.enum_info.empty()  );
00087   STKUNIT_ASSERT( traits.class_info.empty() );
00088 
00089   STKUNIT_ASSERT_THROW( traits.construct( NULL , 0 ) , std::runtime_error );
00090   STKUNIT_ASSERT_THROW( traits.destroy( NULL , 0 ) , std::runtime_error );
00091   STKUNIT_ASSERT_THROW( traits.copy( NULL , NULL , 0 ) , std::runtime_error );
00092   STKUNIT_ASSERT_THROW( traits.sum( NULL , NULL , 0 ) , std::runtime_error );
00093   STKUNIT_ASSERT_THROW( traits.max( NULL , NULL , 0 ) , std::runtime_error );
00094   STKUNIT_ASSERT_THROW( traits.min( NULL , NULL , 0 ) , std::runtime_error );
00095   STKUNIT_ASSERT_THROW( traits.bit_and( NULL, NULL, 0 ), std::runtime_error );
00096   STKUNIT_ASSERT_THROW( traits.bit_or( NULL , NULL, 0 ), std::runtime_error );
00097   STKUNIT_ASSERT_THROW( traits.bit_xor( NULL, NULL, 0 ), std::runtime_error );
00098   STKUNIT_ASSERT_THROW( traits.print( std::cout, NULL, 0 ), std::runtime_error );
00099 
00100   if ( testComm ) {
00101     CommAll all( MPI_COMM_WORLD );
00102     STKUNIT_ASSERT_THROW( traits.pack( all.send_buffer(0) , NULL , 0 ), std::runtime_error );
00103     all.allocate_buffers( 0 );
00104     all.communicate();
00105     STKUNIT_ASSERT_THROW( traits.unpack( all.recv_buffer(0) , NULL , 0 ), std::runtime_error );
00106   }
00107 }
00108 
00109 
00110 
00111 //----------------------------------------------------------------------
00112 
00113 template< typename T , bool is_integral , bool is_signed >
00114 void test_fundemental_type( bool testComm )
00115 {
00116   const DataTraits & traits = data_traits<T>();
00117   STKUNIT_ASSERT(       traits.type_info        == typeid(T) );
00118   STKUNIT_ASSERT_EQUAL( traits.size_of           , sizeof(T) );
00119   STKUNIT_ASSERT_EQUAL( traits.alignment_of      , sizeof(T) );
00120   STKUNIT_ASSERT_EQUAL( traits.stride_of         , sizeof(T) );
00121   STKUNIT_ASSERT_EQUAL( traits.is_void           , false );
00122   STKUNIT_ASSERT_EQUAL( traits.is_integral       , is_integral );
00123   STKUNIT_ASSERT_EQUAL( traits.is_floating_point , ! is_integral );
00124   STKUNIT_ASSERT_EQUAL( traits.is_array          , false );
00125   STKUNIT_ASSERT_EQUAL( traits.is_pointer        , false );
00126   STKUNIT_ASSERT_EQUAL( traits.is_enum           , false );
00127   STKUNIT_ASSERT_EQUAL( traits.is_class          , false );
00128   STKUNIT_ASSERT_EQUAL( traits.is_pod            , true );
00129   STKUNIT_ASSERT_EQUAL( traits.is_signed         , is_signed );
00130   STKUNIT_ASSERT_EQUAL( traits.is_unsigned       , is_integral && ! is_signed );
00131 
00132   STKUNIT_ASSERT( ! traits.remove_pointer   );
00133   STKUNIT_ASSERT( traits.enum_info.empty()  );
00134   STKUNIT_ASSERT( traits.class_info.empty() );
00135 
00136 
00137   const T a[3] = { T(1) , T(2) , T(4) };
00138   T b[3] ;
00139 
00140   traits.construct( b , 3 );
00141   STKUNIT_ASSERT_EQUAL( T(0) , b[0] );
00142   STKUNIT_ASSERT_EQUAL( T(0) , b[1] );
00143   STKUNIT_ASSERT_EQUAL( T(0) , b[2] );
00144 
00145   traits.copy( b , a , 3 );
00146   STKUNIT_ASSERT_EQUAL( T(1) , b[0] );
00147   STKUNIT_ASSERT_EQUAL( T(2) , b[1] );
00148   STKUNIT_ASSERT_EQUAL( T(4) , b[2] );
00149 
00150   traits.sum( b , a , 3 );
00151   STKUNIT_ASSERT_EQUAL( T(2) , b[0] );
00152   STKUNIT_ASSERT_EQUAL( T(4) , b[1] );
00153   STKUNIT_ASSERT_EQUAL( T(8) , b[2] );
00154 
00155   traits.min( b , a , 3 );
00156   STKUNIT_ASSERT_EQUAL( T(1) , b[0] );
00157   STKUNIT_ASSERT_EQUAL( T(2) , b[1] );
00158   STKUNIT_ASSERT_EQUAL( T(4) , b[2] );
00159 
00160   traits.sum( b , a , 3 );
00161   traits.max( b , a , 3 );
00162   STKUNIT_ASSERT_EQUAL( T(2) , b[0] );
00163   STKUNIT_ASSERT_EQUAL( T(4) , b[1] );
00164   STKUNIT_ASSERT_EQUAL( T(8) , b[2] );
00165 
00166   if ( is_integral ) {
00167     traits.bit_or( b , a , 3 );
00168     STKUNIT_ASSERT_EQUAL( T(3) , b[0] );
00169     STKUNIT_ASSERT_EQUAL( T(6) , b[1] );
00170     STKUNIT_ASSERT_EQUAL( T(12) , b[2] );
00171 
00172     traits.bit_and( b , a , 3 );
00173     STKUNIT_ASSERT_EQUAL( T(1) , b[0] );
00174     STKUNIT_ASSERT_EQUAL( T(2) , b[1] );
00175     STKUNIT_ASSERT_EQUAL( T(4) , b[2] );
00176 
00177     traits.bit_xor( b , a , 3 );
00178     STKUNIT_ASSERT_EQUAL( T(0) , b[0] );
00179     STKUNIT_ASSERT_EQUAL( T(0) , b[1] );
00180     STKUNIT_ASSERT_EQUAL( T(0) , b[2] );
00181   }
00182   else {
00183     STKUNIT_ASSERT_THROW( traits.bit_or(  b , a , 3 ), std::runtime_error );
00184     STKUNIT_ASSERT_THROW( traits.bit_and( b , a , 3 ), std::runtime_error );
00185     STKUNIT_ASSERT_THROW( traits.bit_xor( b , a , 3 ), std::runtime_error );
00186   }
00187 
00188   if ( testComm ) {
00189     traits.construct( b , 3 );
00190     CommAll all( MPI_COMM_WORLD );
00191     traits.pack( all.send_buffer(0) , a , 3 );
00192     all.allocate_buffers( 0 );
00193     traits.pack( all.send_buffer(0) , a , 3 );
00194     all.communicate();
00195     traits.unpack( all.recv_buffer(0) , b , 3 );
00196     STKUNIT_ASSERT_EQUAL( T(1) , b[0] );
00197     STKUNIT_ASSERT_EQUAL( T(2) , b[1] );
00198     STKUNIT_ASSERT_EQUAL( T(4) , b[2] );
00199   }
00200 
00201   std::cout << traits.name << " " ;
00202   traits.print( std::cout , a , 3 );
00203   std::cout << std::endl ;
00204 
00205   traits.destroy( b , 3 );
00206 }
00207 
00208 
00209 void UnitTestDataTraits::testFundemental( bool testComm )
00210 {
00211   test_fundemental_type<char,           true, true >( testComm );
00212   test_fundemental_type<unsigned char,  true, false>( testComm );
00213   test_fundemental_type<short,          true, true >( testComm );
00214   test_fundemental_type<unsigned short, true, false>( testComm );
00215   test_fundemental_type<int,            true, true >( testComm );
00216   test_fundemental_type<unsigned int,   true, false>( testComm );
00217   test_fundemental_type<long,           true, true >( testComm );
00218   test_fundemental_type<unsigned long,  true, false>( testComm );
00219   test_fundemental_type<float,          false,false>( testComm );
00220   test_fundemental_type<double,         false,false>( testComm );
00221 }
00222 
00223 //----------------------------------------------------------------------
00224 
00225 namespace {
00226 
00227 template< typename T >
00228 void test_fundemental_pointer( bool testComm )
00229 {
00230   const DataTraits & traits = data_traits<T*>();
00231   STKUNIT_ASSERT(       traits.type_info        == typeid(T*) );
00232   STKUNIT_ASSERT_EQUAL( traits.size_of           , sizeof(T*) );
00233   STKUNIT_ASSERT_EQUAL( traits.alignment_of      , sizeof(T*) );
00234   STKUNIT_ASSERT_EQUAL( traits.stride_of         , sizeof(T*) );
00235   STKUNIT_ASSERT_EQUAL( traits.is_void           , false );
00236   STKUNIT_ASSERT_EQUAL( traits.is_integral       , false );
00237   STKUNIT_ASSERT_EQUAL( traits.is_floating_point , false );
00238   STKUNIT_ASSERT_EQUAL( traits.is_array          , false );
00239   STKUNIT_ASSERT_EQUAL( traits.is_pointer        , true );
00240   STKUNIT_ASSERT_EQUAL( traits.is_enum           , false );
00241   STKUNIT_ASSERT_EQUAL( traits.is_class          , false );
00242   STKUNIT_ASSERT_EQUAL( traits.is_pod            , false );
00243   STKUNIT_ASSERT_EQUAL( traits.is_signed         , false );
00244   STKUNIT_ASSERT_EQUAL( traits.is_unsigned       , false );
00245 
00246   STKUNIT_ASSERT( traits.remove_pointer == & data_traits<T>()  );
00247   STKUNIT_ASSERT( traits.enum_info.empty()  );
00248   STKUNIT_ASSERT( traits.class_info.empty() );
00249 
00250 
00251   T val[3] = { T(1) , T(2) , T(4) };
00252   T * const a[3] = { val , val + 1 , val + 2 };
00253   T * b[3] ;
00254 
00255   traits.construct( b , 3 );
00256   STKUNIT_ASSERT_EQUAL( static_cast<T*>(NULL) , b[0] );
00257   STKUNIT_ASSERT_EQUAL( static_cast<T*>(NULL) , b[1] );
00258   STKUNIT_ASSERT_EQUAL( static_cast<T*>(NULL) , b[2] );
00259 
00260   traits.copy( b , a , 3 );
00261   STKUNIT_ASSERT_EQUAL( val + 0 , b[0] );
00262   STKUNIT_ASSERT_EQUAL( val + 1 , b[1] );
00263   STKUNIT_ASSERT_EQUAL( val + 2 , b[2] );
00264 
00265   traits.destroy( b , 3 );
00266   STKUNIT_ASSERT_EQUAL( static_cast<T*>(NULL) , b[0] );
00267   STKUNIT_ASSERT_EQUAL( static_cast<T*>(NULL) , b[1] );
00268   STKUNIT_ASSERT_EQUAL( static_cast<T*>(NULL) , b[2] );
00269 
00270   STKUNIT_ASSERT_THROW( traits.sum( b , a , 3 ) , std::runtime_error );
00271   STKUNIT_ASSERT_THROW( traits.max( b , a , 3 ) , std::runtime_error );
00272   STKUNIT_ASSERT_THROW( traits.min( b , a , 3 ) , std::runtime_error );
00273   STKUNIT_ASSERT_THROW( traits.bit_and( b, a, 3 ), std::runtime_error );
00274   STKUNIT_ASSERT_THROW( traits.bit_or(  b, a, 3 ), std::runtime_error );
00275   STKUNIT_ASSERT_THROW( traits.bit_xor( b, a, 3 ), std::runtime_error );
00276   STKUNIT_ASSERT_THROW( traits.print( std::cout, NULL, 0 ), std::runtime_error );
00277 
00278   if ( testComm ) {
00279     CommAll all( MPI_COMM_WORLD );
00280     STKUNIT_ASSERT_THROW( traits.pack( all.send_buffer(0) , a , 3 ), std::runtime_error );
00281     all.allocate_buffers( 0 );
00282     all.communicate();
00283     STKUNIT_ASSERT_THROW( traits.unpack( all.recv_buffer(0) , b , 3 ), std::runtime_error );
00284   }
00285 }
00286 
00287 }
00288 
00289 
00290 void UnitTestDataTraits::testPointer( bool testComm )
00291 {
00292   test_fundemental_pointer<char          >( testComm );
00293   test_fundemental_pointer<unsigned char >( testComm );
00294   test_fundemental_pointer<short         >( testComm );
00295   test_fundemental_pointer<unsigned short>( testComm );
00296   test_fundemental_pointer<int           >( testComm );
00297   test_fundemental_pointer<unsigned int  >( testComm );
00298   test_fundemental_pointer<long          >( testComm );
00299   test_fundemental_pointer<unsigned long >( testComm );
00300   test_fundemental_pointer<float         >( testComm );
00301   test_fundemental_pointer<double        >( testComm );
00302 }
00303 
00304 //----------------------------------------------------------------------
00305 
00306 enum EType { val_a = 'a' , val_b = 'b' , val_c = 'c' };
00307 
00308 DATA_TRAITS_ENUM_3( EType , val_a , val_b , val_c )
00309 
00310 void UnitTestDataTraits::testEnum( bool testComm )
00311 {
00312   typedef EType T ;
00313   const DataTraits & traits = data_traits<T>();
00314 
00315   STKUNIT_ASSERT(       traits.type_info        == typeid(T) );
00316   STKUNIT_ASSERT_EQUAL( traits.size_of           , sizeof(T) );
00317   STKUNIT_ASSERT_EQUAL( traits.alignment_of      , sizeof(T) );
00318   STKUNIT_ASSERT_EQUAL( traits.stride_of         , sizeof(T) );
00319   STKUNIT_ASSERT_EQUAL( traits.is_integral       , false );
00320   STKUNIT_ASSERT_EQUAL( traits.is_floating_point , false );
00321   STKUNIT_ASSERT_EQUAL( traits.is_array          , false );
00322   STKUNIT_ASSERT_EQUAL( traits.is_pointer        , false );
00323   STKUNIT_ASSERT_EQUAL( traits.is_enum           , true );
00324   STKUNIT_ASSERT_EQUAL( traits.is_class          , false );
00325   STKUNIT_ASSERT_EQUAL( traits.is_pod            , true );
00326   STKUNIT_ASSERT_EQUAL( traits.is_signed         , false );
00327   STKUNIT_ASSERT_EQUAL( traits.is_unsigned       , false );
00328 
00329   STKUNIT_ASSERT( ! traits.remove_pointer   );
00330   STKUNIT_ASSERT( traits.class_info.empty() );
00331 
00332   STKUNIT_ASSERT_EQUAL( traits.enum_info.size()   , size_t(3) );
00333   STKUNIT_ASSERT_EQUAL( (traits.enum_info[0].name == "val_a"), true );
00334   STKUNIT_ASSERT_EQUAL( (traits.enum_info[1].name  == "val_b"), true );
00335   STKUNIT_ASSERT_EQUAL( (traits.enum_info[2].name  == "val_c"), true );
00336   STKUNIT_ASSERT_EQUAL( traits.enum_info[0].value , long(val_a) );
00337   STKUNIT_ASSERT_EQUAL( traits.enum_info[1].value , long(val_b) );
00338   STKUNIT_ASSERT_EQUAL( traits.enum_info[2].value , long(val_c) );
00339 
00340   EType a[3] = { val_a , val_b , val_c };
00341   EType b[3] ;
00342 
00343   traits.construct( b , 3 );
00344   STKUNIT_ASSERT_EQUAL( val_a , b[0] );
00345   STKUNIT_ASSERT_EQUAL( val_a , b[1] );
00346   STKUNIT_ASSERT_EQUAL( val_a , b[2] );
00347 
00348   traits.copy( b , a , 3 );
00349   STKUNIT_ASSERT_EQUAL( a[0] , b[0] );
00350   STKUNIT_ASSERT_EQUAL( a[1] , b[1] );
00351   STKUNIT_ASSERT_EQUAL( a[2] , b[2] );
00352 
00353   b[0] = val_b ; b[1] = val_b ; b[2] = val_b ;
00354 
00355   traits.min( b , a , 3 );
00356   STKUNIT_ASSERT_EQUAL( val_a , b[0] );
00357   STKUNIT_ASSERT_EQUAL( val_b , b[1] );
00358   STKUNIT_ASSERT_EQUAL( val_b , b[2] );
00359 
00360   b[0] = val_b ; b[1] = val_b ; b[2] = val_b ;
00361 
00362   traits.max( b , a , 3 );
00363   STKUNIT_ASSERT_EQUAL( val_b , b[0] );
00364   STKUNIT_ASSERT_EQUAL( val_b , b[1] );
00365   STKUNIT_ASSERT_EQUAL( val_c , b[2] );
00366 
00367   STKUNIT_ASSERT_THROW( traits.sum( b , a , 3 ) , std::runtime_error );
00368   STKUNIT_ASSERT_THROW( traits.bit_and( b, a, 3 ), std::runtime_error );
00369   STKUNIT_ASSERT_THROW( traits.bit_or(  b, a, 3 ), std::runtime_error );
00370   STKUNIT_ASSERT_THROW( traits.bit_xor( b, a, 3 ), std::runtime_error );
00371 
00372   if ( testComm ) {
00373     traits.construct( b , 3 );
00374     CommAll all( MPI_COMM_WORLD );
00375     traits.pack( all.send_buffer(0) , a , 3 );
00376     all.allocate_buffers( 0 );
00377     traits.pack( all.send_buffer(0) , a , 3 );
00378     all.communicate();
00379     traits.unpack( all.recv_buffer(0) , b , 3 );
00380     STKUNIT_ASSERT_EQUAL( a[0] , b[0] );
00381     STKUNIT_ASSERT_EQUAL( a[1] , b[1] );
00382     STKUNIT_ASSERT_EQUAL( a[2] , b[2] );
00383   }
00384 
00385   b[2] = static_cast<EType>( 'd' );
00386   std::cout << traits.name << " " ;
00387   traits.print( std::cout , b , 3 );
00388   std::cout << std::endl ;
00389 
00390   traits.destroy( b , 3 );
00391 }
00392 
00393 //----------------------------------------------------------------------
00394 
00395 struct Vec3 { double x , y , z ; };
00396 
00397 DATA_TRAITS_POD_CLASS_3( Vec3 , x , y , z )
00398 
00399 void UnitTestDataTraits::testClass( bool testComm )
00400 {
00401   typedef Vec3 T ;
00402   const DataTraits & traits = data_traits<T>();
00403 
00404   STKUNIT_ASSERT(       traits.type_info        == typeid(T) );
00405   STKUNIT_ASSERT_EQUAL( traits.size_of           , sizeof(T) );
00406   STKUNIT_ASSERT_EQUAL( traits.alignment_of      , sizeof(double) );
00407   STKUNIT_ASSERT_EQUAL( traits.stride_of         , sizeof(T) );
00408   STKUNIT_ASSERT_EQUAL( traits.is_integral       , false );
00409   STKUNIT_ASSERT_EQUAL( traits.is_floating_point , false );
00410   STKUNIT_ASSERT_EQUAL( traits.is_array          , false );
00411   STKUNIT_ASSERT_EQUAL( traits.is_pointer        , false );
00412   STKUNIT_ASSERT_EQUAL( traits.is_enum           , false );
00413   STKUNIT_ASSERT_EQUAL( traits.is_class          , true );
00414   STKUNIT_ASSERT_EQUAL( traits.is_pod            , true );
00415   STKUNIT_ASSERT_EQUAL( traits.is_signed         , false );
00416   STKUNIT_ASSERT_EQUAL( traits.is_unsigned       , false );
00417 
00418   STKUNIT_ASSERT( ! traits.remove_pointer   );
00419   STKUNIT_ASSERT( traits.enum_info.empty() );
00420 
00421   const Vec3 a = { 1.0 , 2.0 , 3.0 };
00422   const size_t dx = reinterpret_cast<const unsigned char *>( & a.x ) -
00423                     reinterpret_cast<const unsigned char *>( & a );
00424   const size_t dy = reinterpret_cast<const unsigned char *>( & a.y ) -
00425                     reinterpret_cast<const unsigned char *>( & a );
00426   const size_t dz = reinterpret_cast<const unsigned char *>( & a.z ) -
00427                     reinterpret_cast<const unsigned char *>( & a );
00428 
00429   STKUNIT_ASSERT_EQUAL( traits.class_info.size() , size_t(3) );
00430   STKUNIT_ASSERT_EQUAL( (traits.class_info[0].name == "x"), true );
00431   STKUNIT_ASSERT_EQUAL( (traits.class_info[1].name == "y"), true );
00432   STKUNIT_ASSERT_EQUAL( (traits.class_info[2].name == "z"), true );
00433   STKUNIT_ASSERT_EQUAL( traits.class_info[0].traits, & data_traits<double>() );
00434   STKUNIT_ASSERT_EQUAL( traits.class_info[1].traits, & data_traits<double>() );
00435   STKUNIT_ASSERT_EQUAL( traits.class_info[2].traits, & data_traits<double>() );
00436   STKUNIT_ASSERT_EQUAL( traits.class_info[0].offset, dx );
00437   STKUNIT_ASSERT_EQUAL( traits.class_info[1].offset, dy );
00438   STKUNIT_ASSERT_EQUAL( traits.class_info[2].offset, dz );
00439 
00440   Vec3 b ;
00441   traits.construct( & b , 1 );
00442   traits.copy( & b , & a , 1 );
00443   STKUNIT_ASSERT_EQUAL( b.x , a.x );
00444   STKUNIT_ASSERT_EQUAL( b.y , a.y );
00445   STKUNIT_ASSERT_EQUAL( b.z , a.z );
00446 
00447   STKUNIT_ASSERT_THROW( traits.sum( NULL , NULL , 0 ) , std::runtime_error );
00448   STKUNIT_ASSERT_THROW( traits.max( NULL , NULL , 0 ) , std::runtime_error );
00449   STKUNIT_ASSERT_THROW( traits.min( NULL , NULL , 0 ) , std::runtime_error );
00450   STKUNIT_ASSERT_THROW( traits.bit_and( NULL, NULL, 0 ), std::runtime_error );
00451   STKUNIT_ASSERT_THROW( traits.bit_or( NULL , NULL, 0 ), std::runtime_error );
00452   STKUNIT_ASSERT_THROW( traits.bit_xor( NULL, NULL, 0 ), std::runtime_error );
00453   STKUNIT_ASSERT_THROW( traits.print( std::cout, NULL, 0 ), std::runtime_error );
00454 
00455   if ( testComm ) {
00456     traits.construct( & b , 1 );
00457     CommAll all( MPI_COMM_WORLD );
00458     traits.pack( all.send_buffer(0) , & a , 1 );
00459     all.allocate_buffers( 0 );
00460     traits.pack( all.send_buffer(0) , & a , 1 );
00461     all.communicate();
00462     traits.unpack( all.recv_buffer(0) , & b , 1 );
00463     STKUNIT_ASSERT_EQUAL( a.x , b.x );
00464     STKUNIT_ASSERT_EQUAL( a.y , b.y );
00465     STKUNIT_ASSERT_EQUAL( a.z , b.z );
00466   }
00467 
00468   traits.destroy( & b , 1 );
00469 
00470 }
00471 
00472 }
00473 }
00474 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends