comparison UnitTestsSources/ServerIndexTests.cpp @ 3081:2e5970ddcfeb db-changes

simplification of unit tests
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 03 Jan 2019 20:03:35 +0100
parents 1a75595d8e44
children 2e1808b6146a
comparison
equal deleted inserted replaced
3080:1a75595d8e44 3081:2e5970ddcfeb
46 46
47 using namespace Orthanc; 47 using namespace Orthanc;
48 48
49 namespace 49 namespace
50 { 50 {
51 enum DatabaseWrapperClass
52 {
53 DatabaseWrapperClass_SQLite
54 };
55
56
57 class TestDatabaseListener : public IDatabaseListener 51 class TestDatabaseListener : public IDatabaseListener
58 { 52 {
59 public: 53 public:
60 std::vector<std::string> deletedFiles_; 54 std::vector<std::string> deletedFiles_;
61 std::vector<std::string> deletedResources_; 55 std::vector<std::string> deletedResources_;
92 86
93 LOG(INFO) << "Change related to resource " << change.GetPublicId() << " of type " 87 LOG(INFO) << "Change related to resource " << change.GetPublicId() << " of type "
94 << EnumerationToString(change.GetResourceType()) << ": " 88 << EnumerationToString(change.GetResourceType()) << ": "
95 << EnumerationToString(change.GetChangeType()); 89 << EnumerationToString(change.GetChangeType());
96 } 90 }
97
98 }; 91 };
99 92
100 93
101 class DatabaseWrapperTest : public ::testing::TestWithParam<DatabaseWrapperClass> 94 class DatabaseWrapperTest : public ::testing::Test
102 { 95 {
103 protected: 96 protected:
104 std::auto_ptr<TestDatabaseListener> listener_; 97 std::auto_ptr<TestDatabaseListener> listener_;
105 std::auto_ptr<IDatabaseWrapper> index_; 98 std::auto_ptr<SQLiteDatabaseWrapper> index_;
106 99
100 public:
107 DatabaseWrapperTest() 101 DatabaseWrapperTest()
108 { 102 {
109 } 103 }
110 104
111 virtual void SetUp() ORTHANC_OVERRIDE 105 virtual void SetUp() ORTHANC_OVERRIDE
112 { 106 {
113 listener_.reset(new TestDatabaseListener); 107 listener_.reset(new TestDatabaseListener);
114 108 index_.reset(new SQLiteDatabaseWrapper);
115 switch (GetParam())
116 {
117 case DatabaseWrapperClass_SQLite:
118 index_.reset(new SQLiteDatabaseWrapper());
119 break;
120
121 default:
122 throw OrthancException(ErrorCode_InternalError);
123 }
124
125 index_->SetListener(*listener_); 109 index_->SetListener(*listener_);
126 index_->Open(); 110 index_->Open();
127 } 111 }
128 112
129 virtual void TearDown() ORTHANC_OVERRIDE 113 virtual void TearDown() ORTHANC_OVERRIDE
133 listener_.reset(NULL); 117 listener_.reset(NULL);
134 } 118 }
135 119
136 void CheckTableRecordCount(uint32_t expected, const char* table) 120 void CheckTableRecordCount(uint32_t expected, const char* table)
137 { 121 {
138 switch (GetParam()) 122 ASSERT_EQ(expected, index_->GetTableRecordCount(table));
139 {
140 case DatabaseWrapperClass_SQLite:
141 {
142 SQLiteDatabaseWrapper* sqlite = dynamic_cast<SQLiteDatabaseWrapper*>(index_.get());
143 ASSERT_EQ(expected, sqlite->GetTableRecordCount(table));
144 break;
145 }
146
147 default:
148 throw OrthancException(ErrorCode_InternalError);
149 }
150 } 123 }
151 124
152 void CheckNoParent(int64_t id) 125 void CheckNoParent(int64_t id)
153 { 126 {
154 std::string s; 127 std::string s;
155 128 ASSERT_FALSE(index_->GetParentPublicId(s, id));
156 switch (GetParam())
157 {
158 case DatabaseWrapperClass_SQLite:
159 {
160 SQLiteDatabaseWrapper* sqlite = dynamic_cast<SQLiteDatabaseWrapper*>(index_.get());
161 ASSERT_FALSE(sqlite->GetParentPublicId(s, id));
162 break;
163 }
164
165 default:
166 throw OrthancException(ErrorCode_InternalError);
167 }
168 } 129 }
169 130
170 void CheckParentPublicId(const char* expected, int64_t id) 131 void CheckParentPublicId(const char* expected, int64_t id)
171 { 132 {
172 std::string s; 133 std::string s;
173 134 ASSERT_TRUE(index_->GetParentPublicId(s, id));
174 switch (GetParam()) 135 ASSERT_EQ(expected, s);
175 {
176 case DatabaseWrapperClass_SQLite:
177 {
178 SQLiteDatabaseWrapper* sqlite = dynamic_cast<SQLiteDatabaseWrapper*>(index_.get());
179 ASSERT_TRUE(sqlite->GetParentPublicId(s, id));
180 ASSERT_EQ(expected, s);
181 break;
182 }
183
184 default:
185 throw OrthancException(ErrorCode_InternalError);
186 }
187 } 136 }
188 137
189 void CheckNoChild(int64_t id) 138 void CheckNoChild(int64_t id)
190 { 139 {
191 std::list<std::string> j; 140 std::list<std::string> j;
192 141 index_->GetChildren(j, id);
193 switch (GetParam()) 142 ASSERT_EQ(0u, j.size());
194 {
195 case DatabaseWrapperClass_SQLite:
196 {
197 SQLiteDatabaseWrapper* sqlite = dynamic_cast<SQLiteDatabaseWrapper*>(index_.get());
198 sqlite->GetChildren(j, id);
199 ASSERT_EQ(0u, j.size());
200 break;
201 }
202
203 default:
204 throw OrthancException(ErrorCode_InternalError);
205 }
206 } 143 }
207 144
208 void CheckOneChild(const char* expected, int64_t id) 145 void CheckOneChild(const char* expected, int64_t id)
209 { 146 {
210 std::list<std::string> j; 147 std::list<std::string> j;
211 148 index_->GetChildren(j, id);
212 switch (GetParam()) 149 ASSERT_EQ(1u, j.size());
213 { 150 ASSERT_EQ(expected, j.front());
214 case DatabaseWrapperClass_SQLite:
215 {
216 SQLiteDatabaseWrapper* sqlite = dynamic_cast<SQLiteDatabaseWrapper*>(index_.get());
217 sqlite->GetChildren(j, id);
218 ASSERT_EQ(1u, j.size());
219 ASSERT_EQ(expected, j.front());
220 break;
221 }
222
223 default:
224 throw OrthancException(ErrorCode_InternalError);
225 }
226 } 151 }
227 152
228 void CheckTwoChildren(const char* expected1, 153 void CheckTwoChildren(const char* expected1,
229 const char* expected2, 154 const char* expected2,
230 int64_t id) 155 int64_t id)
231 { 156 {
232 std::list<std::string> j; 157 std::list<std::string> j;
233 158 index_->GetChildren(j, id);
234 switch (GetParam()) 159 ASSERT_EQ(2u, j.size());
235 { 160 ASSERT_TRUE((expected1 == j.front() && expected2 == j.back()) ||
236 case DatabaseWrapperClass_SQLite: 161 (expected1 == j.back() && expected2 == j.front()));
237 { 162 }
238 SQLiteDatabaseWrapper* sqlite = dynamic_cast<SQLiteDatabaseWrapper*>(index_.get());
239 sqlite->GetChildren(j, id);
240 ASSERT_EQ(2u, j.size());
241 ASSERT_TRUE((expected1 == j.front() && expected2 == j.back()) ||
242 (expected1 == j.back() && expected2 == j.front()));
243 break;
244 }
245
246 default:
247 throw OrthancException(ErrorCode_InternalError);
248 }
249 }
250
251 163
252 void DoLookupIdentifier(std::list<std::string>& result, 164 void DoLookupIdentifier(std::list<std::string>& result,
253 ResourceType level, 165 ResourceType level,
254 const DicomTag& tag, 166 const DicomTag& tag,
255 ConstraintType type, 167 ConstraintType type,
261 173
262 std::vector<DatabaseConstraint> lookup; 174 std::vector<DatabaseConstraint> lookup;
263 lookup.push_back(c.ConvertToDatabaseConstraint(level, DicomTagType_Identifier)); 175 lookup.push_back(c.ConvertToDatabaseConstraint(level, DicomTagType_Identifier));
264 176
265 index_->ApplyLookupResources(result, NULL, lookup, level, 0 /* no limit */); 177 index_->ApplyLookupResources(result, NULL, lookup, level, 0 /* no limit */);
266 } 178 }
267
268 179
269 void DoLookupIdentifier2(std::list<std::string>& result, 180 void DoLookupIdentifier2(std::list<std::string>& result,
270 ResourceType level, 181 ResourceType level,
271 const DicomTag& tag, 182 const DicomTag& tag,
272 ConstraintType type1, 183 ConstraintType type1,
287 } 198 }
288 }; 199 };
289 } 200 }
290 201
291 202
292 INSTANTIATE_TEST_CASE_P(DatabaseWrapperName, 203 TEST_F(DatabaseWrapperTest, Simple)
293 DatabaseWrapperTest,
294 ::testing::Values(DatabaseWrapperClass_SQLite));
295
296
297 TEST_P(DatabaseWrapperTest, Simple)
298 { 204 {
299 int64_t a[] = { 205 int64_t a[] = {
300 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).CreateResource("a", ResourceType_Patient), // 0 206 index_->CreateResource("a", ResourceType_Patient), // 0
301 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).CreateResource("b", ResourceType_Study), // 1 207 index_->CreateResource("b", ResourceType_Study), // 1
302 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).CreateResource("c", ResourceType_Series), // 2 208 index_->CreateResource("c", ResourceType_Series), // 2
303 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).CreateResource("d", ResourceType_Instance), // 3 209 index_->CreateResource("d", ResourceType_Instance), // 3
304 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).CreateResource("e", ResourceType_Instance), // 4 210 index_->CreateResource("e", ResourceType_Instance), // 4
305 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).CreateResource("f", ResourceType_Instance), // 5 211 index_->CreateResource("f", ResourceType_Instance), // 5
306 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).CreateResource("g", ResourceType_Study) // 6 212 index_->CreateResource("g", ResourceType_Study) // 6
307 }; 213 };
308 214
309 ASSERT_EQ("a", dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetPublicId(a[0])); 215 ASSERT_EQ("a", index_->GetPublicId(a[0]));
310 ASSERT_EQ("b", dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetPublicId(a[1])); 216 ASSERT_EQ("b", index_->GetPublicId(a[1]));
311 ASSERT_EQ("c", dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetPublicId(a[2])); 217 ASSERT_EQ("c", index_->GetPublicId(a[2]));
312 ASSERT_EQ("d", dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetPublicId(a[3])); 218 ASSERT_EQ("d", index_->GetPublicId(a[3]));
313 ASSERT_EQ("e", dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetPublicId(a[4])); 219 ASSERT_EQ("e", index_->GetPublicId(a[4]));
314 ASSERT_EQ("f", dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetPublicId(a[5])); 220 ASSERT_EQ("f", index_->GetPublicId(a[5]));
315 ASSERT_EQ("g", dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetPublicId(a[6])); 221 ASSERT_EQ("g", index_->GetPublicId(a[6]));
316 222
317 ASSERT_EQ(ResourceType_Patient, dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetResourceType(a[0])); 223 ASSERT_EQ(ResourceType_Patient, index_->GetResourceType(a[0]));
318 ASSERT_EQ(ResourceType_Study, dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetResourceType(a[1])); 224 ASSERT_EQ(ResourceType_Study, index_->GetResourceType(a[1]));
319 ASSERT_EQ(ResourceType_Series, dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetResourceType(a[2])); 225 ASSERT_EQ(ResourceType_Series, index_->GetResourceType(a[2]));
320 ASSERT_EQ(ResourceType_Instance, dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetResourceType(a[3])); 226 ASSERT_EQ(ResourceType_Instance, index_->GetResourceType(a[3]));
321 ASSERT_EQ(ResourceType_Instance, dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetResourceType(a[4])); 227 ASSERT_EQ(ResourceType_Instance, index_->GetResourceType(a[4]));
322 ASSERT_EQ(ResourceType_Instance, dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetResourceType(a[5])); 228 ASSERT_EQ(ResourceType_Instance, index_->GetResourceType(a[5]));
323 ASSERT_EQ(ResourceType_Study, dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetResourceType(a[6])); 229 ASSERT_EQ(ResourceType_Study, index_->GetResourceType(a[6]));
324 230
325 { 231 {
326 std::list<std::string> t; 232 std::list<std::string> t;
327 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetAllPublicIds(t, ResourceType_Patient); 233 index_->GetAllPublicIds(t, ResourceType_Patient);
328 234
329 ASSERT_EQ(1u, t.size()); 235 ASSERT_EQ(1u, t.size());
330 ASSERT_EQ("a", t.front()); 236 ASSERT_EQ("a", t.front());
331 237
332 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetAllPublicIds(t, ResourceType_Series); 238 index_->GetAllPublicIds(t, ResourceType_Series);
333 ASSERT_EQ(1u, t.size()); 239 ASSERT_EQ(1u, t.size());
334 ASSERT_EQ("c", t.front()); 240 ASSERT_EQ("c", t.front());
335 241
336 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetAllPublicIds(t, ResourceType_Study); 242 index_->GetAllPublicIds(t, ResourceType_Study);
337 ASSERT_EQ(2u, t.size()); 243 ASSERT_EQ(2u, t.size());
338 244
339 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetAllPublicIds(t, ResourceType_Instance); 245 index_->GetAllPublicIds(t, ResourceType_Instance);
340 ASSERT_EQ(3u, t.size()); 246 ASSERT_EQ(3u, t.size());
341 } 247 }
342 248
343 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SetGlobalProperty(GlobalProperty_FlushSleep, "World"); 249 index_->SetGlobalProperty(GlobalProperty_FlushSleep, "World");
344 250
345 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).AttachChild(a[0], a[1]); 251 index_->AttachChild(a[0], a[1]);
346 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).AttachChild(a[1], a[2]); 252 index_->AttachChild(a[1], a[2]);
347 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).AttachChild(a[2], a[3]); 253 index_->AttachChild(a[2], a[3]);
348 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).AttachChild(a[2], a[4]); 254 index_->AttachChild(a[2], a[4]);
349 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).AttachChild(a[6], a[5]); 255 index_->AttachChild(a[6], a[5]);
350 256
351 int64_t parent; 257 int64_t parent;
352 ASSERT_FALSE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).LookupParent(parent, a[0])); 258 ASSERT_FALSE(index_->LookupParent(parent, a[0]));
353 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).LookupParent(parent, a[1])); ASSERT_EQ(a[0], parent); 259 ASSERT_TRUE(index_->LookupParent(parent, a[1])); ASSERT_EQ(a[0], parent);
354 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).LookupParent(parent, a[2])); ASSERT_EQ(a[1], parent); 260 ASSERT_TRUE(index_->LookupParent(parent, a[2])); ASSERT_EQ(a[1], parent);
355 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).LookupParent(parent, a[3])); ASSERT_EQ(a[2], parent); 261 ASSERT_TRUE(index_->LookupParent(parent, a[3])); ASSERT_EQ(a[2], parent);
356 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).LookupParent(parent, a[4])); ASSERT_EQ(a[2], parent); 262 ASSERT_TRUE(index_->LookupParent(parent, a[4])); ASSERT_EQ(a[2], parent);
357 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).LookupParent(parent, a[5])); ASSERT_EQ(a[6], parent); 263 ASSERT_TRUE(index_->LookupParent(parent, a[5])); ASSERT_EQ(a[6], parent);
358 ASSERT_FALSE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).LookupParent(parent, a[6])); 264 ASSERT_FALSE(index_->LookupParent(parent, a[6]));
359 265
360 std::string s; 266 std::string s;
361 267
362 CheckNoParent(a[0]); 268 CheckNoParent(a[0]);
363 CheckNoParent(a[6]); 269 CheckNoParent(a[6]);
366 CheckParentPublicId("c", a[3]); 272 CheckParentPublicId("c", a[3]);
367 CheckParentPublicId("c", a[4]); 273 CheckParentPublicId("c", a[4]);
368 CheckParentPublicId("g", a[5]); 274 CheckParentPublicId("g", a[5]);
369 275
370 std::list<std::string> l; 276 std::list<std::string> l;
371 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetChildrenPublicId(l, a[0]); ASSERT_EQ(1u, l.size()); ASSERT_EQ("b", l.front()); 277 index_->GetChildrenPublicId(l, a[0]); ASSERT_EQ(1u, l.size()); ASSERT_EQ("b", l.front());
372 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetChildrenPublicId(l, a[1]); ASSERT_EQ(1u, l.size()); ASSERT_EQ("c", l.front()); 278 index_->GetChildrenPublicId(l, a[1]); ASSERT_EQ(1u, l.size()); ASSERT_EQ("c", l.front());
373 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetChildrenPublicId(l, a[3]); ASSERT_EQ(0u, l.size()); 279 index_->GetChildrenPublicId(l, a[3]); ASSERT_EQ(0u, l.size());
374 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetChildrenPublicId(l, a[4]); ASSERT_EQ(0u, l.size()); 280 index_->GetChildrenPublicId(l, a[4]); ASSERT_EQ(0u, l.size());
375 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetChildrenPublicId(l, a[5]); ASSERT_EQ(0u, l.size()); 281 index_->GetChildrenPublicId(l, a[5]); ASSERT_EQ(0u, l.size());
376 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetChildrenPublicId(l, a[6]); ASSERT_EQ(1u, l.size()); ASSERT_EQ("f", l.front()); 282 index_->GetChildrenPublicId(l, a[6]); ASSERT_EQ(1u, l.size()); ASSERT_EQ("f", l.front());
377 283
378 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetChildrenPublicId(l, a[2]); ASSERT_EQ(2u, l.size()); 284 index_->GetChildrenPublicId(l, a[2]); ASSERT_EQ(2u, l.size());
379 if (l.front() == "d") 285 if (l.front() == "d")
380 { 286 {
381 ASSERT_EQ("e", l.back()); 287 ASSERT_EQ("e", l.back());
382 } 288 }
383 else 289 else
385 ASSERT_EQ("d", l.back()); 291 ASSERT_EQ("d", l.back());
386 ASSERT_EQ("e", l.front()); 292 ASSERT_EQ("e", l.front());
387 } 293 }
388 294
389 std::list<MetadataType> md; 295 std::list<MetadataType> md;
390 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).ListAvailableMetadata(md, a[4]); 296 index_->ListAvailableMetadata(md, a[4]);
391 ASSERT_EQ(0u, md.size()); 297 ASSERT_EQ(0u, md.size());
392 298
393 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).AddAttachment(a[4], FileInfo("my json file", FileContentType_DicomAsJson, 42, "md5", 299 index_->AddAttachment(a[4], FileInfo("my json file", FileContentType_DicomAsJson, 42, "md5",
394 CompressionType_ZlibWithSize, 21, "compressedMD5")); 300 CompressionType_ZlibWithSize, 21, "compressedMD5"));
395 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).AddAttachment(a[4], FileInfo("my dicom file", FileContentType_Dicom, 42, "md5")); 301 index_->AddAttachment(a[4], FileInfo("my dicom file", FileContentType_Dicom, 42, "md5"));
396 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).AddAttachment(a[6], FileInfo("world", FileContentType_Dicom, 44, "md5")); 302 index_->AddAttachment(a[6], FileInfo("world", FileContentType_Dicom, 44, "md5"));
397 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SetMetadata(a[4], MetadataType_Instance_RemoteAet, "PINNACLE"); 303 index_->SetMetadata(a[4], MetadataType_Instance_RemoteAet, "PINNACLE");
398 304
399 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).ListAvailableMetadata(md, a[4]); 305 index_->ListAvailableMetadata(md, a[4]);
400 ASSERT_EQ(1u, md.size()); 306 ASSERT_EQ(1u, md.size());
401 ASSERT_EQ(MetadataType_Instance_RemoteAet, md.front()); 307 ASSERT_EQ(MetadataType_Instance_RemoteAet, md.front());
402 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SetMetadata(a[4], MetadataType_ModifiedFrom, "TUTU"); 308 index_->SetMetadata(a[4], MetadataType_ModifiedFrom, "TUTU");
403 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).ListAvailableMetadata(md, a[4]); 309 index_->ListAvailableMetadata(md, a[4]);
404 ASSERT_EQ(2u, md.size()); 310 ASSERT_EQ(2u, md.size());
405 311
406 std::map<MetadataType, std::string> md2; 312 std::map<MetadataType, std::string> md2;
407 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetAllMetadata(md2, a[4]); 313 index_->GetAllMetadata(md2, a[4]);
408 ASSERT_EQ(2u, md2.size()); 314 ASSERT_EQ(2u, md2.size());
409 ASSERT_EQ("TUTU", md2[MetadataType_ModifiedFrom]); 315 ASSERT_EQ("TUTU", md2[MetadataType_ModifiedFrom]);
410 ASSERT_EQ("PINNACLE", md2[MetadataType_Instance_RemoteAet]); 316 ASSERT_EQ("PINNACLE", md2[MetadataType_Instance_RemoteAet]);
411 317
412 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteMetadata(a[4], MetadataType_ModifiedFrom); 318 index_->DeleteMetadata(a[4], MetadataType_ModifiedFrom);
413 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).ListAvailableMetadata(md, a[4]); 319 index_->ListAvailableMetadata(md, a[4]);
414 ASSERT_EQ(1u, md.size()); 320 ASSERT_EQ(1u, md.size());
415 ASSERT_EQ(MetadataType_Instance_RemoteAet, md.front()); 321 ASSERT_EQ(MetadataType_Instance_RemoteAet, md.front());
416 322
417 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetAllMetadata(md2, a[4]); 323 index_->GetAllMetadata(md2, a[4]);
418 ASSERT_EQ(1u, md2.size()); 324 ASSERT_EQ(1u, md2.size());
419 ASSERT_EQ("PINNACLE", md2[MetadataType_Instance_RemoteAet]); 325 ASSERT_EQ("PINNACLE", md2[MetadataType_Instance_RemoteAet]);
420 326
421 327
422 ASSERT_EQ(21u + 42u + 44u, dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetTotalCompressedSize()); 328 ASSERT_EQ(21u + 42u + 44u, index_->GetTotalCompressedSize());
423 ASSERT_EQ(42u + 42u + 44u, dynamic_cast<SQLiteDatabaseWrapper&>(*index_).GetTotalUncompressedSize()); 329 ASSERT_EQ(42u + 42u + 44u, index_->GetTotalUncompressedSize());
424 330
425 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SetMainDicomTag(a[3], DicomTag(0x0010, 0x0010), "PatientName"); 331 index_->SetMainDicomTag(a[3], DicomTag(0x0010, 0x0010), "PatientName");
426 332
427 int64_t b; 333 int64_t b;
428 ResourceType t; 334 ResourceType t;
429 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).LookupResource(b, t, "g")); 335 ASSERT_TRUE(index_->LookupResource(b, t, "g"));
430 ASSERT_EQ(7, b); 336 ASSERT_EQ(7, b);
431 ASSERT_EQ(ResourceType_Study, t); 337 ASSERT_EQ(ResourceType_Study, t);
432 338
433 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).LookupMetadata(s, a[4], MetadataType_Instance_RemoteAet)); 339 ASSERT_TRUE(index_->LookupMetadata(s, a[4], MetadataType_Instance_RemoteAet));
434 ASSERT_FALSE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).LookupMetadata(s, a[4], MetadataType_Instance_IndexInSeries)); 340 ASSERT_FALSE(index_->LookupMetadata(s, a[4], MetadataType_Instance_IndexInSeries));
435 ASSERT_EQ("PINNACLE", s); 341 ASSERT_EQ("PINNACLE", s);
436 342
437 std::string u; 343 std::string u;
438 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).LookupMetadata(u, a[4], MetadataType_Instance_RemoteAet)); 344 ASSERT_TRUE(index_->LookupMetadata(u, a[4], MetadataType_Instance_RemoteAet));
439 ASSERT_EQ("PINNACLE", u); 345 ASSERT_EQ("PINNACLE", u);
440 ASSERT_FALSE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).LookupMetadata(u, a[4], MetadataType_Instance_IndexInSeries)); 346 ASSERT_FALSE(index_->LookupMetadata(u, a[4], MetadataType_Instance_IndexInSeries));
441 347
442 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).LookupGlobalProperty(s, GlobalProperty_FlushSleep)); 348 ASSERT_TRUE(index_->LookupGlobalProperty(s, GlobalProperty_FlushSleep));
443 ASSERT_FALSE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).LookupGlobalProperty(s, static_cast<GlobalProperty>(42))); 349 ASSERT_FALSE(index_->LookupGlobalProperty(s, static_cast<GlobalProperty>(42)));
444 ASSERT_EQ("World", s); 350 ASSERT_EQ("World", s);
445 351
446 FileInfo att; 352 FileInfo att;
447 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).LookupAttachment(att, a[4], FileContentType_DicomAsJson)); 353 ASSERT_TRUE(index_->LookupAttachment(att, a[4], FileContentType_DicomAsJson));
448 ASSERT_EQ("my json file", att.GetUuid()); 354 ASSERT_EQ("my json file", att.GetUuid());
449 ASSERT_EQ(21u, att.GetCompressedSize()); 355 ASSERT_EQ(21u, att.GetCompressedSize());
450 ASSERT_EQ("md5", att.GetUncompressedMD5()); 356 ASSERT_EQ("md5", att.GetUncompressedMD5());
451 ASSERT_EQ("compressedMD5", att.GetCompressedMD5()); 357 ASSERT_EQ("compressedMD5", att.GetCompressedMD5());
452 ASSERT_EQ(42u, att.GetUncompressedSize()); 358 ASSERT_EQ(42u, att.GetUncompressedSize());
453 ASSERT_EQ(CompressionType_ZlibWithSize, att.GetCompressionType()); 359 ASSERT_EQ(CompressionType_ZlibWithSize, att.GetCompressionType());
454 360
455 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).LookupAttachment(att, a[6], FileContentType_Dicom)); 361 ASSERT_TRUE(index_->LookupAttachment(att, a[6], FileContentType_Dicom));
456 ASSERT_EQ("world", att.GetUuid()); 362 ASSERT_EQ("world", att.GetUuid());
457 ASSERT_EQ(44u, att.GetCompressedSize()); 363 ASSERT_EQ(44u, att.GetCompressedSize());
458 ASSERT_EQ("md5", att.GetUncompressedMD5()); 364 ASSERT_EQ("md5", att.GetUncompressedMD5());
459 ASSERT_EQ("md5", att.GetCompressedMD5()); 365 ASSERT_EQ("md5", att.GetCompressedMD5());
460 ASSERT_EQ(44u, att.GetUncompressedSize()); 366 ASSERT_EQ(44u, att.GetUncompressedSize());
466 CheckTableRecordCount(7, "Resources"); 372 CheckTableRecordCount(7, "Resources");
467 CheckTableRecordCount(3, "AttachedFiles"); 373 CheckTableRecordCount(3, "AttachedFiles");
468 CheckTableRecordCount(1, "Metadata"); 374 CheckTableRecordCount(1, "Metadata");
469 CheckTableRecordCount(1, "MainDicomTags"); 375 CheckTableRecordCount(1, "MainDicomTags");
470 376
471 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteResource(a[0]); 377 index_->DeleteResource(a[0]);
472 ASSERT_EQ(5u, listener_->deletedResources_.size()); 378 ASSERT_EQ(5u, listener_->deletedResources_.size());
473 ASSERT_EQ(2u, listener_->deletedFiles_.size()); 379 ASSERT_EQ(2u, listener_->deletedFiles_.size());
474 ASSERT_FALSE(std::find(listener_->deletedFiles_.begin(), 380 ASSERT_FALSE(std::find(listener_->deletedFiles_.begin(),
475 listener_->deletedFiles_.end(), 381 listener_->deletedFiles_.end(),
476 "my json file") == listener_->deletedFiles_.end()); 382 "my json file") == listener_->deletedFiles_.end());
481 CheckTableRecordCount(2, "Resources"); 387 CheckTableRecordCount(2, "Resources");
482 CheckTableRecordCount(0, "Metadata"); 388 CheckTableRecordCount(0, "Metadata");
483 CheckTableRecordCount(1, "AttachedFiles"); 389 CheckTableRecordCount(1, "AttachedFiles");
484 CheckTableRecordCount(0, "MainDicomTags"); 390 CheckTableRecordCount(0, "MainDicomTags");
485 391
486 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteResource(a[5]); 392 index_->DeleteResource(a[5]);
487 ASSERT_EQ(7u, listener_->deletedResources_.size()); 393 ASSERT_EQ(7u, listener_->deletedResources_.size());
488 394
489 CheckTableRecordCount(0, "Resources"); 395 CheckTableRecordCount(0, "Resources");
490 CheckTableRecordCount(0, "AttachedFiles"); 396 CheckTableRecordCount(0, "AttachedFiles");
491 CheckTableRecordCount(3, "GlobalProperties"); 397 CheckTableRecordCount(3, "GlobalProperties");
492 398
493 std::string tmp; 399 std::string tmp;
494 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).LookupGlobalProperty(tmp, GlobalProperty_DatabaseSchemaVersion)); 400 ASSERT_TRUE(index_->LookupGlobalProperty(tmp, GlobalProperty_DatabaseSchemaVersion));
495 ASSERT_EQ("6", tmp); 401 ASSERT_EQ("6", tmp);
496 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).LookupGlobalProperty(tmp, GlobalProperty_FlushSleep)); 402 ASSERT_TRUE(index_->LookupGlobalProperty(tmp, GlobalProperty_FlushSleep));
497 ASSERT_EQ("World", tmp); 403 ASSERT_EQ("World", tmp);
498 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).LookupGlobalProperty(tmp, GlobalProperty_GetTotalSizeIsFast)); 404 ASSERT_TRUE(index_->LookupGlobalProperty(tmp, GlobalProperty_GetTotalSizeIsFast));
499 ASSERT_EQ("1", tmp); 405 ASSERT_EQ("1", tmp);
500 406
501 ASSERT_EQ(3u, listener_->deletedFiles_.size()); 407 ASSERT_EQ(3u, listener_->deletedFiles_.size());
502 ASSERT_FALSE(std::find(listener_->deletedFiles_.begin(), 408 ASSERT_FALSE(std::find(listener_->deletedFiles_.begin(),
503 listener_->deletedFiles_.end(), 409 listener_->deletedFiles_.end(),
504 "world") == listener_->deletedFiles_.end()); 410 "world") == listener_->deletedFiles_.end());
505 } 411 }
506 412
507 413
508 414 TEST_F(DatabaseWrapperTest, Upward)
509
510 TEST_P(DatabaseWrapperTest, Upward)
511 { 415 {
512 int64_t a[] = { 416 int64_t a[] = {
513 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).CreateResource("a", ResourceType_Patient), // 0 417 index_->CreateResource("a", ResourceType_Patient), // 0
514 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).CreateResource("b", ResourceType_Study), // 1 418 index_->CreateResource("b", ResourceType_Study), // 1
515 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).CreateResource("c", ResourceType_Series), // 2 419 index_->CreateResource("c", ResourceType_Series), // 2
516 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).CreateResource("d", ResourceType_Instance), // 3 420 index_->CreateResource("d", ResourceType_Instance), // 3
517 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).CreateResource("e", ResourceType_Instance), // 4 421 index_->CreateResource("e", ResourceType_Instance), // 4
518 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).CreateResource("f", ResourceType_Study), // 5 422 index_->CreateResource("f", ResourceType_Study), // 5
519 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).CreateResource("g", ResourceType_Series), // 6 423 index_->CreateResource("g", ResourceType_Series), // 6
520 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).CreateResource("h", ResourceType_Series) // 7 424 index_->CreateResource("h", ResourceType_Series) // 7
521 }; 425 };
522 426
523 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).AttachChild(a[0], a[1]); 427 index_->AttachChild(a[0], a[1]);
524 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).AttachChild(a[1], a[2]); 428 index_->AttachChild(a[1], a[2]);
525 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).AttachChild(a[2], a[3]); 429 index_->AttachChild(a[2], a[3]);
526 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).AttachChild(a[2], a[4]); 430 index_->AttachChild(a[2], a[4]);
527 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).AttachChild(a[1], a[6]); 431 index_->AttachChild(a[1], a[6]);
528 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).AttachChild(a[0], a[5]); 432 index_->AttachChild(a[0], a[5]);
529 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).AttachChild(a[5], a[7]); 433 index_->AttachChild(a[5], a[7]);
530 434
531 CheckTwoChildren("b", "f", a[0]); 435 CheckTwoChildren("b", "f", a[0]);
532 CheckTwoChildren("c", "g", a[1]); 436 CheckTwoChildren("c", "g", a[1]);
533 CheckTwoChildren("d", "e", a[2]); 437 CheckTwoChildren("d", "e", a[2]);
534 CheckNoChild(a[3]); 438 CheckNoChild(a[3]);
536 CheckOneChild("h", a[5]); 440 CheckOneChild("h", a[5]);
537 CheckNoChild(a[6]); 441 CheckNoChild(a[6]);
538 CheckNoChild(a[7]); 442 CheckNoChild(a[7]);
539 443
540 listener_->Reset(); 444 listener_->Reset();
541 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteResource(a[3]); 445 index_->DeleteResource(a[3]);
542 ASSERT_EQ("c", listener_->ancestorId_); 446 ASSERT_EQ("c", listener_->ancestorId_);
543 ASSERT_EQ(ResourceType_Series, listener_->ancestorType_); 447 ASSERT_EQ(ResourceType_Series, listener_->ancestorType_);
544 448
545 listener_->Reset(); 449 listener_->Reset();
546 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteResource(a[4]); 450 index_->DeleteResource(a[4]);
547 ASSERT_EQ("b", listener_->ancestorId_); 451 ASSERT_EQ("b", listener_->ancestorId_);
548 ASSERT_EQ(ResourceType_Study, listener_->ancestorType_); 452 ASSERT_EQ(ResourceType_Study, listener_->ancestorType_);
549 453
550 listener_->Reset(); 454 listener_->Reset();
551 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteResource(a[7]); 455 index_->DeleteResource(a[7]);
552 ASSERT_EQ("a", listener_->ancestorId_); 456 ASSERT_EQ("a", listener_->ancestorId_);
553 ASSERT_EQ(ResourceType_Patient, listener_->ancestorType_); 457 ASSERT_EQ(ResourceType_Patient, listener_->ancestorType_);
554 458
555 listener_->Reset(); 459 listener_->Reset();
556 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteResource(a[6]); 460 index_->DeleteResource(a[6]);
557 ASSERT_EQ("", listener_->ancestorId_); // No more ancestor 461 ASSERT_EQ("", listener_->ancestorId_); // No more ancestor
558 } 462 }
559 463
560 464
561 TEST_P(DatabaseWrapperTest, PatientRecycling) 465 TEST_F(DatabaseWrapperTest, PatientRecycling)
562 { 466 {
563 std::vector<int64_t> patients; 467 std::vector<int64_t> patients;
564 for (int i = 0; i < 10; i++) 468 for (int i = 0; i < 10; i++)
565 { 469 {
566 std::string p = "Patient " + boost::lexical_cast<std::string>(i); 470 std::string p = "Patient " + boost::lexical_cast<std::string>(i);
567 patients.push_back(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).CreateResource(p, ResourceType_Patient)); 471 patients.push_back(index_->CreateResource(p, ResourceType_Patient));
568 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).AddAttachment(patients[i], FileInfo(p, FileContentType_Dicom, i + 10, 472 index_->AddAttachment(patients[i], FileInfo(p, FileContentType_Dicom, i + 10,
569 "md5-" + boost::lexical_cast<std::string>(i))); 473 "md5-" + boost::lexical_cast<std::string>(i)));
570 ASSERT_FALSE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).IsProtectedPatient(patients[i])); 474 ASSERT_FALSE(index_->IsProtectedPatient(patients[i]));
571 } 475 }
572 476
573 CheckTableRecordCount(10u, "Resources"); 477 CheckTableRecordCount(10u, "Resources");
574 CheckTableRecordCount(10u, "PatientRecyclingOrder"); 478 CheckTableRecordCount(10u, "PatientRecyclingOrder");
575 479
576 listener_->Reset(); 480 listener_->Reset();
577 ASSERT_EQ(0u, listener_->deletedResources_.size()); 481 ASSERT_EQ(0u, listener_->deletedResources_.size());
578 482
579 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteResource(patients[5]); 483 index_->DeleteResource(patients[5]);
580 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteResource(patients[0]); 484 index_->DeleteResource(patients[0]);
581 ASSERT_EQ(2u, listener_->deletedResources_.size()); 485 ASSERT_EQ(2u, listener_->deletedResources_.size());
582 486
583 CheckTableRecordCount(8u, "Resources"); 487 CheckTableRecordCount(8u, "Resources");
584 CheckTableRecordCount(8u, "PatientRecyclingOrder"); 488 CheckTableRecordCount(8u, "PatientRecyclingOrder");
585 489
586 ASSERT_EQ(2u, listener_->deletedFiles_.size()); 490 ASSERT_EQ(2u, listener_->deletedFiles_.size());
587 ASSERT_EQ("Patient 5", listener_->deletedFiles_[0]); 491 ASSERT_EQ("Patient 5", listener_->deletedFiles_[0]);
588 ASSERT_EQ("Patient 0", listener_->deletedFiles_[1]); 492 ASSERT_EQ("Patient 0", listener_->deletedFiles_[1]);
589 493
590 int64_t p; 494 int64_t p;
591 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[1]); 495 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[1]);
592 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteResource(p); 496 index_->DeleteResource(p);
593 ASSERT_EQ(3u, listener_->deletedResources_.size()); 497 ASSERT_EQ(3u, listener_->deletedResources_.size());
594 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[2]); 498 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[2]);
595 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteResource(p); 499 index_->DeleteResource(p);
596 ASSERT_EQ(4u, listener_->deletedResources_.size()); 500 ASSERT_EQ(4u, listener_->deletedResources_.size());
597 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[3]); 501 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[3]);
598 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteResource(p); 502 index_->DeleteResource(p);
599 ASSERT_EQ(5u, listener_->deletedResources_.size()); 503 ASSERT_EQ(5u, listener_->deletedResources_.size());
600 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[4]); 504 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[4]);
601 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteResource(p); 505 index_->DeleteResource(p);
602 ASSERT_EQ(6u, listener_->deletedResources_.size()); 506 ASSERT_EQ(6u, listener_->deletedResources_.size());
603 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[6]); 507 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[6]);
604 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteResource(p); 508 index_->DeleteResource(p);
605 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteResource(patients[8]); 509 index_->DeleteResource(patients[8]);
606 ASSERT_EQ(8u, listener_->deletedResources_.size()); 510 ASSERT_EQ(8u, listener_->deletedResources_.size());
607 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[7]); 511 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[7]);
608 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteResource(p); 512 index_->DeleteResource(p);
609 ASSERT_EQ(9u, listener_->deletedResources_.size()); 513 ASSERT_EQ(9u, listener_->deletedResources_.size());
610 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[9]); 514 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[9]);
611 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteResource(p); 515 index_->DeleteResource(p);
612 ASSERT_FALSE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SelectPatientToRecycle(p)); 516 ASSERT_FALSE(index_->SelectPatientToRecycle(p));
613 ASSERT_EQ(10u, listener_->deletedResources_.size()); 517 ASSERT_EQ(10u, listener_->deletedResources_.size());
614 518
615 ASSERT_EQ(10u, listener_->deletedFiles_.size()); 519 ASSERT_EQ(10u, listener_->deletedFiles_.size());
616 520
617 CheckTableRecordCount(0, "Resources"); 521 CheckTableRecordCount(0, "Resources");
618 CheckTableRecordCount(0, "PatientRecyclingOrder"); 522 CheckTableRecordCount(0, "PatientRecyclingOrder");
619 } 523 }
620 524
621 525
622 TEST_P(DatabaseWrapperTest, PatientProtection) 526 TEST_F(DatabaseWrapperTest, PatientProtection)
623 { 527 {
624 std::vector<int64_t> patients; 528 std::vector<int64_t> patients;
625 for (int i = 0; i < 5; i++) 529 for (int i = 0; i < 5; i++)
626 { 530 {
627 std::string p = "Patient " + boost::lexical_cast<std::string>(i); 531 std::string p = "Patient " + boost::lexical_cast<std::string>(i);
628 patients.push_back(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).CreateResource(p, ResourceType_Patient)); 532 patients.push_back(index_->CreateResource(p, ResourceType_Patient));
629 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).AddAttachment(patients[i], FileInfo(p, FileContentType_Dicom, i + 10, 533 index_->AddAttachment(patients[i], FileInfo(p, FileContentType_Dicom, i + 10,
630 "md5-" + boost::lexical_cast<std::string>(i))); 534 "md5-" + boost::lexical_cast<std::string>(i)));
631 ASSERT_FALSE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).IsProtectedPatient(patients[i])); 535 ASSERT_FALSE(index_->IsProtectedPatient(patients[i]));
632 } 536 }
633 537
634 CheckTableRecordCount(5, "Resources"); 538 CheckTableRecordCount(5, "Resources");
635 CheckTableRecordCount(5, "PatientRecyclingOrder"); 539 CheckTableRecordCount(5, "PatientRecyclingOrder");
636 540
637 ASSERT_FALSE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).IsProtectedPatient(patients[2])); 541 ASSERT_FALSE(index_->IsProtectedPatient(patients[2]));
638 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SetProtectedPatient(patients[2], true); 542 index_->SetProtectedPatient(patients[2], true);
639 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).IsProtectedPatient(patients[2])); 543 ASSERT_TRUE(index_->IsProtectedPatient(patients[2]));
640 CheckTableRecordCount(5, "Resources"); 544 CheckTableRecordCount(5, "Resources");
641 CheckTableRecordCount(4, "PatientRecyclingOrder"); 545 CheckTableRecordCount(4, "PatientRecyclingOrder");
642 546
643 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SetProtectedPatient(patients[2], true); 547 index_->SetProtectedPatient(patients[2], true);
644 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).IsProtectedPatient(patients[2])); 548 ASSERT_TRUE(index_->IsProtectedPatient(patients[2]));
645 CheckTableRecordCount(4, "PatientRecyclingOrder"); 549 CheckTableRecordCount(4, "PatientRecyclingOrder");
646 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SetProtectedPatient(patients[2], false); 550 index_->SetProtectedPatient(patients[2], false);
647 ASSERT_FALSE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).IsProtectedPatient(patients[2])); 551 ASSERT_FALSE(index_->IsProtectedPatient(patients[2]));
648 CheckTableRecordCount(5, "PatientRecyclingOrder"); 552 CheckTableRecordCount(5, "PatientRecyclingOrder");
649 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SetProtectedPatient(patients[2], false); 553 index_->SetProtectedPatient(patients[2], false);
650 ASSERT_FALSE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).IsProtectedPatient(patients[2])); 554 ASSERT_FALSE(index_->IsProtectedPatient(patients[2]));
651 CheckTableRecordCount(5, "PatientRecyclingOrder"); 555 CheckTableRecordCount(5, "PatientRecyclingOrder");
652 CheckTableRecordCount(5, "Resources"); 556 CheckTableRecordCount(5, "Resources");
653 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SetProtectedPatient(patients[2], true); 557 index_->SetProtectedPatient(patients[2], true);
654 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).IsProtectedPatient(patients[2])); 558 ASSERT_TRUE(index_->IsProtectedPatient(patients[2]));
655 CheckTableRecordCount(4, "PatientRecyclingOrder"); 559 CheckTableRecordCount(4, "PatientRecyclingOrder");
656 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SetProtectedPatient(patients[2], false); 560 index_->SetProtectedPatient(patients[2], false);
657 ASSERT_FALSE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).IsProtectedPatient(patients[2])); 561 ASSERT_FALSE(index_->IsProtectedPatient(patients[2]));
658 CheckTableRecordCount(5, "PatientRecyclingOrder"); 562 CheckTableRecordCount(5, "PatientRecyclingOrder");
659 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SetProtectedPatient(patients[3], true); 563 index_->SetProtectedPatient(patients[3], true);
660 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).IsProtectedPatient(patients[3])); 564 ASSERT_TRUE(index_->IsProtectedPatient(patients[3]));
661 CheckTableRecordCount(4, "PatientRecyclingOrder"); 565 CheckTableRecordCount(4, "PatientRecyclingOrder");
662 566
663 CheckTableRecordCount(5, "Resources"); 567 CheckTableRecordCount(5, "Resources");
664 ASSERT_EQ(0u, listener_->deletedFiles_.size()); 568 ASSERT_EQ(0u, listener_->deletedFiles_.size());
665 569
666 // Unprotecting a patient puts it at the last position in the recycling queue 570 // Unprotecting a patient puts it at the last position in the recycling queue
667 int64_t p; 571 int64_t p;
668 ASSERT_EQ(0u, listener_->deletedResources_.size()); 572 ASSERT_EQ(0u, listener_->deletedResources_.size());
669 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[0]); 573 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[0]);
670 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteResource(p); 574 index_->DeleteResource(p);
671 ASSERT_EQ(1u, listener_->deletedResources_.size()); 575 ASSERT_EQ(1u, listener_->deletedResources_.size());
672 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SelectPatientToRecycle(p, patients[1])); ASSERT_EQ(p, patients[4]); 576 ASSERT_TRUE(index_->SelectPatientToRecycle(p, patients[1])); ASSERT_EQ(p, patients[4]);
673 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[1]); 577 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[1]);
674 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteResource(p); 578 index_->DeleteResource(p);
675 ASSERT_EQ(2u, listener_->deletedResources_.size()); 579 ASSERT_EQ(2u, listener_->deletedResources_.size());
676 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[4]); 580 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[4]);
677 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteResource(p); 581 index_->DeleteResource(p);
678 ASSERT_EQ(3u, listener_->deletedResources_.size()); 582 ASSERT_EQ(3u, listener_->deletedResources_.size());
679 ASSERT_FALSE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SelectPatientToRecycle(p, patients[2])); 583 ASSERT_FALSE(index_->SelectPatientToRecycle(p, patients[2]));
680 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[2]); 584 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[2]);
681 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteResource(p); 585 index_->DeleteResource(p);
682 ASSERT_EQ(4u, listener_->deletedResources_.size()); 586 ASSERT_EQ(4u, listener_->deletedResources_.size());
683 // "patients[3]" is still protected 587 // "patients[3]" is still protected
684 ASSERT_FALSE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SelectPatientToRecycle(p)); 588 ASSERT_FALSE(index_->SelectPatientToRecycle(p));
685 589
686 ASSERT_EQ(4u, listener_->deletedFiles_.size()); 590 ASSERT_EQ(4u, listener_->deletedFiles_.size());
687 CheckTableRecordCount(1, "Resources"); 591 CheckTableRecordCount(1, "Resources");
688 CheckTableRecordCount(0, "PatientRecyclingOrder"); 592 CheckTableRecordCount(0, "PatientRecyclingOrder");
689 593
690 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SetProtectedPatient(patients[3], false); 594 index_->SetProtectedPatient(patients[3], false);
691 CheckTableRecordCount(1, "PatientRecyclingOrder"); 595 CheckTableRecordCount(1, "PatientRecyclingOrder");
692 ASSERT_FALSE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SelectPatientToRecycle(p, patients[3])); 596 ASSERT_FALSE(index_->SelectPatientToRecycle(p, patients[3]));
693 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SelectPatientToRecycle(p, patients[2])); 597 ASSERT_TRUE(index_->SelectPatientToRecycle(p, patients[2]));
694 ASSERT_TRUE(dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[3]); 598 ASSERT_TRUE(index_->SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[3]);
695 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).DeleteResource(p); 599 index_->DeleteResource(p);
696 ASSERT_EQ(5u, listener_->deletedResources_.size()); 600 ASSERT_EQ(5u, listener_->deletedResources_.size());
697 601
698 ASSERT_EQ(5u, listener_->deletedFiles_.size()); 602 ASSERT_EQ(5u, listener_->deletedFiles_.size());
699 CheckTableRecordCount(0, "Resources"); 603 CheckTableRecordCount(0, "Resources");
700 CheckTableRecordCount(0, "PatientRecyclingOrder"); 604 CheckTableRecordCount(0, "PatientRecyclingOrder");
701 } 605 }
702
703 606
704 607
705 TEST(ServerIndex, Sequence) 608 TEST(ServerIndex, Sequence)
706 { 609 {
707 const std::string path = "UnitTestsStorage"; 610 const std::string path = "UnitTestsStorage";
723 context.Stop(); 626 context.Stop();
724 db.Close(); 627 db.Close();
725 } 628 }
726 629
727 630
728 631 TEST_F(DatabaseWrapperTest, LookupIdentifier)
729 TEST_P(DatabaseWrapperTest, LookupIdentifier)
730 { 632 {
731 int64_t a[] = { 633 int64_t a[] = {
732 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).CreateResource("a", ResourceType_Study), // 0 634 index_->CreateResource("a", ResourceType_Study), // 0
733 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).CreateResource("b", ResourceType_Study), // 1 635 index_->CreateResource("b", ResourceType_Study), // 1
734 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).CreateResource("c", ResourceType_Study), // 2 636 index_->CreateResource("c", ResourceType_Study), // 2
735 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).CreateResource("d", ResourceType_Series) // 3 637 index_->CreateResource("d", ResourceType_Series) // 3
736 }; 638 };
737 639
738 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SetIdentifierTag(a[0], DICOM_TAG_STUDY_INSTANCE_UID, "0"); 640 index_->SetIdentifierTag(a[0], DICOM_TAG_STUDY_INSTANCE_UID, "0");
739 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SetIdentifierTag(a[1], DICOM_TAG_STUDY_INSTANCE_UID, "1"); 641 index_->SetIdentifierTag(a[1], DICOM_TAG_STUDY_INSTANCE_UID, "1");
740 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SetIdentifierTag(a[2], DICOM_TAG_STUDY_INSTANCE_UID, "0"); 642 index_->SetIdentifierTag(a[2], DICOM_TAG_STUDY_INSTANCE_UID, "0");
741 dynamic_cast<SQLiteDatabaseWrapper&>(*index_).SetIdentifierTag(a[3], DICOM_TAG_SERIES_INSTANCE_UID, "0"); 643 index_->SetIdentifierTag(a[3], DICOM_TAG_SERIES_INSTANCE_UID, "0");
742 644
743 std::list<std::string> s; 645 std::list<std::string> s;
744 646
745 DoLookupIdentifier(s, ResourceType_Study, DICOM_TAG_STUDY_INSTANCE_UID, ConstraintType_Equal, "0"); 647 DoLookupIdentifier(s, ResourceType_Study, DICOM_TAG_STUDY_INSTANCE_UID, ConstraintType_Equal, "0");
746 ASSERT_EQ(2u, s.size()); 648 ASSERT_EQ(2u, s.size());
781 683
782 DoLookupIdentifier2(s, ResourceType_Study, DICOM_TAG_STUDY_INSTANCE_UID, 684 DoLookupIdentifier2(s, ResourceType_Study, DICOM_TAG_STUDY_INSTANCE_UID,
783 ConstraintType_GreaterOrEqual, "0", ConstraintType_SmallerOrEqual, "1"); 685 ConstraintType_GreaterOrEqual, "0", ConstraintType_SmallerOrEqual, "1");
784 ASSERT_EQ(3u, s.size()); 686 ASSERT_EQ(3u, s.size());
785 } 687 }
786
787 688
788 689
789 TEST(ServerIndex, AttachmentRecycling) 690 TEST(ServerIndex, AttachmentRecycling)
790 { 691 {
791 const std::string path = "UnitTestsStorage"; 692 const std::string path = "UnitTestsStorage";