annotate MySQL/UnitTests/UnitTestsMain.cpp @ 512:a6300ccf6683 OrthancMySQL-5.2

MySQL 5.2
author Alain Mazy <am@orthanc.team>
date Thu, 06 Jun 2024 11:58:30 +0200
parents 54d518dcd74a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
507
54d518dcd74a updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 459
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
54d518dcd74a updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 459
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
459
ecd0b719cff5 update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 403
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * modify it under the terms of the GNU Affero General Public License
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * as published by the Free Software Foundation, either version 3 of
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * the License, or (at your option) any later version.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * Affero General Public License for more details.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * You should have received a copy of the GNU Affero General Public License
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "../Plugins/MySQLIndex.h"
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
25 #include "../Plugins/MySQLStorageArea.h"
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
309
d192bfd0e752 tagging globalParameters_ as static in MySQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
27 static OrthancDatabases::MySQLParameters globalParameters_;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
29 #include "../../Framework/Common/Integer64Value.h"
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
30 #include "../../Framework/MySQL/MySQLDatabase.h"
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
31 #include "../../Framework/MySQL/MySQLResult.h"
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
32 #include "../../Framework/MySQL/MySQLStatement.h"
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
33 #include "../../Framework/MySQL/MySQLTransaction.h"
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "../../Framework/Plugins/IndexUnitTests.h"
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
36 #include <Compatibility.h> // For std::unique_ptr<>
152
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
37 #include <HttpClient.h>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
38 #include <Logging.h>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
39 #include <Toolbox.h>
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include <gtest/gtest.h>
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 TEST(MySQLIndex, Lock)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 OrthancDatabases::MySQLParameters noLock = globalParameters_;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 noLock.SetLock(false);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 OrthancDatabases::MySQLParameters lock = globalParameters_;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 lock.SetLock(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 195
diff changeset
52 OrthancDatabases::MySQLIndex db1(NULL, noLock);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 db1.SetClearAll(true);
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 219
diff changeset
54
403
91124cc8a8c7 database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
55 std::list<OrthancDatabases::IdentifierTag> identifierTags;
91124cc8a8c7 database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
56
91124cc8a8c7 database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
57 std::unique_ptr<OrthancDatabases::DatabaseManager> manager1(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db1, false, identifierTags));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 195
diff changeset
60 OrthancDatabases::MySQLIndex db2(NULL, lock);
403
91124cc8a8c7 database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
61 std::unique_ptr<OrthancDatabases::DatabaseManager> manager2(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db2, false, identifierTags));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 195
diff changeset
63 OrthancDatabases::MySQLIndex db3(NULL, lock);
403
91124cc8a8c7 database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
64 ASSERT_THROW(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db3, false, identifierTags), Orthanc::OrthancException);
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
65
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 195
diff changeset
68 OrthancDatabases::MySQLIndex db4(NULL, lock);
403
91124cc8a8c7 database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
69 std::unique_ptr<OrthancDatabases::DatabaseManager> manager4(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db4, false, identifierTags));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
135
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
73 TEST(MySQL, Lock2)
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
74 {
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
75 OrthancDatabases::MySQLDatabase::ClearDatabase(globalParameters_);
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
76
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
77 OrthancDatabases::MySQLDatabase db1(globalParameters_);
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
78 db1.Open();
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
79
137
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
80 ASSERT_FALSE(db1.ReleaseAdvisoryLock("mylock")); // lock counter = 0
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
81 ASSERT_TRUE(db1.AcquireAdvisoryLock("mylock")); // lock counter = 1
135
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
82
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
83 // OK, as this is the same connection
138
5c5cd59c991f fix unit tests if MySQL >= 5.7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
84 ASSERT_TRUE(db1.AcquireAdvisoryLock("mylock"));
5c5cd59c991f fix unit tests if MySQL >= 5.7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
85 // lock counter = 2 if MySQL >= 5.7, or 1 if MySQL < 5.7 (because
5c5cd59c991f fix unit tests if MySQL >= 5.7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
86 // acquiring a lock releases all the previously-acquired locks)
5c5cd59c991f fix unit tests if MySQL >= 5.7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
87
5c5cd59c991f fix unit tests if MySQL >= 5.7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
88 ASSERT_TRUE(db1.ReleaseAdvisoryLock("mylock"));
5c5cd59c991f fix unit tests if MySQL >= 5.7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
89 // lock counter = 1 if MySQL >= 5.7, or 0 if MySQL < 5.7
135
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
90
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
91 // Try and release twice the lock
138
5c5cd59c991f fix unit tests if MySQL >= 5.7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
92 db1.ReleaseAdvisoryLock("mylock"); // Succeeds iff MySQL >= 5.7
5c5cd59c991f fix unit tests if MySQL >= 5.7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
93
5c5cd59c991f fix unit tests if MySQL >= 5.7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
94 ASSERT_TRUE(db1.AcquireAdvisoryLock("mylock2")); // lock counter = 1
135
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
95
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
96 {
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
97 OrthancDatabases::MySQLDatabase db2(globalParameters_);
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
98 db2.Open();
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
99
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
100 // The "db1" is still actively locking
138
5c5cd59c991f fix unit tests if MySQL >= 5.7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
101 ASSERT_FALSE(db2.AcquireAdvisoryLock("mylock2"));
135
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
102
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
103 // Release the "db1" lock
138
5c5cd59c991f fix unit tests if MySQL >= 5.7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
104 ASSERT_TRUE(db1.ReleaseAdvisoryLock("mylock2"));
5c5cd59c991f fix unit tests if MySQL >= 5.7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
105 ASSERT_FALSE(db1.ReleaseAdvisoryLock("mylock2"));
135
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
106
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
107 // "db2" can now acquire the lock, but not "db1"
138
5c5cd59c991f fix unit tests if MySQL >= 5.7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
108 ASSERT_TRUE(db2.AcquireAdvisoryLock("mylock2"));
5c5cd59c991f fix unit tests if MySQL >= 5.7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
109 ASSERT_FALSE(db1.AcquireAdvisoryLock("mylock2"));
135
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
110 }
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
111
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
112 // "db2" is closed, "db1" can now acquire the lock
138
5c5cd59c991f fix unit tests if MySQL >= 5.7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
113 ASSERT_TRUE(db1.AcquireAdvisoryLock("mylock2"));
137
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
114 }
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
115
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
116
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
117
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
118 /**
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
119 * WARNING: The following test only succeeds if MySQL >= 5.7. This is
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
120 * because in MySQL < 5.7, acquiring a lock by calling "SELECT
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
121 * GET_LOCK()" releases all the previously acquired locks!
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
122 **/
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
123 TEST(MySQL, DISABLED_Lock3)
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
124 {
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
125 OrthancDatabases::MySQLDatabase::ClearDatabase(globalParameters_);
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
126
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
127 OrthancDatabases::MySQLDatabase db1(globalParameters_);
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
128 db1.Open();
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
129
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
130 ASSERT_TRUE(db1.AcquireAdvisoryLock("mylock1")); // lock counter = 1
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
131 ASSERT_TRUE(db1.AcquireAdvisoryLock("mylock2")); // lock counter = 1
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
132
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
133 {
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
134 OrthancDatabases::MySQLDatabase db2(globalParameters_);
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
135 db2.Open();
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
136
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
137 ASSERT_FALSE(db2.AcquireAdvisoryLock("mylock1"));
52b3859ee0b7 MySQL: acquiring named locks instead of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
138 }
135
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
139 }
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
140
e26690365c25 MySQL: Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
141
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
142 static int64_t CountFiles(OrthancDatabases::MySQLDatabase& db)
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
143 {
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
144 OrthancDatabases::MySQLTransaction transaction(db, OrthancDatabases::TransactionType_ReadOnly);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
145
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
146 int64_t count;
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
147 {
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
148 OrthancDatabases::Query query("SELECT COUNT(*) FROM StorageArea", true);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
149 OrthancDatabases::MySQLStatement s(db, query);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
150 OrthancDatabases::MySQLTransaction t(db, OrthancDatabases::TransactionType_ReadOnly);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
151 OrthancDatabases::Dictionary d;
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
152 std::unique_ptr<OrthancDatabases::IResult> result(s.Execute(t, d));
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
153 count = dynamic_cast<const OrthancDatabases::Integer64Value&>(result->GetField(0)).GetValue();
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
154 }
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
155
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
156 transaction.Commit();
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
157 return count;
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
158 }
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
159
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
160
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
161 TEST(MySQL, StorageArea)
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
162 {
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
163 std::unique_ptr<OrthancDatabases::MySQLDatabase> database(
255
d663d9e44f8d reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
164 OrthancDatabases::MySQLDatabase::CreateDatabaseConnection(globalParameters_));
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
165
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
166 OrthancDatabases::MySQLStorageArea storageArea(globalParameters_, true /* clear database */);
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
167
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
168 {
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
169 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
170
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
171 ASSERT_EQ(0, CountFiles(*database));
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
172
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
173 for (int i = 0; i < 10; i++)
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
174 {
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
175 std::string uuid = boost::lexical_cast<std::string>(i);
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
176 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: 230
diff changeset
177 accessor->Create(uuid, value.c_str(), value.size(), OrthancPluginContentType_Unknown);
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
178 }
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
179
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
180 std::string buffer;
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
181 ASSERT_THROW(OrthancDatabases::StorageBackend::ReadWholeToString(
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
182 buffer, *accessor, "nope", OrthancPluginContentType_Unknown),
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
183 Orthanc::OrthancException);
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
184
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
185 ASSERT_EQ(10, CountFiles(*database));
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
186 accessor->Remove("5", OrthancPluginContentType_Unknown);
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
187
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
188 ASSERT_EQ(9, CountFiles(*database));
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
189
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
190 for (int i = 0; i < 10; i++)
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
191 {
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
192 std::string uuid = boost::lexical_cast<std::string>(i);
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
193 std::string expected = "Value " + boost::lexical_cast<std::string>(i * 2);
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
194
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
195 if (i == 5)
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
196 {
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
197 ASSERT_THROW(OrthancDatabases::StorageBackend::ReadWholeToString(
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
198 buffer, *accessor, uuid, OrthancPluginContentType_Unknown),
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
199 Orthanc::OrthancException);
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
200 }
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
201 else
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
202 {
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
203 OrthancDatabases::StorageBackend::ReadWholeToString(buffer, *accessor, uuid, OrthancPluginContentType_Unknown);
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
204 ASSERT_EQ(expected, buffer);
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
205 }
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
206 }
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
207
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
208 for (int i = 0; i < 10; i++)
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
209 {
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
210 accessor->Remove(boost::lexical_cast<std::string>(i), OrthancPluginContentType_Unknown);
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
211 }
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
212
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
213 ASSERT_EQ(0, CountFiles(*database));
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
214 }
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
215 }
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
216
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
217
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
218 TEST(MySQL, StorageReadRange)
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
219 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
220 std::unique_ptr<OrthancDatabases::MySQLDatabase> database(
255
d663d9e44f8d reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
221 OrthancDatabases::MySQLDatabase::CreateDatabaseConnection(globalParameters_));
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
222
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
223 OrthancDatabases::MySQLStorageArea storageArea(globalParameters_, true /* clear database */);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
224
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
225 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
226 std::unique_ptr<OrthancDatabases::StorageBackend::IAccessor> accessor(storageArea.CreateAccessor());
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
227 ASSERT_EQ(0, CountFiles(*database));
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
228 accessor->Create("uuid", "abcd\0\1\2\3\4\5", 10, OrthancPluginContentType_Unknown);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
229 ASSERT_EQ(1u, CountFiles(*database));
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
230 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
231
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
232 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
233 std::unique_ptr<OrthancDatabases::StorageBackend::IAccessor> accessor(storageArea.CreateAccessor());
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
234 ASSERT_EQ(1u, CountFiles(*database));
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
235
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
236 std::string s;
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
237 OrthancDatabases::StorageBackend::ReadWholeToString(s, *accessor, "uuid", OrthancPluginContentType_Unknown);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
238 ASSERT_EQ(10u, s.size());
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
239 ASSERT_EQ('a', s[0]);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
240 ASSERT_EQ('d', s[3]);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
241 ASSERT_EQ('\0', s[4]);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
242 ASSERT_EQ('\5', s[9]);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
243
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
244 OrthancDatabases::StorageBackend::ReadRangeToString(s, *accessor, "uuid", OrthancPluginContentType_Unknown, 0, 0);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
245 ASSERT_TRUE(s.empty());
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
246
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
247 OrthancDatabases::StorageBackend::ReadRangeToString(s, *accessor, "uuid", OrthancPluginContentType_Unknown, 0, 1);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
248 ASSERT_EQ(1u, s.size());
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
249 ASSERT_EQ('a', s[0]);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
250
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
251 OrthancDatabases::StorageBackend::ReadRangeToString(s, *accessor, "uuid", OrthancPluginContentType_Unknown, 4, 1);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
252 ASSERT_EQ(1u, s.size());
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
253 ASSERT_EQ('\0', s[0]);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
254
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
255 OrthancDatabases::StorageBackend::ReadRangeToString(s, *accessor, "uuid", OrthancPluginContentType_Unknown, 9, 1);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
256 ASSERT_EQ(1u, s.size());
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
257 ASSERT_EQ('\5', s[0]);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
258
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
259 OrthancDatabases::StorageBackend::ReadRangeToString(s, *accessor, "uuid", OrthancPluginContentType_Unknown, 10, 0);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
260 ASSERT_TRUE(s.empty());
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
261
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
262 // Cannot read non-empty range after the end of the string
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
263 ASSERT_THROW(OrthancDatabases::StorageBackend::ReadRangeToString(
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
264 s, *accessor, "uuid", OrthancPluginContentType_Unknown, 10, 1), Orthanc::OrthancException);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
265
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
266 OrthancDatabases::StorageBackend::ReadRangeToString(s, *accessor, "uuid", OrthancPluginContentType_Unknown, 0, 4);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
267 ASSERT_EQ(4u, s.size());
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
268 ASSERT_EQ('a', s[0]);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
269 ASSERT_EQ('b', s[1]);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
270 ASSERT_EQ('c', s[2]);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
271 ASSERT_EQ('d', s[3]);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
272
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
273 OrthancDatabases::StorageBackend::ReadRangeToString(s, *accessor, "uuid", OrthancPluginContentType_Unknown, 4, 6);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
274 ASSERT_EQ(6u, s.size());
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
275 ASSERT_EQ('\0', s[0]);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
276 ASSERT_EQ('\1', s[1]);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
277 ASSERT_EQ('\2', s[2]);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
278 ASSERT_EQ('\3', s[3]);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
279 ASSERT_EQ('\4', s[4]);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
280 ASSERT_EQ('\5', s[5]);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
281
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
282 ASSERT_THROW(OrthancDatabases::StorageBackend::ReadRangeToString(
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
283 s, *accessor, "uuid", OrthancPluginContentType_Unknown, 4, 7), Orthanc::OrthancException);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
284 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
285 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
286
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
287
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
288 TEST(MySQL, ImplicitTransaction)
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
289 {
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
290 OrthancDatabases::MySQLDatabase::ClearDatabase(globalParameters_);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
291 OrthancDatabases::MySQLDatabase db(globalParameters_);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
292 db.Open();
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
293
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
294 {
217
ee5858d438dc TransactionType given to MySQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
295 OrthancDatabases::MySQLTransaction t(db, OrthancDatabases::TransactionType_ReadOnly);
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
296 ASSERT_FALSE(db.DoesTableExist(t, "test"));
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
297 ASSERT_FALSE(db.DoesTableExist(t, "test2"));
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
298 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
299
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
300 {
215
b40b30075c51 added TransactionType_Implicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
301 std::unique_ptr<OrthancDatabases::ITransaction> t(db.CreateTransaction(OrthancDatabases::TransactionType_ReadWrite));
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
302 ASSERT_FALSE(t->IsImplicit());
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
303 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
304
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
305 {
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
306 OrthancDatabases::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
307 std::unique_ptr<OrthancDatabases::IPrecompiledStatement> s(db.Compile(query));
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
308
215
b40b30075c51 added TransactionType_Implicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
309 std::unique_ptr<OrthancDatabases::ITransaction> t(db.CreateTransaction(OrthancDatabases::TransactionType_Implicit));
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
310 ASSERT_TRUE(t->IsImplicit());
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
311 ASSERT_THROW(t->Commit(), Orthanc::OrthancException);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
312 ASSERT_THROW(t->Rollback(), Orthanc::OrthancException);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
313
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
314 OrthancDatabases::Dictionary args;
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
315 t->ExecuteWithoutResult(*s, args);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
316 ASSERT_THROW(t->Rollback(), Orthanc::OrthancException);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
317 t->Commit();
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
318
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
319 ASSERT_THROW(t->Commit(), Orthanc::OrthancException);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
320 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
321
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
322 {
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
323 // An implicit transaction does not need to be explicitely committed
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
324 OrthancDatabases::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
325 std::unique_ptr<OrthancDatabases::IPrecompiledStatement> s(db.Compile(query));
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
326
215
b40b30075c51 added TransactionType_Implicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
327 std::unique_ptr<OrthancDatabases::ITransaction> t(db.CreateTransaction(OrthancDatabases::TransactionType_Implicit));
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
328
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
329 OrthancDatabases::Dictionary args;
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
330 t->ExecuteWithoutResult(*s, args);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
331 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
332
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
333 {
217
ee5858d438dc TransactionType given to MySQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
334 OrthancDatabases::MySQLTransaction t(db, OrthancDatabases::TransactionType_ReadOnly);
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
335 ASSERT_TRUE(db.DoesTableExist(t, "test"));
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
336 ASSERT_TRUE(db.DoesTableExist(t, "test2"));
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
337 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
338 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
339
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
340
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 int main(int argc, char **argv)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 if (argc < 5)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 {
46
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
345 std::cerr
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
346 #if !defined(_WIN32)
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
347 << "Usage (UNIX socket): " << argv[0] << " <socket> <username> <password> <database>"
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
348 << std::endl
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
349 #endif
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
350 << "Usage (TCP connection): " << argv[0] << " <host> <port> <username> <password> <database>"
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
351 << std::endl << std::endl
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
352 #if !defined(_WIN32)
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
353 << "Example (UNIX socket): " << argv[0] << " /var/run/mysqld/mysqld.sock root root orthanctest"
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
354 << std::endl
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
355 #endif
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
356 << "Example (TCP connection): " << argv[0] << " localhost 3306 root root orthanctest"
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
357 << std::endl << std::endl;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 return -1;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360
22
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
361 std::vector<std::string> args;
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
362 for (int i = 1; i < argc; i++)
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
363 {
22
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
364 // Ignore arguments beginning with "-" to allow passing arguments
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
365 // to Google Test such as "--gtest_filter="
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
366 if (argv[i] != NULL &&
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
367 argv[i][0] != '-')
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
368 {
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
369 args.push_back(std::string(argv[i]));
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
370 }
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
371 }
22
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
372
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 ::testing::InitGoogleTest(&argc, argv);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 Orthanc::Logging::Initialize();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 Orthanc::Logging::EnableInfoLevel(true);
335
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 309
diff changeset
376 // Orthanc::Logging::EnableTraceLevel(true);
42
4c3f767ead03 set version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
377 Orthanc::Toolbox::InitializeOpenSsl();
40
5600949bfb12 preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
378 Orthanc::HttpClient::GlobalInitialize();
22
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
379
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
380 if (args.size() == 4)
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
381 {
46
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
382 // UNIX socket flavor
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
383 globalParameters_.SetHost("");
22
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
384 globalParameters_.SetUnixSocket(args[0]);
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
385 globalParameters_.SetUsername(args[1]);
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
386 globalParameters_.SetPassword(args[2]);
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
387 globalParameters_.SetDatabase(args[3]);
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
388 }
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
389 else if (args.size() == 5)
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
390 {
46
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
391 // TCP connection flavor
22
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
392 globalParameters_.SetHost(args[0]);
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
393 globalParameters_.SetPort(boost::lexical_cast<unsigned int>(args[1]));
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
394 globalParameters_.SetUsername(args[2]);
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
395 globalParameters_.SetPassword(args[3]);
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
396 globalParameters_.SetDatabase(args[4]);
46
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
397
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
398 // Force the use of TCP on localhost, even if UNIX sockets are available
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
399 globalParameters_.SetUnixSocket("");
22
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
400 }
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
401 else
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
402 {
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
403 LOG(ERROR) << "Bad number of arguments";
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
404 return -1;
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
405 }
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
406
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
407 Json::Value config;
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
408 globalParameters_.Format(config);
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
409 std::cout << "Parameters of the MySQL connection: " << std::endl
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
410 << config.toStyledString() << std::endl;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 int result = RUN_ALL_TESTS();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413
40
5600949bfb12 preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
414 Orthanc::HttpClient::GlobalFinalize();
42
4c3f767ead03 set version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
415 Orthanc::Toolbox::FinalizeOpenSsl();
4c3f767ead03 set version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
416 OrthancDatabases::MySQLDatabase::GlobalFinalization();
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 Orthanc::Logging::Finalize();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 return result;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 }