* Simple example for a test for the (non-existent) class "UndoController". * * argc and argv are the command line parameters which were passed to * the ADD_TEST command in the CMakeLists.txt file. For the automatic * tests, argv is either empty for the simple tests or contains the filename * of a test image for the image tests (see CMakeLists.txt). */
| 26 | * of a test image for the image tests (see CMakeLists.txt). |
| 27 | */ |
| 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...) |
| 42 | mitk::VerboseLimitedLinearUndo::Pointer standardModel = |
| 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); |
| 49 | mitk::LimitedLinearUndo::Pointer linearModel = |
| 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()); |
| 64 | MITK_TEST_CONDITION_REQUIRED( |
| 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()); |
| 72 | MITK_TEST_CONDITION_REQUIRED( |
| 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 | |
| 81 | mitk::LimitedLinearUndo::Pointer limited = |
| 82 | dynamic_cast<mitk::LimitedLinearUndo *>(myUndoController->GetCurrentUndoModel()); |
| 83 | MITK_TEST_CONDITION_REQUIRED( |
| 84 | limited.IsNotNull(), |
| 85 | "Testing to erase all models. Should be impossible to maintain a working model in UndoController") |
nothing calls this directly
no test coverage detected