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