TestXdmfGridCollection.cpp 2.3 KB
Newer Older
1 2 3
#include <fstream>
#include <sstream>
#include "XdmfGridCollection.hpp"
4
#include "XdmfGridCollectionType.hpp"
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#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();

26
	assert(gridCollection->getNumberGrids() == 0);
27
	gridCollection->insert(childGrid1);
28
	assert(gridCollection->getNumberGrids() == 1);
29 30
	assert(gridCollection->getGrid(0) == childGrid1);
	gridCollection->removeGrid(0);
31
	assert(gridCollection->getNumberGrids() == 0);
32 33 34
	gridCollection->insert(childGrid1);
	gridCollection->insert(childGrid2);

35 36
	gridCollection->setType(XdmfGridCollectionType::Temporal());
	assert(gridCollection->getType() == XdmfGridCollectionType::Temporal());
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

	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;
}