Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkVerboseLimitedLinearUndoTest.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 "mitkInteractionConst.h"
18 #include "mitkOperation.h"
19 #include "mitkUndoController.h"
21 
22 #include "mitkTestingMacros.h"
23 
24 #include <iostream>
25 
27 
28 namespace mitk
29 {
33  class TestOperation : public Operation
34  {
35  public:
36  TestOperation(OperationType operationType) : Operation(operationType) { g_GlobalCounter++; };
37  virtual ~TestOperation() { g_GlobalCounter--; };
38  };
39 } // namespace
40 
60 int mitkVerboseLimitedLinearUndoTest(int /* argc */, char * /*argv*/ [])
61 {
62  // always start with this!
63  MITK_TEST_BEGIN("VerboseLimitedLinearUndo")
64 
65  // an UndoController for the management
66  auto myUndoController = new mitk::UndoController();
67 
68  // set model, even if it is verboseLimitedLinearUndo by default; this already is tested by UndoControllerTest!
69  myUndoController->SwitchUndoModel(mitk::UndoController::VERBOSE_LIMITEDLINEARUNDO);
70 
71  for (int i = 0; i < 2; i++)
72  {
73  auto doOp = new mitk::TestOperation(mitk::OpTEST);
74  auto undoOp = new mitk::TestOperation(mitk::OpTEST);
75  mitk::OperationEvent *operationEvent = new mitk::OperationEvent(nullptr, doOp, undoOp, "Test");
76  myUndoController->SetOperationEvent(operationEvent);
77  // increase the ID to separate the operationEvents from each other. Otherwise they would be undone all together at
78  // once.
80  }
81 
82  // now 2 * 2 operation should have been instanciated
83  MITK_TEST_CONDITION_REQUIRED(g_GlobalCounter == 4, "checking initialization of mitkOperation");
84 
85  // undo one operation; 1 operationEvent element in undo list, 1 in Redo list
86  myUndoController->Undo();
87 
88  // sending two new OperationEvents: RedoList should be deleted and memory of operations freed
89  for (int i = 0; i < 2; i++)
90  {
91  auto doOp = new mitk::TestOperation(mitk::OpTEST);
92  auto undoOp = new mitk::TestOperation(mitk::OpTEST);
93  mitk::OperationEvent *operationEvent = new mitk::OperationEvent(nullptr, doOp, undoOp, "Test");
94  myUndoController->SetOperationEvent(operationEvent);
95  // increase the ID to separate the operationEvents from each other. Otherwise they would be undone all together at
96  // once.
98  }
99 
100  // 2 operations should have been deleted, 4 should have been added
101  MITK_TEST_CONDITION_REQUIRED(g_GlobalCounter == 6, "checking adding of operations");
102 
103  // two operations to RedoList
104  myUndoController->Undo();
105  myUndoController->ClearRedoList();
106 
107  // one operationEvent containing 2 operations should have been deleted
108  MITK_TEST_CONDITION_REQUIRED(g_GlobalCounter == 4, "checking deleting RedoList");
109 
110  // clear all
111  myUndoController->Clear();
112  MITK_TEST_CONDITION_REQUIRED(g_GlobalCounter == 0, "checking deleting all operations in UndoModel");
113 
114  // sending two new OperationEvents
115  for (int i = 0; i < 2; i++)
116  {
117  auto doOp = new mitk::TestOperation(mitk::OpTEST);
118  auto undoOp = new mitk::TestOperation(mitk::OpTEST);
119  mitk::OperationEvent *operationEvent = new mitk::OperationEvent(nullptr, doOp, undoOp, "Test");
120  myUndoController->SetOperationEvent(operationEvent);
121  // increase the ID to separate the operationEvents from each other. Otherwise they would be undone all together at
122  // once.
124  }
125  MITK_TEST_CONDITION_REQUIRED(g_GlobalCounter == 4, "checking added operations in UndoModel");
126 
127  delete myUndoController;
128 
129  // after deleting UndoController g_GlobalCounter will still be 4 because m_CurrentUndoModel inside myUndoModel is a
130  // static singleton
131  MITK_TEST_CONDITION_REQUIRED(g_GlobalCounter == 4, "checking singleton UndoModel");
132 
133  // always end with this!
134  MITK_TEST_END()
135  // operations will be deleted after terminating the application
136 }
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
DataCollection - Class to facilitate loading/accessing structured data.
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
int mitkVerboseLimitedLinearUndoTest(int, char *[])
Test of the LimitedLinearUndo object.
Constants for most interaction classes, due to the generic StateMachines.
int OperationType
Definition: mitkOperation.h:27
static void IncCurrObjectEventId()
Increases the current ObjectEventId For example if a button click generates operations the ObjectEven...
and MITK_TEST_END()
Represents a pair of operations: undo and the according redo.