Medical Imaging Interaction Toolkit  2018.4.99-389bf124
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkUndoController.h"
15 
16 #include "mitkTestingMacros.h"
17 
18 #include <iostream>
19 
28 int mitkUndoControllerTest(int /* argc */, char * /*argv*/ [])
29 {
30  // always start with this!
31  MITK_TEST_BEGIN("UndoController")
32 
33  // let's create an object of our class
34  auto myUndoController = new mitk::UndoController();
35 
36  // first test: did this work?
37  // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since
38  // it makes no sense to continue without an object.
39  MITK_TEST_CONDITION_REQUIRED(myUndoController != nullptr, "Testing instantiation")
40 
41  // check default model (verbose...)
43  dynamic_cast<mitk::VerboseLimitedLinearUndo *>(myUndoController->GetCurrentUndoModel());
44  MITK_TEST_CONDITION_REQUIRED(standardModel.IsNotNull(),
45  "Testing if the standard undo model VerboseLimitedLinearUndo is returned")
46 
47  // switch to limitedlinearundomodel
48  myUndoController->AddUndoModel(mitk::UndoController::LIMITEDLINEARUNDO);
50  dynamic_cast<mitk::LimitedLinearUndo *>(myUndoController->GetCurrentUndoModel());
51  MITK_TEST_CONDITION_REQUIRED(linearModel.IsNotNull(), "Testing to add and then to read a LimitedLinearUndoModel")
52 
53  // switching to verbose again
54  myUndoController->SwitchUndoModel(mitk::UndoController::VERBOSE_LIMITEDLINEARUNDO);
55  mitk::VerboseLimitedLinearUndo::Pointer anotherVerboseModelPointer =
56  dynamic_cast<mitk::VerboseLimitedLinearUndo *>(myUndoController->GetCurrentUndoModel());
57  MITK_TEST_CONDITION_REQUIRED(standardModel == anotherVerboseModelPointer,
58  "Testing to switch back again and to be sure, that the poiinters are the same")
59 
60  // removing verbose; model should be switch to limited
61  myUndoController->RemoveUndoModel(mitk::UndoController::VERBOSE_LIMITEDLINEARUNDO);
62  mitk::LimitedLinearUndo::Pointer anotherLinearModel =
63  dynamic_cast<mitk::LimitedLinearUndo *>(myUndoController->GetCurrentUndoModel());
65  linearModel == anotherLinearModel,
66  "Testing to remove the VerboseLimitedLinearUndoModel and to automatically switch to LimitedLinearUndo")
67 
68  // switch to limitedlinearundomodel
69  myUndoController->AddUndoModel(mitk::UndoController::VERBOSE_LIMITEDLINEARUNDO);
70  mitk::VerboseLimitedLinearUndo::Pointer newVerboseModelPointer =
71  dynamic_cast<mitk::VerboseLimitedLinearUndo *>(myUndoController->GetCurrentUndoModel());
73  newVerboseModelPointer != standardModel,
74  "Testing to add verbose model and if the new model is equal to the deleted one. Should not be the case!")
75 
76  // removing boith models
77  myUndoController->RemoveUndoModel(mitk::UndoController::VERBOSE_LIMITEDLINEARUNDO);
78  // should not detele, to maintain an UndoController with at least one UndoModel
79  myUndoController->RemoveUndoModel(mitk::UndoController::LIMITEDLINEARUNDO);
80 
82  dynamic_cast<mitk::LimitedLinearUndo *>(myUndoController->GetCurrentUndoModel());
84  limited.IsNotNull(),
85  "Testing to erase all models. Should be impossible to maintain a working model in UndoController")
86 
87  delete myUndoController;
88 
89  // always end with this!
91 }
#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()