00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date: 2008-02-25 17:27:17 +0100 (Mo, 25 Feb 2008) $ 00006 Version: $Revision: 7837 $ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 #include "mitkUndoController.h" 00019 #include "mitkVerboseLimitedLinearUndo.h" 00020 00021 #include "mitkTestingMacros.h" 00022 00023 #include <iostream> 00024 00033 int mitkUndoControllerTest(int /* argc */, char* /*argv*/[]) 00034 { 00035 // always start with this! 00036 MITK_TEST_BEGIN("UndoController") 00037 00038 // let's create an object of our class 00039 mitk::UndoController* myUndoController = new mitk::UndoController(); 00040 00041 // first test: did this work? 00042 // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since 00043 // it makes no sense to continue without an object. 00044 MITK_TEST_CONDITION_REQUIRED(myUndoController != NULL, "Testing instantiation") 00045 00046 //check default model (verbose...) 00047 mitk::VerboseLimitedLinearUndo::Pointer standardModel = dynamic_cast<mitk::VerboseLimitedLinearUndo*>(myUndoController->GetCurrentUndoModel()); 00048 MITK_TEST_CONDITION_REQUIRED(standardModel.IsNotNull(),"Testing if the standard undo model VerboseLimitedLinearUndo is returned") 00049 00050 //switch to limitedlinearundomodel 00051 myUndoController->AddUndoModel(mitk::UndoController::LIMITEDLINEARUNDO); 00052 mitk::LimitedLinearUndo::Pointer linearModel = dynamic_cast<mitk::LimitedLinearUndo*>(myUndoController->GetCurrentUndoModel()); 00053 MITK_TEST_CONDITION_REQUIRED(linearModel.IsNotNull(),"Testing to add and then to read a LimitedLinearUndoModel") 00054 00055 //switching to verbose again 00056 myUndoController->SwitchUndoModel(mitk::UndoController::VERBOSE_LIMITEDLINEARUNDO); 00057 mitk::VerboseLimitedLinearUndo::Pointer anotherVerboseModelPointer = dynamic_cast<mitk::VerboseLimitedLinearUndo*>(myUndoController->GetCurrentUndoModel()); 00058 MITK_TEST_CONDITION_REQUIRED(standardModel == anotherVerboseModelPointer,"Testing to switch back again and to be sure, that the poiinters are the same") 00059 00060 //removing verbose; model should be switch to limited 00061 myUndoController->RemoveUndoModel(mitk::UndoController::VERBOSE_LIMITEDLINEARUNDO); 00062 mitk::LimitedLinearUndo::Pointer anotherLinearModel = dynamic_cast<mitk::LimitedLinearUndo*>(myUndoController->GetCurrentUndoModel()); 00063 MITK_TEST_CONDITION_REQUIRED(linearModel == anotherLinearModel,"Testing to remove the VerboseLimitedLinearUndoModel and to automatically switch to LimitedLinearUndo") 00064 00065 //switch to limitedlinearundomodel 00066 myUndoController->AddUndoModel(mitk::UndoController::VERBOSE_LIMITEDLINEARUNDO); 00067 mitk::VerboseLimitedLinearUndo::Pointer newVerboseModelPointer = dynamic_cast<mitk::VerboseLimitedLinearUndo*>(myUndoController->GetCurrentUndoModel()); 00068 MITK_TEST_CONDITION_REQUIRED(newVerboseModelPointer != standardModel,"Testing to add verbose model and if the new model is equal to the deleted one. Should not be the case!") 00069 00070 //removing boith models 00071 myUndoController->RemoveUndoModel(mitk::UndoController::VERBOSE_LIMITEDLINEARUNDO); 00072 //should not detele, to maintain an UndoController with at least one UndoModel 00073 myUndoController->RemoveUndoModel(mitk::UndoController::LIMITEDLINEARUNDO); 00074 00075 mitk::LimitedLinearUndo::Pointer limited = dynamic_cast<mitk::LimitedLinearUndo*>(myUndoController->GetCurrentUndoModel()); 00076 MITK_TEST_CONDITION_REQUIRED(limited.IsNotNull(),"Testing to erase all models. Should be impossible to maintain a working model in UndoController") 00077 00078 delete myUndoController; 00079 00080 // always end with this! 00081 MITK_TEST_END() 00082 } 00083