Commit 57013c8f authored by Valentin Martinet's avatar Valentin Martinet
Browse files

Added and fixed tests, updated to be compliant with CTest

 * imported CTR work on DicomReaderTest
 * Updated tests to be more compliant with CTest
 * Updated ActivityRegistryTest to be compliant with CTest

--HG--
branch : fw4spl_0.9.2
parent 65f9ef43
/* ***** BEGIN LICENSE BLOCK *****
* FW4SPL - Copyright (C) IRCAD, 2009-2013.
* FW4SPL - Copyright (C) IRCAD, 2009-2014.
* Distributed under the terms of the GNU Lesser General Public License (LGPL) as
* published by the Free Software Foundation.
* ****** END LICENSE BLOCK ****** */
......@@ -10,18 +10,6 @@
#include <cppunit/extensions/HelperMacros.h>
#include <fwRuntime/EConfigurationElement.hpp>
namespace fwData
{
class Object;
}
namespace fwRuntime
{
class EConfigurationElement;
}
namespace ioITK
{
namespace ut
......@@ -52,14 +40,6 @@ public:
void ImageSeriesInrTest();
void SeriesDBInrTest();
private :
void executeService(
const SPTR(::fwData::Object)& obj,
const std::string& srvType,
const std::string& srvImpl,
const SPTR(::fwRuntime::EConfigurationElement)& cfg);
};
} //namespace ut
......
......@@ -73,7 +73,7 @@ void IoItkTest::tearDown()
//------------------------------------------------------------------------------
void IoItkTest::executeService(
void executeService(
const SPTR(::fwData::Object)& obj,
const std::string& srvType,
const std::string& srvImpl,
......@@ -114,7 +114,7 @@ void IoItkTest::testImageSeriesWriterJPG()
srvCfg->addConfigurationElement(folderCfg);
// Create and execute service
this->executeService(imageSeries, "::io::IWriter", "::ioITK::SJpgImageSeriesWriter", srvCfg);
executeService(imageSeries, "::io::IWriter", "::ioITK::SJpgImageSeriesWriter", srvCfg);
// Remove path
::boost::filesystem::remove_all( path.string() );
......@@ -140,7 +140,7 @@ void IoItkTest::testImageWriterJPG()
srvCfg->addConfigurationElement(folderCfg);
// Create and execute service
this->executeService( image, "::io::IWriter", "::ioITK::JpgImageWriterService", srvCfg );
executeService( image, "::io::IWriter", "::ioITK::JpgImageWriterService", srvCfg );
// Remove path
::boost::filesystem::remove_all( path.string() );
......@@ -173,11 +173,11 @@ void IoItkTest::testSaveLoadInr()
srvCfg->addConfigurationElement(fileCfg);
// Create and execute service
this->executeService( image, "::io::IWriter", "::ioITK::InrImageWriterService", srvCfg );
executeService( image, "::io::IWriter", "::ioITK::InrImageWriterService", srvCfg );
// load Image
::fwData::Image::sptr image2 = ::fwData::Image::New();
this->executeService( image2, "::io::IReader", "::ioITK::InrImageReaderService", srvCfg );
executeService( image2, "::io::IReader", "::ioITK::InrImageReaderService", srvCfg );
::boost::filesystem::remove_all( PATH.parent_path().string() );
......@@ -214,11 +214,11 @@ void IoItkTest::ImageSeriesInrTest()
srvCfg->addConfigurationElement(fileCfg);
// Create and execute service
this->executeService( imageSeries, "::io::IWriter", "::ioITK::SImageSeriesWriter", srvCfg );
executeService( imageSeries, "::io::IWriter", "::ioITK::SImageSeriesWriter", srvCfg );
// load Image
::fwData::Image::sptr image2 = ::fwData::Image::New();
this->executeService( image2, "::io::IReader", "::ioITK::InrImageReaderService", srvCfg );
executeService( image2, "::io::IReader", "::ioITK::InrImageReaderService", srvCfg );
::boost::filesystem::remove_all( PATH.parent_path().string() );
......@@ -252,7 +252,7 @@ void IoItkTest::SeriesDBInrTest()
// load SeriesDB
::fwMedData::SeriesDB::sptr sdb = ::fwMedData::SeriesDB::New();
this->executeService( sdb, "::io::IReader", "::ioITK::SInrSeriesDBReader", srvCfg );
executeService( sdb, "::io::IReader", "::ioITK::SInrSeriesDBReader", srvCfg );
::fwData::Image::SpacingType spacing = list_of(0.781)(0.781)(1.6);
::fwData::Image::SizeType size = list_of(512)(512)(134);
......
/* ***** BEGIN LICENSE BLOCK *****
* FW4SPL - Copyright (C) IRCAD, 2009-2013.
* FW4SPL - Copyright (C) IRCAD, 2009-2014.
* Distributed under the terms of the GNU Lesser General Public License (LGPL) as
* published by the Free Software Foundation.
* ****** END LICENSE BLOCK ****** */
......@@ -9,11 +9,6 @@
#include <cppunit/extensions/HelperMacros.h>
namespace fwData
{
class Image;
}
namespace ioVTK
{
namespace ut
......@@ -51,15 +46,6 @@ public:
void testMhdImageWriter();
void testImageWriterExtension();
private :
void runImageSrv(
const std::string &srvtype,
const std::string &srv,
const SPTR(::fwRuntime::EConfigurationElement)& cfg,
const SPTR(::fwData::Object)& image);
};
} //namespace ut
......
/* ***** BEGIN LICENSE BLOCK *****
* FW4SPL - Copyright (C) IRCAD, 2009-2013.
* FW4SPL - Copyright (C) IRCAD, 2009-2014.
* Distributed under the terms of the GNU Lesser General Public License (LGPL) as
* published by the Free Software Foundation.
* ****** END LICENSE BLOCK ****** */
......@@ -7,8 +7,6 @@
#ifndef _IOVTK_TEST_TU_SERIESDBREADERTEST_HPP_
#define _IOVTK_TEST_TU_SERIESDBREADERTEST_HPP_
#include <fwMedData/SeriesDB.hpp>
#include <cppunit/extensions/HelperMacros.h>
namespace ioVTK
......
......@@ -44,6 +44,32 @@ namespace ioVTK
namespace ut
{
//------------------------------------------------------------------------------
void runImageSrv(
const std::string &srvtype,
const std::string &srvname,
const SPTR(::fwRuntime::EConfigurationElement)& cfg,
const SPTR(::fwData::Object)& image)
{
::fwServices::IService::sptr srv;
srv = ::fwServices::registry::ServiceFactory::getDefault()->create( srvtype, srvname );
CPPUNIT_ASSERT_MESSAGE(std::string("Failed to create service ") + srvname, srv);
::fwServices::OSR::registerService( image , srv );
CPPUNIT_ASSERT_NO_THROW( srv->setConfiguration(cfg) );
CPPUNIT_ASSERT_NO_THROW( srv->configure() );
CPPUNIT_ASSERT_NO_THROW( srv->start() );
CPPUNIT_ASSERT_NO_THROW( srv->update() );
CPPUNIT_ASSERT_NO_THROW( srv->stop() );
::fwServices::OSR::unregisterService( srv );
}
//------------------------------------------------------------------------------
void ImageReaderWriterTest::setUp()
......@@ -95,7 +121,7 @@ void ImageReaderWriterTest::testVtkImageReader()
sizeExpected[1] = 170;
sizeExpected[2] = 58;
this->runImageSrv("::io::IReader","::ioVTK::ImageReaderService",getIOConfiguration(file), image);
runImageSrv("::io::IReader","::ioVTK::ImageReaderService",getIOConfiguration(file), image);
// Data read.
::fwData::Image::SpacingType spacingRead = image->getSpacing();
......@@ -127,7 +153,7 @@ void ImageReaderWriterTest::testVtiImageReader()
const ::boost::filesystem::path file = ::fwTest::Data::dir() /"fw4spl/image/vti/BostonTeapot.vti";
::fwData::Image::sptr image = ::fwData::Image::New();
this->runImageSrv("::io::IReader","::ioVTK::ImageReaderService",getIOConfiguration(file), image);
runImageSrv("::io::IReader","::ioVTK::ImageReaderService",getIOConfiguration(file), image);
// Data expected
const size_t dim = 3;
......@@ -180,7 +206,7 @@ void ImageReaderWriterTest::testMhdImageReader()
const ::boost::filesystem::path file = ::fwTest::Data::dir() / "fw4spl/image/mhd/BostonTeapot.mhd";
::fwData::Image::sptr image = ::fwData::Image::New();
this->runImageSrv("::io::IReader","::ioVTK::ImageReaderService",getIOConfiguration(file), image);
runImageSrv("::io::IReader","::ioVTK::ImageReaderService",getIOConfiguration(file), image);
// Data expected
const size_t dim = 3;
......@@ -287,12 +313,12 @@ void ImageReaderWriterTest::testVtkImageWriter()
// Write to vtk image.
const ::boost::filesystem::path file = ::fwTools::System::getTemporaryFolder() / "temporaryFile.vtk";
this->runImageSrv("::io::IWriter","::ioVTK::ImageWriterService",getIOConfiguration(file), image);
runImageSrv("::io::IWriter","::ioVTK::ImageWriterService",getIOConfiguration(file), image);
// Read image from disk
::fwData::Image::sptr imageFromDisk = ::fwData::Image::New();
this->runImageSrv("::io::IReader","::ioVTK::ImageReaderService",getIOConfiguration(file), imageFromDisk);
runImageSrv("::io::IReader","::ioVTK::ImageReaderService",getIOConfiguration(file), imageFromDisk);
::boost::filesystem::remove(file);
......@@ -343,11 +369,11 @@ void ImageReaderWriterTest::testVtkImageSeriesWriter()
const ::boost::filesystem::path file = ::fwTools::System::getTemporaryFolder() / "imageSeries.vtk";
// Write image series
this->runImageSrv("::io::IWriter", "::ioVTK::SImageSeriesWriter", getIOConfiguration(file), imageSeries);
runImageSrv("::io::IWriter", "::ioVTK::SImageSeriesWriter", getIOConfiguration(file), imageSeries);
// Read image series
::fwData::Image::sptr newImage = ::fwData::Image::New();
this->runImageSrv("::io::IReader","::ioVTK::ImageReaderService", getIOConfiguration(file), newImage);
runImageSrv("::io::IReader","::ioVTK::ImageReaderService", getIOConfiguration(file), newImage);
::fwDataCamp::visitor::CompareObjects visitor;
visitor.compare(image, newImage);
......@@ -380,12 +406,12 @@ void ImageReaderWriterTest::testVtiImageWriter()
// Write to vtk image.
const ::boost::filesystem::path file = ::fwTools::System::getTemporaryFolder() / "temporaryFile.vti";
this->runImageSrv("::io::IWriter","::ioVTK::ImageWriterService",getIOConfiguration(file), image);
runImageSrv("::io::IWriter","::ioVTK::ImageWriterService",getIOConfiguration(file), image);
// Read image from disk
::fwData::Image::sptr imageFromDisk = ::fwData::Image::New();
this->runImageSrv("::io::IReader","::ioVTK::ImageReaderService",getIOConfiguration(file), imageFromDisk);
runImageSrv("::io::IReader","::ioVTK::ImageReaderService",getIOConfiguration(file), imageFromDisk);
// Data read
::fwData::Image::SpacingType spacingRead = imageFromDisk->getSpacing();
......@@ -446,11 +472,11 @@ void ImageReaderWriterTest::testMhdImageWriter()
// Write to vtk image.
const ::boost::filesystem::path file = ::fwTools::System::getTemporaryFolder()/ "temporaryFile.mhd";
this->runImageSrv("::io::IWriter","::ioVTK::ImageWriterService",getIOConfiguration(file), image);
runImageSrv("::io::IWriter","::ioVTK::ImageWriterService",getIOConfiguration(file), image);
// Read image from disk
::fwData::Image::sptr imageFromDisk = ::fwData::Image::New();
this->runImageSrv("::io::IReader","::ioVTK::ImageReaderService",getIOConfiguration(file), imageFromDisk);
runImageSrv("::io::IReader","::ioVTK::ImageReaderService",getIOConfiguration(file), imageFromDisk);
// Data read
::fwData::Image::SpacingType spacingRead = imageFromDisk->getSpacing();
......@@ -535,30 +561,6 @@ void ImageReaderWriterTest::testImageWriterExtension()
//------------------------------------------------------------------------------
void ImageReaderWriterTest::runImageSrv(
const std::string &srvtype,
const std::string &srvname,
const SPTR(::fwRuntime::EConfigurationElement)& cfg,
const SPTR(::fwData::Object)& image)
{
::fwServices::IService::sptr srv;
srv = ::fwServices::registry::ServiceFactory::getDefault()->create( srvtype, srvname );
CPPUNIT_ASSERT_MESSAGE(std::string("Failed to create service ") + srvname, srv);
::fwServices::OSR::registerService( image , srv );
CPPUNIT_ASSERT_NO_THROW( srv->setConfiguration(cfg) );
CPPUNIT_ASSERT_NO_THROW( srv->configure() );
CPPUNIT_ASSERT_NO_THROW( srv->start() );
CPPUNIT_ASSERT_NO_THROW( srv->update() );
CPPUNIT_ASSERT_NO_THROW( srv->stop() );
::fwServices::OSR::unregisterService( srv );
}
//------------------------------------------------------------------------------
} //namespace ut
} //namespace ioVTK
/* ***** BEGIN LICENSE BLOCK *****
* FW4SPL - Copyright (C) IRCAD, 2009-2013.
* FW4SPL - Copyright (C) IRCAD, 2009-2014.
* Distributed under the terms of the GNU Lesser General Public License (LGPL) as
* published by the Free Software Foundation.
* ****** END LICENSE BLOCK ****** */
......@@ -22,6 +22,7 @@
#include <fwMedData/ImageSeries.hpp>
#include <fwMedData/ModelSeries.hpp>
#include <fwMedData/Series.hpp>
#include <fwMedData/SeriesDB.hpp>
#include <fwDataCamp/visitor/CompareObjects.hpp>
......
/* ***** BEGIN LICENSE BLOCK *****
* FW4SPL - Copyright (C) IRCAD, 2009-2013.
* FW4SPL - Copyright (C) IRCAD, 2009-2014.
* Distributed under the terms of the GNU Lesser General Public License (LGPL) as
* published by the Free Software Foundation.
* ****** END LICENSE BLOCK ****** */
......@@ -9,18 +9,6 @@
#include <cppunit/extensions/HelperMacros.h>
#include <fwRuntime/EConfigurationElement.hpp>
namespace fwData
{
class Object;
}
namespace fwRuntime
{
class EConfigurationElement;
}
namespace patchMedicalData
{
namespace ut
......
/* ***** BEGIN LICENSE BLOCK *****
* FW4SPL - Copyright (C) IRCAD, 2009-2013.
* FW4SPL - Copyright (C) IRCAD, 2009-2014.
* Distributed under the terms of the GNU Lesser General Public License (LGPL) as
* published by the Free Software Foundation.
* ****** END LICENSE BLOCK ****** */
......@@ -9,18 +9,14 @@
#include <cppunit/extensions/HelperMacros.h>
namespace fwRuntime
{
struct Bundle;
}
namespace fwActivities
{
namespace ut
{
struct ActivityRegistryTestPimpl;
class ActivityRegistryTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE( ActivityRegistryTest );
......@@ -38,8 +34,7 @@ public:
protected:
SPTR( fwRuntime::Bundle ) m_bundle;
SPTR( fwActivities::registry::Activities ) m_activities;
SPTR( ActivityRegistryTestPimpl ) m_pimpl;
};
} //namespace ut
......
/* ***** BEGIN LICENSE BLOCK *****
* FW4SPL - Copyright (C) IRCAD, 2009-2013.
* FW4SPL - Copyright (C) IRCAD, 2009-2014.
* Distributed under the terms of the GNU Lesser General Public License (LGPL) as
* published by the Free Software Foundation.
* ****** END LICENSE BLOCK ****** */
......@@ -29,19 +29,27 @@ namespace fwActivities
namespace ut
{
struct ActivityRegistryTestPimpl
{
public:
SPTR(::fwRuntime::Bundle) bundle;
::fwActivities::registry::Activities::sptr activities;
};
//------------------------------------------------------------------------------
void ActivityRegistryTest::setUp()
{
m_pimpl = ::boost::make_shared< ActivityRegistryTestPimpl >();
::boost::filesystem::path plugin = "share/tu_exec_fwActivities_0-0/tu_registry";
m_bundle = ::fwRuntime::io::BundleDescriptorReader::createBundle(plugin);
m_pimpl->bundle = ::fwRuntime::io::BundleDescriptorReader::createBundle(plugin);
m_activities = fwActivities::registry::Activities::New();
m_pimpl->activities = fwActivities::registry::Activities::New();
::fwRuntime::Bundle::ExtensionContainer extensionsSet( m_bundle->extensionsBegin(), m_bundle->extensionsEnd());
::fwRuntime::Bundle::ExtensionContainer extensionsSet( m_pimpl->bundle->extensionsBegin(), m_pimpl->bundle->extensionsEnd());
std::vector< SPTR( ::fwRuntime::Extension ) > extensions(extensionsSet.begin(), extensionsSet.end());
m_activities->parseBundleInformation(extensions);
m_pimpl->activities->parseBundleInformation(extensions);
CPPUNIT_ASSERT_EQUAL( size_t(8) , extensions.size());
......@@ -53,7 +61,7 @@ void ActivityRegistryTest::setUp()
void ActivityRegistryTest::tearDown()
{
// Clean up after the test run.
m_bundle.reset();
m_pimpl.reset();
}
//------------------------------------------------------------------------------
......@@ -75,7 +83,7 @@ void ActivityRegistryTest::registryTest()
// 1 image
v->getContainer().push_back( ::fwData::Image::New() );
activities = m_activities->getInfos(v);
activities = m_pimpl->activities->getInfos(v);
std::sort(activities.begin(), activities.end(), activities_less_than_key());
CPPUNIT_ASSERT_EQUAL( size_t(4), activities.size() );
......@@ -87,7 +95,7 @@ void ActivityRegistryTest::registryTest()
// 2 images
v->getContainer().push_back( ::fwData::Image::New() );
activities = m_activities->getInfos(v);
activities = m_pimpl->activities->getInfos(v);
std::sort(activities.begin(), activities.end(), activities_less_than_key());
CPPUNIT_ASSERT_EQUAL( size_t(3), activities.size() );
......@@ -97,7 +105,7 @@ void ActivityRegistryTest::registryTest()
// 3 images
v->getContainer().push_back( ::fwData::Image::New() );
activities = m_activities->getInfos(v);
activities = m_pimpl->activities->getInfos(v);
std::sort(activities.begin(), activities.end(), activities_less_than_key());
CPPUNIT_ASSERT_EQUAL( size_t(1), activities.size() );
......@@ -105,7 +113,7 @@ void ActivityRegistryTest::registryTest()
// 4 images
v->getContainer().push_back( ::fwData::Image::New() );
activities = m_activities->getInfos(v);
activities = m_pimpl->activities->getInfos(v);
std::sort(activities.begin(), activities.end(), activities_less_than_key());
CPPUNIT_ASSERT_EQUAL( size_t(2), activities.size() );
......@@ -114,7 +122,7 @@ void ActivityRegistryTest::registryTest()
// 5 images
v->getContainer().push_back( ::fwData::Image::New() );
activities = m_activities->getInfos(v);
activities = m_pimpl->activities->getInfos(v);
std::sort(activities.begin(), activities.end(), activities_less_than_key());
CPPUNIT_ASSERT_EQUAL( size_t(2), activities.size() );
......@@ -123,7 +131,7 @@ void ActivityRegistryTest::registryTest()
// 6 images
v->getContainer().push_back( ::fwData::Image::New() );
activities = m_activities->getInfos(v);
activities = m_pimpl->activities->getInfos(v);
std::sort(activities.begin(), activities.end(), activities_less_than_key());
CPPUNIT_ASSERT_EQUAL( size_t(2), activities.size() );
......@@ -132,7 +140,7 @@ void ActivityRegistryTest::registryTest()
// 7 images
v->getContainer().push_back( ::fwData::Image::New() );
activities = m_activities->getInfos(v);
activities = m_pimpl->activities->getInfos(v);
std::sort(activities.begin(), activities.end(), activities_less_than_key());
CPPUNIT_ASSERT_EQUAL( size_t(2), activities.size() );
......@@ -141,7 +149,7 @@ void ActivityRegistryTest::registryTest()
// 8 images
v->getContainer().push_back( ::fwData::Image::New() );
activities = m_activities->getInfos(v);
activities = m_pimpl->activities->getInfos(v);
std::sort(activities.begin(), activities.end(), activities_less_than_key());
CPPUNIT_ASSERT_EQUAL( size_t(2), activities.size() );
......@@ -150,7 +158,7 @@ void ActivityRegistryTest::registryTest()
// 9 images
v->getContainer().push_back( ::fwData::Image::New() );
activities = m_activities->getInfos(v);
activities = m_pimpl->activities->getInfos(v);
std::sort(activities.begin(), activities.end(), activities_less_than_key());
CPPUNIT_ASSERT_EQUAL( size_t(1), activities.size() );
......@@ -158,7 +166,7 @@ void ActivityRegistryTest::registryTest()
// 9 images, 1 mesh
v->getContainer().push_back( ::fwData::Mesh::New() );
activities = m_activities->getInfos(v);
activities = m_pimpl->activities->getInfos(v);
std::sort(activities.begin(), activities.end(), activities_less_than_key());
CPPUNIT_ASSERT_EQUAL( size_t(0), activities.size() );
......@@ -168,7 +176,7 @@ void ActivityRegistryTest::registryTest()
v->getContainer().push_back( ::fwData::Image::New() );
v->getContainer().push_back( ::fwData::Mesh::New() );
activities = m_activities->getInfos(v);
activities = m_pimpl->activities->getInfos(v);
std::sort(activities.begin(), activities.end(), activities_less_than_key());
CPPUNIT_ASSERT_EQUAL( size_t(2), activities.size() );
......@@ -180,7 +188,7 @@ void ActivityRegistryTest::registryTest()
v->getContainer().push_back( ::fwMedData::ImageSeries::New() );
v->getContainer().push_back( ::fwMedData::ModelSeries::New() );
activities = m_activities->getInfos(v);
activities = m_pimpl->activities->getInfos(v);
std::sort(activities.begin(), activities.end(), activities_less_than_key());
CPPUNIT_ASSERT_EQUAL( size_t(1), activities.size() );
......
/* ***** BEGIN LICENSE BLOCK *****
* FW4SPL - Copyright (C) IRCAD, 2009-2012.
* FW4SPL - Copyright (C) IRCAD, 2009-2014.
* Distributed under the terms of the GNU Lesser General Public License (LGPL) as
* published by the Free Software Foundation.
* ****** END LICENSE BLOCK ****** */
......@@ -57,116 +57,6 @@ private:
::fwRuntime::ConfigurationElement::sptr buildCompositeConfig();
};
/**
* @brief Service type for test.
*/
class TestService : public ::fwServices::IService
{
public :
fwCoreServiceClassDefinitionsMacro ( (TestService)(::fwServices::IService) ) ;
TestService() throw()
: m_isUpdated(false),
m_isUpdatedMessage(false)
{}
virtual ~TestService() throw() {}
/// return true if the service is updated with updating() method
bool getIsUpdated() { return m_isUpdated; }
/// return true if the service is updated with updating(msg) method
bool getIsUpdatedMessage() { return m_isUpdatedMessage; }
/// return the message receiving in updating(msg) method
::fwServices::ObjectMsg::sptr getMessage() { return m_compoMsg; }
const std::string & getMessageEvent(){return m_messageEvent;}
protected:
virtual void configuring() throw( ::fwTools::Failed ) {}
virtual void starting() throw(::fwTools::Failed) {}
virtual void stopping() throw(::fwTools::Failed) {}
virtual void updating() throw(::fwTools::Failed) {}
virtual void info( std::ostream &_sstream ) {_sstream << "TestService" ;}
bool m_isUpdated;
bool m_isUpdatedMessage;
std::string m_messageEvent;
::fwServices::ObjectMsg::sptr m_compoMsg;
};
/**
* @brief Test service implementation for composite
*/
class TestServiceImplementationComposite : public TestService
{
public :
fwCoreServiceClassDefinitionsMacro ( (TestServiceImplementationComposite)(::fwComEd::ut::TestService) ) ;
TestServiceImplementationComposite() throw() {};
virtual ~TestServiceImplementationComposite() throw() {};
virtual void configuring() throw( ::fwTools::Failed ) {};
virtual void starting() throw(::fwTools::Failed) {};