MOAB: Mesh Oriented datABase  (version 5.2.1)
TestErrorHandling.cpp
Go to the documentation of this file.
00001 /** @example TestErrorHandling.cpp \n
00002  * Description: This example tests MOAB's trace back error handler in serial. \n
00003  *
00004  * <b>To run</b>: ./TestErrorHandling <test_case_num(1 to 4)> \n
00005  */
00006 
00007 #include "moab/Core.hpp"
00008 #ifdef MOAB_HAVE_MPI
00009 #include "moab_mpi.h"
00010 #endif
00011 
00012 #include <iostream>
00013 
00014 using namespace moab;
00015 using namespace std;
00016 
00017 // In this test case, an error MB_NOT_IMPLEMENTED is returned by MOAB
00018 ErrorCode TestErrorHandling_1()
00019 {
00020     Core moab;
00021     Interface& mb = moab;
00022 
00023     // Load a CAM-FV file and read a variable on edges (not supported yet)
00024     string test_file = string( MESH_DIR ) + string( "/io/fv3x46x72.t.3.nc" );
00025     ErrorCode rval   = mb.load_file( test_file.c_str(), NULL, "VARIABLE=US" );MB_CHK_ERR( rval );
00026 
00027     return MB_SUCCESS;
00028 }
00029 
00030 // In this test case, an error MB_TYPE_OUT_OF_RANGE is returned by MOAB
00031 ErrorCode TestErrorHandling_2()
00032 {
00033     Core moab;
00034     Interface& mb = moab;
00035 
00036     // Load a HOMME file with an invalid GATHER_SET option
00037     string test_file = string( MESH_DIR ) + string( "/io/homme3x3458.t.3.nc" );
00038     ErrorCode rval   = mb.load_file( test_file.c_str(), NULL, "VARIABLE=T;GATHER_SET=0.1" );MB_CHK_ERR( rval );
00039 
00040     return MB_SUCCESS;
00041 }
00042 
00043 // In this test case, an error MB_FAILURE is returned by MOAB
00044 ErrorCode TestErrorHandling_3()
00045 {
00046     Core moab;
00047     Interface& mb = moab;
00048 
00049     // Load a CAM-FV file with NOMESH option and a NULL file set
00050     string test_file = string( MESH_DIR ) + string( "/io/fv3x46x72.t.3.nc" );
00051     ErrorCode rval   = mb.load_file( test_file.c_str(), NULL, "NOMESH;VARIABLE=" );MB_CHK_ERR( rval );
00052 
00053     return MB_SUCCESS;
00054 }
00055 
00056 // In this test case, an error MB_VARIABLE_DATA_LENGTH is returned by MOAB
00057 ErrorCode TestErrorHandling_4()
00058 {
00059     Core moab;
00060     Interface& mb = moab;
00061 
00062     // Create 100 vertices
00063     const int NUM_VTX = 100;
00064     vector< double > coords( 3 * NUM_VTX );
00065     Range verts;
00066     ErrorCode rval = mb.create_vertices( &coords[0], NUM_VTX, verts );MB_CHK_SET_ERR( rval, "Failed to create vertices" );
00067 
00068     // Create a variable-length dense tag
00069     Tag tag;
00070     rval = mb.tag_get_handle( "var_len_den", 1, MB_TYPE_INTEGER, tag, MB_TAG_VARLEN | MB_TAG_DENSE | MB_TAG_CREAT );MB_CHK_SET_ERR( rval, "Failed to create a tag" );
00071 
00072     // Attempt to iterate over a variable-length tag, which will never be possible
00073     void* ptr = NULL;
00074     int count = 0;
00075     rval      = mb.tag_iterate( tag, verts.begin(), verts.end(), count, ptr );MB_CHK_SET_ERR( rval, "Failed to iterate over tag on " << NUM_VTX << " vertices" );
00076 
00077     return MB_SUCCESS;
00078 }
00079 
00080 int main( int argc, char** argv )
00081 {
00082     if( argc < 2 )
00083     {
00084         cout << "Usage: " << argv[0] << " <test_case_num(1 to 4)>" << endl;
00085         return 0;
00086     }
00087 
00088 #ifdef MOAB_HAVE_MPI
00089     MPI_Init( &argc, &argv );
00090 #endif
00091 
00092     // Initialize error handler, optional for this example (using moab instances)
00093     MBErrorHandler_Init();
00094 
00095     ErrorCode rval = MB_SUCCESS;
00096 
00097     int test_case_num = atoi( argv[1] );
00098     switch( test_case_num )
00099     {
00100         case 1:
00101             rval = TestErrorHandling_1();MB_CHK_ERR( rval );
00102             break;
00103         case 2:
00104             rval = TestErrorHandling_2();MB_CHK_ERR( rval );
00105             break;
00106         case 3:
00107             rval = TestErrorHandling_3();MB_CHK_ERR( rval );
00108             break;
00109         case 4:
00110             rval = TestErrorHandling_4();MB_CHK_ERR( rval );
00111             break;
00112         default:
00113             break;
00114     }
00115 
00116     // Finalize error handler, optional for this example (using moab instances)
00117     MBErrorHandler_Finalize();
00118 
00119 #ifdef MOAB_HAVE_MPI
00120     MPI_Finalize();
00121 #endif
00122 
00123     return 0;
00124 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines