TestXdmfXPath.cpp 1.6 KB
Newer Older
1
#include "XdmfDomain.hpp"
2
#include "XdmfReader.hpp"
3 4
#include "XdmfWriter.hpp"

5
#include "XdmfTestCompareFiles.hpp"
6 7
#include "XdmfTestDataGenerator.hpp"

8
int main(int, char *)
9
{
10
	boost::shared_ptr<XdmfWriter> writer = XdmfWriter::New("XdmfXPath1.xmf");
11
	boost::shared_ptr<XdmfGridUnstructured> grid = XdmfTestDataGenerator::createHexahedron();
12

13
	boost::shared_ptr<XdmfGridUnstructured> newGrid = XdmfGridUnstructured::New();
14 15 16 17 18 19 20 21 22 23 24
	newGrid->setName("NoAttributes");
	newGrid->setGeometry(grid->getGeometry());
	newGrid->setTopology(grid->getTopology());

	boost::shared_ptr<XdmfDomain> domain = XdmfDomain::New();
	domain->insert(grid);
	domain->insert(grid);
	domain->insert(newGrid);
	domain->accept(writer);

	// Try to find xpaths written to file
25
	std::ifstream file("XdmfXPath1.xmf");
26 27 28 29 30 31 32 33
	std::stringstream fileBuffer;
	fileBuffer << file.rdbuf();
	std::string fileContents(fileBuffer.str());

	assert(fileContents.find("xpointer=\"element(/1/1/1)\"") != std::string::npos);
	assert(fileContents.find("xpointer=\"element(/1/1/1/2)\"") != std::string::npos);
	assert(fileContents.find("xpointer=\"element(/1/1/1/3)\"") != std::string::npos);

34 35
	// Make sure when we read it in we get the same structure as when we wrote it out (multiple items holding the same shared pointers)
	boost::shared_ptr<XdmfReader> reader = XdmfReader::New();
36 37
	boost::shared_ptr<XdmfDomain> domain2 = boost::shared_dynamic_cast<XdmfDomain>(reader->read("XdmfXPath1.xmf"));
	boost::shared_ptr<XdmfWriter> writer2 = XdmfWriter::New("XdmfXPath2.xmf");
38 39
	domain2->accept(writer2);

40
	assert(XdmfTestCompareFiles::compareFiles("XdmfXPath1.xmf", "XdmfXPath2.xmf"));
41

42 43
	return 0;
}