[cig-commits] r7374 - in short/3D/PyLith/trunk: libsrc/meshio unittests/libtests/meshio unittests/libtests/meshio/data

brad at geodynamics.org brad at geodynamics.org
Fri Jun 22 07:55:11 PDT 2007


Author: brad
Date: 2007-06-22 07:55:11 -0700 (Fri, 22 Jun 2007)
New Revision: 7374

Modified:
   short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc
   short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.cc
   short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.hh
   short/3D/PyLith/trunk/unittests/libtests/meshio/data/Makefile.am
Log:
Added unit test for reading mesh file with comments. Fixed bug that prevented comments within indices list in groups.

Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc	2007-06-22 13:56:09 UTC (rev 7373)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc	2007-06-22 14:55:11 UTC (rev 7374)
@@ -460,13 +460,15 @@
       points->resize(numPoints);
       buffer.str(parser.next());
       buffer.clear();
-      for (int i=0; i < numPoints; ++i) {
-	buffer >> (*points)[i];
-	if (!buffer.good() && i < numPoints-1) {
+      int i = 0;
+      while (buffer.good() && i < numPoints) {
+	buffer >> (*points)[i++];
+	buffer >> std::ws;
+	if (!buffer.good() && i < numPoints) {
 	  buffer.str(parser.next());
 	  buffer.clear();
 	} // if
-      } // for
+      } // while
       parser.ignore('}');
     } else {
       std::ostringstream msg;

Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.cc	2007-06-22 13:56:09 UTC (rev 7373)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.cc	2007-06-22 14:55:11 UTC (rev 7374)
@@ -127,6 +127,16 @@
 } // testWriteRead3D
 
 // ----------------------------------------------------------------------
+// Test write() and read() for 2D mesh in 2D space with comments.
+void
+pylith::meshio::TestMeshIOAscii::testReadComments(void)
+{ // testWriteReadComments
+  MeshData2D data;
+  const char* filename = "data/mesh2D_comments.txt";
+  _testRead(data, filename);
+} // testWriteReadComments
+
+// ----------------------------------------------------------------------
 // Build mesh, perform write() and read(), and then check values.
 void
 pylith::meshio::TestMeshIOAscii::_testWriteRead(const MeshData& data,
@@ -148,4 +158,21 @@
   _checkVals(meshIn, data);
 } // _testWriteRead
 
+// ----------------------------------------------------------------------
+// Read mesh and then check values.
+void
+pylith::meshio::TestMeshIOAscii::_testRead(const MeshData& data,
+					   const char* filename)
+{ // _testWriteRead
+  // Read mesh
+  ALE::Obj<Mesh> mesh;
+  MeshIOAscii iohandler;
+  iohandler.filename(filename);
+  iohandler.read(&mesh);
+
+  // Make sure mesh matches data
+  _checkVals(mesh, data);
+} // _testRead
+
+
 // End of file 

Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.hh	2007-06-22 13:56:09 UTC (rev 7373)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.hh	2007-06-22 14:55:11 UTC (rev 7374)
@@ -37,6 +37,7 @@
 
   // CPPUNIT TEST SUITE /////////////////////////////////////////////////
   CPPUNIT_TEST_SUITE( TestMeshIOAscii );
+
   CPPUNIT_TEST( testConstructor );
   CPPUNIT_TEST( testDebug );
   CPPUNIT_TEST( testInterpolate );
@@ -47,6 +48,8 @@
   CPPUNIT_TEST( testWriteRead2D );
   CPPUNIT_TEST( testWriteRead2Din3D );
   CPPUNIT_TEST( testWriteRead3D );
+  CPPUNIT_TEST( testReadComments );
+
   CPPUNIT_TEST_SUITE_END();
 
   // PUBLIC METHODS /////////////////////////////////////////////////////
@@ -82,6 +85,9 @@
   /// Test write() and read() for 3D mesh in 3D space.
   void testWriteRead3D(void);
 
+  /// Test and read() for 2D mesh in 2D space with comments.
+  void testReadComments(void);
+
   // PRIVATE METHODS ////////////////////////////////////////////////////
 private :
 
@@ -93,6 +99,14 @@
   void _testWriteRead(const MeshData& data,
 		      const char* filename);
 
+  /** Read mesh and then check values.
+   *
+   * @param data Mesh data
+   * @param filename Name of mesh file to read
+   */
+  void _testRead(const MeshData& data,
+		 const char* filename);
+
 }; // class TestMeshIOAscii
 
 #endif // pylith_meshio_testmeshioascii_hh

Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/data/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/data/Makefile.am	2007-06-22 13:56:09 UTC (rev 7373)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/data/Makefile.am	2007-06-22 14:55:11 UTC (rev 7374)
@@ -18,7 +18,8 @@
 	twotri3.exo \
 	twoquad4.exo \
 	twotet4.exo \
-	twohex8.exo
+	twohex8.exo \
+	mesh2D_comments.txt
 
 noinst_TMP =
 
@@ -30,8 +31,7 @@
 BUILT_SOURCES = export-data
 
 CLEANFILES = \
-	$(export_datadir)/$(noinst_DATA) \
-	$(export_datadir)/$(noinst_TMP)
+	$(export_datadir)/$(noinst_DATA)
 
 
 # End of file 



More information about the cig-commits mailing list