MOAB: Mesh Oriented datABase  (version 5.5.0)
h5regression.cpp File Reference
#include "moab/Core.hpp"
#include "TestUtil.hpp"
#include "moab/Range.hpp"
#include "moab/ReadUtilIface.hpp"
#include "WriteHDF5.hpp"
#include "moab/FileOptions.hpp"
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <cmath>
+ Include dependency graph for h5regression.cpp:

Go to the source code of this file.

Functions

void test_write_invalid_elem ()
 
void test_write_read_many_tags ()
 
int main (int argc, char *argv[])
 

Variables

const char filename [] = "bad.h5m"
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 25 of file h5regression.cpp.

26 {
27 #ifdef MOAB_HAVE_MPI
28  int fail = MPI_Init( &argc, &argv );
29  if( fail ) return fail;
30 #else
31  argv[0] = argv[argc - argc]; // warning in serial
32 #endif
33 
34  int exitval = 0;
35  exitval += RUN_TEST( test_write_invalid_elem );
36  exitval += RUN_TEST( test_write_read_many_tags );
37 
38 #ifdef MOAB_HAVE_MPI
39  fail = MPI_Finalize();
40  if( fail ) return fail;
41 #endif
42 
43  return exitval;
44 }

References moab::fail(), RUN_TEST, test_write_invalid_elem(), and test_write_read_many_tags().

◆ test_write_invalid_elem()

void test_write_invalid_elem ( )

Definition at line 46 of file h5regression.cpp.

47 {
48  Core mbcore;
50  ReadUtilIface* readtool = 0;
51  ErrorCode rval;
52 
53  rval = moab.query_interface( readtool );CHECK_ERR( rval );
54  CHECK( readtool != 0 );
55 
56  // create two nodes
57  EntityHandle first_node;
58  std::vector< double* > coords;
59  rval = readtool->get_node_coords( 3, 2, 1, first_node, coords );CHECK_ERR( rval );
60  // Cppcheck warning (false positive): variable coords is assigned a value that is never used
61  coords[0][0] = coords[0][1] = 0.0;
62  coords[1][0] = coords[1][1] = 0.0;
63  coords[2][0] = coords[2][1] = 0.0;
64 
65  // create a triangle with an invalid node handle for its
66  // third vertex
67  EntityHandle tri;
68  EntityHandle* conn = 0;
69  rval = readtool->get_element_connect( 1, 3, MBTRI, 1, tri, conn );CHECK_ERR( rval );
70  conn[0] = first_node; // valid
71  conn[1] = first_node + 1; // valid
72  conn[2] = first_node + 2; // invalid
73 
74  // try to write the file (should fail)
75  WriteHDF5 writer( &moab );
76  FileOptions opts( 0 );
77  rval = writer.write_file( filename, true, opts, 0, 0, std::vector< std::string >() );
78  CHECK( MB_SUCCESS != rval );
79 }

References CHECK, CHECK_ERR, ErrorCode, filename, moab::ReadUtilIface::get_element_connect(), moab::ReadUtilIface::get_node_coords(), MB_SUCCESS, mbcore, MBTRI, and moab::WriteHDF5::write_file().

Referenced by main().

◆ test_write_read_many_tags()

void test_write_read_many_tags ( )

Definition at line 81 of file h5regression.cpp.

82 {
83  const int N = 200;
84  Core mbcore;
85  Interface& mb = mbcore;
86  ErrorCode rval;
87 
88  double coords[3] = { 0, 0, 0 };
89  EntityHandle node;
90  rval = mb.create_vertex( coords, node );CHECK_ERR( rval );
91 
92  // create a lot of tags
93  std::vector< Tag > tags;
94  for( int i = 0; i < N; ++i )
95  {
96  Tag t;
97  std::ostringstream name( "IntTag" );
98  name << i;
99  rval = mb.tag_get_handle( name.str().c_str(), 1, MB_TYPE_INTEGER, t,
100  ( i % 2 ? MB_TAG_SPARSE : MB_TAG_DENSE ) | MB_TAG_EXCL, &i );CHECK_ERR( rval );
101  tags.push_back( t );
102  }
103 
104  // write the file
105  rval = mb.write_file( filename, "MOAB" );CHECK_ERR( rval );
106 
107  // clear moab instance
108  rval = mb.delete_mesh();CHECK_ERR( rval );
109  for( int i = 0; i < N; ++i )
110  {
111  rval = mb.tag_delete( tags[i] );CHECK_ERR( rval );
112  }
113 
114  // read the file
115  rval = mb.load_file( filename );CHECK_ERR( rval );
116  remove( filename );
117 
118  // check that we have the expected tags
119  for( int i = 0; i < N; ++i )
120  {
121  Tag t;
122  std::ostringstream name( "IntTag" );
123  name << i;
124  rval = mb.tag_get_handle( name.str().c_str(), 1, MB_TYPE_INTEGER, t );CHECK_ERR( rval );
125 
126  TagType storage;
127  rval = mb.tag_get_type( t, storage );CHECK_ERR( rval );
128  CHECK_EQUAL( ( i % 2 ) ? MB_TAG_SPARSE : MB_TAG_DENSE, storage );
129 
130  DataType type;
131  rval = mb.tag_get_data_type( t, type );CHECK_ERR( rval );
132  CHECK_EQUAL( MB_TYPE_INTEGER, type );
133 
134  int size;
135  rval = mb.tag_get_length( t, size );CHECK_ERR( rval );
136  CHECK_EQUAL( 1, size );
137 
138  int def;
139  rval = mb.tag_get_default_value( t, &def );CHECK_ERR( rval );
140  CHECK_EQUAL( i, def );
141  }
142 }

References CHECK_EQUAL, CHECK_ERR, moab::Core::create_vertex(), moab::Core::delete_mesh(), ErrorCode, filename, moab::Core::load_file(), mb, MB_TAG_DENSE, MB_TAG_EXCL, MB_TAG_SPARSE, MB_TYPE_INTEGER, mbcore, size, t, moab::Core::tag_delete(), moab::Core::tag_get_data_type(), moab::Core::tag_get_default_value(), moab::Core::tag_get_handle(), moab::Core::tag_get_length(), moab::Core::tag_get_type(), TagType, and moab::Core::write_file().

Referenced by main().

Variable Documentation

◆ filename

const char filename[] = "bad.h5m"

Definition at line 20 of file h5regression.cpp.

Referenced by test_write_invalid_elem(), and test_write_read_many_tags().