Commit 8bc3c4d3 authored by Zack Galbreath's avatar Zack Galbreath

consolidate tests for PhyloXML

Combine PhyloXML reader & writer tests into a single test,
and make it more thorough.

Change-Id: Ibb32ece7de203269a8508cb06eee91d94706f197
parent 04711678
......@@ -7,21 +7,10 @@ vtk_add_test_cxx(NO_VALID
TestNewickTreeReader.cxx
TestNewickTreeWriter.cxx
TestMultiNewickTreeReader.cxx
TestPhyloXMLTreeReadWrite.cxx
TestRISReader.cxx
TestTulipReaderProperties.cxx
TestDelimitedTextReader2.cxx
)
# The PhyloXML test is handled separately because its baseline is a .xml file
# (not a png)
set_property(DIRECTORY APPEND PROPERTY VTK_TEST_CXX_SOURCES
TestPhyloXMLTreeWriter.cxx
)
ExternalData_add_test(VTKData
NAME ${vtk-module}Cxx-PhyloXMLTreeWriter
COMMAND ${vtk-module}CxxTests TestPhyloXMLTreeWriter 1
-D ${VTK_TEST_DATA_DIR}
-T ${VTK_TEST_OUTPUT_DIR}
-V DATA{../Data/Baseline/TestPhyloXMLTreeWriter.xml,:})
vtk_test_cxx_executable(${vtk-module}CxxTests)
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: TestPhyloXMLTreeReader.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtksys/SystemTools.hxx"
#include "vtkAbstractArray.h"
#include "vtkNew.h"
#include "vtkPhyloXMLTreeReader.h"
#include "vtkPhyloXMLTreeWriter.h"
#include "vtkTesting.h"
#include "vtkTestUtilities.h"
#include "vtkTree.h"
int TestPhyloXMLTreeReader(int argc, char* argv[])
{
// get the full path to the input file
char* inputFile = vtkTestUtilities::GetArgOrEnvOrDefault("-V", argc, argv,
"", "");
cout << "reading from a file: "<< inputFile << endl;
// read the input file into a vtkTree
vtkNew<vtkPhyloXMLTreeReader> reader;
reader->SetFileName(inputFile);
reader->Update();
vtkTree *tree = reader->GetOutput();
delete[] inputFile;
// write this vtkTree out to disk in PhyloXML format
vtkNew<vtkPhyloXMLTreeWriter> writer;
writer->SetInputData(tree);
writer->SetFileName("/tmp/zackdebug.xml");
writer->IgnoreArray("node weight");
writer->Update();
return EXIT_SUCCESS;
}
/*=========================================================================
Program: Visualization Toolkit
Module: TestPhyloXMLTreeWriter.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtksys/SystemTools.hxx"
#include "vtkAbstractArray.h"
#include "vtkNew.h"
#include "vtkNewickTreeReader.h"
#include "vtkPhyloXMLTreeWriter.h"
#include "vtkTesting.h"
#include "vtkTestUtilities.h"
#include "vtkTree.h"
int TestPhyloXMLTreeWriter(int argc, char* argv[])
{
// get the full path to the input file
char* inputFile = vtkTestUtilities::ExpandDataFileName(
argc, argv, "Data/Infovis/rep_set.tre");
cout << "reading from a file: "<< inputFile << endl;
// read the input file into a vtkTree
vtkNew<vtkNewickTreeReader> reader;
reader->SetFileName(inputFile);
reader->Update();
vtkTree *tree = reader->GetOutput();
delete[] inputFile;
// generate the full path to the testing file
vtkNew<vtkTesting> testHelper;
testHelper->AddArguments(argc,const_cast<const char **>(argv));
std::string testFile = testHelper->GetTempDirectory();
testFile += "/TestPhyloXMLTreeWriter.xml";
// write this vtkTree out to disk in PhyloXML format
vtkNew<vtkPhyloXMLTreeWriter> writer;
writer->SetInputData(tree);
writer->SetFileName(testFile.c_str());
writer->IgnoreArray("node weight");
writer->Update();
// get the full path to the baseline file. This is specified as the -V
// argument to the test.
char* baselineFile = vtkTestUtilities::GetArgOrEnvOrDefault("-V", argc, argv,
"", "");
// compare the baseline file to the test file
int result = EXIT_SUCCESS;
if(vtksys::SystemTools::FilesDiffer(baselineFile, testFile.c_str()))
{
cout << baselineFile << " and " << testFile << " differ." << endl;
result = EXIT_FAILURE;
}
// also test the "write to string" capabilities of this class
std::ifstream inFileStream;
inFileStream.open(baselineFile);
std::string baselineStr;
inFileStream.seekg(0, std::ios::end);
baselineStr.reserve(inFileStream.tellg());
inFileStream.seekg(0, std::ios::beg);
baselineStr.assign((std::istreambuf_iterator<char>(inFileStream)),
std::istreambuf_iterator<char>());
writer->SetWriteToOutputString(1);
writer->Update();
std::string testStr = writer->GetOutputString();
if (baselineStr.compare(testStr) != 0)
{
cout << "PhyloXML write to string did not yield expected results." << endl;
result = EXIT_FAILURE;
}
delete [] baselineFile;
return result;
}
7ab4dfd7a7bd46a50dafbf9af2c6453e
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