[MOAB-dev] r2305 - in MOAB/trunk: . test/h5file

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Wed Dec 3 12:17:53 CST 2008


Author: kraftche
Date: 2008-12-03 12:17:52 -0600 (Wed, 03 Dec 2008)
New Revision: 2305

Added:
   MOAB/trunk/test/h5file/h5regression.cpp
Modified:
   MOAB/trunk/WriteHDF5.cpp
   MOAB/trunk/test/h5file/Makefile.am
   MOAB/trunk/test/h5file/h5sets_test.cpp
Log:
o Make HDF5 writer fail if element connectivity list contains invalid
  vertex handles (better to fail when writing than when reading.)

o Add test to verify that writer fails for invalid connectivity.

o Fix bug in existing test (missing return value from 'main')



Modified: MOAB/trunk/WriteHDF5.cpp
===================================================================
--- MOAB/trunk/WriteHDF5.cpp	2008-12-03 18:16:20 UTC (rev 2304)
+++ MOAB/trunk/WriteHDF5.cpp	2008-12-03 18:17:52 UTC (rev 2305)
@@ -772,7 +772,8 @@
     iter = next;
     
     for (long i = 0; i < count*nodes_per_elem; ++i)
-      buffer[i] = idMap.find( buffer[i] );
+      if (0 == (buffer[i] = idMap.find( buffer[i] )))
+        return MB_FAILURE;
     
     mhdf_writeConnectivity( elem_table, offset, count, 
                             id_type, buffer, &status );

Modified: MOAB/trunk/test/h5file/Makefile.am
===================================================================
--- MOAB/trunk/test/h5file/Makefile.am	2008-12-03 18:16:20 UTC (rev 2304)
+++ MOAB/trunk/test/h5file/Makefile.am	2008-12-03 18:17:52 UTC (rev 2305)
@@ -1,6 +1,6 @@
 DEFS = $(DEFINES)
 INCLUDES += -I$(top_srcdir) -I$(top_srcdir)/mhdf/include -I$(top_builddir)
-check_PROGRAMS = h5test h5legacy h5varlen h5sets_test
+check_PROGRAMS = h5test h5legacy h5varlen h5sets_test h5regression
 
 TESTS = $(check_PROGRAMS)
 LDADD = $(top_builddir)/libMOAB.la
@@ -9,3 +9,4 @@
 h5legacy_SOURCES = h5legacy.cpp
 h5varlen_SOURCES = h5varlen.cpp
 h5sets_test_SOURCES = h5sets_test.cpp
+h5regression_SOURCES = h5regression.cpp

Added: MOAB/trunk/test/h5file/h5regression.cpp
===================================================================
--- MOAB/trunk/test/h5file/h5regression.cpp	                        (rev 0)
+++ MOAB/trunk/test/h5file/h5regression.cpp	2008-12-03 18:17:52 UTC (rev 2305)
@@ -0,0 +1,65 @@
+#include "MBCore.hpp"
+#include "testdir.h"
+#include "TestUtil.hpp"
+#include "MBRange.hpp"
+#include "MBReadUtilIface.hpp"
+#include "WriteHDF5.hpp"
+#include "FileOptions.hpp"
+
+#include <algorithm>
+#include <iostream>
+#include <stdlib.h>
+#include <math.h>
+
+const char filename[] = "bad.h5m";
+  
+void test_write_invalid_elem();
+
+int main(int argc, char* argv[])
+{
+  int exitval = 0;
+  exitval += RUN_TEST( test_write_invalid_elem );
+  return exitval;
+}
+
+  
+void test_write_invalid_elem()
+{
+  MBCore mbcore;
+  MBInterface& moab = mbcore;
+  MBReadUtilIface* readtool = 0;
+  MBErrorCode rval;
+  
+  void* ptr = 0;
+  rval = moab.query_interface( "MBReadUtilIface", &ptr );
+  CHECK_ERR(rval);
+  CHECK( ptr != 0 );
+  readtool = reinterpret_cast<MBReadUtilIface*>(ptr);
+  
+    // create two nodes
+  MBEntityHandle first_node;
+  std::vector<double*> coords;
+  rval = readtool->get_node_arrays( 3, 2, 1, first_node, coords );
+  CHECK_ERR(rval);
+  coords[0][0] = coords[0][1] = 0.0;
+  coords[1][0] = coords[1][1] = 0.0;
+  coords[2][0] = coords[2][1] = 0.0;
+  
+    // create a triangle with an invalid node handle for its
+    // third vertex
+  MBEntityHandle tri;
+  MBEntityHandle* conn = 0;
+  rval = readtool->get_element_array( 1, 3, MBTRI, 1, tri, conn );
+  CHECK_ERR(rval);
+  conn[0] = first_node;   // valid
+  conn[1] = first_node+1; // valid
+  conn[2] = first_node+2; // invalid
+  
+    // try to write the file (should fail)
+  WriteHDF5 writer( &moab );
+  FileOptions opts(0);
+  rval = writer.write_file( filename, true, opts, 0, 0, std::vector<std::string>() );
+  CHECK(MB_SUCCESS != rval);
+}
+
+  

Modified: MOAB/trunk/test/h5file/h5sets_test.cpp
===================================================================
--- MOAB/trunk/test/h5file/h5sets_test.cpp	2008-12-03 18:16:20 UTC (rev 2304)
+++ MOAB/trunk/test/h5file/h5sets_test.cpp	2008-12-03 18:17:52 UTC (rev 2305)
@@ -132,6 +132,7 @@
   int exitval = 0;
   exitval += RUN_TEST( test_ranged_set_with_holes );
   exitval += RUN_TEST( test_file_set );
+  return exitval;
 }
 
   




More information about the moab-dev mailing list