MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkOpenIGTLinkImageFactoryTest.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
13#include <mitkTestingMacros.h>
14#include <mitkTestFixture.h>
15
17
18#include <igtlImageMessage.h>
19#include <igtlTransformMessage.h>
20#include <igtlPositionMessage.h>
21#include <igtlStatusMessage.h>
22#include <igtlCapabilityMessage.h>
23#include <igtlStringMessage.h>
25
26static const std::string TYPE_IMAGE = "IMAGE";
27static const std::string TYPE_TRANSFORM = "TRANSFORM";
28static const std::string TYPE_POSITION = "POSITION";
29static const std::string TYPE_STATUS = "STATUS";
30static const std::string TYPE_CAPABILITY = "CAPABILITY";
31static const std::string TYPE_TEST = "TEST";
32
33class mitkOpenIGTLinkImageFactoryTestSuite : public mitk::TestFixture {
34CPPUNIT_TEST_SUITE(mitkOpenIGTLinkImageFactoryTestSuite);
41CPPUNIT_TEST_SUITE_END();
42
43private:
44
45mitk::IGTLMessageFactory::Pointer m_MessageFactory;
46
47public:
48
49void setUp() override
50{
51m_MessageFactory = mitk::IGTLMessageFactory::New();
52}
53
54void tearDown() override
55{
56m_MessageFactory = nullptr;
57}
58
60{
61igtl::MessageBase::Pointer messageBase = m_MessageFactory->CreateInstance(TYPE_IMAGE);
62igtl::ImageMessage::Pointer message = dynamic_cast<igtl::ImageMessage*>(messageBase.GetPointer());
63
64CPPUNIT_ASSERT_MESSAGE("The created message was not of type igtl::ImageMessage", message.IsNotNull());
65}
66
68{
69igtl::MessageBase::Pointer messageBase = m_MessageFactory->CreateInstance(TYPE_TRANSFORM);
70igtl::TransformMessage::Pointer message = dynamic_cast<igtl::TransformMessage*>(messageBase.GetPointer());
71
72CPPUNIT_ASSERT_MESSAGE("The created message was not of type igtl::TransformMessage", message.IsNotNull());
73}
74
76{
77igtl::MessageBase::Pointer messageBase = m_MessageFactory->CreateInstance(TYPE_POSITION);
78igtl::PositionMessage::Pointer message = dynamic_cast<igtl::PositionMessage*>(messageBase.GetPointer());
79
80CPPUNIT_ASSERT_MESSAGE("The created message was not of type igtl::PositionMessage", message.IsNotNull());
81}
82
84{
85igtl::MessageBase::Pointer messageBase = m_MessageFactory->CreateInstance(TYPE_STATUS);
86igtl::StatusMessage::Pointer message = dynamic_cast<igtl::StatusMessage*>(messageBase.GetPointer());
87
88CPPUNIT_ASSERT_MESSAGE("The created message was not of type igtl::StatusMessage", message.IsNotNull());
89}
90
92{
93igtl::MessageBase::Pointer messageBase = m_MessageFactory->CreateInstance(TYPE_CAPABILITY);
94igtl::CapabilityMessage::Pointer message = dynamic_cast<igtl::CapabilityMessage*>(messageBase.GetPointer());
95
96CPPUNIT_ASSERT_MESSAGE("The created message was not of type igtl::CapabilityMessage", message.IsNotNull());
97}
98
100{
101m_MessageFactory->AddMessageNewMethod(TYPE_TEST, (mitk::IGTLMessageFactory::PointerToMessageBaseNew)&mitk::IGTLDummyMessage::New);
102
103igtl::MessageBase::Pointer messageBase = m_MessageFactory->CreateInstance(TYPE_TEST);
104mitk::IGTLDummyMessage::Pointer message = dynamic_cast<mitk::IGTLDummyMessage*>(messageBase.GetPointer());
105
106CPPUNIT_ASSERT_MESSAGE("The created message was not of type mitk::IGTLDummyMessage", message.IsNotNull());
107}
108};
109
110MITK_TEST_SUITE_REGISTRATION(mitkOpenIGTLinkImageFactory)
This class is a dummy message to show how to implement a new message type.
igtl::MessageBase::Pointer(*) PointerToMessageBaseNew()
Function pointer for storing New() static methods of igtl::MessageBase classes.