Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkUndoControllerTest.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkUndoController.h"
19 
20 #include "mitkTestingMacros.h"
21 
22 #include <iostream>
23 
32 int mitkUndoControllerTest(int /* argc */, char * /*argv*/ [])
33 {
34  // always start with this!
35  MITK_TEST_BEGIN("UndoController")
36 
37  // let's create an object of our class
38  auto myUndoController = new mitk::UndoController();
39 
40  // first test: did this work?
41  // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since
42  // it makes no sense to continue without an object.
43  MITK_TEST_CONDITION_REQUIRED(myUndoController != nullptr, "Testing instantiation")
44 
45  // check default model (verbose...)
47  dynamic_cast<mitk::VerboseLimitedLinearUndo *>(myUndoController->GetCurrentUndoModel());
48  MITK_TEST_CONDITION_REQUIRED(standardModel.IsNotNull(),
49  "Testing if the standard undo model VerboseLimitedLinearUndo is returned")
50 
51  // switch to limitedlinearundomodel
52  myUndoController->AddUndoModel(mitk::UndoController::LIMITEDLINEARUNDO);
54  dynamic_cast<mitk::LimitedLinearUndo *>(myUndoController->GetCurrentUndoModel());
55  MITK_TEST_CONDITION_REQUIRED(linearModel.IsNotNull(), "Testing to add and then to read a LimitedLinearUndoModel")
56 
57  // switching to verbose again
58  myUndoController->SwitchUndoModel(mitk::UndoController::VERBOSE_LIMITEDLINEARUNDO);
59  mitk::VerboseLimitedLinearUndo::Pointer anotherVerboseModelPointer =
60  dynamic_cast<mitk::VerboseLimitedLinearUndo *>(myUndoController->GetCurrentUndoModel());
61  MITK_TEST_CONDITION_REQUIRED(standardModel == anotherVerboseModelPointer,
62  "Testing to switch back again and to be sure, that the poiinters are the same")
63 
64  // removing verbose; model should be switch to limited
65  myUndoController->RemoveUndoModel(mitk::UndoController::VERBOSE_LIMITEDLINEARUNDO);
66  mitk::LimitedLinearUndo::Pointer anotherLinearModel =
67  dynamic_cast<mitk::LimitedLinearUndo *>(myUndoController->GetCurrentUndoModel());
69  linearModel == anotherLinearModel,
70  "Testing to remove the VerboseLimitedLinearUndoModel and to automatically switch to LimitedLinearUndo")
71 
72  // switch to limitedlinearundomodel
73  myUndoController->AddUndoModel(mitk::UndoController::VERBOSE_LIMITEDLINEARUNDO);
74  mitk::VerboseLimitedLinearUndo::Pointer newVerboseModelPointer =
75  dynamic_cast<mitk::VerboseLimitedLinearUndo *>(myUndoController->GetCurrentUndoModel());
77  newVerboseModelPointer != standardModel,
78  "Testing to add verbose model and if the new model is equal to the deleted one. Should not be the case!")
79 
80  // removing boith models
81  myUndoController->RemoveUndoModel(mitk::UndoController::VERBOSE_LIMITEDLINEARUNDO);
82  // should not detele, to maintain an UndoController with at least one UndoModel
83  myUndoController->RemoveUndoModel(mitk::UndoController::LIMITEDLINEARUNDO);
84 
86  dynamic_cast<mitk::LimitedLinearUndo *>(myUndoController->GetCurrentUndoModel());
88  limited.IsNotNull(),
89  "Testing to erase all models. Should be impossible to maintain a working model in UndoController")
90 
91  delete myUndoController;
92 
93  // always end with this!
95 }
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
A linear undo model with one undo and one redo stack.
A limited linear undo model providing GUI elements with stack status information. ...
int mitkUndoControllerTest(int, char *[])
and MITK_TEST_END()