annotate UnitTests/ServerIndex.cpp @ 289:ffd98d2f0b91

merge
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 14 Dec 2012 11:22:29 +0100
parents d384af918264
children 4eea080e6e7a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #include "gtest/gtest.h"
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
3 #include "../OrthancServer/DatabaseWrapper.h"
273
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
4 #include "../Core/Uuid.h"
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
5
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 #include <ctype.h>
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 #include <glog/logging.h>
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
9 using namespace Orthanc;
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
11 namespace
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
12 {
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 class ServerIndexListener : public IServerIndexListener
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 {
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 public:
262
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
16 std::vector<std::string> deletedFiles_;
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
17 std::string ancestorId_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
18 ResourceType ancestorType_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
19
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
20 void Reset()
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 {
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
22 ancestorId_ = "";
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
23 deletedFiles_.clear();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
24 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
25
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
26 virtual void SignalRemainingAncestor(ResourceType type,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
27 const std::string& publicId)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
28 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
29 ancestorId_ = publicId;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
30 ancestorType_ = type;
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 }
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
273
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
33 virtual void SignalFileDeleted(const FileInfo& info)
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
273
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
35 const std::string fileUuid = info.GetUuid();
262
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
36 deletedFiles_.push_back(fileUuid);
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 LOG(INFO) << "A file must be removed: " << fileUuid;
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 }
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 };
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 }
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
43 TEST(DatabaseWrapper, Simple)
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 ServerIndexListener listener;
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
46 DatabaseWrapper index(listener);
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 int64_t a[] = {
182
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
49 index.CreateResource("a", ResourceType_Patient), // 0
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
50 index.CreateResource("b", ResourceType_Study), // 1
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
51 index.CreateResource("c", ResourceType_Series), // 2
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
52 index.CreateResource("d", ResourceType_Instance), // 3
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
53 index.CreateResource("e", ResourceType_Instance), // 4
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
54 index.CreateResource("f", ResourceType_Instance), // 5
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
55 index.CreateResource("g", ResourceType_Study) // 6
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 };
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
58 ASSERT_EQ("a", index.GetPublicId(a[0]));
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
59 ASSERT_EQ("b", index.GetPublicId(a[1]));
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
60 ASSERT_EQ("c", index.GetPublicId(a[2]));
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
61 ASSERT_EQ("d", index.GetPublicId(a[3]));
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
62 ASSERT_EQ("e", index.GetPublicId(a[4]));
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
63 ASSERT_EQ("f", index.GetPublicId(a[5]));
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
64 ASSERT_EQ("g", index.GetPublicId(a[6]));
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
65
190
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
66 {
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
67 Json::Value t;
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
68 index.GetAllPublicIds(t, ResourceType_Patient);
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
69
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
70 ASSERT_EQ(1u, t.size());
190
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
71 ASSERT_EQ("a", t[0u].asString());
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
72
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
73 index.GetAllPublicIds(t, ResourceType_Series);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
74 ASSERT_EQ(1u, t.size());
190
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
75 ASSERT_EQ("c", t[0u].asString());
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
76
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
77 index.GetAllPublicIds(t, ResourceType_Study);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
78 ASSERT_EQ(2u, t.size());
190
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
79
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
80 index.GetAllPublicIds(t, ResourceType_Instance);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
81 ASSERT_EQ(3u, t.size());
190
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
82 }
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
83
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
84 index.SetGlobalProperty(GlobalProperty_FlushSleep, "World");
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 index.AttachChild(a[0], a[1]);
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 index.AttachChild(a[1], a[2]);
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 index.AttachChild(a[2], a[3]);
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 index.AttachChild(a[2], a[4]);
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 index.AttachChild(a[6], a[5]);
182
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
91
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
92 int64_t parent;
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
93 ASSERT_FALSE(index.LookupParent(parent, a[0]));
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
94 ASSERT_TRUE(index.LookupParent(parent, a[1])); ASSERT_EQ(a[0], parent);
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
95 ASSERT_TRUE(index.LookupParent(parent, a[2])); ASSERT_EQ(a[1], parent);
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
96 ASSERT_TRUE(index.LookupParent(parent, a[3])); ASSERT_EQ(a[2], parent);
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
97 ASSERT_TRUE(index.LookupParent(parent, a[4])); ASSERT_EQ(a[2], parent);
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
98 ASSERT_TRUE(index.LookupParent(parent, a[5])); ASSERT_EQ(a[6], parent);
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
99 ASSERT_FALSE(index.LookupParent(parent, a[6]));
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
100
182
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
101 std::string s;
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
102
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
103 ASSERT_FALSE(index.GetParentPublicId(s, a[0]));
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
104 ASSERT_FALSE(index.GetParentPublicId(s, a[6]));
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
105 ASSERT_TRUE(index.GetParentPublicId(s, a[1])); ASSERT_EQ("a", s);
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
106 ASSERT_TRUE(index.GetParentPublicId(s, a[2])); ASSERT_EQ("b", s);
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
107 ASSERT_TRUE(index.GetParentPublicId(s, a[3])); ASSERT_EQ("c", s);
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
108 ASSERT_TRUE(index.GetParentPublicId(s, a[4])); ASSERT_EQ("c", s);
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
109 ASSERT_TRUE(index.GetParentPublicId(s, a[5])); ASSERT_EQ("g", s);
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
110
185
5185ae1d9af5 fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
111 std::list<std::string> l;
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
112 index.GetChildrenPublicId(l, a[0]); ASSERT_EQ(1u, l.size()); ASSERT_EQ("b", l.front());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
113 index.GetChildrenPublicId(l, a[1]); ASSERT_EQ(1u, l.size()); ASSERT_EQ("c", l.front());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
114 index.GetChildrenPublicId(l, a[3]); ASSERT_EQ(0u, l.size());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
115 index.GetChildrenPublicId(l, a[4]); ASSERT_EQ(0u, l.size());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
116 index.GetChildrenPublicId(l, a[5]); ASSERT_EQ(0u, l.size());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
117 index.GetChildrenPublicId(l, a[6]); ASSERT_EQ(1u, l.size()); ASSERT_EQ("f", l.front());
182
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
118
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
119 index.GetChildrenPublicId(l, a[2]); ASSERT_EQ(2u, l.size());
182
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
120 if (l.front() == "d")
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
121 {
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
122 ASSERT_EQ("e", l.back());
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
123 }
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
124 else
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
125 {
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
126 ASSERT_EQ("d", l.back());
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
127 ASSERT_EQ("e", l.front());
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
128 }
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
129
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
130 index.AddAttachment(a[4], FileInfo("my json file", FileContentType_Json, 42, CompressionType_Zlib, 21));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
131 index.AddAttachment(a[4], FileInfo("my dicom file", FileContentType_Dicom, 42));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
132 index.AddAttachment(a[6], FileInfo("world", FileContentType_Dicom, 44));
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
133 index.SetMetadata(a[4], MetadataType_Instance_RemoteAet, "PINNACLE");
182
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
134
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
135 ASSERT_EQ(21u + 42u + 44u, index.GetTotalCompressedSize());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
136 ASSERT_EQ(42u + 42u + 44u, index.GetTotalUncompressedSize());
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 DicomMap m;
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 m.SetValue(0x0010, 0x0010, "PatientName");
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 index.SetMainDicomTags(a[3], m);
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 int64_t b;
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 ResourceType t;
188
090cefdab1d1 fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
144 ASSERT_TRUE(index.LookupResource("g", b, t));
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 ASSERT_EQ(7, b);
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 ASSERT_EQ(ResourceType_Study, t);
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
188
090cefdab1d1 fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
148 ASSERT_TRUE(index.LookupMetadata(s, a[4], MetadataType_Instance_RemoteAet));
090cefdab1d1 fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
149 ASSERT_FALSE(index.LookupMetadata(s, a[4], MetadataType_Instance_IndexInSeries));
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 ASSERT_EQ("PINNACLE", s);
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 ASSERT_EQ("PINNACLE", index.GetMetadata(a[4], MetadataType_Instance_RemoteAet));
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 ASSERT_EQ("None", index.GetMetadata(a[4], MetadataType_Instance_IndexInSeries, "None"));
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
154 ASSERT_TRUE(index.LookupGlobalProperty(s, GlobalProperty_FlushSleep));
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
155 ASSERT_FALSE(index.LookupGlobalProperty(s, static_cast<GlobalProperty>(42)));
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 ASSERT_EQ("World", s);
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
157 ASSERT_EQ("World", index.GetGlobalProperty(GlobalProperty_FlushSleep));
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
158 ASSERT_EQ("None", index.GetGlobalProperty(static_cast<GlobalProperty>(42), "None"));
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
160 FileInfo att;
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
161 ASSERT_TRUE(index.LookupAttachment(att, a[4], FileContentType_Json));
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
162 ASSERT_EQ("my json file", att.GetUuid());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
163 ASSERT_EQ(21u, att.GetCompressedSize());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
164 ASSERT_EQ(42u, att.GetUncompressedSize());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
165 ASSERT_EQ(CompressionType_Zlib, att.GetCompressionType());
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166
188
090cefdab1d1 fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
167 ASSERT_EQ(0u, listener.deletedFiles_.size());
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
168 ASSERT_EQ(7u, index.GetTableRecordCount("Resources"));
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
169 ASSERT_EQ(3u, index.GetTableRecordCount("AttachedFiles"));
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
170 ASSERT_EQ(1u, index.GetTableRecordCount("Metadata"));
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
171 ASSERT_EQ(1u, index.GetTableRecordCount("MainDicomTags"));
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 index.DeleteResource(a[0]);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
173
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
174 ASSERT_EQ(2u, listener.deletedFiles_.size());
262
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
175 ASSERT_FALSE(std::find(listener.deletedFiles_.begin(),
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
176 listener.deletedFiles_.end(),
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
177 "my json file") == listener.deletedFiles_.end());
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
178 ASSERT_FALSE(std::find(listener.deletedFiles_.begin(),
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
179 listener.deletedFiles_.end(),
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
180 "my dicom file") == listener.deletedFiles_.end());
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
181
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
182 ASSERT_EQ(2u, index.GetTableRecordCount("Resources"));
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
183 ASSERT_EQ(0u, index.GetTableRecordCount("Metadata"));
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
184 ASSERT_EQ(1u, index.GetTableRecordCount("AttachedFiles"));
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
185 ASSERT_EQ(0u, index.GetTableRecordCount("MainDicomTags"));
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
186 index.DeleteResource(a[5]);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
187 ASSERT_EQ(0u, index.GetTableRecordCount("Resources"));
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
188 ASSERT_EQ(0u, index.GetTableRecordCount("AttachedFiles"));
252
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
189 ASSERT_EQ(2u, index.GetTableRecordCount("GlobalProperties"));
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
190
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
191 ASSERT_EQ(3u, listener.deletedFiles_.size());
262
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
192 ASSERT_FALSE(std::find(listener.deletedFiles_.begin(),
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
193 listener.deletedFiles_.end(),
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
194 "world") == listener.deletedFiles_.end());
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
195 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
196
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
197
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
198
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
199
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
200 TEST(DatabaseWrapper, Upward)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
201 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
202 ServerIndexListener listener;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
203 DatabaseWrapper index(listener);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
204
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
205 int64_t a[] = {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
206 index.CreateResource("a", ResourceType_Patient), // 0
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
207 index.CreateResource("b", ResourceType_Study), // 1
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
208 index.CreateResource("c", ResourceType_Series), // 2
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
209 index.CreateResource("d", ResourceType_Instance), // 3
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
210 index.CreateResource("e", ResourceType_Instance), // 4
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
211 index.CreateResource("f", ResourceType_Study), // 5
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
212 index.CreateResource("g", ResourceType_Series), // 6
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
213 index.CreateResource("h", ResourceType_Series) // 7
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
214 };
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
215
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
216 index.AttachChild(a[0], a[1]);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
217 index.AttachChild(a[1], a[2]);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
218 index.AttachChild(a[2], a[3]);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
219 index.AttachChild(a[2], a[4]);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
220 index.AttachChild(a[1], a[6]);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
221 index.AttachChild(a[0], a[5]);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
222 index.AttachChild(a[5], a[7]);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
223
193
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 190
diff changeset
224 {
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 190
diff changeset
225 Json::Value j;
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 190
diff changeset
226 index.GetChildren(j, a[0]);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
227 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
228 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
229 (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
230
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 190
diff changeset
231 index.GetChildren(j, a[1]);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
232 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
233 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
234 (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
235
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 190
diff changeset
236 index.GetChildren(j, a[2]);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
237 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
238 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
239 (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
240
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
241 index.GetChildren(j, a[3]); ASSERT_EQ(0u, j.size());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
242 index.GetChildren(j, a[4]); ASSERT_EQ(0u, j.size());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
243 index.GetChildren(j, a[5]); ASSERT_EQ(1u, j.size()); ASSERT_EQ("h", j[0u].asString());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
244 index.GetChildren(j, a[6]); ASSERT_EQ(0u, j.size());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
245 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
246 }
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 190
diff changeset
247
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
248 listener.Reset();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
249 index.DeleteResource(a[3]);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
250 ASSERT_EQ("c", listener.ancestorId_);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
251 ASSERT_EQ(ResourceType_Series, listener.ancestorType_);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
252
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
253 listener.Reset();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
254 index.DeleteResource(a[4]);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
255 ASSERT_EQ("b", listener.ancestorId_);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
256 ASSERT_EQ(ResourceType_Study, listener.ancestorType_);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
257
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
258 listener.Reset();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
259 index.DeleteResource(a[7]);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
260 ASSERT_EQ("a", listener.ancestorId_);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
261 ASSERT_EQ(ResourceType_Patient, listener.ancestorType_);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
262
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
263 listener.Reset();
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 index.DeleteResource(a[6]);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
265 ASSERT_EQ("", listener.ancestorId_); // No more ancestor
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 }
262
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
267
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
268
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
269 TEST(DatabaseWrapper, PatientRecycling)
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
270 {
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
271 ServerIndexListener listener;
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
272 DatabaseWrapper index(listener);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
273
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
274 std::vector<int64_t> patients;
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
275 for (int i = 0; i < 10; i++)
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
276 {
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
277 std::string p = "Patient " + boost::lexical_cast<std::string>(i);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
278 patients.push_back(index.CreateResource(p, ResourceType_Patient));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
279 index.AddAttachment(patients[i], FileInfo(p, FileContentType_Dicom, i + 10));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
280 ASSERT_FALSE(index.IsProtectedPatient(patients[i]));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
281 }
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
282
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
283 ASSERT_EQ(10u, index.GetTableRecordCount("Resources"));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
284 ASSERT_EQ(10u, index.GetTableRecordCount("PatientRecyclingOrder"));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
285
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
286 listener.Reset();
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
287
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
288 index.DeleteResource(patients[5]);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
289 index.DeleteResource(patients[0]);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
290 ASSERT_EQ(8u, index.GetTableRecordCount("Resources"));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
291 ASSERT_EQ(8u, index.GetTableRecordCount("PatientRecyclingOrder"));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
292
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
293 ASSERT_EQ(2u, listener.deletedFiles_.size());
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
294 ASSERT_EQ("Patient 5", listener.deletedFiles_[0]);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
295 ASSERT_EQ("Patient 0", listener.deletedFiles_[1]);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
296
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
297 int64_t p;
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
298 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[1]);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
299 index.DeleteResource(p);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
300 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[2]);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
301 index.DeleteResource(p);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
302 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[3]);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
303 index.DeleteResource(p);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
304 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[4]);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
305 index.DeleteResource(p);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
306 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[6]);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
307 index.DeleteResource(p);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
308 index.DeleteResource(patients[8]);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
309 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[7]);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
310 index.DeleteResource(p);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
311 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[9]);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
312 index.DeleteResource(p);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
313 ASSERT_FALSE(index.SelectPatientToRecycle(p));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
314
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
315 ASSERT_EQ(10u, listener.deletedFiles_.size());
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
316 ASSERT_EQ(0u, index.GetTableRecordCount("Resources"));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
317 ASSERT_EQ(0u, index.GetTableRecordCount("PatientRecyclingOrder"));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
318 }
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
319
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
320
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
321 TEST(DatabaseWrapper, PatientProtection)
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
322 {
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
323 ServerIndexListener listener;
266
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
324 DatabaseWrapper index(listener);
262
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
325
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
326 std::vector<int64_t> patients;
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
327 for (int i = 0; i < 5; i++)
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
328 {
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
329 std::string p = "Patient " + boost::lexical_cast<std::string>(i);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
330 patients.push_back(index.CreateResource(p, ResourceType_Patient));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
331 index.AddAttachment(patients[i], FileInfo(p, FileContentType_Dicom, i + 10));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
332 ASSERT_FALSE(index.IsProtectedPatient(patients[i]));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
333 }
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 ASSERT_EQ(5u, index.GetTableRecordCount("Resources"));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
336 ASSERT_EQ(5u, index.GetTableRecordCount("PatientRecyclingOrder"));
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 ASSERT_FALSE(index.IsProtectedPatient(patients[2]));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
339 index.SetProtectedPatient(patients[2], true);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
340 ASSERT_TRUE(index.IsProtectedPatient(patients[2]));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
341 ASSERT_EQ(4u, index.GetTableRecordCount("PatientRecyclingOrder"));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
342 ASSERT_EQ(5u, index.GetTableRecordCount("Resources"));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
343
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
344 index.SetProtectedPatient(patients[2], true);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
345 ASSERT_TRUE(index.IsProtectedPatient(patients[2]));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
346 ASSERT_EQ(4u, index.GetTableRecordCount("PatientRecyclingOrder"));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
347 index.SetProtectedPatient(patients[2], false);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
348 ASSERT_FALSE(index.IsProtectedPatient(patients[2]));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
349 ASSERT_EQ(5u, index.GetTableRecordCount("PatientRecyclingOrder"));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
350 index.SetProtectedPatient(patients[2], false);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
351 ASSERT_FALSE(index.IsProtectedPatient(patients[2]));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
352 ASSERT_EQ(5u, index.GetTableRecordCount("PatientRecyclingOrder"));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
353
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
354 ASSERT_EQ(5u, index.GetTableRecordCount("Resources"));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
355 ASSERT_EQ(5u, index.GetTableRecordCount("PatientRecyclingOrder"));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
356 index.SetProtectedPatient(patients[2], true);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
357 ASSERT_TRUE(index.IsProtectedPatient(patients[2]));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
358 ASSERT_EQ(4u, index.GetTableRecordCount("PatientRecyclingOrder"));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
359 index.SetProtectedPatient(patients[2], false);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
360 ASSERT_FALSE(index.IsProtectedPatient(patients[2]));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
361 ASSERT_EQ(5u, index.GetTableRecordCount("PatientRecyclingOrder"));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
362 index.SetProtectedPatient(patients[3], true);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
363 ASSERT_TRUE(index.IsProtectedPatient(patients[3]));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
364 ASSERT_EQ(4u, index.GetTableRecordCount("PatientRecyclingOrder"));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
365
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
366 ASSERT_EQ(5u, index.GetTableRecordCount("Resources"));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
367 ASSERT_EQ(0u, listener.deletedFiles_.size());
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
368
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
369 // 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
370 int64_t p;
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
371 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[0]);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
372 index.DeleteResource(p);
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 266
diff changeset
373 ASSERT_TRUE(index.SelectPatientToRecycle(p, patients[1])); ASSERT_EQ(p, patients[4]);
262
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
374 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[1]);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
375 index.DeleteResource(p);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
376 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[4]);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
377 index.DeleteResource(p);
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 266
diff changeset
378 ASSERT_FALSE(index.SelectPatientToRecycle(p, patients[2]));
262
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
379 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[2]);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
380 index.DeleteResource(p);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
381 // "patients[3]" is still protected
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
382 ASSERT_FALSE(index.SelectPatientToRecycle(p));
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 ASSERT_EQ(4u, listener.deletedFiles_.size());
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
385 ASSERT_EQ(1u, index.GetTableRecordCount("Resources"));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
386 ASSERT_EQ(0u, index.GetTableRecordCount("PatientRecyclingOrder"));
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 index.SetProtectedPatient(patients[3], false);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
389 ASSERT_EQ(1u, index.GetTableRecordCount("PatientRecyclingOrder"));
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 266
diff changeset
390 ASSERT_FALSE(index.SelectPatientToRecycle(p, patients[3]));
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 266
diff changeset
391 ASSERT_TRUE(index.SelectPatientToRecycle(p, patients[2]));
262
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
392 ASSERT_TRUE(index.SelectPatientToRecycle(p)); ASSERT_EQ(p, patients[3]);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
393 index.DeleteResource(p);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
394
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
395 ASSERT_EQ(5u, listener.deletedFiles_.size());
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
396 ASSERT_EQ(0u, index.GetTableRecordCount("Resources"));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
397 ASSERT_EQ(0u, index.GetTableRecordCount("PatientRecyclingOrder"));
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
398 }