annotate UnitTests/ServerIndex.cpp @ 263:3b3525dee661 Orthanc-0.3.1

fix build
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 09 Dec 2012 15:01:00 +0100
parents bd009f0b1931
children 2354560daf2f
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"
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
4
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 #include <ctype.h>
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 #include <glog/logging.h>
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
8 using namespace Orthanc;
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
10 namespace
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
11 {
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 class ServerIndexListener : public IServerIndexListener
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 {
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 public:
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
15 std::set<std::string> deletedFiles_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
16 std::string ancestorId_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
17 ResourceType ancestorType_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
18
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
19 void Reset()
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 {
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
21 ancestorId_ = "";
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
22 deletedFiles_.clear();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
23 }
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 virtual void SignalRemainingAncestor(ResourceType type,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
26 const std::string& publicId)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
27 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
28 ancestorId_ = publicId;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
29 ancestorType_ = type;
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 }
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 virtual void SignalFileDeleted(const std::string& fileUuid)
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 {
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
34 deletedFiles_.insert(fileUuid);
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 LOG(INFO) << "A file must be removed: " << fileUuid;
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 }
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 };
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
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
41 TEST(DatabaseWrapper, Simple)
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 ServerIndexListener listener;
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
44 DatabaseWrapper index(listener);
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 int64_t a[] = {
182
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
47 index.CreateResource("a", ResourceType_Patient), // 0
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
48 index.CreateResource("b", ResourceType_Study), // 1
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
49 index.CreateResource("c", ResourceType_Series), // 2
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
50 index.CreateResource("d", ResourceType_Instance), // 3
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
51 index.CreateResource("e", ResourceType_Instance), // 4
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
52 index.CreateResource("f", ResourceType_Instance), // 5
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
53 index.CreateResource("g", ResourceType_Study) // 6
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 };
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
64 {
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
65 Json::Value t;
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
66 index.GetAllPublicIds(t, ResourceType_Patient);
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
67
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
68 ASSERT_EQ(1u, t.size());
190
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
69 ASSERT_EQ("a", t[0u].asString());
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
70
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
71 index.GetAllPublicIds(t, ResourceType_Series);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
72 ASSERT_EQ(1u, t.size());
190
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
73 ASSERT_EQ("c", t[0u].asString());
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
74
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
75 index.GetAllPublicIds(t, ResourceType_Study);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
76 ASSERT_EQ(2u, t.size());
190
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
77
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
78 index.GetAllPublicIds(t, ResourceType_Instance);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
79 ASSERT_EQ(3u, t.size());
190
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
80 }
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
81
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
82 index.SetGlobalProperty(GlobalProperty_FlushSleep, "World");
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 index.AttachChild(a[0], a[1]);
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 index.AttachChild(a[1], a[2]);
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 index.AttachChild(a[2], a[3]);
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 index.AttachChild(a[2], a[4]);
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 index.AttachChild(a[6], a[5]);
182
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
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
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
99 std::string s;
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
100
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
101 ASSERT_FALSE(index.GetParentPublicId(s, a[0]));
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
102 ASSERT_FALSE(index.GetParentPublicId(s, a[6]));
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
103 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
104 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
105 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
106 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
107 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
108
185
5185ae1d9af5 fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
109 std::list<std::string> l;
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
110 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
111 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
112 index.GetChildrenPublicId(l, a[3]); ASSERT_EQ(0u, l.size());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
113 index.GetChildrenPublicId(l, a[4]); ASSERT_EQ(0u, l.size());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
114 index.GetChildrenPublicId(l, a[5]); ASSERT_EQ(0u, l.size());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
115 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
116
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
117 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
118 if (l.front() == "d")
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
119 {
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
120 ASSERT_EQ("e", l.back());
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 else
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 ASSERT_EQ("d", l.back());
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
125 ASSERT_EQ("e", l.front());
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
126 }
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
127
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
128 index.AddAttachment(a[4], FileInfo("my json file", FileContentType_Json, 42, CompressionType_Zlib, 21));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
129 index.AddAttachment(a[4], FileInfo("my dicom file", FileContentType_Dicom, 42));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
130 index.AddAttachment(a[6], FileInfo("world", FileContentType_Dicom, 44));
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
131 index.SetMetadata(a[4], MetadataType_Instance_RemoteAet, "PINNACLE");
182
93ff5babcaf8 children public id
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
132
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
133 ASSERT_EQ(21u + 42u + 44u, index.GetTotalCompressedSize());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
134 ASSERT_EQ(42u + 42u + 44u, index.GetTotalUncompressedSize());
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 DicomMap m;
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 m.SetValue(0x0010, 0x0010, "PatientName");
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 index.SetMainDicomTags(a[3], m);
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 int64_t b;
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 ASSERT_EQ(7, b);
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 ASSERT_EQ(ResourceType_Study, t);
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 ASSERT_EQ("PINNACLE", s);
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 ASSERT_EQ("PINNACLE", index.GetMetadata(a[4], MetadataType_Instance_RemoteAet));
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 ASSERT_EQ("None", index.GetMetadata(a[4], MetadataType_Instance_IndexInSeries, "None"));
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
158 FileInfo att;
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
159 ASSERT_TRUE(index.LookupAttachment(att, a[4], FileContentType_Json));
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
160 ASSERT_EQ("my json file", att.GetUuid());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
161 ASSERT_EQ(21u, att.GetCompressedSize());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
162 ASSERT_EQ(42u, att.GetUncompressedSize());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
163 ASSERT_EQ(CompressionType_Zlib, att.GetCompressionType());
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
188
090cefdab1d1 fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
165 ASSERT_EQ(0u, listener.deletedFiles_.size());
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
166 ASSERT_EQ(7u, index.GetTableRecordCount("Resources"));
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
167 ASSERT_EQ(3u, index.GetTableRecordCount("AttachedFiles"));
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
168 ASSERT_EQ(1u, index.GetTableRecordCount("Metadata"));
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
169 ASSERT_EQ(1u, index.GetTableRecordCount("MainDicomTags"));
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 index.DeleteResource(a[0]);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
171
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
172 ASSERT_EQ(2u, listener.deletedFiles_.size());
185
5185ae1d9af5 fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
173 ASSERT_FALSE(listener.deletedFiles_.find("my json file") == listener.deletedFiles_.end());
5185ae1d9af5 fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
174 ASSERT_FALSE(listener.deletedFiles_.find("my dicom file") == listener.deletedFiles_.end());
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
175
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
176 ASSERT_EQ(2u, index.GetTableRecordCount("Resources"));
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
177 ASSERT_EQ(0u, index.GetTableRecordCount("Metadata"));
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
178 ASSERT_EQ(1u, index.GetTableRecordCount("AttachedFiles"));
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
179 ASSERT_EQ(0u, index.GetTableRecordCount("MainDicomTags"));
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
180 index.DeleteResource(a[5]);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
181 ASSERT_EQ(0u, index.GetTableRecordCount("Resources"));
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
182 ASSERT_EQ(0u, index.GetTableRecordCount("AttachedFiles"));
252
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
183 ASSERT_EQ(2u, index.GetTableRecordCount("GlobalProperties"));
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
184
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
185 ASSERT_EQ(3u, listener.deletedFiles_.size());
185
5185ae1d9af5 fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
186 ASSERT_FALSE(listener.deletedFiles_.find("world") == listener.deletedFiles_.end());
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
187 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
188
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
189
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
190
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
191
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
192 TEST(DatabaseWrapper, Upward)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
193 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
194 ServerIndexListener listener;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
195 DatabaseWrapper index(listener);
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 int64_t a[] = {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
198 index.CreateResource("a", ResourceType_Patient), // 0
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
199 index.CreateResource("b", ResourceType_Study), // 1
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
200 index.CreateResource("c", ResourceType_Series), // 2
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
201 index.CreateResource("d", ResourceType_Instance), // 3
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
202 index.CreateResource("e", ResourceType_Instance), // 4
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
203 index.CreateResource("f", ResourceType_Study), // 5
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
204 index.CreateResource("g", ResourceType_Series), // 6
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
205 index.CreateResource("h", ResourceType_Series) // 7
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
206 };
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
207
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
208 index.AttachChild(a[0], a[1]);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
209 index.AttachChild(a[1], a[2]);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
210 index.AttachChild(a[2], a[3]);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
211 index.AttachChild(a[2], a[4]);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
212 index.AttachChild(a[1], a[6]);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
213 index.AttachChild(a[0], a[5]);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
214 index.AttachChild(a[5], a[7]);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
215
193
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 190
diff changeset
216 {
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 190
diff changeset
217 Json::Value j;
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 190
diff changeset
218 index.GetChildren(j, a[0]);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
219 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
220 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
221 (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
222
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 190
diff changeset
223 index.GetChildren(j, a[1]);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
224 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
225 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
226 (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
227
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 190
diff changeset
228 index.GetChildren(j, a[2]);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
229 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
230 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
231 (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
232
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
233 index.GetChildren(j, a[3]); ASSERT_EQ(0u, j.size());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
234 index.GetChildren(j, a[4]); ASSERT_EQ(0u, j.size());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
235 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
236 index.GetChildren(j, a[6]); ASSERT_EQ(0u, j.size());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
237 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
238 }
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 190
diff changeset
239
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
240 listener.Reset();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
241 index.DeleteResource(a[3]);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
242 ASSERT_EQ("c", listener.ancestorId_);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
243 ASSERT_EQ(ResourceType_Series, listener.ancestorType_);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
244
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
245 listener.Reset();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
246 index.DeleteResource(a[4]);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
247 ASSERT_EQ("b", listener.ancestorId_);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
248 ASSERT_EQ(ResourceType_Study, listener.ancestorType_);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
249
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
250 listener.Reset();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
251 index.DeleteResource(a[7]);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
252 ASSERT_EQ("a", listener.ancestorId_);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
253 ASSERT_EQ(ResourceType_Patient, listener.ancestorType_);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
254
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
255 listener.Reset();
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 index.DeleteResource(a[6]);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
257 ASSERT_EQ("", listener.ancestorId_); // No more ancestor
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 }