Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkDICOMPropertyTest.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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkDICOMProperty.h"
18 
19 #include "mitkImage.h"
20 #include "mitkTestFixture.h"
21 #include "mitkTestingMacros.h"
22 
23 class mitkDICOMPropertyTestSuite : public mitk::TestFixture
24 {
25  CPPUNIT_TEST_SUITE(mitkDICOMPropertyTestSuite);
26 
28  MITK_TEST(GetPropertyByDICOMTagPath_2);
29 
30  CPPUNIT_TEST_SUITE_END();
31 
32 private:
33 
34  mitk::DICOMTagPath simplePath;
35  mitk::DICOMTagPath deepPath;
36  mitk::DICOMTagPath deepPath2;
37  mitk::DICOMTagPath deepPath_withAnyElement;
38  mitk::DICOMTagPath deepPath_withAnySelection;
39  mitk::DICOMTagPath deepPath_withSelection;
40  mitk::DICOMTagPath deepPath_withSelection2;
41 
42  mitk::DICOMTagPath emptyPath;
43 
45 
46  std::string simplePathStr;
47  std::string deepPathStr;
48  std::string deepPath2Str;
49  std::string deepPath_withSelectionStr;
50 
51 public:
52 
53  void setUp() override
54  {
55  simplePath.AddElement(0x0010, 0x0010);
56 
57  deepPath.AddElement(0x0010, 0x0011).AddElement(0x0020, 0x0022).AddElement(0x0030, 0x0033);
58 
59  deepPath2.AddElement(0x0010, 0x0011).AddElement(0x0020, 0x0023).AddElement(0x0030, 0x0033);
60 
61  deepPath_withAnyElement.AddElement(0x0010, 0x0011).AddAnyElement().AddElement(0x0030, 0x0033);
62 
63  deepPath_withAnySelection.AddElement(0x0010, 0x0011).AddAnySelection(0x0020, 0x0024).AddElement(0x0030, 0x0033);
64 
65  deepPath_withSelection.AddElement(0x0010, 0x0011).AddSelection(0x0020, 0x0024, 1).AddElement(0x0030, 0x0033);
66 
67  deepPath_withSelection2.AddElement(0x0010, 0x0011).AddSelection(0x0020, 0x0024, 2).AddElement(0x0030, 0x0033);
68 
69  simplePathStr = mitk::DICOMTagPathToPropertyName(simplePath);
70  deepPathStr = mitk::DICOMTagPathToPropertyName(deepPath);
71  deepPath2Str = mitk::DICOMTagPathToPropertyName(deepPath2);
72  deepPath_withSelectionStr = mitk::DICOMTagPathToPropertyName(deepPath_withSelection);
73 
74  data = mitk::Image::New();
75  data->GetPropertyList()->SetStringProperty(simplePathStr.c_str(), "simplePath");
76  data->GetPropertyList()->SetStringProperty(deepPathStr.c_str(), "deepPath");
77  data->GetPropertyList()->SetStringProperty(deepPath2Str.c_str(), "deepPath2");
78  data->GetPropertyList()->SetStringProperty(deepPath_withSelectionStr.c_str(), "deepPath_withSelection");
79  data->GetPropertyList()->SetStringProperty("DICOM.0003.0003", "otherPath");
80  data->GetPropertyList()->SetStringProperty("not_a_dicom_prop", "not_a_dicom_prop");
81  }
82 
83  void tearDown() override
84  {
85  }
86 
88  {
89  std::map< std::string, mitk::BaseProperty::Pointer> result = mitk::GetPropertyByDICOMTagPath(data, simplePath);
90  CPPUNIT_ASSERT(result.size() == 1);
91  CPPUNIT_ASSERT_EQUAL(result.begin()->second->GetValueAsString(), std::string("simplePath"));
92 
93  result = mitk::GetPropertyByDICOMTagPath(data, deepPath);
94  CPPUNIT_ASSERT(result.size() == 1);
95  CPPUNIT_ASSERT_EQUAL(result.begin()->second->GetValueAsString(), std::string("deepPath"));
96 
97  result = mitk::GetPropertyByDICOMTagPath(data, deepPath2);
98  CPPUNIT_ASSERT(result.size() == 1);
99  CPPUNIT_ASSERT_EQUAL(result.begin()->second->GetValueAsString(), std::string("deepPath2"));
100 
101  result = mitk::GetPropertyByDICOMTagPath(data, deepPath_withAnyElement);
102  CPPUNIT_ASSERT(result.size() == 3);
103  CPPUNIT_ASSERT_EQUAL(result[deepPathStr]->GetValueAsString(), std::string("deepPath"));
104  CPPUNIT_ASSERT_EQUAL(result[deepPath2Str]->GetValueAsString(), std::string("deepPath2"));
105  CPPUNIT_ASSERT_EQUAL(result[deepPath_withSelectionStr]->GetValueAsString(), std::string("deepPath_withSelection"));
106 
107  result = mitk::GetPropertyByDICOMTagPath(data, deepPath_withSelection);
108  CPPUNIT_ASSERT(result.size() == 1);
109  CPPUNIT_ASSERT_EQUAL(result[deepPath_withSelectionStr]->GetValueAsString(), std::string("deepPath_withSelection"));
110 
111  result = mitk::GetPropertyByDICOMTagPath(data, deepPath_withSelection2);
112  CPPUNIT_ASSERT(result.size() == 0);
113 
114  result = mitk::GetPropertyByDICOMTagPath(data, emptyPath);
115  CPPUNIT_ASSERT(result.size() == 0);
116  }
117 
118 
119  void GetPropertyByDICOMTagPath_2()
120  {
121  std::map< std::string, mitk::BaseProperty::Pointer> result = mitk::GetPropertyByDICOMTagPath(data->GetPropertyList(), simplePath);
122  CPPUNIT_ASSERT(result.size() == 1);
123  CPPUNIT_ASSERT_EQUAL(result.begin()->second->GetValueAsString(), std::string("simplePath"));
124 
125  result = mitk::GetPropertyByDICOMTagPath(data->GetPropertyList(), deepPath);
126  CPPUNIT_ASSERT(result.size() == 1);
127  CPPUNIT_ASSERT_EQUAL(result.begin()->second->GetValueAsString(), std::string("deepPath"));
128 
129  result = mitk::GetPropertyByDICOMTagPath(data->GetPropertyList(), deepPath2);
130  CPPUNIT_ASSERT(result.size() == 1);
131  CPPUNIT_ASSERT_EQUAL(result.begin()->second->GetValueAsString(), std::string("deepPath2"));
132 
133  result = mitk::GetPropertyByDICOMTagPath(data->GetPropertyList(), deepPath_withAnyElement);
134  CPPUNIT_ASSERT(result.size() == 3);
135  CPPUNIT_ASSERT_EQUAL(result[deepPathStr]->GetValueAsString(), std::string("deepPath"));
136  CPPUNIT_ASSERT_EQUAL(result[deepPath2Str]->GetValueAsString(), std::string("deepPath2"));
137  CPPUNIT_ASSERT_EQUAL(result[deepPath_withSelectionStr]->GetValueAsString(), std::string("deepPath_withSelection"));
138 
139  result = mitk::GetPropertyByDICOMTagPath(data->GetPropertyList(), deepPath_withSelection);
140  CPPUNIT_ASSERT(result.size() == 1);
141  CPPUNIT_ASSERT_EQUAL(result[deepPath_withSelectionStr]->GetValueAsString(), std::string("deepPath_withSelection"));
142 
143  result = mitk::GetPropertyByDICOMTagPath(data->GetPropertyList(), deepPath_withSelection2);
144  CPPUNIT_ASSERT(result.size() == 0);
145 
146  result = mitk::GetPropertyByDICOMTagPath(data->GetPropertyList(), emptyPath);
147  CPPUNIT_ASSERT(result.size() == 0);
148  }
149 
150 
151 };
152 
153 MITK_TEST_SUITE_REGISTRATION(mitkDICOMProperty)
DICOMTagPath & AddElement(unsigned int group, unsigned int element)
DICOMTagPath & AddAnySelection(unsigned int group, unsigned int element)
Class is used to identify (nested) attributes in a DICOM dataset. In contrast to the class DICOMTag...
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
DICOMTagPath & AddAnyElement()
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
MITKDICOMREADER_EXPORT std::string DICOMTagPathToPropertyName(const DICOMTagPath &tagPath)
Test fixture for parameterized tests.
static Pointer New()
DICOMTagPath & AddSelection(unsigned int group, unsigned int element, ItemSelectionIndex index)
MITKDICOMREADER_EXPORT std::map< std::string, BaseProperty::Pointer > GetPropertyByDICOMTagPath(const PropertyList *list, const DICOMTagPath &path)