annotate MySQL/UnitTests/UnitTestsMain.cpp @ 115:d4a995d2a726

merge
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 23 Jan 2019 20:14:41 +0100
parents 714c5d2bee76
children e26690365c25
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
67
714c5d2bee76 preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 46
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * 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
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * 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
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
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 #include "../Plugins/MySQLIndex.h"
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
23 #include "../Plugins/MySQLStorageArea.h"
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 OrthancDatabases::MySQLParameters globalParameters_;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
27 #include "../../Framework/Common/Integer64Value.h"
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
28 #include "../../Framework/MySQL/MySQLDatabase.h"
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
29 #include "../../Framework/MySQL/MySQLResult.h"
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
30 #include "../../Framework/MySQL/MySQLStatement.h"
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
31 #include "../../Framework/MySQL/MySQLTransaction.h"
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include "../../Framework/Plugins/IndexUnitTests.h"
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
40
5600949bfb12 preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
34 #include <Core/HttpClient.h>
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include <Core/Logging.h>
42
4c3f767ead03 set version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
36 #include <Core/Toolbox.h>
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include <gtest/gtest.h>
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
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 TEST(MySQLIndex, Lock)
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 OrthancDatabases::MySQLParameters noLock = globalParameters_;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 noLock.SetLock(false);
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 lock = globalParameters_;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 lock.SetLock(true);
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::MySQLIndex db1(noLock);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 db1.SetClearAll(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 db1.Open();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 OrthancDatabases::MySQLIndex db2(lock);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 db2.Open();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 OrthancDatabases::MySQLIndex db3(lock);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 ASSERT_THROW(db3.Open(), Orthanc::OrthancException);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 OrthancDatabases::MySQLIndex db4(lock);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 db4.Open();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
17
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
66 static int64_t CountFiles(OrthancDatabases::MySQLDatabase& db)
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
67 {
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
68 OrthancDatabases::Query query("SELECT COUNT(*) FROM StorageArea", true);
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
69 OrthancDatabases::MySQLStatement s(db, query);
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
70 OrthancDatabases::MySQLTransaction t(db);
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
71 OrthancDatabases::Dictionary d;
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
72 std::auto_ptr<OrthancDatabases::IResult> result(s.Execute(t, d));
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
73 return dynamic_cast<const OrthancDatabases::Integer64Value&>(result->GetField(0)).GetValue();
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
74 }
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
75
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
76
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
77 TEST(MySQL, StorageArea)
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
78 {
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
79 OrthancDatabases::MySQLStorageArea storageArea(globalParameters_);
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
80 storageArea.SetClearAll(true);
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
81
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
82 {
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
83 OrthancDatabases::DatabaseManager::Transaction transaction(storageArea.GetManager());
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
84 OrthancDatabases::MySQLDatabase& db =
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
85 dynamic_cast<OrthancDatabases::MySQLDatabase&>(transaction.GetDatabase());
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
86
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
87 ASSERT_EQ(0, CountFiles(db));
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
88
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
89 for (int i = 0; i < 10; i++)
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
90 {
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
91 std::string uuid = boost::lexical_cast<std::string>(i);
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
92 std::string value = "Value " + boost::lexical_cast<std::string>(i * 2);
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
93 storageArea.Create(transaction, uuid, value.c_str(), value.size(), OrthancPluginContentType_Unknown);
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
94 }
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
95
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
96 std::string tmp;
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
97 ASSERT_THROW(storageArea.ReadToString(tmp, transaction, "nope", OrthancPluginContentType_Unknown),
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
98 Orthanc::OrthancException);
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
99
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
100 ASSERT_EQ(10, CountFiles(db));
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
101 storageArea.Remove(transaction, "5", OrthancPluginContentType_Unknown);
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
102
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
103 ASSERT_EQ(9, CountFiles(db));
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
104
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
105 for (int i = 0; i < 10; i++)
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
106 {
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
107 std::string uuid = boost::lexical_cast<std::string>(i);
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
108 std::string expected = "Value " + boost::lexical_cast<std::string>(i * 2);
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
109 std::string content;
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
110
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
111 if (i == 5)
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
112 {
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
113 ASSERT_THROW(storageArea.ReadToString(content, transaction, uuid, OrthancPluginContentType_Unknown),
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
114 Orthanc::OrthancException);
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
115 }
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
116 else
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
117 {
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
118 storageArea.ReadToString(content, transaction, uuid, OrthancPluginContentType_Unknown);
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
119 ASSERT_EQ(expected, content);
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
120 }
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
121 }
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
122
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
123 for (int i = 0; i < 10; i++)
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
124 {
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
125 storageArea.Remove(transaction, boost::lexical_cast<std::string>(i),
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
126 OrthancPluginContentType_Unknown);
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
127 }
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
128
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
129 ASSERT_EQ(0, CountFiles(db));
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
130
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
131 transaction.Commit();
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
132 }
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
133 }
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
134
54ea251aed70 unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
135
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
136 TEST(MySQL, ImplicitTransaction)
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
137 {
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
138 OrthancDatabases::MySQLDatabase::ClearDatabase(globalParameters_);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
139 OrthancDatabases::MySQLDatabase db(globalParameters_);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
140 db.Open();
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
141
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
142 {
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
143 OrthancDatabases::MySQLTransaction t(db);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
144 ASSERT_FALSE(db.DoesTableExist(t, "test"));
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
145 ASSERT_FALSE(db.DoesTableExist(t, "test2"));
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
146 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
147
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
148 {
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
149 std::auto_ptr<OrthancDatabases::ITransaction> t(db.CreateTransaction(false));
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
150 ASSERT_FALSE(t->IsImplicit());
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
151 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
152
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
153 {
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
154 OrthancDatabases::Query query("CREATE TABLE test(id INT)", false);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
155 std::auto_ptr<OrthancDatabases::IPrecompiledStatement> s(db.Compile(query));
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
156
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
157 std::auto_ptr<OrthancDatabases::ITransaction> t(db.CreateTransaction(true));
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
158 ASSERT_TRUE(t->IsImplicit());
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
159 ASSERT_THROW(t->Commit(), Orthanc::OrthancException);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
160 ASSERT_THROW(t->Rollback(), Orthanc::OrthancException);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
161
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
162 OrthancDatabases::Dictionary args;
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
163 t->ExecuteWithoutResult(*s, args);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
164 ASSERT_THROW(t->Rollback(), Orthanc::OrthancException);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
165 t->Commit();
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
166
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
167 ASSERT_THROW(t->Commit(), Orthanc::OrthancException);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
168 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
169
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
170 {
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
171 // 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
172 OrthancDatabases::Query query("CREATE TABLE test2(id INT)", false);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
173 std::auto_ptr<OrthancDatabases::IPrecompiledStatement> s(db.Compile(query));
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
174
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
175 std::auto_ptr<OrthancDatabases::ITransaction> t(db.CreateTransaction(true));
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
176
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
177 OrthancDatabases::Dictionary args;
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
178 t->ExecuteWithoutResult(*s, args);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
179 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
180
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
181 {
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
182 OrthancDatabases::MySQLTransaction t(db);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
183 ASSERT_TRUE(db.DoesTableExist(t, "test"));
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
184 ASSERT_TRUE(db.DoesTableExist(t, "test2"));
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
185 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
186 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
187
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
188
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 int main(int argc, char **argv)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 if (argc < 5)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 {
46
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
193 std::cerr
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
194 #if !defined(_WIN32)
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
195 << "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
196 << std::endl
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
197 #endif
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
198 << "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
199 << std::endl << std::endl
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
200 #if !defined(_WIN32)
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
201 << "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
202 << std::endl
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
203 #endif
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
204 << "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
205 << std::endl << std::endl;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 return -1;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208
22
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
209 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
210 for (int i = 1; i < argc; i++)
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
211 {
22
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
212 // 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
213 // 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
214 if (argv[i] != NULL &&
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
215 argv[i][0] != '-')
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
216 {
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
217 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
218 }
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
219 }
22
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
220
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 ::testing::InitGoogleTest(&argc, argv);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 Orthanc::Logging::Initialize();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 Orthanc::Logging::EnableInfoLevel(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 Orthanc::Logging::EnableTraceLevel(true);
42
4c3f767ead03 set version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
225 Orthanc::Toolbox::InitializeOpenSsl();
40
5600949bfb12 preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
226 Orthanc::HttpClient::GlobalInitialize();
22
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
227
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
228 if (args.size() == 4)
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
229 {
46
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
230 // UNIX socket flavor
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
231 globalParameters_.SetHost("");
22
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
232 globalParameters_.SetUnixSocket(args[0]);
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
233 globalParameters_.SetUsername(args[1]);
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
234 globalParameters_.SetPassword(args[2]);
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
235 globalParameters_.SetDatabase(args[3]);
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
236 }
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
237 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
238 {
46
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
239 // TCP connection flavor
22
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
240 globalParameters_.SetHost(args[0]);
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
241 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
242 globalParameters_.SetUsername(args[2]);
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
243 globalParameters_.SetPassword(args[3]);
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
244 globalParameters_.SetDatabase(args[4]);
46
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
245
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 42
diff changeset
246 // 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
247 globalParameters_.SetUnixSocket("");
22
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
248 }
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
249 else
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
250 {
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
251 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
252 return -1;
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
253 }
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
254
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
255 Json::Value config;
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
256 globalParameters_.Format(config);
1e9bad493475 prevent running unit tests on a non-existing db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 17
diff changeset
257 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
258 << config.toStyledString() << std::endl;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 int result = RUN_ALL_TESTS();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261
40
5600949bfb12 preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
262 Orthanc::HttpClient::GlobalFinalize();
42
4c3f767ead03 set version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
263 Orthanc::Toolbox::FinalizeOpenSsl();
4c3f767ead03 set version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
264 OrthancDatabases::MySQLDatabase::GlobalFinalization();
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 Orthanc::Logging::Finalize();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 return result;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 }