Mercurial > hg > orthanc
comparison UnitTestsSources/DicomMapTests.cpp @ 2884:497a637366b4 db-changes
integration mainline->db-changes
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 12 Oct 2018 15:18:10 +0200 |
parents | da12ba232119 |
children | 8265a6b56100 |
comparison
equal
deleted
inserted
replaced
1762:2b91363cc1d1 | 2884:497a637366b4 |
---|---|
1 /** | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
4 * Department, University Hospital of Liege, Belgium | 4 * Department, University Hospital of Liege, Belgium |
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium | |
5 * | 6 * |
6 * This program is free software: you can redistribute it and/or | 7 * 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 * 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 * published by the Free Software Foundation, either version 3 of the |
9 * License, or (at your option) any later version. | 10 * License, or (at your option) any later version. |
31 | 32 |
32 | 33 |
33 #include "PrecompiledHeadersUnitTests.h" | 34 #include "PrecompiledHeadersUnitTests.h" |
34 #include "gtest/gtest.h" | 35 #include "gtest/gtest.h" |
35 | 36 |
36 #include "../Core/Uuid.h" | |
37 #include "../Core/OrthancException.h" | 37 #include "../Core/OrthancException.h" |
38 #include "../Core/DicomFormat/DicomMap.h" | 38 #include "../Core/DicomFormat/DicomMap.h" |
39 #include "../OrthancServer/FromDcmtkBridge.h" | 39 #include "../Core/DicomParsing/FromDcmtkBridge.h" |
40 | 40 |
41 #include <memory> | 41 #include <memory> |
42 | 42 |
43 using namespace Orthanc; | 43 using namespace Orthanc; |
44 | 44 |
88 m.GetTags(s); | 88 m.GetTags(s); |
89 ASSERT_EQ(0u, s.size()); | 89 ASSERT_EQ(0u, s.size()); |
90 | 90 |
91 ASSERT_FALSE(m.HasTag(DICOM_TAG_PATIENT_NAME)); | 91 ASSERT_FALSE(m.HasTag(DICOM_TAG_PATIENT_NAME)); |
92 ASSERT_FALSE(m.HasTag(0x0010, 0x0010)); | 92 ASSERT_FALSE(m.HasTag(0x0010, 0x0010)); |
93 m.SetValue(0x0010, 0x0010, "PatientName"); | 93 m.SetValue(0x0010, 0x0010, "PatientName", false); |
94 ASSERT_TRUE(m.HasTag(DICOM_TAG_PATIENT_NAME)); | 94 ASSERT_TRUE(m.HasTag(DICOM_TAG_PATIENT_NAME)); |
95 ASSERT_TRUE(m.HasTag(0x0010, 0x0010)); | 95 ASSERT_TRUE(m.HasTag(0x0010, 0x0010)); |
96 | 96 |
97 m.GetTags(s); | 97 m.GetTags(s); |
98 ASSERT_EQ(1u, s.size()); | 98 ASSERT_EQ(1u, s.size()); |
99 ASSERT_EQ(DICOM_TAG_PATIENT_NAME, *s.begin()); | 99 ASSERT_EQ(DICOM_TAG_PATIENT_NAME, *s.begin()); |
100 | 100 |
101 ASSERT_FALSE(m.HasTag(DICOM_TAG_PATIENT_ID)); | 101 ASSERT_FALSE(m.HasTag(DICOM_TAG_PATIENT_ID)); |
102 m.SetValue(DICOM_TAG_PATIENT_ID, "PatientID"); | 102 m.SetValue(DICOM_TAG_PATIENT_ID, "PatientID", false); |
103 ASSERT_TRUE(m.HasTag(0x0010, 0x0020)); | 103 ASSERT_TRUE(m.HasTag(0x0010, 0x0020)); |
104 m.SetValue(DICOM_TAG_PATIENT_ID, "PatientID2"); | 104 m.SetValue(DICOM_TAG_PATIENT_ID, "PatientID2", false); |
105 ASSERT_EQ("PatientID2", m.GetValue(0x0010, 0x0020).GetContent()); | 105 ASSERT_EQ("PatientID2", m.GetValue(0x0010, 0x0020).GetContent()); |
106 | 106 |
107 m.GetTags(s); | 107 m.GetTags(s); |
108 ASSERT_EQ(2u, s.size()); | 108 ASSERT_EQ(2u, s.size()); |
109 | 109 |
115 ASSERT_EQ(DICOM_TAG_PATIENT_NAME, *s.begin()); | 115 ASSERT_EQ(DICOM_TAG_PATIENT_NAME, *s.begin()); |
116 | 116 |
117 std::auto_ptr<DicomMap> mm(m.Clone()); | 117 std::auto_ptr<DicomMap> mm(m.Clone()); |
118 ASSERT_EQ("PatientName", mm->GetValue(DICOM_TAG_PATIENT_NAME).GetContent()); | 118 ASSERT_EQ("PatientName", mm->GetValue(DICOM_TAG_PATIENT_NAME).GetContent()); |
119 | 119 |
120 m.SetValue(DICOM_TAG_PATIENT_ID, "Hello"); | 120 m.SetValue(DICOM_TAG_PATIENT_ID, "Hello", false); |
121 ASSERT_THROW(mm->GetValue(DICOM_TAG_PATIENT_ID), OrthancException); | 121 ASSERT_THROW(mm->GetValue(DICOM_TAG_PATIENT_ID), OrthancException); |
122 mm->CopyTagIfExists(m, DICOM_TAG_PATIENT_ID); | 122 mm->CopyTagIfExists(m, DICOM_TAG_PATIENT_ID); |
123 ASSERT_EQ("Hello", mm->GetValue(DICOM_TAG_PATIENT_ID).GetContent()); | 123 ASSERT_EQ("Hello", mm->GetValue(DICOM_TAG_PATIENT_ID).GetContent()); |
124 | 124 |
125 DicomValue v; | 125 DicomValue v; |
149 | 149 |
150 | 150 |
151 static void TestModule(ResourceType level, | 151 static void TestModule(ResourceType level, |
152 DicomModule module) | 152 DicomModule module) |
153 { | 153 { |
154 // REFERENCE: DICOM PS3.3 2015c - Information Object Definitions | |
155 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html | |
156 | |
154 std::set<DicomTag> moduleTags, main; | 157 std::set<DicomTag> moduleTags, main; |
155 DicomTag::AddTagsForModule(moduleTags, module); | 158 DicomTag::AddTagsForModule(moduleTags, module); |
156 DicomMap::GetMainDicomTags(main, level); | 159 DicomMap::GetMainDicomTags(main, level); |
157 | 160 |
158 // The main dicom tags are a subset of the module | 161 // The main dicom tags are a subset of the module |
159 for (std::set<DicomTag>::const_iterator it = main.begin(); it != main.end(); ++it) | 162 for (std::set<DicomTag>::const_iterator it = main.begin(); it != main.end(); ++it) |
160 { | 163 { |
161 bool ok = moduleTags.find(*it) != moduleTags.end(); | 164 bool ok = moduleTags.find(*it) != moduleTags.end(); |
162 | 165 |
163 // Exceptions for the Series level | 166 // Exceptions for the Study level |
164 /*if ((// | 167 if (level == ResourceType_Study && |
165 *it == DicomTag(0x, 0x) && | 168 (*it == DicomTag(0x0008, 0x0080) || /* InstitutionName, from Visit identification module, related to Visit */ |
166 level == ResourceType_Series)) | 169 *it == DicomTag(0x0032, 0x1032) || /* RequestingPhysician, from Imaging Service Request module, related to Study */ |
167 { | 170 *it == DicomTag(0x0032, 0x1060))) /* RequestedProcedureDescription, from Requested Procedure module, related to Study */ |
168 ok = true; | |
169 }*/ | |
170 | |
171 // Exceptions for the Instance level | |
172 if (level == ResourceType_Instance && | |
173 (*it == DicomTag(0x0020, 0x0012) || /* Accession number, from Image module */ | |
174 *it == DicomTag(0x0054, 0x1330) || /* Image Index, from PET Image module */ | |
175 *it == DicomTag(0x0020, 0x0100) || /* Temporal Position Identifier, from MR Image module */ | |
176 *it == DicomTag(0x0028, 0x0008) || /* Number of Frames, from Multi-frame module attributes, related to Image IOD */ | |
177 *it == DICOM_TAG_IMAGE_POSITION_PATIENT)) | |
178 { | 171 { |
179 ok = true; | 172 ok = true; |
180 } | 173 } |
181 | 174 |
175 // Exceptions for the Series level | |
176 if (level == ResourceType_Series && | |
177 (*it == DicomTag(0x0008, 0x0070) || /* Manufacturer, from General Equipment Module */ | |
178 *it == DicomTag(0x0008, 0x1010) || /* StationName, from General Equipment Module */ | |
179 *it == DicomTag(0x0018, 0x0024) || /* SequenceName, from MR Image Module (SIMPLIFICATION => Series) */ | |
180 *it == DicomTag(0x0018, 0x1090) || /* CardiacNumberOfImages, from MR Image Module (SIMPLIFICATION => Series) */ | |
181 *it == DicomTag(0x0020, 0x0037) || /* ImageOrientationPatient, from Image Plane Module (SIMPLIFICATION => Series) */ | |
182 *it == DicomTag(0x0020, 0x0105) || /* NumberOfTemporalPositions, from MR Image Module (SIMPLIFICATION => Series) */ | |
183 *it == DicomTag(0x0020, 0x1002) || /* ImagesInAcquisition, from General Image Module (SIMPLIFICATION => Series) */ | |
184 *it == DicomTag(0x0054, 0x0081) || /* NumberOfSlices, from PET Series module */ | |
185 *it == DicomTag(0x0054, 0x0101) || /* NumberOfTimeSlices, from PET Series module */ | |
186 *it == DicomTag(0x0054, 0x1000) || /* SeriesType, from PET Series module */ | |
187 *it == DicomTag(0x0018, 0x1400) || /* AcquisitionDeviceProcessingDescription, from CR/X-Ray/DX/WholeSlideMicro Image (SIMPLIFICATION => Series) */ | |
188 *it == DicomTag(0x0018, 0x0010))) /* ContrastBolusAgent, from Contrast/Bolus module (SIMPLIFICATION => Series) */ | |
189 { | |
190 ok = true; | |
191 } | |
192 | |
193 // Exceptions for the Instance level | |
194 if (level == ResourceType_Instance && | |
195 (*it == DicomTag(0x0020, 0x0012) || /* AccessionNumber, from General Image module */ | |
196 *it == DicomTag(0x0054, 0x1330) || /* ImageIndex, from PET Image module */ | |
197 *it == DicomTag(0x0020, 0x0100) || /* TemporalPositionIdentifier, from MR Image module */ | |
198 *it == DicomTag(0x0028, 0x0008) || /* NumberOfFrames, from Multi-frame module attributes, related to Image */ | |
199 *it == DicomTag(0x0020, 0x0032) || /* ImagePositionPatient, from Image Plan module, related to Image */ | |
200 *it == DicomTag(0x0020, 0x0037) || /* ImageOrientationPatient, from Image Plane Module (Orthanc 1.4.2) */ | |
201 *it == DicomTag(0x0020, 0x4000))) /* ImageComments, from General Image module */ | |
202 { | |
203 ok = true; | |
204 } | |
205 | |
182 if (!ok) | 206 if (!ok) |
183 { | 207 { |
184 std::cout << it->Format() << ": " << FromDcmtkBridge::GetName(*it) | 208 std::cout << it->Format() << ": " << FromDcmtkBridge::GetTagName(*it, "") |
185 << " not expected at level " << EnumerationToString(level) << std::endl; | 209 << " not expected at level " << EnumerationToString(level) << std::endl; |
186 } | 210 } |
187 | 211 |
188 EXPECT_TRUE(ok); | 212 EXPECT_TRUE(ok); |
189 } | 213 } |
192 | 216 |
193 TEST(DicomMap, Modules) | 217 TEST(DicomMap, Modules) |
194 { | 218 { |
195 TestModule(ResourceType_Patient, DicomModule_Patient); | 219 TestModule(ResourceType_Patient, DicomModule_Patient); |
196 TestModule(ResourceType_Study, DicomModule_Study); | 220 TestModule(ResourceType_Study, DicomModule_Study); |
197 //TestModule(ResourceType_Series, DicomModule_Series); // TODO | 221 TestModule(ResourceType_Series, DicomModule_Series); // TODO |
198 TestModule(ResourceType_Instance, DicomModule_Instance); | 222 TestModule(ResourceType_Instance, DicomModule_Instance); |
199 } | 223 } |
224 | |
225 | |
226 TEST(DicomMap, Parse) | |
227 { | |
228 DicomMap m; | |
229 float f; | |
230 double d; | |
231 int32_t i; | |
232 int64_t j; | |
233 uint32_t k; | |
234 uint64_t l; | |
235 std::string s; | |
236 | |
237 m.SetValue(DICOM_TAG_PATIENT_NAME, " ", false); // Empty value | |
238 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseFloat(f)); | |
239 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseDouble(d)); | |
240 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger32(i)); | |
241 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger64(j)); | |
242 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger32(k)); | |
243 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger64(l)); | |
244 | |
245 m.SetValue(DICOM_TAG_PATIENT_NAME, "0", true); // Binary value | |
246 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseFloat(f)); | |
247 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseDouble(d)); | |
248 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger32(i)); | |
249 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger64(j)); | |
250 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger32(k)); | |
251 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger64(l)); | |
252 | |
253 ASSERT_FALSE(m.CopyToString(s, DICOM_TAG_PATIENT_NAME, false)); | |
254 ASSERT_TRUE(m.CopyToString(s, DICOM_TAG_PATIENT_NAME, true)); | |
255 ASSERT_EQ("0", s); | |
256 | |
257 | |
258 // 2**31-1 | |
259 m.SetValue(DICOM_TAG_PATIENT_NAME, "2147483647", false); | |
260 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseFloat(f)); | |
261 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseDouble(d)); | |
262 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger32(i)); | |
263 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger64(j)); | |
264 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger32(k)); | |
265 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger64(l)); | |
266 ASSERT_FLOAT_EQ(2147483647.0f, f); | |
267 ASSERT_DOUBLE_EQ(2147483647.0, d); | |
268 ASSERT_EQ(2147483647, i); | |
269 ASSERT_EQ(2147483647ll, j); | |
270 ASSERT_EQ(2147483647u, k); | |
271 ASSERT_EQ(2147483647ull, l); | |
272 | |
273 // Test shortcuts | |
274 m.SetValue(DICOM_TAG_PATIENT_NAME, "42", false); | |
275 ASSERT_TRUE(m.ParseFloat(f, DICOM_TAG_PATIENT_NAME)); | |
276 ASSERT_TRUE(m.ParseDouble(d, DICOM_TAG_PATIENT_NAME)); | |
277 ASSERT_TRUE(m.ParseInteger32(i, DICOM_TAG_PATIENT_NAME)); | |
278 ASSERT_TRUE(m.ParseInteger64(j, DICOM_TAG_PATIENT_NAME)); | |
279 ASSERT_TRUE(m.ParseUnsignedInteger32(k, DICOM_TAG_PATIENT_NAME)); | |
280 ASSERT_TRUE(m.ParseUnsignedInteger64(l, DICOM_TAG_PATIENT_NAME)); | |
281 ASSERT_FLOAT_EQ(42.0f, f); | |
282 ASSERT_DOUBLE_EQ(42.0, d); | |
283 ASSERT_EQ(42, i); | |
284 ASSERT_EQ(42ll, j); | |
285 ASSERT_EQ(42u, k); | |
286 ASSERT_EQ(42ull, l); | |
287 | |
288 ASSERT_TRUE(m.CopyToString(s, DICOM_TAG_PATIENT_NAME, false)); | |
289 ASSERT_EQ("42", s); | |
290 ASSERT_TRUE(m.CopyToString(s, DICOM_TAG_PATIENT_NAME, true)); | |
291 ASSERT_EQ("42", s); | |
292 | |
293 | |
294 // 2**31 | |
295 m.SetValue(DICOM_TAG_PATIENT_NAME, "2147483648", false); | |
296 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseFloat(f)); | |
297 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseDouble(d)); | |
298 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger32(i)); | |
299 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger64(j)); | |
300 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger32(k)); | |
301 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger64(l)); | |
302 ASSERT_FLOAT_EQ(2147483648.0f, f); | |
303 ASSERT_DOUBLE_EQ(2147483648.0, d); | |
304 ASSERT_EQ(2147483648ll, j); | |
305 ASSERT_EQ(2147483648u, k); | |
306 ASSERT_EQ(2147483648ull, l); | |
307 | |
308 // 2**32-1 | |
309 m.SetValue(DICOM_TAG_PATIENT_NAME, "4294967295", false); | |
310 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseFloat(f)); | |
311 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseDouble(d)); | |
312 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger32(i)); | |
313 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger64(j)); | |
314 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger32(k)); | |
315 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger64(l)); | |
316 ASSERT_FLOAT_EQ(4294967295.0f, f); | |
317 ASSERT_DOUBLE_EQ(4294967295.0, d); | |
318 ASSERT_EQ(4294967295ll, j); | |
319 ASSERT_EQ(4294967295u, k); | |
320 ASSERT_EQ(4294967295ull, l); | |
321 | |
322 // 2**32 | |
323 m.SetValue(DICOM_TAG_PATIENT_NAME, "4294967296", false); | |
324 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseFloat(f)); | |
325 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseDouble(d)); | |
326 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger32(i)); | |
327 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger64(j)); | |
328 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger32(k)); | |
329 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger64(l)); | |
330 ASSERT_FLOAT_EQ(4294967296.0f, f); | |
331 ASSERT_DOUBLE_EQ(4294967296.0, d); | |
332 ASSERT_EQ(4294967296ll, j); | |
333 ASSERT_EQ(4294967296ull, l); | |
334 | |
335 m.SetValue(DICOM_TAG_PATIENT_NAME, "-1", false); | |
336 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseFloat(f)); | |
337 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseDouble(d)); | |
338 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger32(i)); | |
339 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger64(j)); | |
340 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger32(k)); | |
341 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger64(l)); | |
342 ASSERT_FLOAT_EQ(-1.0f, f); | |
343 ASSERT_DOUBLE_EQ(-1.0, d); | |
344 ASSERT_EQ(-1, i); | |
345 ASSERT_EQ(-1ll, j); | |
346 | |
347 // -2**31 | |
348 m.SetValue(DICOM_TAG_PATIENT_NAME, "-2147483648", false); | |
349 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseFloat(f)); | |
350 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseDouble(d)); | |
351 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger32(i)); | |
352 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger64(j)); | |
353 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger32(k)); | |
354 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger64(l)); | |
355 ASSERT_FLOAT_EQ(-2147483648.0f, f); | |
356 ASSERT_DOUBLE_EQ(-2147483648.0, d); | |
357 ASSERT_EQ(static_cast<int32_t>(-2147483648ll), i); | |
358 ASSERT_EQ(-2147483648ll, j); | |
359 | |
360 // -2**31 - 1 | |
361 m.SetValue(DICOM_TAG_PATIENT_NAME, "-2147483649", false); | |
362 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseFloat(f)); | |
363 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseDouble(d)); | |
364 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger32(i)); | |
365 ASSERT_TRUE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseInteger64(j)); | |
366 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger32(k)); | |
367 ASSERT_FALSE(m.GetValue(DICOM_TAG_PATIENT_NAME).ParseUnsignedInteger64(l)); | |
368 ASSERT_FLOAT_EQ(-2147483649.0f, f); | |
369 ASSERT_DOUBLE_EQ(-2147483649.0, d); | |
370 ASSERT_EQ(-2147483649ll, j); | |
371 } | |
372 | |
373 | |
374 TEST(DicomMap, Serialize) | |
375 { | |
376 Json::Value s; | |
377 | |
378 { | |
379 DicomMap m; | |
380 m.SetValue(DICOM_TAG_PATIENT_NAME, "Hello", false); | |
381 m.SetValue(DICOM_TAG_STUDY_DESCRIPTION, "Binary", true); | |
382 m.SetNullValue(DICOM_TAG_SERIES_DESCRIPTION); | |
383 m.Serialize(s); | |
384 } | |
385 | |
386 { | |
387 DicomMap m; | |
388 m.Unserialize(s); | |
389 | |
390 const DicomValue* v = m.TestAndGetValue(DICOM_TAG_ACCESSION_NUMBER); | |
391 ASSERT_TRUE(v == NULL); | |
392 | |
393 v = m.TestAndGetValue(DICOM_TAG_PATIENT_NAME); | |
394 ASSERT_TRUE(v != NULL); | |
395 ASSERT_FALSE(v->IsNull()); | |
396 ASSERT_FALSE(v->IsBinary()); | |
397 ASSERT_EQ("Hello", v->GetContent()); | |
398 | |
399 v = m.TestAndGetValue(DICOM_TAG_STUDY_DESCRIPTION); | |
400 ASSERT_TRUE(v != NULL); | |
401 ASSERT_FALSE(v->IsNull()); | |
402 ASSERT_TRUE(v->IsBinary()); | |
403 ASSERT_EQ("Binary", v->GetContent()); | |
404 | |
405 v = m.TestAndGetValue(DICOM_TAG_SERIES_DESCRIPTION); | |
406 ASSERT_TRUE(v != NULL); | |
407 ASSERT_TRUE(v->IsNull()); | |
408 ASSERT_FALSE(v->IsBinary()); | |
409 ASSERT_THROW(v->GetContent(), OrthancException); | |
410 } | |
411 } |