diff --git a/Modules/Core/test/mitkSurfaceVtkWriterTest.cpp b/Modules/Core/test/mitkSurfaceVtkWriterTest.cpp index 509e0605fe..ce8cb40262 100644 --- a/Modules/Core/test/mitkSurfaceVtkWriterTest.cpp +++ b/Modules/Core/test/mitkSurfaceVtkWriterTest.cpp @@ -1,71 +1,68 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ -#include "mitkIOUtil.h" -#include "mitkSurface.h" -#include "mitkTestingMacros.h" +#include +#include +#include +#include -#include -#include +#include +#include +#include -#include - -/** - * Simple example for a test for the (non-existent) class "ClassName". - * - * argc and argv are the command line parameters which were passed to - * the ADD_TEST command in the CMakeLists.txt file. For the automatic - * tests, argv is either empty for the simple tests or contains the filename - * of a test image for the image tests (see CMakeLists.txt). - */ -int mitkSurfaceVtkWriterTest(int /*argc*/, char *argv[]) +int mitkSurfaceVtkWriterTest(int, char *argv[]) { - // always start with this! MITK_TEST_BEGIN("SurfaceVtkWriter") - // create contour - vtkPolyDataReader *reader = vtkPolyDataReader::New(); - reader->SetFileName(argv[1]); - reader->Update(); - if (reader->GetOutput()) + mitk::Surface::Pointer surface; + + try + { + MITK_TEST_OUTPUT(<< "Load surface from \"" << argv[1] << "\"") + surface = mitk::IOUtil::Load(argv[1]); + } + catch (...) { - mitk::Surface::Pointer surface = mitk::Surface::New(); - surface->SetVtkPolyData(reader->GetOutput()); - surface->Update(); + } - MITK_TEST_CONDITION_REQUIRED(surface.IsNotNull(), "Surface creation") + if (surface.IsNotNull()) + { + std::string path; try { - // test for exception handling - mitk::IOUtil::Save(surface, "/usr/bin"); - MITK_TEST_FAILED_MSG(<< "itk::ExceptionObject expected") - } - catch (const mitk::Exception &) - { /* this is expected */ + std::ofstream stream; + path = mitk::IOUtil::CreateTemporaryFile(stream, "XXXXXX.vtp"); } catch (...) { - // this means that a wrong exception (i.e. no itk:Exception) has been thrown - MITK_TEST_FAILED_MSG(<< "Wrong exception (i.e. no itk:Exception) caught during write [FAILED]") } - // write your own tests here and use the macros from mitkTestingMacros.h !!! - // do not write to std::cout and do not return from this function yourself! - } + if (!path.empty()) + { + try + { + MITK_TEST_OUTPUT(<< "Save surface as \"" << path << "\"") + mitk::IOUtil::Save(surface, path); + } + catch (const std::exception& e) + { + std::remove(path.c_str()); + MITK_TEST_FAILED_MSG(<< "Caught exception: " << e.what() << " [FAILED]") + } - // Delete reader correctly - reader->Delete(); + mitk::TestManager::GetInstance()->TestPassed(); + } + } - // always end with this! MITK_TEST_END() }