diff --git a/Core/Code/Testing/mitkPointSetDataInteractorTest.cpp b/Core/Code/Testing/mitkPointSetDataInteractorTest.cpp index c23f6789ab..fca9afbd33 100644 --- a/Core/Code/Testing/mitkPointSetDataInteractorTest.cpp +++ b/Core/Code/Testing/mitkPointSetDataInteractorTest.cpp @@ -1,96 +1,98 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkTestingMacros.h" #include #include #include #include #include #include class mitkPointSetDataInteractorTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkPointSetDataInteractorTestSuite); MITK_TEST(AddPointInteraction); CPPUNIT_TEST_SUITE_END(); private: mitk::DataNode::Pointer testPointSetNode; mitk::PointSetDataInteractor::Pointer dataInteractor; mitk::PointSet::Pointer testPointSet; - mitk::InteractionTestHelper* interactionTestHelper; + mitk::InteractionTestHelper::Pointer interactionTestHelper; public: void setUp() { //Create DataNode as a container for our PointSet to be tested testPointSetNode = mitk::DataNode::New(); // Create PointSetData Interactor dataInteractor = mitk::PointSetDataInteractor::New(); // Load the according state machine for regular point set interaction dataInteractor->LoadStateMachine("PointSet.xml"); // Set the configuration file that defines the triggers for the transitions dataInteractor->SetEventConfig("PointSetConfig.xml"); // set the DataNode (which already is added to the DataStorage) dataInteractor->SetDataNode(testPointSetNode); //Create new PointSet which will receive the interaction input testPointSet = mitk::PointSet::New(); testPointSetNode->SetData(testPointSet); } void tearDown() { + //destroy all objects testPointSetNode = NULL; testPointSet = NULL; dataInteractor = NULL; - delete interactionTestHelper; + //make sure to destroy the test helper object after each test + interactionTestHelper = NULL; } void AddPointInteraction() { //Path to the reference PointSet std::string referencePointSetPath = "/Users/schroedt/Desktop/pointsetTestRef.mps"; //Path to the interaction xml file std::string interactionXmlPath = "/Users/schroedt/Desktop/pointsetTest.xml"; //Create test helper to initialize all necessary objects for interaction - interactionTestHelper = new mitk::InteractionTestHelper(interactionXmlPath); + interactionTestHelper = mitk::InteractionTestHelper::New(interactionXmlPath); //Add our test node to the DataStorage of our test helper interactionTestHelper->AddNodeToStorage(testPointSetNode); //Start Interaction interactionTestHelper->PlaybackInteraction(); //Load the reference PointSet mitk::PointSet::Pointer referencePointSet = mitk::IOUtil::LoadPointSet(referencePointSetPath); //Compare reference with the result of the interaction MITK_ASSERT_EQUAL(testPointSet.GetPointer(), referencePointSet.GetPointer(), ""); } }; MITK_TEST_SUITE_REGISTRATION(mitkPointSetDataInteractor) diff --git a/Core/Code/TestingHelper/mitkInteractionTestHelper.h b/Core/Code/TestingHelper/mitkInteractionTestHelper.h index 6267ed22a4..3211dba169 100644 --- a/Core/Code/TestingHelper/mitkInteractionTestHelper.h +++ b/Core/Code/TestingHelper/mitkInteractionTestHelper.h @@ -1,111 +1,120 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkInteractionTestHelper_h #define mitkInteractionTestHelper_h #include #include #include #include #include #include class vtkRenderWindow; class vtkRenderer; namespace mitk { /** @brief Creates everything needed to load and playback interaction events. * * The interaction is loaded from an xml file and the event are created. This file is * usually a recorded user interaction with the GUI. This can be done with InteractionEventRecorder * plugin. Also all necessary objects to handle interaction events are generated. * The user of this class is responsible to add the data object to interact with to the data storage * of InteractionTestHelper. And must also make sure that a proper data interactor is associated with the data object. * - * To test PointSet interaction for instance make sure you have a PointSet node and a PointSetDataInteractor. + * To test a PointSet interaction for instance make sure you have a PointSet node and a PointSetDataInteractor. * Then just add the node to the storage of the your InteractionTestHelper by calling InteractionTestHelper::AddNodeToStorage. - * Use InteractionTestHelper::PlaybackInteraction to execute. + * Use InteractionTestHelper::PlaybackInteraction to execute. The result can afterwards be compared to a reference object. + * + * Make sure to destroy the test helper instance after each test, since all render windows and its renderers have to be unregistered. * * \sa XML2EventParser * \sa EventFactory * \sa EventRecorder */ -class MITK_TESTINGHELPER_EXPORT InteractionTestHelper +class MITK_TESTINGHELPER_EXPORT InteractionTestHelper : public itk::LightObject { public: - InteractionTestHelper(const std::string &interactionXmlFilePath); + mitkClassMacro(InteractionTestHelper, LightObject); + mitkNewMacro1Param(InteractionTestHelper, const std::string &); - ~InteractionTestHelper(); /** @brief Returns the datastorage, in order to modify the data inside a rendering test. **/ mitk::DataStorage::Pointer GetDataStorage(); /** * @brief AddNodeToStorage Add a node to the datastorage and perform a reinit which is necessary for rendering. * @param node The data you want to add. */ void AddNodeToStorage(mitk::DataNode::Pointer node); /** * @brief PlaybackInteraction playback loaded interaction by passing events to the dispatcher. */ void PlaybackInteraction(); /** * @brief SetTimeStep Sets timesteps of all SliceNavigationControllers to given timestep. * @param newTimeStep new timestep * * Does the same as using ImageNavigators Time slider. Use this if your data was modified in a timestep other than 0. */ void SetTimeStep(int newTimeStep); typedef std::vector RenderWindowListType; protected: + + /** + * @brief InteractionTestHelper set up all neseccary objects by calling Initialize. + * @param interactionXmlFilePath path to xml file containing events and configuration information for the render windows. + */ + InteractionTestHelper(const std::string &interactionXmlFilePath); + + //unregisters all render windows and its renderers. + virtual ~InteractionTestHelper(); + /** * @brief Initialize Internal method to initialize the renderwindow and set the datastorage. * @throws mitk::Exception if interaction xml file can not be loaded. */ void Initialize(const std::string &interactionXmlFilePath); /** * @brief LoadInteraction loads events from xml file. * @param interactionXmlPath path to xml file with interaction events. */ void LoadInteraction(); mitk::XML2EventParser::EventContainerType m_Events; // List with loaded interaction events std::string m_InteractionFilePath; RenderWindowListType m_RenderWindowList; - mitk::RenderWindow::Pointer m_RenderWindowAxial; - mitk::RenderWindow::Pointer m_RenderWindowSagittal; - mitk::RenderWindow::Pointer m_RenderWindowFrontal; mitk::DataStorage::Pointer m_DataStorage; mitk::MouseModeSwitcher::Pointer m_MouseModeSwitcher; }; }//namespace mitk #endif