Mercurial > hg > orthanc
annotate UnitTestsSources/ServerIndexTests.cpp @ 826:f2509d3624f6
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 02 Jun 2014 11:40:45 +0200 |
parents | 4689e400e0fa |
children | 3d6f9b7d0add |
rev | line source |
---|---|
181 | 1 #include "gtest/gtest.h" |
2 | |
183 | 3 #include "../OrthancServer/DatabaseWrapper.h" |
705 | 4 #include "../OrthancServer/ServerContext.h" |
5 #include "../OrthancServer/ServerIndex.h" | |
273
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
6 #include "../Core/Uuid.h" |
711
8f62e8d5a384
test main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
7 #include "../Core/DicomFormat/DicomNullValue.h" |
183 | 8 |
181 | 9 #include <ctype.h> |
10 #include <glog/logging.h> | |
521 | 11 #include <algorithm> |
181 | 12 |
183 | 13 using namespace Orthanc; |
181 | 14 |
183 | 15 namespace |
16 { | |
737
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
17 enum DatabaseWrapperClass |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
18 { |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
19 DatabaseWrapperClass_SQLite |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
20 }; |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
21 |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
22 |
181 | 23 class ServerIndexListener : public IServerIndexListener |
24 { | |
25 public: | |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
26 std::vector<std::string> deletedFiles_; |
183 | 27 std::string ancestorId_; |
28 ResourceType ancestorType_; | |
29 | |
30 void Reset() | |
181 | 31 { |
183 | 32 ancestorId_ = ""; |
33 deletedFiles_.clear(); | |
34 } | |
35 | |
36 virtual void SignalRemainingAncestor(ResourceType type, | |
37 const std::string& publicId) | |
38 { | |
39 ancestorId_ = publicId; | |
40 ancestorType_ = type; | |
181 | 41 } |
42 | |
273
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
43 virtual void SignalFileDeleted(const FileInfo& info) |
181 | 44 { |
273
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
45 const std::string fileUuid = info.GetUuid(); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
46 deletedFiles_.push_back(fileUuid); |
181 | 47 LOG(INFO) << "A file must be removed: " << fileUuid; |
48 } | |
49 }; | |
737
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
50 |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
51 |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
52 class DatabaseWrapperTest : public ::testing::TestWithParam<DatabaseWrapperClass> |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
53 { |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
54 protected: |
738 | 55 std::auto_ptr<ServerIndexListener> listener_; |
56 std::auto_ptr<DatabaseWrapper> index_; | |
737
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
57 |
738 | 58 DatabaseWrapperTest() |
737
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
59 { |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
60 } |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
61 |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
62 virtual void SetUp() |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
63 { |
738 | 64 listener_.reset(new ServerIndexListener); |
65 index_.reset(new DatabaseWrapper(*listener_)); | |
737
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
66 } |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
67 |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
68 virtual void TearDown() |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
69 { |
738 | 70 index_.reset(NULL); |
71 listener_.reset(NULL); | |
737
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
72 } |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
73 }; |
181 | 74 } |
75 | |
76 | |
737
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
77 INSTANTIATE_TEST_CASE_P(DatabaseWrapperName, |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
78 DatabaseWrapperTest, |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
79 ::testing::Values(DatabaseWrapperClass_SQLite)); |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
80 |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
81 |
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
82 TEST_P(DatabaseWrapperTest, Simple) |
181 | 83 { |
84 int64_t a[] = { | |
738 | 85 index_->CreateResource("a", ResourceType_Patient), // 0 |
86 index_->CreateResource("b", ResourceType_Study), // 1 | |
87 index_->CreateResource("c", ResourceType_Series), // 2 | |
88 index_->CreateResource("d", ResourceType_Instance), // 3 | |
89 index_->CreateResource("e", ResourceType_Instance), // 4 | |
90 index_->CreateResource("f", ResourceType_Instance), // 5 | |
91 index_->CreateResource("g", ResourceType_Study) // 6 | |
181 | 92 }; |
93 | |
738 | 94 ASSERT_EQ("a", index_->GetPublicId(a[0])); |
95 ASSERT_EQ("b", index_->GetPublicId(a[1])); | |
96 ASSERT_EQ("c", index_->GetPublicId(a[2])); | |
97 ASSERT_EQ("d", index_->GetPublicId(a[3])); | |
98 ASSERT_EQ("e", index_->GetPublicId(a[4])); | |
99 ASSERT_EQ("f", index_->GetPublicId(a[5])); | |
100 ASSERT_EQ("g", index_->GetPublicId(a[6])); | |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
101 |
738 | 102 ASSERT_EQ(ResourceType_Patient, index_->GetResourceType(a[0])); |
103 ASSERT_EQ(ResourceType_Study, index_->GetResourceType(a[1])); | |
104 ASSERT_EQ(ResourceType_Series, index_->GetResourceType(a[2])); | |
105 ASSERT_EQ(ResourceType_Instance, index_->GetResourceType(a[3])); | |
106 ASSERT_EQ(ResourceType_Instance, index_->GetResourceType(a[4])); | |
107 ASSERT_EQ(ResourceType_Instance, index_->GetResourceType(a[5])); | |
108 ASSERT_EQ(ResourceType_Study, index_->GetResourceType(a[6])); | |
304 | 109 |
190 | 110 { |
111 Json::Value t; | |
738 | 112 index_->GetAllPublicIds(t, ResourceType_Patient); |
190 | 113 |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
114 ASSERT_EQ(1u, t.size()); |
190 | 115 ASSERT_EQ("a", t[0u].asString()); |
116 | |
738 | 117 index_->GetAllPublicIds(t, ResourceType_Series); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
118 ASSERT_EQ(1u, t.size()); |
190 | 119 ASSERT_EQ("c", t[0u].asString()); |
120 | |
738 | 121 index_->GetAllPublicIds(t, ResourceType_Study); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
122 ASSERT_EQ(2u, t.size()); |
190 | 123 |
738 | 124 index_->GetAllPublicIds(t, ResourceType_Instance); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
125 ASSERT_EQ(3u, t.size()); |
190 | 126 } |
127 | |
738 | 128 index_->SetGlobalProperty(GlobalProperty_FlushSleep, "World"); |
181 | 129 |
738 | 130 index_->AttachChild(a[0], a[1]); |
131 index_->AttachChild(a[1], a[2]); | |
132 index_->AttachChild(a[2], a[3]); | |
133 index_->AttachChild(a[2], a[4]); | |
134 index_->AttachChild(a[6], a[5]); | |
182 | 135 |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
136 int64_t parent; |
738 | 137 ASSERT_FALSE(index_->LookupParent(parent, a[0])); |
138 ASSERT_TRUE(index_->LookupParent(parent, a[1])); ASSERT_EQ(a[0], parent); | |
139 ASSERT_TRUE(index_->LookupParent(parent, a[2])); ASSERT_EQ(a[1], parent); | |
140 ASSERT_TRUE(index_->LookupParent(parent, a[3])); ASSERT_EQ(a[2], parent); | |
141 ASSERT_TRUE(index_->LookupParent(parent, a[4])); ASSERT_EQ(a[2], parent); | |
142 ASSERT_TRUE(index_->LookupParent(parent, a[5])); ASSERT_EQ(a[6], parent); | |
143 ASSERT_FALSE(index_->LookupParent(parent, a[6])); | |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
144 |
182 | 145 std::string s; |
146 | |
738 | 147 ASSERT_FALSE(index_->GetParentPublicId(s, a[0])); |
148 ASSERT_FALSE(index_->GetParentPublicId(s, a[6])); | |
149 ASSERT_TRUE(index_->GetParentPublicId(s, a[1])); ASSERT_EQ("a", s); | |
150 ASSERT_TRUE(index_->GetParentPublicId(s, a[2])); ASSERT_EQ("b", s); | |
151 ASSERT_TRUE(index_->GetParentPublicId(s, a[3])); ASSERT_EQ("c", s); | |
152 ASSERT_TRUE(index_->GetParentPublicId(s, a[4])); ASSERT_EQ("c", s); | |
153 ASSERT_TRUE(index_->GetParentPublicId(s, a[5])); ASSERT_EQ("g", s); | |
182 | 154 |
185 | 155 std::list<std::string> l; |
738 | 156 index_->GetChildrenPublicId(l, a[0]); ASSERT_EQ(1u, l.size()); ASSERT_EQ("b", l.front()); |
157 index_->GetChildrenPublicId(l, a[1]); ASSERT_EQ(1u, l.size()); ASSERT_EQ("c", l.front()); | |
158 index_->GetChildrenPublicId(l, a[3]); ASSERT_EQ(0u, l.size()); | |
159 index_->GetChildrenPublicId(l, a[4]); ASSERT_EQ(0u, l.size()); | |
160 index_->GetChildrenPublicId(l, a[5]); ASSERT_EQ(0u, l.size()); | |
161 index_->GetChildrenPublicId(l, a[6]); ASSERT_EQ(1u, l.size()); ASSERT_EQ("f", l.front()); | |
182 | 162 |
738 | 163 index_->GetChildrenPublicId(l, a[2]); ASSERT_EQ(2u, l.size()); |
182 | 164 if (l.front() == "d") |
165 { | |
166 ASSERT_EQ("e", l.back()); | |
167 } | |
168 else | |
169 { | |
170 ASSERT_EQ("d", l.back()); | |
171 ASSERT_EQ("e", l.front()); | |
172 } | |
173 | |
436
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
310
diff
changeset
|
174 std::list<MetadataType> md; |
738 | 175 index_->ListAvailableMetadata(md, a[4]); |
436
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
310
diff
changeset
|
176 ASSERT_EQ(0u, md.size()); |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
310
diff
changeset
|
177 |
738 | 178 index_->AddAttachment(a[4], FileInfo("my json file", FileContentType_DicomAsJson, 42, "md5", |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
179 CompressionType_Zlib, 21, "compressedMD5")); |
738 | 180 index_->AddAttachment(a[4], FileInfo("my dicom file", FileContentType_Dicom, 42, "md5")); |
181 index_->AddAttachment(a[6], FileInfo("world", FileContentType_Dicom, 44, "md5")); | |
182 index_->SetMetadata(a[4], MetadataType_Instance_RemoteAet, "PINNACLE"); | |
436
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
310
diff
changeset
|
183 |
738 | 184 index_->ListAvailableMetadata(md, a[4]); |
436
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
310
diff
changeset
|
185 ASSERT_EQ(1u, md.size()); |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
310
diff
changeset
|
186 ASSERT_EQ(MetadataType_Instance_RemoteAet, md.front()); |
738 | 187 index_->SetMetadata(a[4], MetadataType_ModifiedFrom, "TUTU"); |
188 index_->ListAvailableMetadata(md, a[4]); | |
438 | 189 ASSERT_EQ(2u, md.size()); |
738 | 190 index_->DeleteMetadata(a[4], MetadataType_ModifiedFrom); |
191 index_->ListAvailableMetadata(md, a[4]); | |
438 | 192 ASSERT_EQ(1u, md.size()); |
193 ASSERT_EQ(MetadataType_Instance_RemoteAet, md.front()); | |
182 | 194 |
738 | 195 ASSERT_EQ(21u + 42u + 44u, index_->GetTotalCompressedSize()); |
196 ASSERT_EQ(42u + 42u + 44u, index_->GetTotalUncompressedSize()); | |
181 | 197 |
198 DicomMap m; | |
199 m.SetValue(0x0010, 0x0010, "PatientName"); | |
738 | 200 index_->SetMainDicomTags(a[3], m); |
181 | 201 |
202 int64_t b; | |
203 ResourceType t; | |
738 | 204 ASSERT_TRUE(index_->LookupResource("g", b, t)); |
181 | 205 ASSERT_EQ(7, b); |
206 ASSERT_EQ(ResourceType_Study, t); | |
207 | |
738 | 208 ASSERT_TRUE(index_->LookupMetadata(s, a[4], MetadataType_Instance_RemoteAet)); |
209 ASSERT_FALSE(index_->LookupMetadata(s, a[4], MetadataType_Instance_IndexInSeries)); | |
181 | 210 ASSERT_EQ("PINNACLE", s); |
738 | 211 ASSERT_EQ("PINNACLE", index_->GetMetadata(a[4], MetadataType_Instance_RemoteAet)); |
212 ASSERT_EQ("None", index_->GetMetadata(a[4], MetadataType_Instance_IndexInSeries, "None")); | |
181 | 213 |
738 | 214 ASSERT_TRUE(index_->LookupGlobalProperty(s, GlobalProperty_FlushSleep)); |
215 ASSERT_FALSE(index_->LookupGlobalProperty(s, static_cast<GlobalProperty>(42))); | |
181 | 216 ASSERT_EQ("World", s); |
738 | 217 ASSERT_EQ("World", index_->GetGlobalProperty(GlobalProperty_FlushSleep)); |
218 ASSERT_EQ("None", index_->GetGlobalProperty(static_cast<GlobalProperty>(42), "None")); | |
181 | 219 |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
220 FileInfo att; |
738 | 221 ASSERT_TRUE(index_->LookupAttachment(att, a[4], FileContentType_DicomAsJson)); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
222 ASSERT_EQ("my json file", att.GetUuid()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
223 ASSERT_EQ(21u, att.GetCompressedSize()); |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
224 ASSERT_EQ("md5", att.GetUncompressedMD5()); |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
225 ASSERT_EQ("compressedMD5", att.GetCompressedMD5()); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
226 ASSERT_EQ(42u, att.GetUncompressedSize()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
227 ASSERT_EQ(CompressionType_Zlib, att.GetCompressionType()); |
181 | 228 |
738 | 229 ASSERT_TRUE(index_->LookupAttachment(att, a[6], FileContentType_Dicom)); |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
230 ASSERT_EQ("world", att.GetUuid()); |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
231 ASSERT_EQ(44u, att.GetCompressedSize()); |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
232 ASSERT_EQ("md5", att.GetUncompressedMD5()); |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
233 ASSERT_EQ("md5", att.GetCompressedMD5()); |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
234 ASSERT_EQ(44u, att.GetUncompressedSize()); |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
235 ASSERT_EQ(CompressionType_None, att.GetCompressionType()); |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
236 |
738 | 237 ASSERT_EQ(0u, listener_->deletedFiles_.size()); |
238 ASSERT_EQ(7u, index_->GetTableRecordCount("Resources")); | |
239 ASSERT_EQ(3u, index_->GetTableRecordCount("AttachedFiles")); | |
240 ASSERT_EQ(1u, index_->GetTableRecordCount("Metadata")); | |
241 ASSERT_EQ(1u, index_->GetTableRecordCount("MainDicomTags")); | |
242 index_->DeleteResource(a[0]); | |
183 | 243 |
738 | 244 ASSERT_EQ(2u, listener_->deletedFiles_.size()); |
245 ASSERT_FALSE(std::find(listener_->deletedFiles_.begin(), | |
246 listener_->deletedFiles_.end(), | |
247 "my json file") == listener_->deletedFiles_.end()); | |
248 ASSERT_FALSE(std::find(listener_->deletedFiles_.begin(), | |
249 listener_->deletedFiles_.end(), | |
250 "my dicom file") == listener_->deletedFiles_.end()); | |
183 | 251 |
738 | 252 ASSERT_EQ(2u, index_->GetTableRecordCount("Resources")); |
253 ASSERT_EQ(0u, index_->GetTableRecordCount("Metadata")); | |
254 ASSERT_EQ(1u, index_->GetTableRecordCount("AttachedFiles")); | |
255 ASSERT_EQ(0u, index_->GetTableRecordCount("MainDicomTags")); | |
256 index_->DeleteResource(a[5]); | |
257 ASSERT_EQ(0u, index_->GetTableRecordCount("Resources")); | |
258 ASSERT_EQ(0u, index_->GetTableRecordCount("AttachedFiles")); | |
259 ASSERT_EQ(2u, index_->GetTableRecordCount("GlobalProperties")); | |
183 | 260 |
738 | 261 ASSERT_EQ(3u, listener_->deletedFiles_.size()); |
262 ASSERT_FALSE(std::find(listener_->deletedFiles_.begin(), | |
263 listener_->deletedFiles_.end(), | |
264 "world") == listener_->deletedFiles_.end()); | |
183 | 265 } |
266 | |
267 | |
268 | |
269 | |
737
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
270 TEST_P(DatabaseWrapperTest, Upward) |
183 | 271 { |
272 int64_t a[] = { | |
738 | 273 index_->CreateResource("a", ResourceType_Patient), // 0 |
274 index_->CreateResource("b", ResourceType_Study), // 1 | |
275 index_->CreateResource("c", ResourceType_Series), // 2 | |
276 index_->CreateResource("d", ResourceType_Instance), // 3 | |
277 index_->CreateResource("e", ResourceType_Instance), // 4 | |
278 index_->CreateResource("f", ResourceType_Study), // 5 | |
279 index_->CreateResource("g", ResourceType_Series), // 6 | |
280 index_->CreateResource("h", ResourceType_Series) // 7 | |
183 | 281 }; |
282 | |
738 | 283 index_->AttachChild(a[0], a[1]); |
284 index_->AttachChild(a[1], a[2]); | |
285 index_->AttachChild(a[2], a[3]); | |
286 index_->AttachChild(a[2], a[4]); | |
287 index_->AttachChild(a[1], a[6]); | |
288 index_->AttachChild(a[0], a[5]); | |
289 index_->AttachChild(a[5], a[7]); | |
183 | 290 |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
291 { |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
292 Json::Value j; |
738 | 293 index_->GetChildren(j, a[0]); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
294 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
|
295 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
|
296 (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
|
297 |
738 | 298 index_->GetChildren(j, a[1]); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
299 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
|
300 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
|
301 (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
|
302 |
738 | 303 index_->GetChildren(j, a[2]); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
304 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
|
305 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
|
306 (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
|
307 |
738 | 308 index_->GetChildren(j, a[3]); ASSERT_EQ(0u, j.size()); |
309 index_->GetChildren(j, a[4]); ASSERT_EQ(0u, j.size()); | |
310 index_->GetChildren(j, a[5]); ASSERT_EQ(1u, j.size()); ASSERT_EQ("h", j[0u].asString()); | |
311 index_->GetChildren(j, a[6]); ASSERT_EQ(0u, j.size()); | |
312 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
|
313 } |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
314 |
738 | 315 listener_->Reset(); |
316 index_->DeleteResource(a[3]); | |
317 ASSERT_EQ("c", listener_->ancestorId_); | |
318 ASSERT_EQ(ResourceType_Series, listener_->ancestorType_); | |
183 | 319 |
738 | 320 listener_->Reset(); |
321 index_->DeleteResource(a[4]); | |
322 ASSERT_EQ("b", listener_->ancestorId_); | |
323 ASSERT_EQ(ResourceType_Study, listener_->ancestorType_); | |
183 | 324 |
738 | 325 listener_->Reset(); |
326 index_->DeleteResource(a[7]); | |
327 ASSERT_EQ("a", listener_->ancestorId_); | |
328 ASSERT_EQ(ResourceType_Patient, listener_->ancestorType_); | |
183 | 329 |
738 | 330 listener_->Reset(); |
331 index_->DeleteResource(a[6]); | |
332 ASSERT_EQ("", listener_->ancestorId_); // No more ancestor | |
181 | 333 } |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
334 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
335 |
737
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
336 TEST_P(DatabaseWrapperTest, PatientRecycling) |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
337 { |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
338 std::vector<int64_t> patients; |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
339 for (int i = 0; i < 10; i++) |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
340 { |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
341 std::string p = "Patient " + boost::lexical_cast<std::string>(i); |
738 | 342 patients.push_back(index_->CreateResource(p, ResourceType_Patient)); |
343 index_->AddAttachment(patients[i], FileInfo(p, FileContentType_Dicom, i + 10, | |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
344 "md5-" + boost::lexical_cast<std::string>(i))); |
738 | 345 ASSERT_FALSE(index_->IsProtectedPatient(patients[i])); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
346 } |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
347 |
738 | 348 ASSERT_EQ(10u, index_->GetTableRecordCount("Resources")); |
349 ASSERT_EQ(10u, index_->GetTableRecordCount("PatientRecyclingOrder")); | |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
350 |
738 | 351 listener_->Reset(); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
352 |
738 | 353 index_->DeleteResource(patients[5]); |
354 index_->DeleteResource(patients[0]); | |
355 ASSERT_EQ(8u, index_->GetTableRecordCount("Resources")); | |
356 ASSERT_EQ(8u, index_->GetTableRecordCount("PatientRecyclingOrder")); | |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
357 |
738 | 358 ASSERT_EQ(2u, listener_->deletedFiles_.size()); |
359 ASSERT_EQ("Patient 5", listener_->deletedFiles_[0]); | |
360 ASSERT_EQ("Patient 0", listener_->deletedFiles_[1]); | |
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 int64_t p; |
738 | 363 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[1]); |
364 index_->DeleteResource(p); | |
365 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[2]); | |
366 index_->DeleteResource(p); | |
367 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[3]); | |
368 index_->DeleteResource(p); | |
369 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[4]); | |
370 index_->DeleteResource(p); | |
371 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[6]); | |
372 index_->DeleteResource(p); | |
373 index_->DeleteResource(patients[8]); | |
374 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[7]); | |
375 index_->DeleteResource(p); | |
376 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[9]); | |
377 index_->DeleteResource(p); | |
378 ASSERT_FALSE(index_->SelectPatientToRecycle(p)); | |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
379 |
738 | 380 ASSERT_EQ(10u, listener_->deletedFiles_.size()); |
381 ASSERT_EQ(0u, index_->GetTableRecordCount("Resources")); | |
382 ASSERT_EQ(0u, index_->GetTableRecordCount("PatientRecyclingOrder")); | |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
383 } |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
384 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
385 |
737
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
386 TEST_P(DatabaseWrapperTest, PatientProtection) |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
387 { |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
388 std::vector<int64_t> patients; |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
389 for (int i = 0; i < 5; i++) |
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 std::string p = "Patient " + boost::lexical_cast<std::string>(i); |
738 | 392 patients.push_back(index_->CreateResource(p, ResourceType_Patient)); |
393 index_->AddAttachment(patients[i], FileInfo(p, FileContentType_Dicom, i + 10, | |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
394 "md5-" + boost::lexical_cast<std::string>(i))); |
738 | 395 ASSERT_FALSE(index_->IsProtectedPatient(patients[i])); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
396 } |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
397 |
738 | 398 ASSERT_EQ(5u, index_->GetTableRecordCount("Resources")); |
399 ASSERT_EQ(5u, index_->GetTableRecordCount("PatientRecyclingOrder")); | |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
400 |
738 | 401 ASSERT_FALSE(index_->IsProtectedPatient(patients[2])); |
402 index_->SetProtectedPatient(patients[2], true); | |
403 ASSERT_TRUE(index_->IsProtectedPatient(patients[2])); | |
404 ASSERT_EQ(4u, index_->GetTableRecordCount("PatientRecyclingOrder")); | |
405 ASSERT_EQ(5u, index_->GetTableRecordCount("Resources")); | |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
406 |
738 | 407 index_->SetProtectedPatient(patients[2], true); |
408 ASSERT_TRUE(index_->IsProtectedPatient(patients[2])); | |
409 ASSERT_EQ(4u, index_->GetTableRecordCount("PatientRecyclingOrder")); | |
410 index_->SetProtectedPatient(patients[2], false); | |
411 ASSERT_FALSE(index_->IsProtectedPatient(patients[2])); | |
412 ASSERT_EQ(5u, index_->GetTableRecordCount("PatientRecyclingOrder")); | |
413 index_->SetProtectedPatient(patients[2], false); | |
414 ASSERT_FALSE(index_->IsProtectedPatient(patients[2])); | |
415 ASSERT_EQ(5u, index_->GetTableRecordCount("PatientRecyclingOrder")); | |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
416 |
738 | 417 ASSERT_EQ(5u, index_->GetTableRecordCount("Resources")); |
418 ASSERT_EQ(5u, index_->GetTableRecordCount("PatientRecyclingOrder")); | |
419 index_->SetProtectedPatient(patients[2], true); | |
420 ASSERT_TRUE(index_->IsProtectedPatient(patients[2])); | |
421 ASSERT_EQ(4u, index_->GetTableRecordCount("PatientRecyclingOrder")); | |
422 index_->SetProtectedPatient(patients[2], false); | |
423 ASSERT_FALSE(index_->IsProtectedPatient(patients[2])); | |
424 ASSERT_EQ(5u, index_->GetTableRecordCount("PatientRecyclingOrder")); | |
425 index_->SetProtectedPatient(patients[3], true); | |
426 ASSERT_TRUE(index_->IsProtectedPatient(patients[3])); | |
427 ASSERT_EQ(4u, index_->GetTableRecordCount("PatientRecyclingOrder")); | |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
428 |
738 | 429 ASSERT_EQ(5u, index_->GetTableRecordCount("Resources")); |
430 ASSERT_EQ(0u, listener_->deletedFiles_.size()); | |
262
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 // 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
|
433 int64_t p; |
738 | 434 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[0]); |
435 index_->DeleteResource(p); | |
436 ASSERT_TRUE(index_->SelectPatientToRecycle(p, patients[1])); ASSERT_EQ(p, patients[4]); | |
437 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[1]); | |
438 index_->DeleteResource(p); | |
439 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[4]); | |
440 index_->DeleteResource(p); | |
441 ASSERT_FALSE(index_->SelectPatientToRecycle(p, patients[2])); | |
442 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[2]); | |
443 index_->DeleteResource(p); | |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
444 // "patients[3]" is still protected |
738 | 445 ASSERT_FALSE(index_->SelectPatientToRecycle(p)); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
446 |
738 | 447 ASSERT_EQ(4u, listener_->deletedFiles_.size()); |
448 ASSERT_EQ(1u, index_->GetTableRecordCount("Resources")); | |
449 ASSERT_EQ(0u, index_->GetTableRecordCount("PatientRecyclingOrder")); | |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
450 |
738 | 451 index_->SetProtectedPatient(patients[3], false); |
452 ASSERT_EQ(1u, index_->GetTableRecordCount("PatientRecyclingOrder")); | |
453 ASSERT_FALSE(index_->SelectPatientToRecycle(p, patients[3])); | |
454 ASSERT_TRUE(index_->SelectPatientToRecycle(p, patients[2])); | |
455 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[3]); | |
456 index_->DeleteResource(p); | |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
457 |
738 | 458 ASSERT_EQ(5u, listener_->deletedFiles_.size()); |
459 ASSERT_EQ(0u, index_->GetTableRecordCount("Resources")); | |
460 ASSERT_EQ(0u, index_->GetTableRecordCount("PatientRecyclingOrder")); | |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
461 } |
310 | 462 |
463 | |
464 | |
737
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
465 TEST_P(DatabaseWrapperTest, Sequence) |
310 | 466 { |
738 | 467 ASSERT_EQ(1u, index_->IncrementGlobalSequence(GlobalProperty_AnonymizationSequence)); |
468 ASSERT_EQ(2u, index_->IncrementGlobalSequence(GlobalProperty_AnonymizationSequence)); | |
469 ASSERT_EQ(3u, index_->IncrementGlobalSequence(GlobalProperty_AnonymizationSequence)); | |
470 ASSERT_EQ(4u, index_->IncrementGlobalSequence(GlobalProperty_AnonymizationSequence)); | |
310 | 471 } |
521 | 472 |
473 | |
474 | |
737
1dee6e9bdbf4
abstraction of databasewrapper tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
475 TEST_P(DatabaseWrapperTest, LookupTagValue) |
521 | 476 { |
477 int64_t a[] = { | |
738 | 478 index_->CreateResource("a", ResourceType_Study), // 0 |
479 index_->CreateResource("b", ResourceType_Study), // 1 | |
480 index_->CreateResource("c", ResourceType_Study), // 2 | |
481 index_->CreateResource("d", ResourceType_Series) // 3 | |
521 | 482 }; |
483 | |
484 DicomMap m; | |
738 | 485 m.Clear(); m.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "0"); index_->SetMainDicomTags(a[0], m); |
486 m.Clear(); m.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "1"); index_->SetMainDicomTags(a[1], m); | |
487 m.Clear(); m.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "0"); index_->SetMainDicomTags(a[2], m); | |
488 m.Clear(); m.SetValue(DICOM_TAG_SERIES_INSTANCE_UID, "0"); index_->SetMainDicomTags(a[3], m); | |
521 | 489 |
490 std::list<int64_t> s; | |
491 | |
738 | 492 index_->LookupTagValue(s, DICOM_TAG_STUDY_INSTANCE_UID, "0"); |
521 | 493 ASSERT_EQ(2u, s.size()); |
494 ASSERT_TRUE(std::find(s.begin(), s.end(), a[0]) != s.end()); | |
495 ASSERT_TRUE(std::find(s.begin(), s.end(), a[2]) != s.end()); | |
496 | |
738 | 497 index_->LookupTagValue(s, "0"); |
521 | 498 ASSERT_EQ(3u, s.size()); |
499 ASSERT_TRUE(std::find(s.begin(), s.end(), a[0]) != s.end()); | |
500 ASSERT_TRUE(std::find(s.begin(), s.end(), a[2]) != s.end()); | |
501 ASSERT_TRUE(std::find(s.begin(), s.end(), a[3]) != s.end()); | |
502 | |
738 | 503 index_->LookupTagValue(s, DICOM_TAG_STUDY_INSTANCE_UID, "1"); |
521 | 504 ASSERT_EQ(1u, s.size()); |
505 ASSERT_TRUE(std::find(s.begin(), s.end(), a[1]) != s.end()); | |
506 | |
738 | 507 index_->LookupTagValue(s, "1"); |
521 | 508 ASSERT_EQ(1u, s.size()); |
509 ASSERT_TRUE(std::find(s.begin(), s.end(), a[1]) != s.end()); | |
510 | |
511 | |
512 /*{ | |
513 std::list<std::string> s; | |
514 context.GetIndex().LookupTagValue(s, DICOM_TAG_STUDY_INSTANCE_UID, "1.2.250.1.74.20130819132500.29000036381059"); | |
515 for (std::list<std::string>::iterator i = s.begin(); i != s.end(); i++) | |
516 { | |
517 std::cout << "*** " << *i << std::endl;; | |
518 } | |
519 }*/ | |
562
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
521
diff
changeset
|
520 } |
705 | 521 |
522 | |
523 | |
713
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
524 TEST(ServerIndex, AttachmentRecycling) |
705 | 525 { |
803
4689e400e0fa
directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
526 const std::string path = "UnitTestsStorage"; |
705 | 527 Toolbox::RemoveFile(path + "/index"); |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
706
diff
changeset
|
528 ServerContext context(path, ":memory:"); // The SQLite DB is in memory |
705 | 529 ServerIndex& index = context.GetIndex(); |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
706
diff
changeset
|
530 |
706 | 531 index.SetMaximumStorageSize(10); |
532 | |
705 | 533 Json::Value tmp; |
534 index.ComputeStatistics(tmp); | |
713
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
535 ASSERT_EQ(0, tmp["CountPatients"].asInt()); |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
536 ASSERT_EQ(0, boost::lexical_cast<int>(tmp["TotalDiskSize"].asString())); |
705 | 537 |
538 ServerIndex::Attachments attachments; | |
539 | |
713
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
540 std::vector<std::string> ids; |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
541 for (int i = 0; i < 10; i++) |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
542 { |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
543 std::string id = boost::lexical_cast<std::string>(i); |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
544 DicomMap instance; |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
545 instance.SetValue(DICOM_TAG_PATIENT_ID, "patient-" + id); |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
546 instance.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "study-" + id); |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
547 instance.SetValue(DICOM_TAG_SERIES_INSTANCE_UID, "series-" + id); |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
548 instance.SetValue(DICOM_TAG_SOP_INSTANCE_UID, "instance-" + id); |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
549 ASSERT_EQ(StoreStatus_Success, index.Store(instance, attachments, "")); |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
550 |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
551 DicomInstanceHasher hasher(instance); |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
552 ids.push_back(hasher.HashPatient()); |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
553 ids.push_back(hasher.HashStudy()); |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
554 ids.push_back(hasher.HashSeries()); |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
555 ids.push_back(hasher.HashInstance()); |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
556 } |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
557 |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
558 index.ComputeStatistics(tmp); |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
559 ASSERT_EQ(10, tmp["CountPatients"].asInt()); |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
560 ASSERT_EQ(0, boost::lexical_cast<int>(tmp["TotalDiskSize"].asString())); |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
561 |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
562 for (size_t i = 0; i < ids.size(); i++) |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
563 { |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
564 FileInfo info(Toolbox::GenerateUuid(), FileContentType_Dicom, 1, "md5"); |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
565 index.AddAttachment(info, ids[i]); |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
566 |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
567 index.ComputeStatistics(tmp); |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
568 ASSERT_GE(10, boost::lexical_cast<int>(tmp["TotalDiskSize"].asString())); |
9d1973813d8b
test attachment recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
569 } |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
706
diff
changeset
|
570 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
706
diff
changeset
|
571 // Because the DB is in memory, the SQLite index must not have been created |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
706
diff
changeset
|
572 ASSERT_THROW(Toolbox::GetFileSize(path + "/index"), OrthancException); |
705 | 573 } |