Commit f5cd8422 authored by Kenneth Leiter's avatar Kenneth Leiter
Browse files

ENH: Add test for XdmfGridCollection.

parent 28e67e9a
...@@ -485,7 +485,7 @@ std::string XdmfArray::getType() const ...@@ -485,7 +485,7 @@ std::string XdmfArray::getType() const
{ {
return mHDF5Controller->getType(); return mHDF5Controller->getType();
} }
return ""; return "None";
} }
const void * const XdmfArray::getValuesPointer() const const void * const XdmfArray::getValuesPointer() const
...@@ -536,22 +536,26 @@ void XdmfArray::initialize(const std::string & type, const unsigned int precisio ...@@ -536,22 +536,26 @@ void XdmfArray::initialize(const std::string & type, const unsigned int precisio
{ {
this->initialize<float>(); this->initialize<float>();
} }
else if(type.compare("Double") == 0 && precision == 8) else if(type.compare("Float") == 0 && precision == 8)
{ {
this->initialize<double>(); this->initialize<double>();
} }
else if(type.compare("UChar") == 0 && precision == 8) else if(type.compare("UChar") == 0 && precision == 1)
{ {
this->initialize<unsigned char>(); this->initialize<unsigned char>();
} }
else if(type.compare("UShort") == 0 && precision == 8) else if(type.compare("UShort") == 0 && precision == 2)
{ {
this->initialize<unsigned short>(); this->initialize<unsigned short>();
} }
else if(type.compare("UInt") == 0 && precision == 8) else if(type.compare("UInt") == 0 && precision == 4)
{ {
this->initialize<unsigned int>(); this->initialize<unsigned int>();
} }
else if(type.compare("None") == 0)
{
// No-op uninitialized!
}
else else
{ {
assert(false); assert(false);
......
...@@ -150,7 +150,7 @@ void XdmfGrid::populateItem(const std::map<std::string, std::string> & itemPrope ...@@ -150,7 +150,7 @@ void XdmfGrid::populateItem(const std::map<std::string, std::string> & itemPrope
} }
else else
{ {
assert(false); //assert(false);
} }
} }
} }
......
...@@ -65,6 +65,7 @@ void XdmfGridCollection::insert(boost::shared_ptr<XdmfGrid> grid) ...@@ -65,6 +65,7 @@ void XdmfGridCollection::insert(boost::shared_ptr<XdmfGrid> grid)
void XdmfGridCollection::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems) void XdmfGridCollection::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems)
{ {
mCollectionType = XdmfGridCollectionType::New(itemProperties);
for(std::vector<boost::shared_ptr<XdmfItem> >::const_iterator iter = childItems.begin(); iter != childItems.end(); ++iter) for(std::vector<boost::shared_ptr<XdmfItem> >::const_iterator iter = childItems.begin(); iter != childItems.end(); ++iter)
{ {
if(boost::shared_ptr<XdmfGrid> grid = boost::shared_dynamic_cast<XdmfGrid>(*iter)) if(boost::shared_ptr<XdmfGrid> grid = boost::shared_dynamic_cast<XdmfGrid>(*iter))
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "XdmfDomain.hpp" #include "XdmfDomain.hpp"
#include "XdmfGeometry.hpp" #include "XdmfGeometry.hpp"
#include "XdmfGrid.hpp" #include "XdmfGrid.hpp"
#include "XdmfGridCollection.hpp"
#include "XdmfSet.hpp" #include "XdmfSet.hpp"
#include "XdmfTopology.hpp" #include "XdmfTopology.hpp"
...@@ -48,9 +49,17 @@ public: ...@@ -48,9 +49,17 @@ public:
newItem = XdmfGeometry::New(); newItem = XdmfGeometry::New();
} }
else if(itemTag.compare(XdmfGrid::ItemTag) == 0) else if(itemTag.compare(XdmfGrid::ItemTag) == 0)
{
std::map<std::string, std::string>::const_iterator gridType = itemProperties.find("GridType");
if(gridType->second.compare("Collection") == 0)
{
newItem = XdmfGridCollection::New();
}
else
{ {
newItem = XdmfGrid::New(); newItem = XdmfGrid::New();
} }
}
else if(itemTag.compare(XdmfSet::ItemTag) == 0) else if(itemTag.compare(XdmfSet::ItemTag) == 0)
{ {
newItem = XdmfSet::New(); newItem = XdmfSet::New();
...@@ -76,7 +85,15 @@ public: ...@@ -76,7 +85,15 @@ public:
if(currNode->type == XML_ELEMENT_NODE) if(currNode->type == XML_ELEMENT_NODE)
{ {
std::map<std::string, std::string> itemProperties; std::map<std::string, std::string> itemProperties;
std::cout << currNode->name << std::endl;
if(currNode->children != NULL)
{
itemProperties["Content"] = (const char *)currNode->children->content; itemProperties["Content"] = (const char *)currNode->children->content;
}
else
{
itemProperties["Content"] = "";
}
xmlAttrPtr currAttribute = currNode->properties; xmlAttrPtr currAttribute = currNode->properties;
while(currAttribute != NULL) while(currAttribute != NULL)
{ {
...@@ -104,7 +121,7 @@ XdmfReader::~XdmfReader() ...@@ -104,7 +121,7 @@ XdmfReader::~XdmfReader()
std::cout << "Deleted XdmfReader " << this << std::endl; std::cout << "Deleted XdmfReader " << this << std::endl;
} }
boost::shared_ptr<XdmfDomain> XdmfReader::read(const std::string & filePath) const boost::shared_ptr<XdmfItem> XdmfReader::read(const std::string & filePath) const
{ {
xmlDocPtr document; xmlDocPtr document;
xmlNodePtr currNode; xmlNodePtr currNode;
...@@ -121,7 +138,7 @@ boost::shared_ptr<XdmfDomain> XdmfReader::read(const std::string & filePath) con ...@@ -121,7 +138,7 @@ boost::shared_ptr<XdmfDomain> XdmfReader::read(const std::string & filePath) con
xmlFreeDoc(document); xmlFreeDoc(document);
xmlCleanupParser(); xmlCleanupParser();
return boost::shared_dynamic_cast<XdmfDomain>(toReturn[0]); return toReturn[0];
} }
...@@ -19,7 +19,7 @@ public: ...@@ -19,7 +19,7 @@ public:
XdmfNewMacro(XdmfReader); XdmfNewMacro(XdmfReader);
boost::shared_ptr<XdmfDomain> read(const std::string & fileName) const; boost::shared_ptr<XdmfItem> read(const std::string & fileName) const;
protected: protected:
......
...@@ -5,6 +5,7 @@ set(XdmfCxxTests ...@@ -5,6 +5,7 @@ set(XdmfCxxTests
TestXdmfDataItem TestXdmfDataItem
TestXdmfGeometry TestXdmfGeometry
TestXdmfGrid TestXdmfGrid
TestXdmfGridCollection
TestXdmfHDF5Writer TestXdmfHDF5Writer
TestXdmfReader TestXdmfReader
TestXdmfSet TestXdmfSet
......
...@@ -14,7 +14,7 @@ int main(int argc, char* argv[]) ...@@ -14,7 +14,7 @@ int main(int argc, char* argv[])
*/ */
boost::shared_ptr<XdmfArray> array = XdmfArray::New(); boost::shared_ptr<XdmfArray> array = XdmfArray::New();
assert(array->getSize() == 0); assert(array->getSize() == 0);
assert(array->getType() == ""); assert(array->getType() == "None");
assert(array->getPrecision() == 0); assert(array->getPrecision() == 0);
assert(array->getValuesString() == ""); assert(array->getValuesString() == "");
assert(array->getValuesPointer() == NULL); assert(array->getValuesPointer() == NULL);
......
#include <fstream>
#include <sstream>
#include "XdmfGridCollection.hpp"
#include "XdmfReader.hpp"
#include "XdmfWriter.hpp"
#include "XdmfTestDataGenerator.hpp"
int main(int argc, char* argv[])
{
// Test != and == operators
assert(XdmfGridCollectionType::Spatial() == XdmfGridCollectionType::Spatial());
assert(XdmfGridCollectionType::Spatial() == XdmfGridCollectionType::Temporal() == false);
assert(XdmfGridCollectionType::Spatial() != XdmfGridCollectionType::Spatial() == false);
assert(XdmfGridCollectionType::Spatial() != XdmfGridCollectionType::Temporal());
boost::shared_ptr<XdmfGridCollection> gridCollection = XdmfGridCollection::New();
gridCollection->setName("Collection2");
assert(gridCollection->getName().compare("Collection2") == 0);
boost::shared_ptr<XdmfGrid> childGrid1 = XdmfTestDataGenerator::createHexahedron();
boost::shared_ptr<XdmfGrid> childGrid2 = XdmfTestDataGenerator::createHexahedron();
assert(gridCollection->getNumberOfGrids() == 0);
gridCollection->insert(childGrid1);
assert(gridCollection->getNumberOfGrids() == 1);
assert(gridCollection->getGrid(0) == childGrid1);
gridCollection->removeGrid(0);
assert(gridCollection->getNumberOfGrids() == 0);
gridCollection->insert(childGrid1);
gridCollection->insert(childGrid2);
gridCollection->setGridCollectionType(XdmfGridCollectionType::Temporal());
boost::shared_ptr<XdmfWriter> writer = XdmfWriter::New("TestXdmfGridCollection1.xmf");
gridCollection->accept(writer);
boost::shared_ptr<XdmfReader> reader = XdmfReader::New();
boost::shared_ptr<XdmfGridCollection> gridCollection2 = boost::shared_dynamic_cast<XdmfGridCollection>(reader->read("TestXdmfGridCollection1.xmf"));
boost::shared_ptr<XdmfWriter> writer2 = XdmfWriter::New("TestXdmfGridCollection2.xmf");
gridCollection2->accept(writer2);
// Compare two files for equality
std::ifstream firstFile("TestXdmfGridCollection1.xmf");
std::ifstream secondFile("TestXdmfGridCollection2.xmf");
std::stringstream firstBuffer;
std::stringstream secondBuffer;
firstBuffer << firstFile.rdbuf();
secondBuffer << secondFile.rdbuf();
std::string firstContents(firstBuffer.str());
std::string secondContents(secondBuffer.str());
assert(firstContents.compare(secondContents) == 0);
return 0;
}
#include <fstream> #include <fstream>
#include <sstream>
#include "XdmfItem.hpp"
#include "XdmfReader.hpp" #include "XdmfReader.hpp"
#include "XdmfWriter.hpp" #include "XdmfWriter.hpp"
...@@ -16,26 +18,26 @@ int main(int argc, char* argv[]) ...@@ -16,26 +18,26 @@ int main(int argc, char* argv[])
domain->accept(writer); domain->accept(writer);
boost::shared_ptr<XdmfReader> reader = XdmfReader::New(); boost::shared_ptr<XdmfReader> reader = XdmfReader::New();
boost::shared_ptr<XdmfDomain> readDomain = reader->read("TestXdmfReader1.xmf"); boost::shared_ptr<XdmfDomain> readDomain = boost::shared_dynamic_cast<XdmfDomain>(reader->read("TestXdmfReader1.xmf"));
boost::shared_ptr<XdmfWriter> writer2 = XdmfWriter::New("TestXdmfReader2.xmf"); boost::shared_ptr<XdmfWriter> writer2 = XdmfWriter::New("TestXdmfReader2.xmf");
readDomain->accept(writer2); readDomain->accept(writer2);
// Compare two files for equality
std::ifstream firstFile("TestXdmfReader1.xmf"); std::ifstream firstFile("TestXdmfReader1.xmf");
std::ifstream secondFile("TestXdmfReader2.xmf"); std::ifstream secondFile("TestXdmfReader2.xmf");
std::string firstLine; std::stringstream firstBuffer;
std::string secondLine; std::stringstream secondBuffer;
while(!firstFile.eof()) firstBuffer << firstFile.rdbuf();
{ secondBuffer << secondFile.rdbuf();
std::getline(firstFile, firstLine);
std::getline(secondFile, secondLine); std::string firstContents(firstBuffer.str());
if(firstLine.compare(secondLine) != 0) std::string secondContents(secondBuffer.str());
{
assert(false); assert(firstContents.compare(secondContents) == 0);
}
}
return 0; return 0;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment