Mercurial > hg > orthanc
annotate UnitTests/ServerIndex.cpp @ 223:6f0e4a8ebb0f
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 29 Nov 2012 18:07:50 +0100 |
parents | 0200cd330582 |
children | 5368bbe813cf |
rev | line source |
---|---|
181 | 1 #include "gtest/gtest.h" |
2 | |
183 | 3 #include "../OrthancServer/DatabaseWrapper.h" |
4 | |
181 | 5 #include <ctype.h> |
6 #include <glog/logging.h> | |
7 | |
183 | 8 using namespace Orthanc; |
181 | 9 |
183 | 10 namespace |
11 { | |
181 | 12 class ServerIndexListener : public IServerIndexListener |
13 { | |
14 public: | |
183 | 15 std::set<std::string> deletedFiles_; |
16 std::string ancestorId_; | |
17 ResourceType ancestorType_; | |
18 | |
19 void Reset() | |
181 | 20 { |
183 | 21 ancestorId_ = ""; |
22 deletedFiles_.clear(); | |
23 } | |
24 | |
25 virtual void SignalRemainingAncestor(ResourceType type, | |
26 const std::string& publicId) | |
27 { | |
28 ancestorId_ = publicId; | |
29 ancestorType_ = type; | |
181 | 30 } |
31 | |
32 virtual void SignalFileDeleted(const std::string& fileUuid) | |
33 { | |
183 | 34 deletedFiles_.insert(fileUuid); |
181 | 35 LOG(INFO) << "A file must be removed: " << fileUuid; |
36 } | |
37 }; | |
38 } | |
39 | |
40 | |
183 | 41 TEST(DatabaseWrapper, Simple) |
181 | 42 { |
43 ServerIndexListener listener; | |
183 | 44 DatabaseWrapper index(listener); |
181 | 45 |
46 int64_t a[] = { | |
182 | 47 index.CreateResource("a", ResourceType_Patient), // 0 |
48 index.CreateResource("b", ResourceType_Study), // 1 | |
49 index.CreateResource("c", ResourceType_Series), // 2 | |
50 index.CreateResource("d", ResourceType_Instance), // 3 | |
51 index.CreateResource("e", ResourceType_Instance), // 4 | |
52 index.CreateResource("f", ResourceType_Instance), // 5 | |
53 index.CreateResource("g", ResourceType_Study) // 6 | |
181 | 54 }; |
55 | |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
56 ASSERT_EQ("a", index.GetPublicId(a[0])); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
57 ASSERT_EQ("b", index.GetPublicId(a[1])); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
58 ASSERT_EQ("c", index.GetPublicId(a[2])); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
59 ASSERT_EQ("d", index.GetPublicId(a[3])); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
60 ASSERT_EQ("e", index.GetPublicId(a[4])); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
61 ASSERT_EQ("f", index.GetPublicId(a[5])); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
62 ASSERT_EQ("g", index.GetPublicId(a[6])); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
63 |
190 | 64 { |
65 Json::Value t; | |
66 index.GetAllPublicIds(t, ResourceType_Patient); | |
67 | |
68 ASSERT_EQ(1, t.size()); | |
69 ASSERT_EQ("a", t[0u].asString()); | |
70 | |
71 index.GetAllPublicIds(t, ResourceType_Series); | |
72 ASSERT_EQ(1, t.size()); | |
73 ASSERT_EQ("c", t[0u].asString()); | |
74 | |
75 index.GetAllPublicIds(t, ResourceType_Study); | |
76 ASSERT_EQ(2, t.size()); | |
77 | |
78 index.GetAllPublicIds(t, ResourceType_Instance); | |
79 ASSERT_EQ(3, t.size()); | |
80 } | |
81 | |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
198
diff
changeset
|
82 index.SetGlobalProperty(GlobalProperty_FlushSleep, "World"); |
181 | 83 |
84 index.AttachChild(a[0], a[1]); | |
85 index.AttachChild(a[1], a[2]); | |
86 index.AttachChild(a[2], a[3]); | |
87 index.AttachChild(a[2], a[4]); | |
88 index.AttachChild(a[6], a[5]); | |
182 | 89 |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
90 int64_t parent; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
91 ASSERT_FALSE(index.LookupParent(parent, a[0])); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 ASSERT_FALSE(index.LookupParent(parent, a[6])); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
98 |
182 | 99 std::string s; |
100 | |
101 ASSERT_FALSE(index.GetParentPublicId(s, a[0])); | |
102 ASSERT_FALSE(index.GetParentPublicId(s, a[6])); | |
103 ASSERT_TRUE(index.GetParentPublicId(s, a[1])); ASSERT_EQ("a", s); | |
104 ASSERT_TRUE(index.GetParentPublicId(s, a[2])); ASSERT_EQ("b", s); | |
105 ASSERT_TRUE(index.GetParentPublicId(s, a[3])); ASSERT_EQ("c", s); | |
106 ASSERT_TRUE(index.GetParentPublicId(s, a[4])); ASSERT_EQ("c", s); | |
107 ASSERT_TRUE(index.GetParentPublicId(s, a[5])); ASSERT_EQ("g", s); | |
108 | |
185 | 109 std::list<std::string> l; |
182 | 110 index.GetChildrenPublicId(l, a[0]); ASSERT_EQ(1, l.size()); ASSERT_EQ("b", l.front()); |
111 index.GetChildrenPublicId(l, a[1]); ASSERT_EQ(1, l.size()); ASSERT_EQ("c", l.front()); | |
112 index.GetChildrenPublicId(l, a[3]); ASSERT_EQ(0, l.size()); | |
113 index.GetChildrenPublicId(l, a[4]); ASSERT_EQ(0, l.size()); | |
114 index.GetChildrenPublicId(l, a[5]); ASSERT_EQ(0, l.size()); | |
115 index.GetChildrenPublicId(l, a[6]); ASSERT_EQ(1, l.size()); ASSERT_EQ("f", l.front()); | |
116 | |
117 index.GetChildrenPublicId(l, a[2]); ASSERT_EQ(2, l.size()); | |
118 if (l.front() == "d") | |
119 { | |
120 ASSERT_EQ("e", l.back()); | |
121 } | |
122 else | |
123 { | |
124 ASSERT_EQ("d", l.back()); | |
125 ASSERT_EQ("e", l.front()); | |
126 } | |
127 | |
197
530a25320461
removal of text as ids in sqlite db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
128 index.AttachFile(a[4], AttachedFileType_Json, "my json file", 21, 42, CompressionType_Zlib); |
530a25320461
removal of text as ids in sqlite db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
129 index.AttachFile(a[4], AttachedFileType_Dicom, "my dicom file", 42); |
530a25320461
removal of text as ids in sqlite db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
130 index.AttachFile(a[6], AttachedFileType_Dicom, "world", 44); |
183 | 131 index.SetMetadata(a[4], MetadataType_Instance_RemoteAet, "PINNACLE"); |
182 | 132 |
183 | 133 ASSERT_EQ(21 + 42 + 44, index.GetTotalCompressedSize()); |
134 ASSERT_EQ(42 + 42 + 44, index.GetTotalUncompressedSize()); | |
181 | 135 |
136 DicomMap m; | |
137 m.SetValue(0x0010, 0x0010, "PatientName"); | |
138 index.SetMainDicomTags(a[3], m); | |
139 | |
140 int64_t b; | |
141 ResourceType t; | |
188
090cefdab1d1
fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
185
diff
changeset
|
142 ASSERT_TRUE(index.LookupResource("g", b, t)); |
181 | 143 ASSERT_EQ(7, b); |
144 ASSERT_EQ(ResourceType_Study, t); | |
145 | |
188
090cefdab1d1
fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
185
diff
changeset
|
146 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
|
147 ASSERT_FALSE(index.LookupMetadata(s, a[4], MetadataType_Instance_IndexInSeries)); |
181 | 148 ASSERT_EQ("PINNACLE", s); |
149 ASSERT_EQ("PINNACLE", index.GetMetadata(a[4], MetadataType_Instance_RemoteAet)); | |
150 ASSERT_EQ("None", index.GetMetadata(a[4], MetadataType_Instance_IndexInSeries, "None")); | |
151 | |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
198
diff
changeset
|
152 ASSERT_TRUE(index.LookupGlobalProperty(s, GlobalProperty_FlushSleep)); |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
198
diff
changeset
|
153 ASSERT_FALSE(index.LookupGlobalProperty(s, static_cast<GlobalProperty>(42))); |
181 | 154 ASSERT_EQ("World", s); |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
198
diff
changeset
|
155 ASSERT_EQ("World", index.GetGlobalProperty(GlobalProperty_FlushSleep)); |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
198
diff
changeset
|
156 ASSERT_EQ("None", index.GetGlobalProperty(static_cast<GlobalProperty>(42), "None")); |
181 | 157 |
188
090cefdab1d1
fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
185
diff
changeset
|
158 uint64_t us, cs; |
181 | 159 CompressionType ct; |
197
530a25320461
removal of text as ids in sqlite db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
160 ASSERT_TRUE(index.LookupFile(a[4], AttachedFileType_Json, s, cs, us, ct)); |
181 | 161 ASSERT_EQ("my json file", s); |
183 | 162 ASSERT_EQ(21, cs); |
181 | 163 ASSERT_EQ(42, us); |
164 ASSERT_EQ(CompressionType_Zlib, ct); | |
165 | |
188
090cefdab1d1
fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
185
diff
changeset
|
166 ASSERT_EQ(0u, listener.deletedFiles_.size()); |
218 | 167 ASSERT_EQ(7, index.GetTableRecordCount("Resources")); |
183 | 168 ASSERT_EQ(3, index.GetTableRecordCount("AttachedFiles")); |
181 | 169 ASSERT_EQ(1, index.GetTableRecordCount("Metadata")); |
170 ASSERT_EQ(1, index.GetTableRecordCount("MainDicomTags")); | |
171 index.DeleteResource(a[0]); | |
183 | 172 |
173 ASSERT_EQ(2, listener.deletedFiles_.size()); | |
185 | 174 ASSERT_FALSE(listener.deletedFiles_.find("my json file") == listener.deletedFiles_.end()); |
175 ASSERT_FALSE(listener.deletedFiles_.find("my dicom file") == listener.deletedFiles_.end()); | |
183 | 176 |
181 | 177 ASSERT_EQ(2, index.GetTableRecordCount("Resources")); |
178 ASSERT_EQ(0, index.GetTableRecordCount("Metadata")); | |
183 | 179 ASSERT_EQ(1, index.GetTableRecordCount("AttachedFiles")); |
180 ASSERT_EQ(0, index.GetTableRecordCount("MainDicomTags")); | |
181 index.DeleteResource(a[5]); | |
182 ASSERT_EQ(0, index.GetTableRecordCount("Resources")); | |
181 | 183 ASSERT_EQ(0, index.GetTableRecordCount("AttachedFiles")); |
183 | 184 ASSERT_EQ(1, index.GetTableRecordCount("GlobalProperties")); |
185 | |
186 ASSERT_EQ(3, listener.deletedFiles_.size()); | |
185 | 187 ASSERT_FALSE(listener.deletedFiles_.find("world") == listener.deletedFiles_.end()); |
183 | 188 } |
189 | |
190 | |
191 | |
192 | |
193 TEST(DatabaseWrapper, Upward) | |
194 { | |
195 ServerIndexListener listener; | |
196 DatabaseWrapper index(listener); | |
197 | |
198 int64_t a[] = { | |
199 index.CreateResource("a", ResourceType_Patient), // 0 | |
200 index.CreateResource("b", ResourceType_Study), // 1 | |
201 index.CreateResource("c", ResourceType_Series), // 2 | |
202 index.CreateResource("d", ResourceType_Instance), // 3 | |
203 index.CreateResource("e", ResourceType_Instance), // 4 | |
204 index.CreateResource("f", ResourceType_Study), // 5 | |
205 index.CreateResource("g", ResourceType_Series), // 6 | |
206 index.CreateResource("h", ResourceType_Series) // 7 | |
207 }; | |
208 | |
209 index.AttachChild(a[0], a[1]); | |
210 index.AttachChild(a[1], a[2]); | |
211 index.AttachChild(a[2], a[3]); | |
212 index.AttachChild(a[2], a[4]); | |
213 index.AttachChild(a[1], a[6]); | |
214 index.AttachChild(a[0], a[5]); | |
215 index.AttachChild(a[5], a[7]); | |
216 | |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
217 { |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
218 Json::Value j; |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
219 index.GetChildren(j, a[0]); |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
220 ASSERT_EQ(2, j.size()); |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
221 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
|
222 (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
|
223 |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
224 index.GetChildren(j, a[1]); |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
225 ASSERT_EQ(2, j.size()); |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
226 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
|
227 (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
|
228 |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
229 index.GetChildren(j, a[2]); |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
230 ASSERT_EQ(2, j.size()); |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
231 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
|
232 (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
|
233 |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
234 index.GetChildren(j, a[3]); ASSERT_EQ(0, j.size()); |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
235 index.GetChildren(j, a[4]); ASSERT_EQ(0, j.size()); |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
236 index.GetChildren(j, a[5]); ASSERT_EQ(1, j.size()); ASSERT_EQ("h", j[0u].asString()); |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
237 index.GetChildren(j, a[6]); ASSERT_EQ(0, j.size()); |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
238 index.GetChildren(j, a[7]); ASSERT_EQ(0, j.size()); |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
239 } |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
240 |
183 | 241 listener.Reset(); |
242 index.DeleteResource(a[3]); | |
243 ASSERT_EQ("c", listener.ancestorId_); | |
244 ASSERT_EQ(ResourceType_Series, listener.ancestorType_); | |
245 | |
246 listener.Reset(); | |
247 index.DeleteResource(a[4]); | |
248 ASSERT_EQ("b", listener.ancestorId_); | |
249 ASSERT_EQ(ResourceType_Study, listener.ancestorType_); | |
250 | |
251 listener.Reset(); | |
252 index.DeleteResource(a[7]); | |
253 ASSERT_EQ("a", listener.ancestorId_); | |
254 ASSERT_EQ(ResourceType_Patient, listener.ancestorType_); | |
255 | |
256 listener.Reset(); | |
181 | 257 index.DeleteResource(a[6]); |
183 | 258 ASSERT_EQ("", listener.ancestorId_); // No more ancestor |
181 | 259 } |