Mercurial > hg > orthanc
annotate UnitTestsSources/ServerIndex.cpp @ 693:01d8611c4a60
md5 for attached files
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 04 Feb 2014 17:52:51 +0100 |
parents | 17815b9d4280 |
children | 4c1860179cc5 |
rev | line source |
---|---|
181 | 1 #include "gtest/gtest.h" |
2 | |
183 | 3 #include "../OrthancServer/DatabaseWrapper.h" |
273
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
4 #include "../Core/Uuid.h" |
183 | 5 |
181 | 6 #include <ctype.h> |
7 #include <glog/logging.h> | |
521 | 8 #include <algorithm> |
181 | 9 |
183 | 10 using namespace Orthanc; |
181 | 11 |
183 | 12 namespace |
13 { | |
181 | 14 class ServerIndexListener : public IServerIndexListener |
15 { | |
16 public: | |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
17 std::vector<std::string> deletedFiles_; |
183 | 18 std::string ancestorId_; |
19 ResourceType ancestorType_; | |
20 | |
21 void Reset() | |
181 | 22 { |
183 | 23 ancestorId_ = ""; |
24 deletedFiles_.clear(); | |
25 } | |
26 | |
27 virtual void SignalRemainingAncestor(ResourceType type, | |
28 const std::string& publicId) | |
29 { | |
30 ancestorId_ = publicId; | |
31 ancestorType_ = type; | |
181 | 32 } |
33 | |
273
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
34 virtual void SignalFileDeleted(const FileInfo& info) |
181 | 35 { |
273
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
36 const std::string fileUuid = info.GetUuid(); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
37 deletedFiles_.push_back(fileUuid); |
181 | 38 LOG(INFO) << "A file must be removed: " << fileUuid; |
39 } | |
40 }; | |
41 } | |
42 | |
43 | |
183 | 44 TEST(DatabaseWrapper, Simple) |
181 | 45 { |
46 ServerIndexListener listener; | |
183 | 47 DatabaseWrapper index(listener); |
181 | 48 |
49 int64_t a[] = { | |
182 | 50 index.CreateResource("a", ResourceType_Patient), // 0 |
51 index.CreateResource("b", ResourceType_Study), // 1 | |
52 index.CreateResource("c", ResourceType_Series), // 2 | |
53 index.CreateResource("d", ResourceType_Instance), // 3 | |
54 index.CreateResource("e", ResourceType_Instance), // 4 | |
55 index.CreateResource("f", ResourceType_Instance), // 5 | |
56 index.CreateResource("g", ResourceType_Study) // 6 | |
181 | 57 }; |
58 | |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
59 ASSERT_EQ("a", index.GetPublicId(a[0])); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
60 ASSERT_EQ("b", index.GetPublicId(a[1])); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
61 ASSERT_EQ("c", index.GetPublicId(a[2])); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
62 ASSERT_EQ("d", index.GetPublicId(a[3])); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
63 ASSERT_EQ("e", index.GetPublicId(a[4])); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
64 ASSERT_EQ("f", index.GetPublicId(a[5])); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
65 ASSERT_EQ("g", index.GetPublicId(a[6])); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
66 |
304 | 67 ASSERT_EQ(ResourceType_Patient, index.GetResourceType(a[0])); |
68 ASSERT_EQ(ResourceType_Study, index.GetResourceType(a[1])); | |
69 ASSERT_EQ(ResourceType_Series, index.GetResourceType(a[2])); | |
70 ASSERT_EQ(ResourceType_Instance, index.GetResourceType(a[3])); | |
71 ASSERT_EQ(ResourceType_Instance, index.GetResourceType(a[4])); | |
72 ASSERT_EQ(ResourceType_Instance, index.GetResourceType(a[5])); | |
73 ASSERT_EQ(ResourceType_Study, index.GetResourceType(a[6])); | |
74 | |
190 | 75 { |
76 Json::Value t; | |
77 index.GetAllPublicIds(t, ResourceType_Patient); | |
78 | |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
79 ASSERT_EQ(1u, t.size()); |
190 | 80 ASSERT_EQ("a", t[0u].asString()); |
81 | |
82 index.GetAllPublicIds(t, ResourceType_Series); | |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
83 ASSERT_EQ(1u, t.size()); |
190 | 84 ASSERT_EQ("c", t[0u].asString()); |
85 | |
86 index.GetAllPublicIds(t, ResourceType_Study); | |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
87 ASSERT_EQ(2u, t.size()); |
190 | 88 |
89 index.GetAllPublicIds(t, ResourceType_Instance); | |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
90 ASSERT_EQ(3u, t.size()); |
190 | 91 } |
92 | |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
198
diff
changeset
|
93 index.SetGlobalProperty(GlobalProperty_FlushSleep, "World"); |
181 | 94 |
95 index.AttachChild(a[0], a[1]); | |
96 index.AttachChild(a[1], a[2]); | |
97 index.AttachChild(a[2], a[3]); | |
98 index.AttachChild(a[2], a[4]); | |
99 index.AttachChild(a[6], a[5]); | |
182 | 100 |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
101 int64_t parent; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
102 ASSERT_FALSE(index.LookupParent(parent, a[0])); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
103 ASSERT_TRUE(index.LookupParent(parent, a[1])); ASSERT_EQ(a[0], parent); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
104 ASSERT_TRUE(index.LookupParent(parent, a[2])); ASSERT_EQ(a[1], parent); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
105 ASSERT_TRUE(index.LookupParent(parent, a[3])); ASSERT_EQ(a[2], parent); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
106 ASSERT_TRUE(index.LookupParent(parent, a[4])); ASSERT_EQ(a[2], parent); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
107 ASSERT_TRUE(index.LookupParent(parent, a[5])); ASSERT_EQ(a[6], parent); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
108 ASSERT_FALSE(index.LookupParent(parent, a[6])); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
109 |
182 | 110 std::string s; |
111 | |
112 ASSERT_FALSE(index.GetParentPublicId(s, a[0])); | |
113 ASSERT_FALSE(index.GetParentPublicId(s, a[6])); | |
114 ASSERT_TRUE(index.GetParentPublicId(s, a[1])); ASSERT_EQ("a", s); | |
115 ASSERT_TRUE(index.GetParentPublicId(s, a[2])); ASSERT_EQ("b", s); | |
116 ASSERT_TRUE(index.GetParentPublicId(s, a[3])); ASSERT_EQ("c", s); | |
117 ASSERT_TRUE(index.GetParentPublicId(s, a[4])); ASSERT_EQ("c", s); | |
118 ASSERT_TRUE(index.GetParentPublicId(s, a[5])); ASSERT_EQ("g", s); | |
119 | |
185 | 120 std::list<std::string> l; |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
121 index.GetChildrenPublicId(l, a[0]); ASSERT_EQ(1u, l.size()); ASSERT_EQ("b", l.front()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
122 index.GetChildrenPublicId(l, a[1]); ASSERT_EQ(1u, l.size()); ASSERT_EQ("c", l.front()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
123 index.GetChildrenPublicId(l, a[3]); ASSERT_EQ(0u, l.size()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
124 index.GetChildrenPublicId(l, a[4]); ASSERT_EQ(0u, l.size()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
125 index.GetChildrenPublicId(l, a[5]); ASSERT_EQ(0u, l.size()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
126 index.GetChildrenPublicId(l, a[6]); ASSERT_EQ(1u, l.size()); ASSERT_EQ("f", l.front()); |
182 | 127 |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
128 index.GetChildrenPublicId(l, a[2]); ASSERT_EQ(2u, l.size()); |
182 | 129 if (l.front() == "d") |
130 { | |
131 ASSERT_EQ("e", l.back()); | |
132 } | |
133 else | |
134 { | |
135 ASSERT_EQ("d", l.back()); | |
136 ASSERT_EQ("e", l.front()); | |
137 } | |
138 | |
436
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
310
diff
changeset
|
139 std::list<MetadataType> md; |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
310
diff
changeset
|
140 index.ListAvailableMetadata(md, a[4]); |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
310
diff
changeset
|
141 ASSERT_EQ(0u, md.size()); |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
310
diff
changeset
|
142 |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
143 index.AddAttachment(a[4], FileInfo("my json file", FileContentType_Json, 42, "md5", |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
144 CompressionType_Zlib, 21, "compressedMD5")); |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
145 index.AddAttachment(a[4], FileInfo("my dicom file", FileContentType_Dicom, 42, "md5")); |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
146 index.AddAttachment(a[6], FileInfo("world", FileContentType_Dicom, 44, "md5")); |
183 | 147 index.SetMetadata(a[4], MetadataType_Instance_RemoteAet, "PINNACLE"); |
436
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
310
diff
changeset
|
148 |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
310
diff
changeset
|
149 index.ListAvailableMetadata(md, a[4]); |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
310
diff
changeset
|
150 ASSERT_EQ(1u, md.size()); |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
310
diff
changeset
|
151 ASSERT_EQ(MetadataType_Instance_RemoteAet, md.front()); |
438 | 152 index.SetMetadata(a[4], MetadataType_ModifiedFrom, "TUTU"); |
153 index.ListAvailableMetadata(md, a[4]); | |
154 ASSERT_EQ(2u, md.size()); | |
155 index.DeleteMetadata(a[4], MetadataType_ModifiedFrom); | |
156 index.ListAvailableMetadata(md, a[4]); | |
157 ASSERT_EQ(1u, md.size()); | |
158 ASSERT_EQ(MetadataType_Instance_RemoteAet, md.front()); | |
182 | 159 |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
160 ASSERT_EQ(21u + 42u + 44u, index.GetTotalCompressedSize()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
161 ASSERT_EQ(42u + 42u + 44u, index.GetTotalUncompressedSize()); |
181 | 162 |
163 DicomMap m; | |
164 m.SetValue(0x0010, 0x0010, "PatientName"); | |
165 index.SetMainDicomTags(a[3], m); | |
166 | |
167 int64_t b; | |
168 ResourceType t; | |
188
090cefdab1d1
fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
185
diff
changeset
|
169 ASSERT_TRUE(index.LookupResource("g", b, t)); |
181 | 170 ASSERT_EQ(7, b); |
171 ASSERT_EQ(ResourceType_Study, t); | |
172 | |
188
090cefdab1d1
fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
185
diff
changeset
|
173 ASSERT_TRUE(index.LookupMetadata(s, a[4], MetadataType_Instance_RemoteAet)); |
090cefdab1d1
fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
185
diff
changeset
|
174 ASSERT_FALSE(index.LookupMetadata(s, a[4], MetadataType_Instance_IndexInSeries)); |
181 | 175 ASSERT_EQ("PINNACLE", s); |
176 ASSERT_EQ("PINNACLE", index.GetMetadata(a[4], MetadataType_Instance_RemoteAet)); | |
177 ASSERT_EQ("None", index.GetMetadata(a[4], MetadataType_Instance_IndexInSeries, "None")); | |
178 | |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
198
diff
changeset
|
179 ASSERT_TRUE(index.LookupGlobalProperty(s, GlobalProperty_FlushSleep)); |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
198
diff
changeset
|
180 ASSERT_FALSE(index.LookupGlobalProperty(s, static_cast<GlobalProperty>(42))); |
181 | 181 ASSERT_EQ("World", s); |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
198
diff
changeset
|
182 ASSERT_EQ("World", index.GetGlobalProperty(GlobalProperty_FlushSleep)); |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
198
diff
changeset
|
183 ASSERT_EQ("None", index.GetGlobalProperty(static_cast<GlobalProperty>(42), "None")); |
181 | 184 |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
185 FileInfo att; |
233 | 186 ASSERT_TRUE(index.LookupAttachment(att, a[4], FileContentType_Json)); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
187 ASSERT_EQ("my json file", att.GetUuid()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
188 ASSERT_EQ(21u, att.GetCompressedSize()); |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
189 ASSERT_EQ("md5", att.GetUncompressedMD5()); |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
190 ASSERT_EQ("compressedMD5", att.GetCompressedMD5()); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
191 ASSERT_EQ(42u, att.GetUncompressedSize()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
192 ASSERT_EQ(CompressionType_Zlib, att.GetCompressionType()); |
181 | 193 |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
194 ASSERT_TRUE(index.LookupAttachment(att, a[6], FileContentType_Dicom)); |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
195 ASSERT_EQ("world", att.GetUuid()); |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
196 ASSERT_EQ(44u, att.GetCompressedSize()); |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
197 ASSERT_EQ("md5", att.GetUncompressedMD5()); |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
198 ASSERT_EQ("md5", att.GetCompressedMD5()); |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
199 ASSERT_EQ(44u, att.GetUncompressedSize()); |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
200 ASSERT_EQ(CompressionType_None, att.GetCompressionType()); |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
201 |
188
090cefdab1d1
fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
185
diff
changeset
|
202 ASSERT_EQ(0u, listener.deletedFiles_.size()); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
203 ASSERT_EQ(7u, index.GetTableRecordCount("Resources")); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
204 ASSERT_EQ(3u, index.GetTableRecordCount("AttachedFiles")); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
205 ASSERT_EQ(1u, index.GetTableRecordCount("Metadata")); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
206 ASSERT_EQ(1u, index.GetTableRecordCount("MainDicomTags")); |
181 | 207 index.DeleteResource(a[0]); |
183 | 208 |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
209 ASSERT_EQ(2u, listener.deletedFiles_.size()); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
210 ASSERT_FALSE(std::find(listener.deletedFiles_.begin(), |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
211 listener.deletedFiles_.end(), |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
212 "my json file") == listener.deletedFiles_.end()); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
213 ASSERT_FALSE(std::find(listener.deletedFiles_.begin(), |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
214 listener.deletedFiles_.end(), |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
215 "my dicom file") == listener.deletedFiles_.end()); |
183 | 216 |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
217 ASSERT_EQ(2u, index.GetTableRecordCount("Resources")); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
218 ASSERT_EQ(0u, index.GetTableRecordCount("Metadata")); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
219 ASSERT_EQ(1u, index.GetTableRecordCount("AttachedFiles")); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
220 ASSERT_EQ(0u, index.GetTableRecordCount("MainDicomTags")); |
183 | 221 index.DeleteResource(a[5]); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
222 ASSERT_EQ(0u, index.GetTableRecordCount("Resources")); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
223 ASSERT_EQ(0u, index.GetTableRecordCount("AttachedFiles")); |
252 | 224 ASSERT_EQ(2u, index.GetTableRecordCount("GlobalProperties")); |
183 | 225 |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
226 ASSERT_EQ(3u, listener.deletedFiles_.size()); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
227 ASSERT_FALSE(std::find(listener.deletedFiles_.begin(), |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
228 listener.deletedFiles_.end(), |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
229 "world") == listener.deletedFiles_.end()); |
183 | 230 } |
231 | |
232 | |
233 | |
234 | |
235 TEST(DatabaseWrapper, Upward) | |
236 { | |
237 ServerIndexListener listener; | |
238 DatabaseWrapper index(listener); | |
239 | |
240 int64_t a[] = { | |
241 index.CreateResource("a", ResourceType_Patient), // 0 | |
242 index.CreateResource("b", ResourceType_Study), // 1 | |
243 index.CreateResource("c", ResourceType_Series), // 2 | |
244 index.CreateResource("d", ResourceType_Instance), // 3 | |
245 index.CreateResource("e", ResourceType_Instance), // 4 | |
246 index.CreateResource("f", ResourceType_Study), // 5 | |
247 index.CreateResource("g", ResourceType_Series), // 6 | |
248 index.CreateResource("h", ResourceType_Series) // 7 | |
249 }; | |
250 | |
251 index.AttachChild(a[0], a[1]); | |
252 index.AttachChild(a[1], a[2]); | |
253 index.AttachChild(a[2], a[3]); | |
254 index.AttachChild(a[2], a[4]); | |
255 index.AttachChild(a[1], a[6]); | |
256 index.AttachChild(a[0], a[5]); | |
257 index.AttachChild(a[5], a[7]); | |
258 | |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
259 { |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
260 Json::Value j; |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
261 index.GetChildren(j, a[0]); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
262 ASSERT_EQ(2u, j.size()); |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
263 ASSERT_TRUE((j[0u] == "b" && j[1u] == "f") || |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
264 (j[1u] == "b" && j[0u] == "f")); |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
265 |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
266 index.GetChildren(j, a[1]); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
267 ASSERT_EQ(2u, j.size()); |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
268 ASSERT_TRUE((j[0u] == "c" && j[1u] == "g") || |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
269 (j[1u] == "c" && j[0u] == "g")); |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
270 |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
271 index.GetChildren(j, a[2]); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
272 ASSERT_EQ(2u, j.size()); |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
273 ASSERT_TRUE((j[0u] == "d" && j[1u] == "e") || |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
274 (j[1u] == "d" && j[0u] == "e")); |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
275 |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
276 index.GetChildren(j, a[3]); ASSERT_EQ(0u, j.size()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
277 index.GetChildren(j, a[4]); ASSERT_EQ(0u, j.size()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
278 index.GetChildren(j, a[5]); ASSERT_EQ(1u, j.size()); ASSERT_EQ("h", j[0u].asString()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
279 index.GetChildren(j, a[6]); ASSERT_EQ(0u, j.size()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
280 index.GetChildren(j, a[7]); ASSERT_EQ(0u, j.size()); |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
281 } |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
282 |
183 | 283 listener.Reset(); |
284 index.DeleteResource(a[3]); | |
285 ASSERT_EQ("c", listener.ancestorId_); | |
286 ASSERT_EQ(ResourceType_Series, listener.ancestorType_); | |
287 | |
288 listener.Reset(); | |
289 index.DeleteResource(a[4]); | |
290 ASSERT_EQ("b", listener.ancestorId_); | |
291 ASSERT_EQ(ResourceType_Study, listener.ancestorType_); | |
292 | |
293 listener.Reset(); | |
294 index.DeleteResource(a[7]); | |
295 ASSERT_EQ("a", listener.ancestorId_); | |
296 ASSERT_EQ(ResourceType_Patient, listener.ancestorType_); | |
297 | |
298 listener.Reset(); | |
181 | 299 index.DeleteResource(a[6]); |
183 | 300 ASSERT_EQ("", listener.ancestorId_); // No more ancestor |
181 | 301 } |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
302 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
303 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
304 TEST(DatabaseWrapper, PatientRecycling) |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
305 { |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
306 ServerIndexListener listener; |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
307 DatabaseWrapper index(listener); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
308 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
309 std::vector<int64_t> patients; |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
310 for (int i = 0; i < 10; i++) |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
311 { |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
312 std::string p = "Patient " + boost::lexical_cast<std::string>(i); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
313 patients.push_back(index.CreateResource(p, ResourceType_Patient)); |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
314 index.AddAttachment(patients[i], FileInfo(p, FileContentType_Dicom, i + 10, |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
315 "md5-" + boost::lexical_cast<std::string>(i))); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
316 ASSERT_FALSE(index.IsProtectedPatient(patients[i])); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
317 } |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
318 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
319 ASSERT_EQ(10u, index.GetTableRecordCount("Resources")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
320 ASSERT_EQ(10u, index.GetTableRecordCount("PatientRecyclingOrder")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
321 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
322 listener.Reset(); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
323 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
324 index.DeleteResource(patients[5]); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
325 index.DeleteResource(patients[0]); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
326 ASSERT_EQ(8u, index.GetTableRecordCount("Resources")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
327 ASSERT_EQ(8u, index.GetTableRecordCount("PatientRecyclingOrder")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
328 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
329 ASSERT_EQ(2u, listener.deletedFiles_.size()); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
330 ASSERT_EQ("Patient 5", listener.deletedFiles_[0]); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
331 ASSERT_EQ("Patient 0", listener.deletedFiles_[1]); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
332 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
333 int64_t p; |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
334 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[1]); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
335 index.DeleteResource(p); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
336 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[2]); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
337 index.DeleteResource(p); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
338 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[3]); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
339 index.DeleteResource(p); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
340 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[4]); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
341 index.DeleteResource(p); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
342 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[6]); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
343 index.DeleteResource(p); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
344 index.DeleteResource(patients[8]); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
345 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[7]); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
346 index.DeleteResource(p); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
347 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[9]); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
348 index.DeleteResource(p); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
349 ASSERT_FALSE(index.SelectPatientToRecycle(p)); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
350 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
351 ASSERT_EQ(10u, listener.deletedFiles_.size()); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
352 ASSERT_EQ(0u, index.GetTableRecordCount("Resources")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
353 ASSERT_EQ(0u, index.GetTableRecordCount("PatientRecyclingOrder")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
354 } |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
355 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
356 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
357 TEST(DatabaseWrapper, PatientProtection) |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
358 { |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
359 ServerIndexListener listener; |
266 | 360 DatabaseWrapper index(listener); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
361 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
362 std::vector<int64_t> patients; |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
363 for (int i = 0; i < 5; i++) |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
364 { |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
365 std::string p = "Patient " + boost::lexical_cast<std::string>(i); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
366 patients.push_back(index.CreateResource(p, ResourceType_Patient)); |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
367 index.AddAttachment(patients[i], FileInfo(p, FileContentType_Dicom, i + 10, |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
368 "md5-" + boost::lexical_cast<std::string>(i))); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
369 ASSERT_FALSE(index.IsProtectedPatient(patients[i])); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
370 } |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
371 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
372 ASSERT_EQ(5u, index.GetTableRecordCount("Resources")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
373 ASSERT_EQ(5u, index.GetTableRecordCount("PatientRecyclingOrder")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
374 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
375 ASSERT_FALSE(index.IsProtectedPatient(patients[2])); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
376 index.SetProtectedPatient(patients[2], true); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
377 ASSERT_TRUE(index.IsProtectedPatient(patients[2])); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
378 ASSERT_EQ(4u, index.GetTableRecordCount("PatientRecyclingOrder")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
379 ASSERT_EQ(5u, index.GetTableRecordCount("Resources")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
380 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
381 index.SetProtectedPatient(patients[2], true); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
382 ASSERT_TRUE(index.IsProtectedPatient(patients[2])); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
383 ASSERT_EQ(4u, index.GetTableRecordCount("PatientRecyclingOrder")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
384 index.SetProtectedPatient(patients[2], false); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
385 ASSERT_FALSE(index.IsProtectedPatient(patients[2])); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
386 ASSERT_EQ(5u, index.GetTableRecordCount("PatientRecyclingOrder")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
387 index.SetProtectedPatient(patients[2], false); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
388 ASSERT_FALSE(index.IsProtectedPatient(patients[2])); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
389 ASSERT_EQ(5u, index.GetTableRecordCount("PatientRecyclingOrder")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
390 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
391 ASSERT_EQ(5u, index.GetTableRecordCount("Resources")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
392 ASSERT_EQ(5u, index.GetTableRecordCount("PatientRecyclingOrder")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
393 index.SetProtectedPatient(patients[2], true); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
394 ASSERT_TRUE(index.IsProtectedPatient(patients[2])); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
395 ASSERT_EQ(4u, index.GetTableRecordCount("PatientRecyclingOrder")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
396 index.SetProtectedPatient(patients[2], false); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
397 ASSERT_FALSE(index.IsProtectedPatient(patients[2])); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
398 ASSERT_EQ(5u, index.GetTableRecordCount("PatientRecyclingOrder")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
399 index.SetProtectedPatient(patients[3], true); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
400 ASSERT_TRUE(index.IsProtectedPatient(patients[3])); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
401 ASSERT_EQ(4u, index.GetTableRecordCount("PatientRecyclingOrder")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
402 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
403 ASSERT_EQ(5u, index.GetTableRecordCount("Resources")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
404 ASSERT_EQ(0u, listener.deletedFiles_.size()); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
405 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
406 // Unprotecting a patient puts it at the last position in the recycling queue |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
407 int64_t p; |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
408 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[0]); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
409 index.DeleteResource(p); |
268
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
266
diff
changeset
|
410 ASSERT_TRUE(index.SelectPatientToRecycle(p, patients[1])); ASSERT_EQ(p, patients[4]); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
411 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[1]); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
412 index.DeleteResource(p); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
413 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[4]); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
414 index.DeleteResource(p); |
268
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
266
diff
changeset
|
415 ASSERT_FALSE(index.SelectPatientToRecycle(p, patients[2])); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
416 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[2]); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
417 index.DeleteResource(p); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
418 // "patients[3]" is still protected |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
419 ASSERT_FALSE(index.SelectPatientToRecycle(p)); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
420 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
421 ASSERT_EQ(4u, listener.deletedFiles_.size()); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
422 ASSERT_EQ(1u, index.GetTableRecordCount("Resources")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
423 ASSERT_EQ(0u, index.GetTableRecordCount("PatientRecyclingOrder")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
424 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
425 index.SetProtectedPatient(patients[3], false); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
426 ASSERT_EQ(1u, index.GetTableRecordCount("PatientRecyclingOrder")); |
268
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
266
diff
changeset
|
427 ASSERT_FALSE(index.SelectPatientToRecycle(p, patients[3])); |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
266
diff
changeset
|
428 ASSERT_TRUE(index.SelectPatientToRecycle(p, patients[2])); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
429 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[3]); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
430 index.DeleteResource(p); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
431 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
432 ASSERT_EQ(5u, listener.deletedFiles_.size()); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
433 ASSERT_EQ(0u, index.GetTableRecordCount("Resources")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
434 ASSERT_EQ(0u, index.GetTableRecordCount("PatientRecyclingOrder")); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
435 } |
310 | 436 |
437 | |
438 | |
439 TEST(DatabaseWrapper, Sequence) | |
440 { | |
441 ServerIndexListener listener; | |
442 DatabaseWrapper index(listener); | |
443 | |
444 ASSERT_EQ(1u, index.IncrementGlobalSequence(GlobalProperty_AnonymizationSequence)); | |
445 ASSERT_EQ(2u, index.IncrementGlobalSequence(GlobalProperty_AnonymizationSequence)); | |
446 ASSERT_EQ(3u, index.IncrementGlobalSequence(GlobalProperty_AnonymizationSequence)); | |
447 ASSERT_EQ(4u, index.IncrementGlobalSequence(GlobalProperty_AnonymizationSequence)); | |
448 } | |
521 | 449 |
450 | |
451 | |
452 TEST(DatabaseWrapper, LookupTagValue) | |
453 { | |
454 ServerIndexListener listener; | |
455 DatabaseWrapper index(listener); | |
456 | |
457 int64_t a[] = { | |
458 index.CreateResource("a", ResourceType_Study), // 0 | |
459 index.CreateResource("b", ResourceType_Study), // 1 | |
460 index.CreateResource("c", ResourceType_Study), // 2 | |
461 index.CreateResource("d", ResourceType_Series) // 3 | |
462 }; | |
463 | |
464 DicomMap m; | |
465 m.Clear(); m.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "0"); index.SetMainDicomTags(a[0], m); | |
466 m.Clear(); m.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "1"); index.SetMainDicomTags(a[1], m); | |
467 m.Clear(); m.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "0"); index.SetMainDicomTags(a[2], m); | |
468 m.Clear(); m.SetValue(DICOM_TAG_SERIES_INSTANCE_UID, "0"); index.SetMainDicomTags(a[3], m); | |
469 | |
470 std::list<int64_t> s; | |
471 | |
472 index.LookupTagValue(s, DICOM_TAG_STUDY_INSTANCE_UID, "0"); | |
473 ASSERT_EQ(2u, s.size()); | |
474 ASSERT_TRUE(std::find(s.begin(), s.end(), a[0]) != s.end()); | |
475 ASSERT_TRUE(std::find(s.begin(), s.end(), a[2]) != s.end()); | |
476 | |
477 index.LookupTagValue(s, "0"); | |
478 ASSERT_EQ(3u, s.size()); | |
479 ASSERT_TRUE(std::find(s.begin(), s.end(), a[0]) != s.end()); | |
480 ASSERT_TRUE(std::find(s.begin(), s.end(), a[2]) != s.end()); | |
481 ASSERT_TRUE(std::find(s.begin(), s.end(), a[3]) != s.end()); | |
482 | |
483 index.LookupTagValue(s, DICOM_TAG_STUDY_INSTANCE_UID, "1"); | |
484 ASSERT_EQ(1u, s.size()); | |
485 ASSERT_TRUE(std::find(s.begin(), s.end(), a[1]) != s.end()); | |
486 | |
487 index.LookupTagValue(s, "1"); | |
488 ASSERT_EQ(1u, s.size()); | |
489 ASSERT_TRUE(std::find(s.begin(), s.end(), a[1]) != s.end()); | |
490 | |
491 | |
492 /*{ | |
493 std::list<std::string> s; | |
494 context.GetIndex().LookupTagValue(s, DICOM_TAG_STUDY_INSTANCE_UID, "1.2.250.1.74.20130819132500.29000036381059"); | |
495 for (std::list<std::string>::iterator i = s.begin(); i != s.end(); i++) | |
496 { | |
497 std::cout << "*** " << *i << std::endl;; | |
498 } | |
499 }*/ | |
500 | |
501 | |
502 } | |
562
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
521
diff
changeset
|
503 |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
521
diff
changeset
|
504 |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
521
diff
changeset
|
505 TEST(DicomMap, MainTags) |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
521
diff
changeset
|
506 { |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
521
diff
changeset
|
507 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_PATIENT_ID)); |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
521
diff
changeset
|
508 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_PATIENT_ID, ResourceType_Patient)); |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
521
diff
changeset
|
509 ASSERT_FALSE(DicomMap::IsMainDicomTag(DICOM_TAG_PATIENT_ID, ResourceType_Study)); |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
521
diff
changeset
|
510 } |