MOAB: Mesh Oriented datABase  (version 5.4.1)
h5regression.cpp
Go to the documentation of this file.
00001 #include "moab/Core.hpp"
00002 #include "TestUtil.hpp"
00003 #include "moab/Range.hpp"
00004 #include "moab/ReadUtilIface.hpp"
00005 #include "WriteHDF5.hpp"
00006 #include "moab/FileOptions.hpp"
00007 
00008 #ifdef MOAB_HAVE_MPI
00009 #include "moab_mpi.h"
00010 #endif
00011 
00012 #include <algorithm>
00013 #include <iostream>
00014 #include <sstream>
00015 #include <cstdlib>
00016 #include <cmath>
00017 
00018 using namespace moab;
00019 
00020 const char filename[] = "bad.h5m";
00021 
00022 void test_write_invalid_elem();
00023 void test_write_read_many_tags();
00024 
00025 int main( int argc, char* argv[] )
00026 {
00027 #ifdef MOAB_HAVE_MPI
00028     int fail = MPI_Init( &argc, &argv );
00029     if( fail ) return fail;
00030 #else
00031     argv[0] = argv[argc - argc];  // warning in serial
00032 #endif
00033 
00034     int exitval = 0;
00035     exitval += RUN_TEST( test_write_invalid_elem );
00036     exitval += RUN_TEST( test_write_read_many_tags );
00037 
00038 #ifdef MOAB_HAVE_MPI
00039     fail = MPI_Finalize();
00040     if( fail ) return fail;
00041 #endif
00042 
00043     return exitval;
00044 }
00045 
00046 void test_write_invalid_elem()
00047 {
00048     Core mbcore;
00049     Interface& moab         = mbcore;
00050     ReadUtilIface* readtool = 0;
00051     ErrorCode rval;
00052 
00053     rval = moab.query_interface( readtool );CHECK_ERR( rval );
00054     CHECK( readtool != 0 );
00055 
00056     // create two nodes
00057     EntityHandle first_node;
00058     std::vector< double* > coords;
00059     rval = readtool->get_node_coords( 3, 2, 1, first_node, coords );CHECK_ERR( rval );
00060     // Cppcheck warning (false positive): variable coords is assigned a value that is never used
00061     coords[0][0] = coords[0][1] = 0.0;
00062     coords[1][0] = coords[1][1] = 0.0;
00063     coords[2][0] = coords[2][1] = 0.0;
00064 
00065     // create a triangle with an invalid node handle for its
00066     // third vertex
00067     EntityHandle tri;
00068     EntityHandle* conn = 0;
00069     rval               = readtool->get_element_connect( 1, 3, MBTRI, 1, tri, conn );CHECK_ERR( rval );
00070     conn[0] = first_node;      // valid
00071     conn[1] = first_node + 1;  // valid
00072     conn[2] = first_node + 2;  // invalid
00073 
00074     // try to write the file (should fail)
00075     WriteHDF5 writer( &moab );
00076     FileOptions opts( 0 );
00077     rval = writer.write_file( filename, true, opts, 0, 0, std::vector< std::string >() );
00078     CHECK( MB_SUCCESS != rval );
00079 }
00080 
00081 void test_write_read_many_tags()
00082 {
00083     const int N = 200;
00084     Core mbcore;
00085     Interface& mb = mbcore;
00086     ErrorCode rval;
00087 
00088     double coords[3] = { 0, 0, 0 };
00089     EntityHandle node;
00090     rval = mb.create_vertex( coords, node );CHECK_ERR( rval );
00091 
00092     // create a lot of tags
00093     std::vector< Tag > tags;
00094     for( int i = 0; i < N; ++i )
00095     {
00096         Tag t;
00097         std::ostringstream name( "IntTag" );
00098         name << i;
00099         rval = mb.tag_get_handle( name.str().c_str(), 1, MB_TYPE_INTEGER, t,
00100                                   ( i % 2 ? MB_TAG_SPARSE : MB_TAG_DENSE ) | MB_TAG_EXCL, &i );CHECK_ERR( rval );
00101         tags.push_back( t );
00102     }
00103 
00104     // write the file
00105     rval = mb.write_file( filename, "MOAB" );CHECK_ERR( rval );
00106 
00107     // clear moab instance
00108     rval = mb.delete_mesh();CHECK_ERR( rval );
00109     for( int i = 0; i < N; ++i )
00110     {
00111         rval = mb.tag_delete( tags[i] );CHECK_ERR( rval );
00112     }
00113 
00114     // read the file
00115     rval = mb.load_file( filename );CHECK_ERR( rval );
00116     remove( filename );
00117 
00118     // check that we have the expected tags
00119     for( int i = 0; i < N; ++i )
00120     {
00121         Tag t;
00122         std::ostringstream name( "IntTag" );
00123         name << i;
00124         rval = mb.tag_get_handle( name.str().c_str(), 1, MB_TYPE_INTEGER, t );CHECK_ERR( rval );
00125 
00126         TagType storage;
00127         rval = mb.tag_get_type( t, storage );CHECK_ERR( rval );
00128         CHECK_EQUAL( ( i % 2 ) ? MB_TAG_SPARSE : MB_TAG_DENSE, storage );
00129 
00130         DataType type;
00131         rval = mb.tag_get_data_type( t, type );CHECK_ERR( rval );
00132         CHECK_EQUAL( MB_TYPE_INTEGER, type );
00133 
00134         int size;
00135         rval = mb.tag_get_length( t, size );CHECK_ERR( rval );
00136         CHECK_EQUAL( 1, size );
00137 
00138         int def;
00139         rval = mb.tag_get_default_value( t, &def );CHECK_ERR( rval );
00140         CHECK_EQUAL( i, def );
00141     }
00142 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines