Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkLoggingAdapterTest.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 "mitkTestingMacros.h"
14 #include <mitkCommon.h>
15 #include <mitkItkLoggingAdapter.h>
16 #include <mitkVtkLoggingAdapter.h>
17 
18 class ItkLoggingTestClass : public itk::Object
19 {
20 public:
21  mitkClassMacroItkParent(ItkLoggingTestClass, itk::Object);
22  itkFactorylessNewMacro(Self) itkCloneMacro(Self)
23 
24  void TestItkWarningMessage()
25  {
26  itkWarningMacro("Test ITK Warning message");
27  }
28 };
29 
31 class LoggingAdapterTestClass
32 {
33 public:
34  static void TestVtkLoggingWithoutAdapter()
35  {
37  << "Testing vtk logging without adapter class: a separate window should open and display the logging messages.")
38  vtkOutputWindow::GetInstance()->DisplayText("Test VTK InfoMessage");
39  vtkOutputWindow::GetInstance()->DisplayDebugText("Test Vtk Debug Message");
40  vtkOutputWindow::GetInstance()->DisplayGenericWarningText("Test Vtk Generic Warning Message");
41  vtkOutputWindow::GetInstance()->DisplayWarningText("Test Vtk Warning Message");
42  vtkOutputWindow::GetInstance()->DisplayErrorText("Test Vtk Error Message");
43  MITK_TEST_CONDITION_REQUIRED(true, "Testing if Vtk logging without adapter runs without errors.");
44  }
45  static void TestVtkLoggingWithAdapter()
46  {
48  << "Testing vtk logging with adapter class: Vtk logging messages should be logged as MITK logging messages.")
49  mitk::VtkLoggingAdapter::Initialize();
50  vtkOutputWindow::GetInstance()->DisplayText("Test Vtk Info Message");
51  vtkOutputWindow::GetInstance()->DisplayDebugText("Test Vtk Debug Message");
52  vtkOutputWindow::GetInstance()->DisplayGenericWarningText("Test Vtk Generic Warning Message");
53  vtkOutputWindow::GetInstance()->DisplayWarningText("Test Vtk Warning Message");
54  vtkOutputWindow::GetInstance()->DisplayErrorText("Test Vtk Error Message");
55  MITK_TEST_CONDITION_REQUIRED(true, "Testing if Vtk logging with MITK logging adapter runs without errors.");
56  }
57 
58  static void TestItkLoggingWithoutAdapter()
59  {
60  ItkLoggingTestClass::Pointer myItkLogger = ItkLoggingTestClass::New();
61  myItkLogger->TestItkWarningMessage();
62  }
63 
64  static void TestItkLoggingWithAdapter()
65  {
67  ItkLoggingTestClass::Pointer myItkLogger = ItkLoggingTestClass::New();
68  myItkLogger->TestItkWarningMessage();
69  }
70 };
71 
72 int mitkLoggingAdapterTest(int /*argc*/, char * /*argv*/ [])
73 {
74  MITK_TEST_BEGIN("LoggingAdapters: VTK, ITK");
75  LoggingAdapterTestClass::TestVtkLoggingWithoutAdapter();
76  LoggingAdapterTestClass::TestVtkLoggingWithAdapter();
77  LoggingAdapterTestClass::TestItkLoggingWithoutAdapter();
78  LoggingAdapterTestClass::TestItkLoggingWithAdapter();
79  MITK_TEST_END();
80 }
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
int mitkLoggingAdapterTest(int, char *[])
DataCollection - Class to facilitate loading/accessing structured data.
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
#define MITK_TEST_OUTPUT(x)
Output some text.
#define mitkClassMacroItkParent(className, SuperClassName)
Definition: mitkCommon.h:49
static void Initialize()
Initializes the logging adapter. Itk logging messages are redirected to MITK logging afterwards...
and MITK_TEST_END()