[cig-commits] r7360 - in cs/spatialdata-0.1/trunk/tests/libtests/spatialdb: . data

brad at geodynamics.org brad at geodynamics.org
Thu Jun 21 15:34:08 PDT 2007


Author: brad
Date: 2007-06-21 15:34:07 -0700 (Thu, 21 Jun 2007)
New Revision: 7360

Added:
   cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/data/spatial_comments.dat
Modified:
   cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestSimpleIOAscii.cc
   cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestSimpleIOAscii.hh
   cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/data/Makefile.am
Log:
Added unit test for reading spatial data files with comments.

Modified: cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestSimpleIOAscii.cc
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestSimpleIOAscii.cc	2007-06-21 22:25:40 UTC (rev 7359)
+++ cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestSimpleIOAscii.cc	2007-06-21 22:34:07 UTC (rev 7360)
@@ -30,7 +30,7 @@
 CPPUNIT_TEST_SUITE_REGISTRATION( spatialdata::spatialdb::TestSimpleIOAscii );
 
 // ----------------------------------------------------------------------
-// Test Filename(), Write(), Read()
+// Test filename(), write(), read().
 void
 spatialdata::spatialdb::TestSimpleIOAscii::testIO(void)
 { // testIO
@@ -94,5 +94,55 @@
   delete pCSIn; pCSIn = 0;
 } // testIO
 
+// ----------------------------------------------------------------------
+// Test filename(), read() with spatial database file that contains
+// comments.
+void
+spatialdata::spatialdb::TestSimpleIOAscii::testReadComments(void)
+{ // testReadComments
+  const double data[] = { 0.6, 0.1, 0.2,  6.6, 3.4,
+			  1.0, 1.1, 1.2,  5.5, 6.7,
+			  4.7, 9.5, 8.7,  2.3, 4.1,
+			  3.4, 0.7, 9.8,  5.7, 2.0,
+			  3.4, 9.8, 5.7,  6.3, 6.7};
+  const int spaceDim = 3;
+  const int numLocs = 5;
+  const int numVals = 2;
+  const int dataDim = 3;
+  const char* names[] = { "One", "Two" };
+  const char* units[] = { "m", "m" };
 
+  const char* filename = "data/spatial_comments.dat";
+  SimpleIOAscii dbIO;
+  dbIO.filename(filename);
+
+  SimpleDB::DataStruct dbIn;
+  geocoords::CoordSys* pCSIn = 0;
+  dbIn.data = 0;
+  dbIn.valNames = 0;
+  dbIn.valUnits = 0;
+  dbIO.read(&dbIn, &pCSIn);
+
+  CPPUNIT_ASSERT_EQUAL(numLocs, dbIn.numLocs);
+  CPPUNIT_ASSERT_EQUAL(numVals, dbIn.numVals);
+  CPPUNIT_ASSERT_EQUAL(dataDim, dbIn.dataDim);
+  CPPUNIT_ASSERT_EQUAL(spaceDim, dbIn.spaceDim);
+  for (int iVal=0; iVal < numVals; ++iVal) {
+    CPPUNIT_ASSERT_EQUAL(std::string(names[iVal]),
+			 std::string(dbIn.valNames[iVal].c_str()));
+    CPPUNIT_ASSERT_EQUAL(std::string(units[iVal]),
+			 std::string(dbIn.valUnits[iVal].c_str()));
+  } // for
+  const int dataSize = numLocs*(spaceDim+numVals);
+  const double tolerance = 1.0e-06;
+  for (int i=0; i < dataSize; ++i)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(dbIn.data[i]/data[i], 1.0, tolerance);
+
+  delete[] dbIn.data; dbIn.data = 0;
+  delete[] dbIn.valNames; dbIn.valNames = 0;
+  delete[] dbIn.valUnits; dbIn.valUnits = 0;
+  delete pCSIn; pCSIn = 0;
+} // testReadComments
+
+
 // End of file 

Modified: cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestSimpleIOAscii.hh
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestSimpleIOAscii.hh	2007-06-21 22:25:40 UTC (rev 7359)
+++ cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestSimpleIOAscii.hh	2007-06-21 22:34:07 UTC (rev 7360)
@@ -37,14 +37,19 @@
   // CPPUNIT TEST SUITE /////////////////////////////////////////////////
   CPPUNIT_TEST_SUITE( TestSimpleIOAscii );
   CPPUNIT_TEST( testIO );
+  CPPUNIT_TEST( testReadComments );
   CPPUNIT_TEST_SUITE_END();
 
   // PUBLIC METHODS /////////////////////////////////////////////////////
 public :
 
-  /// Test Filename(), Read(), Write()
+  /// Test filename(), read(), write().
   void testIO(void);
 
+  /// Test filename(), read() with spatial database file that contains
+  /// comments.
+  void testReadComments(void);
+
 }; // class TestSimpleIOAscii
 
 #endif // spatialdata_spatialdb_testsimpleioascii_hh

Modified: cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/data/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/data/Makefile.am	2007-06-21 22:25:40 UTC (rev 7359)
+++ cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/data/Makefile.am	2007-06-21 22:34:07 UTC (rev 7360)
@@ -11,7 +11,8 @@
 #
 
 noinst_DATA = \
-	spatialdb.dat
+	spatialdb.dat \
+	spatial_comments.dat
 
 noinst_TMP = \
 	spatial.dat

Added: cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/data/spatial_comments.dat
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/data/spatial_comments.dat	2007-06-21 22:25:40 UTC (rev 7359)
+++ cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/data/spatial_comments.dat	2007-06-21 22:34:07 UTC (rev 7360)
@@ -0,0 +1,26 @@
+#SPATIAL.ascii 1
+// Comment after header
+SimpleDB {
+  num-values = 2 // comment for value
+    // indented comment on separate line
+  value-names =  One  Two // comment after
+  value-units =  m  m
+  // a comment here
+  // a comment there
+  num-locs = 5 // annotate here
+  // annotate there
+  data-dim = 3
+  cs-data = cartesian {
+    // annotation within cs
+    to-meters = 1.0 // highlight units
+    // comment here
+  } // cs-data
+} // SimpleDB
+// here is the data
+0.6 0.1 0.2  6.6 3.4
+// comment within data
+1.0 1.1 1.2  5.5 6.7
+4.7 9.5 8.7  2.3 4.1 // comment at end of data
+3.4 0.7 9.8  5.7 2.0
+3.4 9.8 5.7  6.3 6.7
+// comment after data



More information about the cig-commits mailing list