/[escript]/trunk/weipa/test/EscriptDatasetTestCase.cpp
ViewVC logotype

Diff of /trunk/weipa/test/EscriptDatasetTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3596 by caltinay, Thu Nov 11 23:26:52 2010 UTC revision 3597 by caltinay, Thu Sep 15 06:03:17 2011 UTC
# Line 12  Line 12 
12  *******************************************************/  *******************************************************/
13    
14    
15    #include "EscriptDatasetTestCase.h"
16  #include "escript/DataFactory.h"  #include "escript/DataFactory.h"
17  #include "finley/CppAdapter/MeshAdapterFactory.h"  #include "finley/CppAdapter/MeshAdapterFactory.h"
18  #include "weipa/EscriptDataset.h"  #include "weipa/EscriptDataset.h"
 #include "EscriptDatasetTestCase.h"  
19    
20  using namespace CppUnitTest;  #include <cppunit/TestCaller.h>
21    
22    using namespace CppUnit;
23  using namespace escript;  using namespace escript;
24  using namespace weipa;  using namespace weipa;
25  using namespace std;  using namespace std;
26    
 void EscriptDatasetTestCase::setUp()  
 {  
     // This is called before each test is run  
 }  
   
 void EscriptDatasetTestCase::tearDown()  
 {  
     // This is called after each test has been run  
 }  
   
