15 #define STRINGIFY_( X ) #X
16 #define STRINGIFY( X ) STRINGIFY_( X )
25 #error Specify MOAB_MESH_DIR to compile test
35 #define CHECK_ERR( A ) check_equal( MB_SUCCESS, ( A ), "MB_SUCCESS", #A, __LINE__, __FILE__ )
37 #define CHECK( A ) check_true( ( A ), #A, __LINE__, __FILE__ )
39 #define CHECK_EQUAL( EXP, ACT ) check_equal( ( EXP ), ( ACT ), #EXP, #ACT, __LINE__, __FILE__ )
41 #define CHECK_REAL_EQUAL( EXP, ACT, EPS ) check_equal( ( EXP ), ( ACT ), ( EPS ), #EXP, #ACT, __LINE__, __FILE__ )
43 #define CHECK_ARRAYS_EQUAL( EXP, EXP_LEN, ACT, ACT_LEN ) \
44 check_array_equal( ( EXP ), ( EXP_LEN ), ( ACT ), ( ACT_LEN ), #EXP, #ACT, __LINE__, __FILE__ )
46 #define CHECK_VECREAL_EQUAL( EXP, ACT, EPS ) \
47 check_equal_cartvect( ( EXP ), ( ACT ), ( EPS ), #EXP, #ACT, __LINE__, __FILE__ )
52 #define RUN_TEST( FUNC ) run_test( &( ( ( ( FUNC ) ) ) ), #FUNC )
56 #define EXCEPTION_MODE 1
70 #define LONGJMP_MODE 3
74 #if defined( _MSC_VER ) || defined( __MINGW32__ )
75 #define MODE EXCEPTION_MODE
77 #define MODE LONGJMP_MODE
103 #if MODE == EXCEPTION_MODE
107 #define FLAG_ERROR throw ErrorExcept()
111 #elif MODE == FORK_MODE
112 #include <sys/types.h>
113 #include <sys/wait.h>
116 #define FLAG_ERROR exit( 1 )
121 #elif MODE == LONGJMP_MODE
124 #define FLAG_ERROR siglongjmp( jmpenv, -1 )
126 #error "MODE not set"
133 #if MODE == LONGJMP_MODE
145 siglongjmp(
jmpenv, sig );
156 if( h == SIG_ERR )
return 1;
159 else if( h != SIG_DFL )
264 #ifndef IS_BUILDING_MB
265 #define IS_BUILDING_MB
267 #undef IS_BUILDING_MB
272 #ifndef TEST_USES_ERR_CODES
277 int run_test( test_func_err
test,
const char* func_name )
284 MPI_Initialized( &isInit );
291 if(
rank == 0 ) printf(
"Running %s ...\n", func_name );
293 #if MODE == EXCEPTION_MODE
304 printf(
"[%d] %s: FAILED\n",
rank, func_name );
309 printf(
"[%d] %s: UNCAUGHT EXCEPTION\n",
rank, func_name );
313 #elif MODE == FORK_MODE
335 waitpid( pid, &status, 0 );
338 if( WIFSIGNALED( status ) )
340 if( WTERMSIG( status ) ) printf(
" %s: TERMINATED (signal %d)\n", func_name, (
int)WTERMSIG( status ) );
341 if( WCOREDUMP( status ) ) printf(
" %s: CORE DUMP\n", func_name );
344 else if( WEXITSTATUS( status ) )
346 printf(
" %s: FAILED\n", func_name );
354 #elif MODE == LONGJMP_MODE
356 int rval = sigsetjmp(
jmpenv, 1 );
370 else if( rval == -1 )
372 printf(
" %s: FAILED\n", func_name );
378 printf(
" %s: TERMINATED (signal %d)\n", func_name, rval );
382 #error "MODE not set"
391 #define EQUAL_TEST_IMPL( TEST, TYPE ) \
394 printf( "Equality Test Failed: %s == %s\n", sA, sB ); \
395 printf( " at line %d of '%s'\n", line, file ); \
396 printf( " Expected value: %" #TYPE "\n", A ); \
397 printf( " Actual value: %" #TYPE "\n", B ); \
402 void check_equal(
int A,
int B,
const char* sA,
const char* sB,
int line,
const char* file )
407 void check_equal(
unsigned A,
unsigned B,
const char* sA,
const char* sB,
int line,
const char* file )
412 void check_equal(
long A,
long B,
const char* sA,
const char* sB,
int line,
const char* file )
417 void check_equal(
unsigned long A,
unsigned long B,
const char* sA,
const char* sB,
int line,
const char* file )
423 unsigned long long B,
432 void check_equal(
long long A,
long long B,
const char* sA,
const char* sB,
int line,
const char* file )
437 void check_equal(
void* A,
void* B,
const char* sA,
const char* sB,
int line,
const char* file )
442 void check_equal(
const char* A,
const char* B,
const char* sA,
const char* sB,
int line,
const char* file )
448 const std::string& B,
454 check_equal( A.c_str(), B.c_str(), sA, sB, line, file );
457 void check_equal(
float A,
float B,
float eps,
const char* sA,
const char* sB,
int line,
const char* file )
462 void check_equal(
double A,
double B,
double eps,
const char* sA,
const char* sB,
int line,
const char* file )
474 return "Index Out of Range";
476 return "Type Out of Range";
478 return "Memory Alloc. Failed";
480 return "Entity Not Found";
482 return "Multiple Entities Found";
484 return "Tag Not Found";
486 return "File Not Found";
488 return "File Write Error";
490 return "Not Implemented";
492 return "Already Allocated";
494 return "Variable Data Length";
496 return "Invalid Size";
498 return "Unsupported Operation";
500 return "Unhandled Option";
502 return "Structured Mesh";
503 case moab::MB_FAILURE:
516 printf(
"ErrorCode Test Failed: %s == %s\n", sA, sB );
517 printf(
" at line %d of '%s'\n", line, file );
518 printf(
" Expected value: %s (%d)\n",
mb_error_str( A ), (
int)A );
519 printf(
" Actual value: %s (%d)\n",
mb_error_str( B ), (
int)B );
535 return "Quadrilateral";
539 return "Tetrahedron";
543 return "Prism (wedge)";
551 return "Entity (Mesh) Set";
585 void check_true(
bool cond,
const char* str,
int line,
const char* file )
589 printf(
"Test Failed: %s\n", str );
590 printf(
" at line %d of '%s'\n", line, file );
596 #ifdef MB_CART_VECT_HPP
608 if( fabs( A[0] - B[0] ) <=
eps && fabs( A[1] - B[1] ) <=
eps && fabs( A[2] - B[2] ) <=
eps )
return;
610 std::cout <<
"Equality Test Failed: " << sA <<
" == " << sB << std::endl;
611 std::cout <<
" at line " << line <<
" of '" << file <<
"'" << std::endl;
613 std::cout <<
" Expected: ";
614 std::cout << A << std::endl;
616 std::cout <<
" Actual: ";
617 std::cout << B << std::endl;
626 template <
typename T >
627 void check_array_equal(
const T* A,
639 if( i == A_size && i == B_size )
641 else if( i == A_size || i == B_size )
643 else if( A[i] != B[i] )
648 std::cout <<
"Equality Test Failed: " << sA <<
" == " << sB << std::endl;
649 std::cout <<
" at line " << line <<
" of '" << file <<
"'" << std::endl;
650 std::cout <<
" Vectors differ at position " << i << std::endl;
653 size_t count = 10, num_front_values = std::min( count / 2, i );
654 size_t max_len = std::max( A_size, B_size );
655 if( i + count - num_front_values > max_len )
657 if( count > max_len )
659 num_front_values = i;
664 num_front_values = count - ( max_len - i );
668 std::cout <<
" Expected: ";
671 std::cout <<
"(empty)" << std::endl;
675 size_t j = i - num_front_values;
676 size_t end = std::min( j + count, A_size );
677 if( j ) std::cout <<
"... ";
678 for( ; j < end; ++j )
681 std::cout << '>
' << A[j] << "< ";
683 std::cout << A[j] << " ";
685 if( end != A_size ) std::cout << "...";
686 std::cout << std::endl;
689 std::cout << " Actual: ";
692 std::cout << "(empty)" << std::endl;
696 size_t j = i - num_front_values;
697 size_t end = std::min( j + count, B_size );
698 if( j ) std::cout << "... ";
699 for( ; j < end; ++j )
702 std::cout << '>
' << B[j] << "< ";
704 std::cout << B[j] << " ";
706 if( end != B_size ) std::cout << ", ...";
707 std::cout << std::endl;
713 template < typename T >
714 void check_equal( const std::vector< T >& A,
715 const std::vector< T >& B,
721 if( A.empty() || B.empty() )
723 if( A.size() != B.size() )
725 std::cout << "Equality Test Failed: " << sA << " == " << sB << std::endl;
726 std::cout << " at line " << line << " of '" << file << "'" << std::endl;
727 std::cout << " Both are not empty " << std::endl;
731 check_array_equal( &A[0], A.size(), &B[0], B.size(), sA, sB, line, file );
734 #ifdef MOAB_RANGE_HPP
736 void check_equal( const moab::Range& A,
737 const moab::Range& B,
745 std::cout << "moab::ErrorCode Test Failed: " << sA << " == " << sB << std::endl;
746 std::cout << " at line " << line << " of '" << file << "'" << std::endl;
747 std::cout << " Expected: " << A << std::endl;
748 std::cout << " Actual : " << B << std::endl;
749 std::cout << std::endl;
753 #endif // #ifdef MOAB_RANGE_HPP
755 void check_baseline_file( std::string basefile,
756 std::vector< int >& gids,
757 std::vector< double >& vals,
763 fs.open( basefile.c_str(), std::fstream::in );
766 std::cout << " error opening base file " << basefile << "\n";
770 std::map< int, double > mapVals;
778 for( size_t i = 0; i < gids.size(); i++ )
780 std::map< int, double >::iterator it = mapVals.find( gids[i] );
781 if( it == mapVals.end() )
783 std::cout << "id - value not found:" << gids[i] << "\n";
787 if( fabs( it->second - vals[i] ) > eps )
789 std::cout << " value out of range: index i=" << i << " id: " << gids[i] << " value:" << vals[i]
790 << " expected : " << it->second << "\n";
795 err_code = 0; // no error
797 #endif /* ifdef __cplusplus */