Mercurial > hg > orthanc
comparison UnitTestsSources/DicomMapTests.cpp @ 967:dfc076546821
add suffix Tests to unit test sources
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 27 Jun 2014 15:36:38 +0200 |
parents | UnitTestsSources/DicomMap.cpp@81134ea872ff |
children | 6164f7200c43 |
comparison
equal
deleted
inserted
replaced
966:886652370ff2 | 967:dfc076546821 |
---|---|
1 /** | |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, | |
4 * Belgium | |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
22 * | |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 #include "PrecompiledHeadersUnitTests.h" | |
34 #include "gtest/gtest.h" | |
35 | |
36 #include "../Core/Uuid.h" | |
37 #include "../Core/OrthancException.h" | |
38 #include "../Core/DicomFormat/DicomMap.h" | |
39 #include "../Core/DicomFormat/DicomNullValue.h" | |
40 #include "../OrthancServer/FromDcmtkBridge.h" | |
41 | |
42 #include <memory> | |
43 | |
44 using namespace Orthanc; | |
45 | |
46 TEST(DicomMap, MainTags) | |
47 { | |
48 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_PATIENT_ID)); | |
49 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_PATIENT_ID, ResourceType_Patient)); | |
50 ASSERT_FALSE(DicomMap::IsMainDicomTag(DICOM_TAG_PATIENT_ID, ResourceType_Study)); | |
51 | |
52 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_STUDY_INSTANCE_UID)); | |
53 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_ACCESSION_NUMBER)); | |
54 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_SERIES_INSTANCE_UID)); | |
55 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_SOP_INSTANCE_UID)); | |
56 | |
57 std::set<DicomTag> s; | |
58 DicomMap::GetMainDicomTags(s); | |
59 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_PATIENT_ID)); | |
60 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_STUDY_INSTANCE_UID)); | |
61 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_ACCESSION_NUMBER)); | |
62 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_SERIES_INSTANCE_UID)); | |
63 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_SOP_INSTANCE_UID)); | |
64 | |
65 DicomMap::GetMainDicomTags(s, ResourceType_Patient); | |
66 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_PATIENT_ID)); | |
67 ASSERT_TRUE(s.end() == s.find(DICOM_TAG_STUDY_INSTANCE_UID)); | |
68 | |
69 DicomMap::GetMainDicomTags(s, ResourceType_Study); | |
70 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_STUDY_INSTANCE_UID)); | |
71 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_ACCESSION_NUMBER)); | |
72 ASSERT_TRUE(s.end() == s.find(DICOM_TAG_PATIENT_ID)); | |
73 | |
74 DicomMap::GetMainDicomTags(s, ResourceType_Series); | |
75 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_SERIES_INSTANCE_UID)); | |
76 ASSERT_TRUE(s.end() == s.find(DICOM_TAG_PATIENT_ID)); | |
77 | |
78 DicomMap::GetMainDicomTags(s, ResourceType_Instance); | |
79 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_SOP_INSTANCE_UID)); | |
80 ASSERT_TRUE(s.end() == s.find(DICOM_TAG_PATIENT_ID)); | |
81 } | |
82 | |
83 | |
84 TEST(DicomMap, Tags) | |
85 { | |
86 DicomMap m; | |
87 ASSERT_FALSE(m.HasTag(DICOM_TAG_PATIENT_NAME)); | |
88 ASSERT_FALSE(m.HasTag(0x0010, 0x0010)); | |
89 m.SetValue(0x0010, 0x0010, "PatientName"); | |
90 ASSERT_TRUE(m.HasTag(DICOM_TAG_PATIENT_NAME)); | |
91 ASSERT_TRUE(m.HasTag(0x0010, 0x0010)); | |
92 | |
93 ASSERT_FALSE(m.HasTag(DICOM_TAG_PATIENT_ID)); | |
94 m.SetValue(DICOM_TAG_PATIENT_ID, "PatientID"); | |
95 ASSERT_TRUE(m.HasTag(0x0010, 0x0020)); | |
96 m.SetValue(DICOM_TAG_PATIENT_ID, "PatientID2"); | |
97 ASSERT_EQ("PatientID2", m.GetValue(0x0010, 0x0020).AsString()); | |
98 | |
99 m.Remove(DICOM_TAG_PATIENT_ID); | |
100 ASSERT_THROW(m.GetValue(0x0010, 0x0020), OrthancException); | |
101 | |
102 std::auto_ptr<DicomMap> mm(m.Clone()); | |
103 ASSERT_EQ("PatientName", mm->GetValue(DICOM_TAG_PATIENT_NAME).AsString()); | |
104 | |
105 m.SetValue(DICOM_TAG_PATIENT_ID, "Hello"); | |
106 ASSERT_THROW(mm->GetValue(DICOM_TAG_PATIENT_ID), OrthancException); | |
107 mm->CopyTagIfExists(m, DICOM_TAG_PATIENT_ID); | |
108 ASSERT_EQ("Hello", mm->GetValue(DICOM_TAG_PATIENT_ID).AsString()); | |
109 | |
110 DicomNullValue v; | |
111 ASSERT_TRUE(v.IsNull()); | |
112 } | |
113 | |
114 | |
115 TEST(DicomMap, FindTemplates) | |
116 { | |
117 DicomMap m; | |
118 | |
119 DicomMap::SetupFindPatientTemplate(m); | |
120 ASSERT_TRUE(m.HasTag(DICOM_TAG_PATIENT_ID)); | |
121 | |
122 DicomMap::SetupFindStudyTemplate(m); | |
123 ASSERT_TRUE(m.HasTag(DICOM_TAG_STUDY_INSTANCE_UID)); | |
124 ASSERT_TRUE(m.HasTag(DICOM_TAG_ACCESSION_NUMBER)); | |
125 | |
126 DicomMap::SetupFindSeriesTemplate(m); | |
127 ASSERT_TRUE(m.HasTag(DICOM_TAG_SERIES_INSTANCE_UID)); | |
128 | |
129 DicomMap::SetupFindInstanceTemplate(m); | |
130 ASSERT_TRUE(m.HasTag(DICOM_TAG_SOP_INSTANCE_UID)); | |
131 } | |
132 | |
133 | |
134 | |
135 | |
136 static void TestModule(ResourceType level) | |
137 { | |
138 std::set<DicomTag> module, main; | |
139 DicomTag::GetTagsForModule(module, level); | |
140 DicomMap::GetMainDicomTags(main, level); | |
141 | |
142 // The main dicom tags are a subset of the module | |
143 for (std::set<DicomTag>::const_iterator it = main.begin(); it != main.end(); it++) | |
144 { | |
145 bool ok = module.find(*it) != module.end(); | |
146 | |
147 // Exceptions for the Series level | |
148 /*if ((// | |
149 *it == DicomTag(0x, 0x) && | |
150 level == ResourceType_Series)) | |
151 { | |
152 ok = true; | |
153 }*/ | |
154 | |
155 // Exceptions for the Instance level | |
156 if ((/* Accession number, from Image module */ | |
157 *it == DicomTag(0x0020, 0x0012) && | |
158 level == ResourceType_Instance) || | |
159 (/* Image Index, from PET Image module */ | |
160 *it == DicomTag(0x0054, 0x1330) && | |
161 level == ResourceType_Instance) || | |
162 (/* Temporal Position Identifier, from MR Image module */ | |
163 *it == DicomTag(0x0020, 0x0100) && | |
164 level == ResourceType_Instance) || | |
165 (/* Number of Frames, from Multi-frame module attributes, related to Image IOD */ | |
166 *it == DicomTag(0x0028, 0x0008) && | |
167 level == ResourceType_Instance )) | |
168 { | |
169 ok = true; | |
170 } | |
171 | |
172 if (!ok) | |
173 { | |
174 std::cout << it->Format() << ": " << FromDcmtkBridge::GetName(*it) | |
175 << " not expected at level " << EnumerationToString(level) << std::endl; | |
176 } | |
177 | |
178 EXPECT_TRUE(ok); | |
179 } | |
180 } | |
181 | |
182 | |
183 TEST(DicomMap, Modules) | |
184 { | |
185 TestModule(ResourceType_Patient); | |
186 TestModule(ResourceType_Study); | |
187 //TestModule(ResourceType_Series); // TODO | |
188 TestModule(ResourceType_Instance); | |
189 } |