Mercurial > hg > orthanc-databases
annotate PostgreSQL/UnitTests/PostgreSQLTests.cpp @ 474:b363f94084c0 OrthancPostgreSQL-6.1
6.1
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 14 Feb 2024 15:06:44 +0100 |
parents | ecd0b719cff5 |
children | 54d518dcd74a |
rev | line source |
---|---|
0 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
459
ecd0b719cff5
update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
403
diff
changeset
|
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium |
ecd0b719cff5
update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
403
diff
changeset
|
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU Affero General Public License | |
10 * as published by the Free Software Foundation, either version 3 of | |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * Affero General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Affero General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
23 #include <gtest/gtest.h> | |
24 | |
25 #if defined(_WIN32) | |
26 // Fix redefinition of symbols on MinGW (these symbols are manually | |
27 // defined both by PostgreSQL and Google Test) | |
28 # undef S_IRGRP | |
29 # undef S_IROTH | |
30 # undef S_IRWXG | |
31 # undef S_IRWXO | |
32 # undef S_IWGRP | |
33 # undef S_IWOTH | |
34 # undef S_IXGRP | |
35 # undef S_IXOTH | |
36 #endif | |
37 | |
152 | 38 #include "../../Framework/Plugins/GlobalProperties.h" |
39 #include "../../Framework/PostgreSQL/PostgreSQLLargeObject.h" | |
40 #include "../../Framework/PostgreSQL/PostgreSQLResult.h" | |
41 #include "../../Framework/PostgreSQL/PostgreSQLTransaction.h" | |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
42 #include "../Plugins/PostgreSQLIndex.h" |
14
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
43 #include "../Plugins/PostgreSQLStorageArea.h" |
0 | 44 |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
45 #include <Compatibility.h> // For std::unique_ptr<> |
152 | 46 #include <OrthancException.h> |
0 | 47 |
48 #include <boost/lexical_cast.hpp> | |
49 | |
50 using namespace OrthancDatabases; | |
51 | |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
52 extern PostgreSQLParameters globalParameters_; |
0 | 53 |
54 | |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
55 static PostgreSQLDatabase* CreateTestDatabase() |
0 | 56 { |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
57 std::unique_ptr<PostgreSQLDatabase> pg |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
58 (new PostgreSQLDatabase(globalParameters_)); |
0 | 59 |
60 pg->Open(); | |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
61 pg->ClearAll(); |
0 | 62 |
63 return pg.release(); | |
64 } | |
65 | |
66 | |
67 static int64_t CountLargeObjects(PostgreSQLDatabase& db) | |
68 { | |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
69 PostgreSQLTransaction transaction(db, TransactionType_ReadOnly); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
70 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
71 int64_t count; |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
72 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
73 { |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
74 // Count the number of large objects in the DB |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
75 PostgreSQLStatement s(db, "SELECT COUNT(*) FROM pg_catalog.pg_largeobject"); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
76 PostgreSQLResult r(s); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
77 count = r.GetInteger64(0); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
78 } |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
79 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
80 transaction.Commit(); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
81 return count; |
0 | 82 } |
83 | |
84 | |
85 TEST(PostgreSQL, Basic) | |
86 { | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
87 std::unique_ptr<PostgreSQLDatabase> pg(CreateTestDatabase()); |
0 | 88 |
89 ASSERT_FALSE(pg->DoesTableExist("Test")); | |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
90 ASSERT_FALSE(pg->DoesColumnExist("Test", "value")); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
91 ASSERT_FALSE(pg->DoesTableExist("TEST")); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
92 ASSERT_FALSE(pg->DoesTableExist("test")); |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
230
diff
changeset
|
93 pg->ExecuteMultiLines("CREATE TABLE Test(name INTEGER, value BIGINT)"); |
0 | 94 ASSERT_TRUE(pg->DoesTableExist("Test")); |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
95 ASSERT_TRUE(pg->DoesTableExist("TEST")); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
96 ASSERT_TRUE(pg->DoesTableExist("test")); |
0 | 97 |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
98 ASSERT_TRUE(pg->DoesColumnExist("Test", "Value")); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
99 ASSERT_TRUE(pg->DoesColumnExist("TEST", "VALUE")); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
100 ASSERT_TRUE(pg->DoesColumnExist("test", "value")); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
101 |
214
ab96698c73a3
removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
102 PostgreSQLStatement s(*pg, "INSERT INTO Test VALUES ($1,$2)"); |
0 | 103 s.DeclareInputInteger(0); |
104 s.DeclareInputInteger64(1); | |
105 | |
106 s.BindInteger(0, 43); | |
107 s.BindNull(0); | |
108 s.BindInteger(0, 42); | |
109 s.BindInteger64(1, -4242); | |
110 s.Run(); | |
111 | |
112 s.BindInteger(0, 43); | |
113 s.BindNull(1); | |
114 s.Run(); | |
115 | |
116 s.BindNull(0); | |
117 s.BindInteger64(1, 4444); | |
118 s.Run(); | |
119 | |
120 { | |
214
ab96698c73a3
removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
121 PostgreSQLStatement t(*pg, "SELECT name, value FROM Test ORDER BY name"); |
0 | 122 PostgreSQLResult r(t); |
123 | |
124 ASSERT_FALSE(r.IsDone()); | |
125 ASSERT_FALSE(r.IsNull(0)); ASSERT_EQ(42, r.GetInteger(0)); | |
126 ASSERT_FALSE(r.IsNull(1)); ASSERT_EQ(-4242, r.GetInteger64(1)); | |
127 | |
128 r.Next(); | |
129 ASSERT_FALSE(r.IsDone()); | |
130 ASSERT_FALSE(r.IsNull(0)); ASSERT_EQ(43, r.GetInteger(0)); | |
131 ASSERT_TRUE(r.IsNull(1)); | |
132 | |
133 r.Next(); | |
134 ASSERT_FALSE(r.IsDone()); | |
135 ASSERT_TRUE(r.IsNull(0)); | |
136 ASSERT_FALSE(r.IsNull(1)); ASSERT_EQ(4444, r.GetInteger64(1)); | |
137 | |
138 r.Next(); | |
139 ASSERT_TRUE(r.IsDone()); | |
140 } | |
141 | |
142 { | |
214
ab96698c73a3
removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
143 PostgreSQLStatement t(*pg, "SELECT name, value FROM Test WHERE name=$1"); |
0 | 144 t.DeclareInputInteger(0); |
145 | |
146 { | |
147 t.BindInteger(0, 42); | |
148 PostgreSQLResult r(t); | |
149 ASSERT_FALSE(r.IsDone()); | |
150 ASSERT_FALSE(r.IsNull(0)); ASSERT_EQ(42, r.GetInteger(0)); | |
151 ASSERT_FALSE(r.IsNull(1)); ASSERT_EQ(-4242, r.GetInteger64(1)); | |
152 | |
153 r.Next(); | |
154 ASSERT_TRUE(r.IsDone()); | |
155 } | |
156 | |
157 { | |
158 t.BindInteger(0, 40); | |
159 PostgreSQLResult r(t); | |
160 ASSERT_TRUE(r.IsDone()); | |
161 } | |
162 } | |
163 | |
164 } | |
165 | |
166 | |
167 TEST(PostgreSQL, String) | |
168 { | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
169 std::unique_ptr<PostgreSQLDatabase> pg(CreateTestDatabase()); |
0 | 170 |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
230
diff
changeset
|
171 pg->ExecuteMultiLines("CREATE TABLE Test(name INTEGER, value VARCHAR(40))"); |
0 | 172 |
214
ab96698c73a3
removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
173 PostgreSQLStatement s(*pg, "INSERT INTO Test VALUES ($1,$2)"); |
0 | 174 s.DeclareInputInteger(0); |
175 s.DeclareInputString(1); | |
176 | |
177 s.BindInteger(0, 42); | |
178 s.BindString(1, "Hello"); | |
179 s.Run(); | |
180 | |
181 s.BindInteger(0, 43); | |
182 s.BindNull(1); | |
183 s.Run(); | |
184 | |
185 s.BindNull(0); | |
186 s.BindString(1, ""); | |
187 s.Run(); | |
188 | |
189 { | |
214
ab96698c73a3
removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
190 PostgreSQLStatement t(*pg, "SELECT name, value FROM Test ORDER BY name"); |
0 | 191 PostgreSQLResult r(t); |
192 | |
193 ASSERT_FALSE(r.IsDone()); | |
194 ASSERT_FALSE(r.IsNull(0)); ASSERT_EQ(42, r.GetInteger(0)); | |
195 ASSERT_FALSE(r.IsNull(1)); ASSERT_EQ("Hello", r.GetString(1)); | |
196 | |
197 r.Next(); | |
198 ASSERT_FALSE(r.IsDone()); | |
199 ASSERT_FALSE(r.IsNull(0)); ASSERT_EQ(43, r.GetInteger(0)); | |
200 ASSERT_TRUE(r.IsNull(1)); | |
201 | |
202 r.Next(); | |
203 ASSERT_FALSE(r.IsDone()); | |
204 ASSERT_TRUE(r.IsNull(0)); | |
205 ASSERT_FALSE(r.IsNull(1)); ASSERT_EQ("", r.GetString(1)); | |
206 | |
207 r.Next(); | |
208 ASSERT_TRUE(r.IsDone()); | |
209 } | |
210 } | |
211 | |
212 | |
213 TEST(PostgreSQL, Transaction) | |
214 { | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
215 std::unique_ptr<PostgreSQLDatabase> pg(CreateTestDatabase()); |
0 | 216 |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
230
diff
changeset
|
217 pg->ExecuteMultiLines("CREATE TABLE Test(name INTEGER, value INTEGER)"); |
0 | 218 |
219 { | |
214
ab96698c73a3
removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
220 PostgreSQLStatement s(*pg, "INSERT INTO Test VALUES ($1,$2)"); |
0 | 221 s.DeclareInputInteger(0); |
222 s.DeclareInputInteger(1); | |
223 s.BindInteger(0, 42); | |
224 s.BindInteger(1, 4242); | |
225 s.Run(); | |
226 | |
227 { | |
216
fbb52129158a
TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
228 PostgreSQLTransaction t(*pg, TransactionType_ReadOnly); |
fbb52129158a
TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
229 s.BindInteger(0, 0); |
fbb52129158a
TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
230 s.BindInteger(1, 1); |
fbb52129158a
TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
231 // Failure, as INSERT in a read-only transaction |
fbb52129158a
TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
232 ASSERT_THROW(s.Run(), Orthanc::OrthancException); |
fbb52129158a
TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
233 } |
fbb52129158a
TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
234 |
fbb52129158a
TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
235 { |
fbb52129158a
TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
236 PostgreSQLTransaction t(*pg, TransactionType_ReadWrite); |
0 | 237 s.BindInteger(0, 43); |
238 s.BindInteger(1, 4343); | |
239 s.Run(); | |
240 s.BindInteger(0, 44); | |
241 s.BindInteger(1, 4444); | |
242 s.Run(); | |
243 | |
214
ab96698c73a3
removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
244 PostgreSQLStatement u(*pg, "SELECT COUNT(*) FROM Test"); |
0 | 245 PostgreSQLResult r(u); |
246 ASSERT_EQ(3, r.GetInteger64(0)); | |
247 | |
248 // No commit | |
249 } | |
250 | |
251 { | |
216
fbb52129158a
TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
252 // Implicit transaction |
214
ab96698c73a3
removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
253 PostgreSQLStatement u(*pg, "SELECT COUNT(*) FROM Test"); |
0 | 254 PostgreSQLResult r(u); |
255 ASSERT_EQ(1, r.GetInteger64(0)); // Just "1" because of implicit rollback | |
256 } | |
257 | |
258 { | |
216
fbb52129158a
TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
259 PostgreSQLTransaction t(*pg, TransactionType_ReadWrite); |
0 | 260 s.BindInteger(0, 43); |
261 s.BindInteger(1, 4343); | |
262 s.Run(); | |
263 s.BindInteger(0, 44); | |
264 s.BindInteger(1, 4444); | |
265 s.Run(); | |
266 | |
267 { | |
214
ab96698c73a3
removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
268 PostgreSQLStatement u(*pg, "SELECT COUNT(*) FROM Test"); |
0 | 269 PostgreSQLResult r(u); |
270 ASSERT_EQ(3, r.GetInteger64(0)); | |
271 | |
272 t.Commit(); | |
273 ASSERT_THROW(t.Rollback(), Orthanc::OrthancException); | |
274 ASSERT_THROW(t.Commit(), Orthanc::OrthancException); | |
275 } | |
276 } | |
277 | |
278 { | |
216
fbb52129158a
TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
279 PostgreSQLTransaction t(*pg, TransactionType_ReadOnly); |
214
ab96698c73a3
removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
280 PostgreSQLStatement u(*pg, "SELECT COUNT(*) FROM Test"); |
0 | 281 PostgreSQLResult r(u); |
282 ASSERT_EQ(3, r.GetInteger64(0)); | |
283 } | |
284 } | |
285 } | |
286 | |
287 | |
288 | |
289 | |
290 | |
291 TEST(PostgreSQL, LargeObject) | |
292 { | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
293 std::unique_ptr<PostgreSQLDatabase> pg(CreateTestDatabase()); |
0 | 294 ASSERT_EQ(0, CountLargeObjects(*pg)); |
295 | |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
230
diff
changeset
|
296 pg->ExecuteMultiLines("CREATE TABLE Test(name VARCHAR, value OID)"); |
0 | 297 |
298 // Automatically remove the large objects associated with the table | |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
230
diff
changeset
|
299 pg->ExecuteMultiLines("CREATE RULE TestDelete AS ON DELETE TO Test DO SELECT lo_unlink(old.value);"); |
0 | 300 |
301 { | |
214
ab96698c73a3
removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
302 PostgreSQLStatement s(*pg, "INSERT INTO Test VALUES ($1,$2)"); |
0 | 303 s.DeclareInputString(0); |
304 s.DeclareInputLargeObject(1); | |
305 | |
306 for (int i = 0; i < 10; i++) | |
307 { | |
216
fbb52129158a
TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
308 PostgreSQLTransaction t(*pg, TransactionType_ReadWrite); |
0 | 309 |
310 std::string value = "Value " + boost::lexical_cast<std::string>(i * 2); | |
311 PostgreSQLLargeObject obj(*pg, value); | |
312 | |
313 s.BindString(0, "Index " + boost::lexical_cast<std::string>(i)); | |
314 s.BindLargeObject(1, obj); | |
315 s.Run(); | |
316 | |
317 std::string tmp; | |
248
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
318 PostgreSQLLargeObject::ReadWhole(tmp, *pg, obj.GetOid()); |
0 | 319 ASSERT_EQ(value, tmp); |
320 | |
321 t.Commit(); | |
322 } | |
323 } | |
324 | |
325 | |
326 ASSERT_EQ(10, CountLargeObjects(*pg)); | |
327 | |
328 { | |
216
fbb52129158a
TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
329 PostgreSQLTransaction t(*pg, TransactionType_ReadOnly); |
214
ab96698c73a3
removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
330 PostgreSQLStatement s(*pg, "SELECT * FROM Test ORDER BY name DESC"); |
0 | 331 PostgreSQLResult r(s); |
332 | |
333 ASSERT_FALSE(r.IsDone()); | |
334 | |
335 ASSERT_FALSE(r.IsNull(0)); | |
336 ASSERT_EQ("Index 9", r.GetString(0)); | |
337 | |
338 std::string data; | |
246
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
242
diff
changeset
|
339 r.GetLargeObjectContent(data, 1); |
0 | 340 ASSERT_EQ("Value 18", data); |
341 | |
342 r.Next(); | |
343 ASSERT_FALSE(r.IsDone()); | |
344 | |
345 //ASSERT_TRUE(r.IsString(0)); | |
346 } | |
347 | |
348 | |
349 { | |
216
fbb52129158a
TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
350 PostgreSQLTransaction t(*pg, TransactionType_ReadWrite); |
214
ab96698c73a3
removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
351 PostgreSQLStatement s(*pg, "DELETE FROM Test WHERE name='Index 9'"); |
0 | 352 s.Run(); |
353 t.Commit(); | |
354 } | |
355 | |
356 | |
357 { | |
358 // Count the number of items in the DB | |
216
fbb52129158a
TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
359 PostgreSQLTransaction t(*pg, TransactionType_ReadOnly); |
214
ab96698c73a3
removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
360 PostgreSQLStatement s(*pg, "SELECT COUNT(*) FROM Test"); |
0 | 361 PostgreSQLResult r(s); |
362 ASSERT_EQ(9, r.GetInteger64(0)); | |
363 } | |
364 | |
365 ASSERT_EQ(9, CountLargeObjects(*pg)); | |
366 } | |
367 | |
368 | |
14
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
369 TEST(PostgreSQL, StorageArea) |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
370 { |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
248
diff
changeset
|
371 std::unique_ptr<PostgreSQLDatabase> database(PostgreSQLDatabase::CreateDatabaseConnection(globalParameters_)); |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
372 |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
373 PostgreSQLStorageArea storageArea(globalParameters_, true /* clear database */); |
0 | 374 |
14
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
375 { |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
376 std::unique_ptr<OrthancDatabases::StorageBackend::IAccessor> accessor(storageArea.CreateAccessor()); |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
377 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
378 ASSERT_EQ(0, CountLargeObjects(*database)); |
14
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
379 |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
380 for (int i = 0; i < 10; i++) |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
381 { |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
382 std::string uuid = boost::lexical_cast<std::string>(i); |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
383 std::string value = "Value " + boost::lexical_cast<std::string>(i * 2); |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
384 accessor->Create(uuid, value.c_str(), value.size(), OrthancPluginContentType_Unknown); |
14
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
385 } |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
386 |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
216
diff
changeset
|
387 std::string buffer; |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
388 ASSERT_THROW(OrthancDatabases::StorageBackend::ReadWholeToString(buffer, *accessor, "nope", OrthancPluginContentType_Unknown), |
14
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
389 Orthanc::OrthancException); |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
390 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
391 ASSERT_EQ(10, CountLargeObjects(*database)); |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
392 accessor->Remove("5", OrthancPluginContentType_Unknown); |
14
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
393 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
394 ASSERT_EQ(9, CountLargeObjects(*database)); |
0 | 395 |
14
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
396 for (int i = 0; i < 10; i++) |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
397 { |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
398 std::string uuid = boost::lexical_cast<std::string>(i); |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
399 std::string expected = "Value " + boost::lexical_cast<std::string>(i * 2); |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
400 |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
401 if (i == 5) |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
402 { |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
403 ASSERT_THROW(OrthancDatabases::StorageBackend::ReadWholeToString(buffer, *accessor, uuid, OrthancPluginContentType_Unknown), |
14
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
404 Orthanc::OrthancException); |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
405 } |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
406 else |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
407 { |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
408 OrthancDatabases::StorageBackend::ReadWholeToString(buffer, *accessor, uuid, OrthancPluginContentType_Unknown); |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
216
diff
changeset
|
409 ASSERT_EQ(expected, buffer); |
14
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
410 } |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
411 } |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
412 |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
413 for (int i = 0; i < 10; i++) |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
414 { |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
415 accessor->Remove(boost::lexical_cast<std::string>(i), OrthancPluginContentType_Unknown); |
14
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
416 } |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
417 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
418 ASSERT_EQ(0, CountLargeObjects(*database)); |
14
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
419 } |
0 | 420 } |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
421 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
422 |
248
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
423 TEST(PostgreSQL, StorageReadRange) |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
424 { |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
425 std::unique_ptr<OrthancDatabases::PostgreSQLDatabase> database( |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
248
diff
changeset
|
426 OrthancDatabases::PostgreSQLDatabase::CreateDatabaseConnection(globalParameters_)); |
248
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
427 |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
428 OrthancDatabases::PostgreSQLStorageArea storageArea(globalParameters_, true /* clear database */); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
429 |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
430 { |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
431 std::unique_ptr<OrthancDatabases::StorageBackend::IAccessor> accessor(storageArea.CreateAccessor()); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
432 ASSERT_EQ(0, CountLargeObjects(*database)); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
433 accessor->Create("uuid", "abcd\0\1\2\3\4\5", 10, OrthancPluginContentType_Unknown); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
434 ASSERT_EQ(1u, CountLargeObjects(*database)); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
435 } |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
436 |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
437 { |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
438 std::unique_ptr<OrthancDatabases::StorageBackend::IAccessor> accessor(storageArea.CreateAccessor()); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
439 ASSERT_EQ(1u, CountLargeObjects(*database)); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
440 |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
441 std::string s; |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
442 OrthancDatabases::StorageBackend::ReadWholeToString(s, *accessor, "uuid", OrthancPluginContentType_Unknown); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
443 ASSERT_EQ(10u, s.size()); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
444 ASSERT_EQ('a', s[0]); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
445 ASSERT_EQ('d', s[3]); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
446 ASSERT_EQ('\0', s[4]); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
447 ASSERT_EQ('\5', s[9]); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
448 |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
449 OrthancDatabases::StorageBackend::ReadRangeToString(s, *accessor, "uuid", OrthancPluginContentType_Unknown, 0, 0); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
450 ASSERT_TRUE(s.empty()); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
451 |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
452 OrthancDatabases::StorageBackend::ReadRangeToString(s, *accessor, "uuid", OrthancPluginContentType_Unknown, 0, 1); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
453 ASSERT_EQ(1u, s.size()); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
454 ASSERT_EQ('a', s[0]); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
455 |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
456 OrthancDatabases::StorageBackend::ReadRangeToString(s, *accessor, "uuid", OrthancPluginContentType_Unknown, 4, 1); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
457 ASSERT_EQ(1u, s.size()); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
458 ASSERT_EQ('\0', s[0]); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
459 |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
460 OrthancDatabases::StorageBackend::ReadRangeToString(s, *accessor, "uuid", OrthancPluginContentType_Unknown, 9, 1); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
461 ASSERT_EQ(1u, s.size()); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
462 ASSERT_EQ('\5', s[0]); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
463 |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
464 // Cannot read non-empty range after the end of the string. NB: |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
465 // The behavior on range (10, 0) is different than in MySQL! |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
466 ASSERT_THROW(OrthancDatabases::StorageBackend::ReadRangeToString( |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
467 s, *accessor, "uuid", OrthancPluginContentType_Unknown, 10, 0), Orthanc::OrthancException); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
468 |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
469 ASSERT_THROW(OrthancDatabases::StorageBackend::ReadRangeToString( |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
470 s, *accessor, "uuid", OrthancPluginContentType_Unknown, 10, 1), Orthanc::OrthancException); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
471 |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
472 OrthancDatabases::StorageBackend::ReadRangeToString(s, *accessor, "uuid", OrthancPluginContentType_Unknown, 0, 4); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
473 ASSERT_EQ(4u, s.size()); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
474 ASSERT_EQ('a', s[0]); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
475 ASSERT_EQ('b', s[1]); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
476 ASSERT_EQ('c', s[2]); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
477 ASSERT_EQ('d', s[3]); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
478 |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
479 OrthancDatabases::StorageBackend::ReadRangeToString(s, *accessor, "uuid", OrthancPluginContentType_Unknown, 4, 6); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
480 ASSERT_EQ(6u, s.size()); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
481 ASSERT_EQ('\0', s[0]); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
482 ASSERT_EQ('\1', s[1]); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
483 ASSERT_EQ('\2', s[2]); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
484 ASSERT_EQ('\3', s[3]); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
485 ASSERT_EQ('\4', s[4]); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
486 ASSERT_EQ('\5', s[5]); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
487 |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
488 ASSERT_THROW(OrthancDatabases::StorageBackend::ReadRangeToString( |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
489 s, *accessor, "uuid", OrthancPluginContentType_Unknown, 4, 7), Orthanc::OrthancException); |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
490 } |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
491 } |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
492 |
7a4f9bcb0bc2
PostgreSQL: Support of range reads from the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
493 |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
494 TEST(PostgreSQL, ImplicitTransaction) |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
495 { |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
496 std::unique_ptr<PostgreSQLDatabase> db(CreateTestDatabase()); |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
497 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
498 ASSERT_FALSE(db->DoesTableExist("test")); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
499 ASSERT_FALSE(db->DoesTableExist("test2")); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
500 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
501 { |
215
b40b30075c51
added TransactionType_Implicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
502 std::unique_ptr<OrthancDatabases::ITransaction> t(db->CreateTransaction(TransactionType_ReadWrite)); |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
503 ASSERT_FALSE(t->IsImplicit()); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
504 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
505 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
506 { |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
507 Query query("CREATE TABLE test(id INT)", false); |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
508 std::unique_ptr<IPrecompiledStatement> s(db->Compile(query)); |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
509 |
215
b40b30075c51
added TransactionType_Implicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
510 std::unique_ptr<ITransaction> t(db->CreateTransaction(TransactionType_Implicit)); |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
511 ASSERT_TRUE(t->IsImplicit()); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
512 ASSERT_THROW(t->Commit(), Orthanc::OrthancException); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
513 ASSERT_THROW(t->Rollback(), Orthanc::OrthancException); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
514 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
515 Dictionary args; |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
516 t->ExecuteWithoutResult(*s, args); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
517 ASSERT_THROW(t->Rollback(), Orthanc::OrthancException); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
518 t->Commit(); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
519 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
520 ASSERT_THROW(t->Commit(), Orthanc::OrthancException); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
521 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
522 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
523 { |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
524 // An implicit transaction does not need to be explicitely committed |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
525 Query query("CREATE TABLE test2(id INT)", false); |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
526 std::unique_ptr<IPrecompiledStatement> s(db->Compile(query)); |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
527 |
215
b40b30075c51
added TransactionType_Implicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
528 std::unique_ptr<ITransaction> t(db->CreateTransaction(TransactionType_Implicit)); |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
529 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
530 Dictionary args; |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
531 t->ExecuteWithoutResult(*s, args); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
532 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
533 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
534 ASSERT_TRUE(db->DoesTableExist("test")); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
535 ASSERT_TRUE(db->DoesTableExist("test2")); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
536 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
537 |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
538 |
78 | 539 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
540 TEST(PostgreSQLIndex, CreateInstance) |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
541 { |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
195
diff
changeset
|
542 OrthancDatabases::PostgreSQLIndex db(NULL, globalParameters_); |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
543 db.SetClearAll(true); |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
544 |
403
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
545 std::list<OrthancDatabases::IdentifierTag> tags; |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
546 std::unique_ptr<OrthancDatabases::DatabaseManager> manager(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db, false, tags)); |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
547 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
548 std::string s; |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
549 ASSERT_TRUE(db.LookupGlobalProperty(s, *manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseInternal1)); |
95 | 550 ASSERT_EQ("2", s); |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
551 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
552 OrthancPluginCreateInstanceResult r1, r2; |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
553 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
554 memset(&r1, 0, sizeof(r1)); |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
555 db.CreateInstance(r1, *manager, "a", "b", "c", "d"); |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
556 ASSERT_TRUE(r1.isNewInstance); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
557 ASSERT_TRUE(r1.isNewSeries); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
558 ASSERT_TRUE(r1.isNewStudy); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
559 ASSERT_TRUE(r1.isNewPatient); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
560 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
561 memset(&r2, 0, sizeof(r2)); |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
562 db.CreateInstance(r2, *manager, "a", "b", "c", "d"); |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
563 ASSERT_FALSE(r2.isNewInstance); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
564 ASSERT_EQ(r1.instanceId, r2.instanceId); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
565 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
566 // Breaking the hierarchy |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
567 memset(&r2, 0, sizeof(r2)); |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
568 ASSERT_THROW(db.CreateInstance(r2, *manager, "a", "e", "c", "f"), Orthanc::OrthancException); |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
569 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
570 memset(&r2, 0, sizeof(r2)); |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
571 db.CreateInstance(r2, *manager, "a", "b", "c", "e"); |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
572 ASSERT_TRUE(r2.isNewInstance); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
573 ASSERT_FALSE(r2.isNewSeries); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
574 ASSERT_FALSE(r2.isNewStudy); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
575 ASSERT_FALSE(r2.isNewPatient); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
576 ASSERT_EQ(r1.patientId, r2.patientId); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
577 ASSERT_EQ(r1.studyId, r2.studyId); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
578 ASSERT_EQ(r1.seriesId, r2.seriesId); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
579 ASSERT_NE(r1.instanceId, r2.instanceId); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
580 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
581 memset(&r2, 0, sizeof(r2)); |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
582 db.CreateInstance(r2, *manager, "a", "b", "f", "g"); |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
583 ASSERT_TRUE(r2.isNewInstance); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
584 ASSERT_TRUE(r2.isNewSeries); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
585 ASSERT_FALSE(r2.isNewStudy); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
586 ASSERT_FALSE(r2.isNewPatient); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
587 ASSERT_EQ(r1.patientId, r2.patientId); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
588 ASSERT_EQ(r1.studyId, r2.studyId); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
589 ASSERT_NE(r1.seriesId, r2.seriesId); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
590 ASSERT_NE(r1.instanceId, r2.instanceId); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
591 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
592 memset(&r2, 0, sizeof(r2)); |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
593 db.CreateInstance(r2, *manager, "a", "h", "i", "j"); |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
594 ASSERT_TRUE(r2.isNewInstance); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
595 ASSERT_TRUE(r2.isNewSeries); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
596 ASSERT_TRUE(r2.isNewStudy); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
597 ASSERT_FALSE(r2.isNewPatient); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
598 ASSERT_EQ(r1.patientId, r2.patientId); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
599 ASSERT_NE(r1.studyId, r2.studyId); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
600 ASSERT_NE(r1.seriesId, r2.seriesId); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
601 ASSERT_NE(r1.instanceId, r2.instanceId); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
602 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
603 memset(&r2, 0, sizeof(r2)); |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
604 db.CreateInstance(r2, *manager, "k", "l", "m", "n"); |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
605 ASSERT_TRUE(r2.isNewInstance); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
606 ASSERT_TRUE(r2.isNewSeries); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
607 ASSERT_TRUE(r2.isNewStudy); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
608 ASSERT_TRUE(r2.isNewPatient); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
609 ASSERT_NE(r1.patientId, r2.patientId); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
610 ASSERT_NE(r1.studyId, r2.studyId); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
611 ASSERT_NE(r1.seriesId, r2.seriesId); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
612 ASSERT_NE(r1.instanceId, r2.instanceId); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
613 } |
73
aa81c1c80c75
fix compatibility with older sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
614 #endif |
134
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
615 |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
616 |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
617 TEST(PostgreSQL, Lock2) |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
618 { |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
619 std::unique_ptr<PostgreSQLDatabase> db1(CreateTestDatabase()); |
134
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
620 |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
621 ASSERT_FALSE(db1->ReleaseAdvisoryLock(43)); // lock counter = 0 |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
622 ASSERT_TRUE(db1->AcquireAdvisoryLock(43)); // lock counter = 1 |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
623 |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
624 // OK, as this is the same connection |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
625 ASSERT_TRUE(db1->AcquireAdvisoryLock(43)); // lock counter = 2 |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
626 ASSERT_TRUE(db1->ReleaseAdvisoryLock(43)); // lock counter = 1 |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
627 |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
628 // Try and release twice the lock |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
629 ASSERT_TRUE(db1->ReleaseAdvisoryLock(43)); // lock counter = 0 |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
630 ASSERT_FALSE(db1->ReleaseAdvisoryLock(43)); // cannot unlock |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
631 ASSERT_TRUE(db1->AcquireAdvisoryLock(43)); // lock counter = 1 |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
632 |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
633 { |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
634 std::unique_ptr<PostgreSQLDatabase> db2(CreateTestDatabase()); |
134
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
635 |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
636 // The "db1" is still actively locking |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
637 ASSERT_FALSE(db2->AcquireAdvisoryLock(43)); |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
638 |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
639 // Release the "db1" lock |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
640 ASSERT_TRUE(db1->ReleaseAdvisoryLock(43)); |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
641 ASSERT_FALSE(db1->ReleaseAdvisoryLock(43)); |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
642 |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
643 // "db2" can now acquire the lock, but not "db1" |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
644 ASSERT_TRUE(db2->AcquireAdvisoryLock(43)); |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
645 ASSERT_FALSE(db1->AcquireAdvisoryLock(43)); |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
646 } |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
647 |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
648 // "db2" is closed, "db1" can now acquire the lock |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
649 ASSERT_TRUE(db1->AcquireAdvisoryLock(43)); |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
650 } |