Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkVtkWidgetRenderingTest.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 "mitkVtkWidgetRendering.h"
14 #include <vtkRenderWindow.h>
15 #include <vtkScalarBarWidget.h>
16 
17 #include "mitkTestingMacros.h"
18 
19 #include <iostream>
20 
30 int mitkVtkWidgetRenderingTest(int /* argc */, char * /*argv*/ [])
31 {
32  // always start with this!
33  MITK_TEST_BEGIN("mitkVTKWidgetRenderingTest")
34 
35  // Test: instantiation
37  MITK_TEST_CONDITION_REQUIRED(widgetRendering.IsNotNull(), "Testing instantiation")
38 
39  // Test: Create and set vtkRenderWindow
40  vtkRenderWindow *renderWindow = vtkRenderWindow::New();
41  // mitk::VtkPropRenderer::Pointer propRenderer = mitk::VtkPropRenderer::New( "the renderer", renderWindow );
42  // propRenderer->SetMapperID(2);
43  widgetRendering->SetRenderWindow(renderWindow);
44  MITK_TEST_CONDITION_REQUIRED(widgetRendering->GetRenderWindow() == renderWindow, "Setting vtkRenderWindow...")
45 
46  // Test: Try to enable before widget has been set (should stay disabled)
47  widgetRendering->Enable();
48  MITK_TEST_CONDITION(!widgetRendering->IsEnabled(), "Trying to enable widget rendering before setting widget")
49  widgetRendering->Disable();
50 
51  // Test: Retrieve widget before it has been set (should return nullptr)
52  MITK_TEST_CONDITION(widgetRendering->GetVtkWidget() == nullptr, "Trying to retrieve widget before it has been set")
53 
54  // Test: Create vtkWidget instance (vtkScalarWidget) and add it
55  vtkScalarBarWidget *scalarBarWidget = vtkScalarBarWidget::New();
56  widgetRendering->SetVtkWidget(scalarBarWidget);
57  MITK_TEST_CONDITION(widgetRendering->GetVtkWidget() == scalarBarWidget, "Retrieving widget after it has been set")
58 
59  // Test: Try to enable widget rendering (should work now)
60  widgetRendering->Enable();
61  MITK_TEST_CONDITION(widgetRendering->IsEnabled(), "Enabling widget rendering")
62 
63  // Test: Try to disable widget rendering (should be disabled)
64  widgetRendering->Disable();
65  MITK_TEST_CONDITION(!widgetRendering->IsEnabled(), "Disabling widget rendering")
66 
67  // Clean up
68  scalarBarWidget->Delete();
69  renderWindow->Delete();
70 
71  // write your own tests here and use the macros from mitkTestingMacros.h !!!
72  // do not write to std::cout and do not return from this function yourself!
73 
74  // always end with this!
76 }
int mitkVtkWidgetRenderingTest(int, char *[])
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
#define MITK_TEST_CONDITION(COND, MSG)
and MITK_TEST_END()
static Pointer New()