Mercurial > hg > orthanc
annotate UnitTestsSources/DicomMap.cpp @ 906:cbc0ea03dffe plugins
sample plugin configuration
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 19 Jun 2014 13:37:49 +0200 |
parents | 84513f2ee1f3 |
children | 81134ea872ff |
rev | line source |
---|---|
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
1 /** |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
4 * Belgium |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
5 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
6 * This program is free software: you can redistribute it and/or |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
7 * modify it under the terms of the GNU General Public License as |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
8 * published by the Free Software Foundation, either version 3 of the |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
9 * License, or (at your option) any later version. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
10 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
11 * In addition, as a special exception, the copyright holders of this |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
12 * program give permission to link the code of its release with the |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
14 * that use the same license as the "OpenSSL" library), and distribute |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
15 * the linked executables. You must obey the GNU General Public License |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
16 * in all respects for all of the code used other than "OpenSSL". If you |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
17 * modify file(s) with this exception, you may extend this exception to |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
18 * your version of the file(s), but you are not obligated to do so. If |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
19 * you do not wish to do so, delete this exception statement from your |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
20 * version. If you delete this exception statement from all source files |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
21 * in the program, then also delete it here. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
22 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
23 * This program is distributed in the hope that it will be useful, but |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
24 * WITHOUT ANY WARRANTY; without even the implied warranty of |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
26 * General Public License for more details. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
27 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
28 * You should have received a copy of the GNU General Public License |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
30 **/ |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
31 |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
32 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
827
diff
changeset
|
33 #include "PrecompiledHeadersUnitTests.h" |
711 | 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 | |
41 #include <memory> | |
42 | |
43 using namespace Orthanc; | |
44 | |
45 TEST(DicomMap, MainTags) | |
46 { | |
47 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_PATIENT_ID)); | |
48 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_PATIENT_ID, ResourceType_Patient)); | |
49 ASSERT_FALSE(DicomMap::IsMainDicomTag(DICOM_TAG_PATIENT_ID, ResourceType_Study)); | |
50 | |
51 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_STUDY_INSTANCE_UID)); | |
52 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_ACCESSION_NUMBER)); | |
53 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_SERIES_INSTANCE_UID)); | |
54 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_SOP_INSTANCE_UID)); | |
55 | |
56 std::set<DicomTag> s; | |
57 DicomMap::GetMainDicomTags(s); | |
58 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_PATIENT_ID)); | |
59 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_STUDY_INSTANCE_UID)); | |
60 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_ACCESSION_NUMBER)); | |
61 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_SERIES_INSTANCE_UID)); | |
62 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_SOP_INSTANCE_UID)); | |
63 | |
64 DicomMap::GetMainDicomTags(s, ResourceType_Patient); | |
65 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_PATIENT_ID)); | |
66 ASSERT_TRUE(s.end() == s.find(DICOM_TAG_STUDY_INSTANCE_UID)); | |
67 | |
68 DicomMap::GetMainDicomTags(s, ResourceType_Study); | |
69 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_STUDY_INSTANCE_UID)); | |
70 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_ACCESSION_NUMBER)); | |
71 ASSERT_TRUE(s.end() == s.find(DICOM_TAG_PATIENT_ID)); | |
72 | |
73 DicomMap::GetMainDicomTags(s, ResourceType_Series); | |
74 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_SERIES_INSTANCE_UID)); | |
75 ASSERT_TRUE(s.end() == s.find(DICOM_TAG_PATIENT_ID)); | |
76 | |
77 DicomMap::GetMainDicomTags(s, ResourceType_Instance); | |
78 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_SOP_INSTANCE_UID)); | |
79 ASSERT_TRUE(s.end() == s.find(DICOM_TAG_PATIENT_ID)); | |
80 } | |
81 | |
82 | |
83 TEST(DicomMap, Tags) | |
84 { | |
85 DicomMap m; | |
86 ASSERT_FALSE(m.HasTag(DICOM_TAG_PATIENT_NAME)); | |
87 ASSERT_FALSE(m.HasTag(0x0010, 0x0010)); | |
88 m.SetValue(0x0010, 0x0010, "PatientName"); | |
89 ASSERT_TRUE(m.HasTag(DICOM_TAG_PATIENT_NAME)); | |
90 ASSERT_TRUE(m.HasTag(0x0010, 0x0010)); | |
91 | |
92 ASSERT_FALSE(m.HasTag(DICOM_TAG_PATIENT_ID)); | |
93 m.SetValue(DICOM_TAG_PATIENT_ID, "PatientID"); | |
94 ASSERT_TRUE(m.HasTag(0x0010, 0x0020)); | |
95 m.SetValue(DICOM_TAG_PATIENT_ID, "PatientID2"); | |
96 ASSERT_EQ("PatientID2", m.GetValue(0x0010, 0x0020).AsString()); | |
97 | |
98 m.Remove(DICOM_TAG_PATIENT_ID); | |
99 ASSERT_THROW(m.GetValue(0x0010, 0x0020), OrthancException); | |
100 | |
101 std::auto_ptr<DicomMap> mm(m.Clone()); | |
102 ASSERT_EQ("PatientName", mm->GetValue(DICOM_TAG_PATIENT_NAME).AsString()); | |
103 | |
104 m.SetValue(DICOM_TAG_PATIENT_ID, "Hello"); | |
105 ASSERT_THROW(mm->GetValue(DICOM_TAG_PATIENT_ID), OrthancException); | |
106 mm->CopyTagIfExists(m, DICOM_TAG_PATIENT_ID); | |
107 ASSERT_EQ("Hello", mm->GetValue(DICOM_TAG_PATIENT_ID).AsString()); | |
108 | |
109 DicomNullValue v; | |
110 ASSERT_TRUE(v.IsNull()); | |
111 } | |
112 | |
113 | |
114 TEST(DicomMap, FindTemplates) | |
115 { | |
116 DicomMap m; | |
117 | |
118 DicomMap::SetupFindPatientTemplate(m); | |
119 ASSERT_TRUE(m.HasTag(DICOM_TAG_PATIENT_ID)); | |
120 | |
121 DicomMap::SetupFindStudyTemplate(m); | |
122 ASSERT_TRUE(m.HasTag(DICOM_TAG_STUDY_INSTANCE_UID)); | |
123 ASSERT_TRUE(m.HasTag(DICOM_TAG_ACCESSION_NUMBER)); | |
124 | |
125 DicomMap::SetupFindSeriesTemplate(m); | |
126 ASSERT_TRUE(m.HasTag(DICOM_TAG_SERIES_INSTANCE_UID)); | |
127 | |
128 DicomMap::SetupFindInstanceTemplate(m); | |
129 ASSERT_TRUE(m.HasTag(DICOM_TAG_SOP_INSTANCE_UID)); | |
130 } |