Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkOperation.h"
00019 #include "mitkUndoController.h"
00020 #include "mitkVerboseLimitedLinearUndo.h"
00021 #include "mitkInteractionConst.h"
00022
00023 #include "mitkTestingMacros.h"
00024
00025 #include <iostream>
00026
00027 int g_GlobalCounter = 0;
00028
00029 namespace mitk {
00030
00034 class TestOperation : public Operation
00035 {
00036 public:
00037 TestOperation(OperationType operationType)
00038 : Operation(operationType)
00039 {
00040 g_GlobalCounter++;
00041 };
00042
00043 virtual ~TestOperation()
00044 {
00045 g_GlobalCounter--;
00046 };
00047 };
00048 }
00049
00050
00070 int mitkVerboseLimitedLinearUndoTest(int , char* [])
00071 {
00072
00073 MITK_TEST_BEGIN("VerboseLimitedLinearUndo")
00074
00075
00076 mitk::UndoController* myUndoController = new mitk::UndoController();
00077
00078
00079 myUndoController->SwitchUndoModel(mitk::UndoController::VERBOSE_LIMITEDLINEARUNDO);
00080
00081 for (int i = 0; i<2; i++)
00082 {
00083 mitk::TestOperation* doOp = new mitk::TestOperation(mitk::OpTEST);
00084 mitk::TestOperation *undoOp = new mitk::TestOperation(mitk::OpTEST);
00085 mitk::OperationEvent *operationEvent = new mitk::OperationEvent(NULL, doOp, undoOp, "Test");
00086 myUndoController->SetOperationEvent(operationEvent);
00087
00088 mitk::OperationEvent::IncCurrObjectEventId();
00089 mitk::UndoStackItem::ExecuteIncrement();
00090 }
00091
00092
00093 MITK_TEST_CONDITION_REQUIRED(g_GlobalCounter == 4,"checking initialization of mitkOperation");
00094
00095
00096 myUndoController->Undo();
00097
00098
00099 for (int i = 0; i<2; i++)
00100 {
00101 mitk::TestOperation* doOp = new mitk::TestOperation(mitk::OpTEST);
00102 mitk::TestOperation *undoOp = new mitk::TestOperation(mitk::OpTEST);
00103 mitk::OperationEvent *operationEvent = new mitk::OperationEvent(NULL, doOp, undoOp, "Test");
00104 myUndoController->SetOperationEvent(operationEvent);
00105
00106 mitk::OperationEvent::IncCurrObjectEventId();
00107 mitk::UndoStackItem::ExecuteIncrement();
00108 }
00109
00110
00111 MITK_TEST_CONDITION_REQUIRED(g_GlobalCounter == 6,"checking adding of operations");
00112
00113
00114 myUndoController->Undo();
00115 myUndoController->ClearRedoList();
00116
00117
00118 MITK_TEST_CONDITION_REQUIRED(g_GlobalCounter == 4,"checking deleting RedoList");
00119
00120
00121 myUndoController->Clear();
00122 MITK_TEST_CONDITION_REQUIRED(g_GlobalCounter == 0,"checking deleting all operations in UndoModel");
00123
00124
00125 for (int i = 0; i<2; i++)
00126 {
00127 mitk::TestOperation* doOp = new mitk::TestOperation(mitk::OpTEST);
00128 mitk::TestOperation *undoOp = new mitk::TestOperation(mitk::OpTEST);
00129 mitk::OperationEvent *operationEvent = new mitk::OperationEvent(NULL, doOp, undoOp, "Test");
00130 myUndoController->SetOperationEvent(operationEvent);
00131
00132 mitk::OperationEvent::IncCurrObjectEventId();
00133 mitk::UndoStackItem::ExecuteIncrement();
00134 }
00135 MITK_TEST_CONDITION_REQUIRED(g_GlobalCounter == 4,"checking added operations in UndoModel");
00136
00137 delete myUndoController;
00138
00139
00140 MITK_TEST_CONDITION_REQUIRED(g_GlobalCounter == 4,"checking singleton UndoModel");
00141
00142
00143 MITK_TEST_END()
00144
00145 }
00146