Commit 1fffa689 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

add tests to read/write multiblock with partial arrays

ref: paraview/paraview#18189
parent ade4e46b
......@@ -2,6 +2,7 @@ set(TestXML_ARGS "DATA{${VTK_TEST_INPUT_DIR}/sample.xml}")
set(all_tests
TestAMRXMLIO.cxx,NO_VALID
TestDataObjectXMLIO.cxx,NO_VALID
TestMultiBlockXMLIOWithPartialArrays.cxx,NO_VALID
TestReadDuplicateDataArrayNames.cxx,NO_DATA,NO_VALID
TestXML.cxx,NO_DATA,NO_VALID,NO_OUTPUT
TestXMLGhostCellsImport.cxx
......
#include <vtkDataArray.h>
#include <vtkMultiBlockDataSet.h>
#include <vtkNew.h>
#include <vtkPointData.h>
#include <vtkPolyData.h>
#include <vtkSphereSource.h>
#include <vtkTesting.h>
#include <vtkXMLMultiBlockDataReader.h>
#include <vtkXMLMultiBlockDataWriter.h>
int TestMultiBlockXMLIOWithPartialArrays(int argc, char* argv[])
{
vtkNew<vtkSphereSource> sp;
sp->Update();
vtkNew<vtkPolyData> pd0;
pd0->DeepCopy(sp->GetOutput());
vtkNew<vtkPolyData> pd1;
pd1->DeepCopy(sp->GetOutput());
pd1->GetPointData()->GetArray("Normals")->SetName("NewNormals");
vtkNew<vtkMultiBlockDataSet> outMB;
outMB->SetBlock(0, pd0);
outMB->SetBlock(1, pd1);
vtkNew<vtkTesting> testing;
testing->AddArguments(argc, argv);
std::ostringstream filename_stream;
filename_stream << testing->GetTempDirectory() << "/TestMultiBlockXMLIOWithPartialArrays.vtm";
vtkNew<vtkXMLMultiBlockDataWriter> writer;
writer->SetFileName(filename_stream.str().c_str());
writer->SetInputDataObject(outMB);
writer->Write();
vtkNew<vtkXMLMultiBlockDataReader> reader;
reader->SetFileName(filename_stream.str().c_str());
reader->Update();
auto inMB = vtkMultiBlockDataSet::SafeDownCast(reader->GetOutputDataObject(0));
if (inMB->GetNumberOfBlocks() != 2 ||
vtkPolyData::SafeDownCast(inMB->GetBlock(0)) == nullptr ||
vtkPolyData::SafeDownCast(inMB->GetBlock(0))->GetPointData()->GetArray("Normals") == nullptr ||
vtkPolyData::SafeDownCast(inMB->GetBlock(0))->GetPointData()->GetArray("NewNormals") != nullptr ||
vtkPolyData::SafeDownCast(inMB->GetBlock(1)) == nullptr ||
vtkPolyData::SafeDownCast(inMB->GetBlock(1))->GetPointData()->GetArray("Normals") != nullptr ||
vtkPolyData::SafeDownCast(inMB->GetBlock(1))->GetPointData()->GetArray("NewNormals") == nullptr)
{
cerr << "ERROR: In/out data mismatched!" << endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
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