27  void EscriptDatasetTestCase::testAll()  void EscriptDatasetTestCase::testAll()
28  {  {
29      cout << endl;      cout << endl;
# Line 39  void EscriptDatasetTestCase::testAll() Line 31  void EscriptDatasetTestCase::testAll()
31      EscriptDataset_ptr dataset(new EscriptDataset());      EscriptDataset_ptr dataset(new EscriptDataset());
32    
33      cout << "\tTest saveSilo without data." << endl;      cout << "\tTest saveSilo without data." << endl;
34      assert(dataset->saveSilo("dummy") == false);      CPPUNIT_ASSERT(dataset->saveSilo("dummy") == false);
35    
36      cout << "\tTest saveVTK without data." << endl;      cout << "\tTest saveVTK without data." << endl;
37      assert(dataset->saveVTK("dummy") == false);      CPPUNIT_ASSERT(dataset->saveVTK("dummy") == false);
38    
39      cout << "\tTest getConvertedDomain without data." << endl;      cout << "\tTest getConvertedDomain without data." << endl;
40      assert(dataset->getConvertedDomain().size() == 0);      CPPUNIT_ASSERT(dataset->getConvertedDomain().size() == 0);
41    
42      cout << "\tTest getVariables without data." << endl;      cout << "\tTest getVariables without data." << endl;
43      assert(dataset->getVariables().size() == 0);      CPPUNIT_ASSERT(dataset->getVariables().size() == 0);
44    
45      cout << "\tTest getMeshVariables without data." << endl;      cout << "\tTest getMeshVariables without data." << endl;
46      assert(dataset->getMeshVariables().size() == 0);      CPPUNIT_ASSERT(dataset->getMeshVariables().size() == 0);
47    
48      // instantiate a domain and data      // instantiate a domain and data
49      Domain_ptr dom(finley::brick());      Domain_ptr dom(finley::brick());
50      escript::Data data = Scalar(0.0, continuousFunction(*dom), true);      escript::Data data = Scalar(0.0, continuousFunction(*dom), true);
51    
52      cout << "\tTest addData with NULL domain." << endl;      cout << "\tTest addData with NULL domain." << endl;
53      assert(dataset->addData(data, "foo", "bar") == false);      CPPUNIT_ASSERT(dataset->addData(data, "foo", "bar") == false);
54    
55      cout << "\tTest setDomain." << endl;      cout << "\tTest setDomain." << endl;
56      assert(dataset->setDomain(dom.get()) == true);      CPPUNIT_ASSERT(dataset->setDomain(dom.get()) == true);
57      assert(dataset->getMeshVariables().size() > 0);      CPPUNIT_ASSERT(dataset->getMeshVariables().size() > 0);
58    
59      cout << "\tTest bogus setDomain call." << endl;      cout << "\tTest bogus setDomain call." << endl;
60      assert(dataset->setDomain(dom.get()) == false);      CPPUNIT_ASSERT(dataset->setDomain(dom.get()) == false);
61    
62      cout << "\tTest getConvertedDomain." << endl;      cout << "\tTest getConvertedDomain." << endl;
63      DomainChunks chunks = dataset->getConvertedDomain();      DomainChunks chunks = dataset->getConvertedDomain();
64      assert(chunks.size() > 0);      CPPUNIT_ASSERT(chunks.size() > 0);
65    
66      StringVec varfiles, varnames;      StringVec varfiles, varnames;
67      varfiles.push_back("testvar%04d.nc");      varfiles.push_back("testvar%04d.nc");
68      varnames.push_back("testvar");      varnames.push_back("testvar");
69      cout << "\tTest bogus loadNetCDF call 1." << endl;      cout << "\tTest bogus loadNetCDF call 1." << endl;
70      assert(dataset->loadNetCDF("mesh%04d.nc", varfiles, varnames, 1) == false);      CPPUNIT_ASSERT(dataset->loadNetCDF("mesh%04d.nc", varfiles, varnames, 1) == false);
71    
72      cout << "\tTest bogus loadNetCDF call 2." << endl;      cout << "\tTest bogus loadNetCDF call 2." << endl;
73      assert(dataset->loadNetCDF(chunks, varfiles, varnames) == false);      CPPUNIT_ASSERT(dataset->loadNetCDF(chunks, varfiles, varnames) == false);
74    
75      cout << "\tTest addData with valid data." << endl;      cout << "\tTest addData with valid data." << endl;
76      assert(dataset->addData(data, "testvar", "cm") == true);      CPPUNIT_ASSERT(dataset->addData(data, "testvar", "cm") == true);
77      assert(dataset->getVariables().size() == 1);      CPPUNIT_ASSERT(dataset->getVariables().size() == 1);
78    
79      cout << "\tTest set/getCycleAndTime." << endl;      cout << "\tTest set/getCycleAndTime." << endl;
80      dataset->setCycleAndTime(42, 3.1415);      dataset->setCycleAndTime(42, 3.1415);
81      assert(dataset->getCycle() == 42);      CPPUNIT_ASSERT(dataset->getCycle() == 42);
82      assert(dataset->getTime()-3.1415 < 0.001);      CPPUNIT_ASSERT(dataset->getTime()-3.1415 < 0.001);
83    
84      dataset->setMetadataSchemaString("xmlns:test=\"http://myschema.com/test\"",      dataset->setMetadataSchemaString("xmlns:test=\"http://myschema.com/test\"",
85              "<MyValue>4711</MyValue>");              "<MyValue>4711</MyValue>");
# Line 96  void EscriptDatasetTestCase::testAll() Line 88  void EscriptDatasetTestCase::testAll()
88    
89  #if USE_SILO  #if USE_SILO
90      cout << "\tTest saveSilo." << endl;      cout << "\tTest saveSilo." << endl;
91      assert(dataset->saveSilo("weipatest.silo") == true);      CPPUNIT_ASSERT(dataset->saveSilo("weipatest.silo") == true);
92      ifstream f("weipatest.silo");      ifstream f("weipatest.silo");
93      assert(f.is_open());      CPPUNIT_ASSERT(f.is_open());
94      f.close();      f.close();
95  #endif  #endif
96    
97      cout << "\tTest saveVTK." << endl;      cout << "\tTest saveVTK." << endl;
98      assert(dataset->saveVTK("weipatest.vtu") == true);      CPPUNIT_ASSERT(dataset->saveVTK("weipatest.vtu") == true);
99      checkVTKfile("weipatest.vtu");      checkVTKfile("weipatest.vtu");
100    
101      //varnames.push_back("dummy");      //varnames.push_back("dummy");
102      //cout << "\tTest loadNetCDF with invalid params." << endl;      //cout << "\tTest loadNetCDF with invalid params." << endl;
103      //assert(dataset->loadNetCDF(blocks, varfiles, varnames) == false);      //CPPUNIT_ASSERT(dataset->loadNetCDF(blocks, varfiles, varnames) == false);
104  }  }
105    
106  TestSuite* EscriptDatasetTestCase::suite()  TestSuite* EscriptDatasetTestCase::suite()
107  {  {
     //  
     // create the suite of tests to perform.  
108      TestSuite *testSuite = new TestSuite("EscriptDatasetTestCase");      TestSuite *testSuite = new TestSuite("EscriptDatasetTestCase");
   
109      testSuite->addTest(new TestCaller<EscriptDatasetTestCase>(      testSuite->addTest(new TestCaller<EscriptDatasetTestCase>(
110                  "testAll",&EscriptDatasetTestCase::testAll));                  "testAll",&EscriptDatasetTestCase::testAll));
111      return testSuite;      return testSuite;
# Line 140  int EscriptDatasetTestCase::getDataArray Line 129  int EscriptDatasetTestCase::getDataArray
129  void EscriptDatasetTestCase::checkVTKfile(std::string filename)  void EscriptDatasetTestCase::checkVTKfile(std::string filename)
130  {  {
131      ifstream f(filename.c_str());      ifstream f(filename.c_str());
132      assert(f.is_open());      CPPUNIT_ASSERT(f.is_open());
133    
134      char line[256];      char line[256];
135      int numPoints=0, numCells=0;      int numPoints=0, numCells=0;
# Line 160  void EscriptDatasetTestCase::checkVTKfil Line 149  void EscriptDatasetTestCase::checkVTKfil
149              break;              break;
150          }          }
151      }      }
152      assert(numPoints>0);      CPPUNIT_ASSERT(numPoints>0);
153      assert(numCells>0);      CPPUNIT_ASSERT(numCells>0);
154    
155      bool pointsFound=false, cellsFound=false;      bool pointsFound=false, cellsFound=false;
156      int numPointData=0, numCellData=0;      int numPointData=0, numCellData=0;
# Line 176  void EscriptDatasetTestCase::checkVTKfil Line 165  void EscriptDatasetTestCase::checkVTKfil
165                  f.getline(line, 256);                  f.getline(line, 256);
166                  s = line;                  s = line;
167                  if (s.find("<DataArray") == 0) {                  if (s.find("<DataArray") == 0) {
168                      assertLongsEqual(numPoints, getDataArrayLength(f));                      CPPUNIT_ASSERT_EQUAL(numPoints, getDataArrayLength(f));
169                  }                  }
170              }              }
171          } else if (s.find("<Cells>") == 0) {          } else if (s.find("<Cells>") == 0) {
# Line 186  void EscriptDatasetTestCase::checkVTKfil Line 175  void EscriptDatasetTestCase::checkVTKfil
175                  f.getline(line, 256);                  f.getline(line, 256);
176                  s = line;                  s = line;
177                  if (s.find("<DataArray") == 0) {                  if (s.find("<DataArray") == 0) {
178                      assertLongsEqual(numCells, getDataArrayLength(f));                      CPPUNIT_ASSERT_EQUAL(numCells, getDataArrayLength(f));
179                  }                  }
180              }              }
181          } else if (s.compare("<PointData>") == 0) {          } else if (s.compare("<PointData>") == 0) {
# Line 196  void EscriptDatasetTestCase::checkVTKfil Line 185  void EscriptDatasetTestCase::checkVTKfil
185                  s = line;                  s = line;
186                  if (s.find("<DataArray") == 0) {                  if (s.find("<DataArray") == 0) {
187                      numPointData++;                      numPointData++;
188                      assertLongsEqual(numPoints, getDataArrayLength(f));                      CPPUNIT_ASSERT_EQUAL(numPoints, getDataArrayLength(f));
189                  }                  }
190              }              }
191          } else if (s.find("<CellData>") == 0) {          } else if (s.find("<CellData>") == 0) {
# Line 206  void EscriptDatasetTestCase::checkVTKfil Line 195  void EscriptDatasetTestCase::checkVTKfil
195                  s = line;                  s = line;
196                  if (s.find("<DataArray") == 0) {                  if (s.find("<DataArray") == 0) {
197                      numCellData++;                      numCellData++;
198                      assertLongsEqual(numCells, getDataArrayLength(f));                      CPPUNIT_ASSERT_EQUAL(numCells, getDataArrayLength(f));
199                  }                  }
200              }              }
201          }          }
202      }      }
203    
204      assert(pointsFound);      CPPUNIT_ASSERT(pointsFound);
205      assert(cellsFound);      CPPUNIT_ASSERT(cellsFound);
206      assert(numPointData>0);      CPPUNIT_ASSERT(numPointData>0);
207      assert(numCellData>0);      CPPUNIT_ASSERT(numCellData>0);
208  }  }
209    

Legend:
Removed from v.3596  
changed lines
  Added in v.3597

  ViewVC Help
Powered by ViewVC 1.1.26