comparison UnitTestsSources/ServerIndexTests.cpp @ 737:1dee6e9bdbf4

abstraction of databasewrapper tests
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 14 Mar 2014 11:23:57 +0100
parents edffcf3ce7ab
children c60743fadd4e
comparison
equal deleted inserted replaced
736:7019922daf3d 737:1dee6e9bdbf4
12 12
13 using namespace Orthanc; 13 using namespace Orthanc;
14 14
15 namespace 15 namespace
16 { 16 {
17 enum DatabaseWrapperClass
18 {
19 DatabaseWrapperClass_SQLite
20 };
21
22
17 class ServerIndexListener : public IServerIndexListener 23 class ServerIndexListener : public IServerIndexListener
18 { 24 {
19 public: 25 public:
20 std::vector<std::string> deletedFiles_; 26 std::vector<std::string> deletedFiles_;
21 std::string ancestorId_; 27 std::string ancestorId_;
39 const std::string fileUuid = info.GetUuid(); 45 const std::string fileUuid = info.GetUuid();
40 deletedFiles_.push_back(fileUuid); 46 deletedFiles_.push_back(fileUuid);
41 LOG(INFO) << "A file must be removed: " << fileUuid; 47 LOG(INFO) << "A file must be removed: " << fileUuid;
42 } 48 }
43 }; 49 };
44 } 50
45 51
46 52 class DatabaseWrapperTest : public ::testing::TestWithParam<DatabaseWrapperClass>
47 TEST(DatabaseWrapper, Simple) 53 {
48 { 54 protected:
49 ServerIndexListener listener; 55 ServerIndexListener listener;
50 DatabaseWrapper index(listener); 56 DatabaseWrapper index;
51 57
58 DatabaseWrapperTest() : index(listener)
59 {
60 }
61
62 virtual void SetUp()
63 {
64 }
65
66 virtual void TearDown()
67 {
68 }
69 };
70 }
71
72
73 INSTANTIATE_TEST_CASE_P(DatabaseWrapperName,
74 DatabaseWrapperTest,
75 ::testing::Values(DatabaseWrapperClass_SQLite));
76
77
78 TEST_P(DatabaseWrapperTest, Simple)
79 {
52 int64_t a[] = { 80 int64_t a[] = {
53 index.CreateResource("a", ResourceType_Patient), // 0 81 index.CreateResource("a", ResourceType_Patient), // 0
54 index.CreateResource("b", ResourceType_Study), // 1 82 index.CreateResource("b", ResourceType_Study), // 1
55 index.CreateResource("c", ResourceType_Series), // 2 83 index.CreateResource("c", ResourceType_Series), // 2
56 index.CreateResource("d", ResourceType_Instance), // 3 84 index.CreateResource("d", ResourceType_Instance), // 3
233 } 261 }
234 262
235 263
236 264
237 265
238 TEST(DatabaseWrapper, Upward) 266 TEST_P(DatabaseWrapperTest, Upward)
239 { 267 {
240 ServerIndexListener listener;
241 DatabaseWrapper index(listener);
242
243 int64_t a[] = { 268 int64_t a[] = {
244 index.CreateResource("a", ResourceType_Patient), // 0 269 index.CreateResource("a", ResourceType_Patient), // 0
245 index.CreateResource("b", ResourceType_Study), // 1 270 index.CreateResource("b", ResourceType_Study), // 1
246 index.CreateResource("c", ResourceType_Series), // 2 271 index.CreateResource("c", ResourceType_Series), // 2
247 index.CreateResource("d", ResourceType_Instance), // 3 272 index.CreateResource("d", ResourceType_Instance), // 3
302 index.DeleteResource(a[6]); 327 index.DeleteResource(a[6]);
303 ASSERT_EQ("", listener.ancestorId_); // No more ancestor 328 ASSERT_EQ("", listener.ancestorId_); // No more ancestor
304 } 329 }
305 330
306 331
307 TEST(DatabaseWrapper, PatientRecycling) 332 TEST_P(DatabaseWrapperTest, PatientRecycling)
308 { 333 {
309 ServerIndexListener listener;
310 DatabaseWrapper index(listener);
311
312 std::vector<int64_t> patients; 334 std::vector<int64_t> patients;
313 for (int i = 0; i < 10; i++) 335 for (int i = 0; i < 10; i++)
314 { 336 {
315 std::string p = "Patient " + boost::lexical_cast<std::string>(i); 337 std::string p = "Patient " + boost::lexical_cast<std::string>(i);
316 patients.push_back(index.CreateResource(p, ResourceType_Patient)); 338 patients.push_back(index.CreateResource(p, ResourceType_Patient));
355 ASSERT_EQ(0u, index.GetTableRecordCount("Resources")); 377 ASSERT_EQ(0u, index.GetTableRecordCount("Resources"));
356 ASSERT_EQ(0u, index.GetTableRecordCount("PatientRecyclingOrder")); 378 ASSERT_EQ(0u, index.GetTableRecordCount("PatientRecyclingOrder"));
357 } 379 }
358 380
359 381
360 TEST(DatabaseWrapper, PatientProtection) 382 TEST_P(DatabaseWrapperTest, PatientProtection)
361 { 383 {
362 ServerIndexListener listener;
363 DatabaseWrapper index(listener);
364
365 std::vector<int64_t> patients; 384 std::vector<int64_t> patients;
366 for (int i = 0; i < 5; i++) 385 for (int i = 0; i < 5; i++)
367 { 386 {
368 std::string p = "Patient " + boost::lexical_cast<std::string>(i); 387 std::string p = "Patient " + boost::lexical_cast<std::string>(i);
369 patients.push_back(index.CreateResource(p, ResourceType_Patient)); 388 patients.push_back(index.CreateResource(p, ResourceType_Patient));
437 ASSERT_EQ(0u, index.GetTableRecordCount("PatientRecyclingOrder")); 456 ASSERT_EQ(0u, index.GetTableRecordCount("PatientRecyclingOrder"));
438 } 457 }
439 458
440 459
441 460
442 TEST(DatabaseWrapper, Sequence) 461 TEST_P(DatabaseWrapperTest, Sequence)
443 { 462 {
444 ServerIndexListener listener;
445 DatabaseWrapper index(listener);
446
447 ASSERT_EQ(1u, index.IncrementGlobalSequence(GlobalProperty_AnonymizationSequence)); 463 ASSERT_EQ(1u, index.IncrementGlobalSequence(GlobalProperty_AnonymizationSequence));
448 ASSERT_EQ(2u, index.IncrementGlobalSequence(GlobalProperty_AnonymizationSequence)); 464 ASSERT_EQ(2u, index.IncrementGlobalSequence(GlobalProperty_AnonymizationSequence));
449 ASSERT_EQ(3u, index.IncrementGlobalSequence(GlobalProperty_AnonymizationSequence)); 465 ASSERT_EQ(3u, index.IncrementGlobalSequence(GlobalProperty_AnonymizationSequence));
450 ASSERT_EQ(4u, index.IncrementGlobalSequence(GlobalProperty_AnonymizationSequence)); 466 ASSERT_EQ(4u, index.IncrementGlobalSequence(GlobalProperty_AnonymizationSequence));
451 } 467 }
452 468
453 469
454 470
455 TEST(DatabaseWrapper, LookupTagValue) 471 TEST_P(DatabaseWrapperTest, LookupTagValue)
456 { 472 {
457 ServerIndexListener listener;
458 DatabaseWrapper index(listener);
459
460 int64_t a[] = { 473 int64_t a[] = {
461 index.CreateResource("a", ResourceType_Study), // 0 474 index.CreateResource("a", ResourceType_Study), // 0
462 index.CreateResource("b", ResourceType_Study), // 1 475 index.CreateResource("b", ResourceType_Study), // 1
463 index.CreateResource("c", ResourceType_Study), // 2 476 index.CreateResource("c", ResourceType_Study), // 2
464 index.CreateResource("d", ResourceType_Series) // 3 477 index.CreateResource("d", ResourceType_Series) // 3