Mercurial > hg > orthanc-databases
annotate PostgreSQL/UnitTests/UnitTestsMain.cpp @ 338:79e21c33962d
cppcheck
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 11 Aug 2021 14:09:43 +0200 |
parents | 7ec461718edb |
children | 16aac0287485 |
rev | line source |
---|---|
0 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
193
3236894320d6
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
172
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "../Plugins/PostgreSQLIndex.h" | |
23 | |
152 | 24 #include <Logging.h> |
267 | 25 #include <Toolbox.h> |
0 | 26 #include <gtest/gtest.h> |
27 | |
28 OrthancDatabases::PostgreSQLParameters globalParameters_; | |
29 | |
30 #include "../../Framework/Plugins/IndexUnitTests.h" | |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
31 #include "../../Framework/PostgreSQL/PostgreSQLDatabase.h" |
0 | 32 |
33 | |
14
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
34 #if ORTHANC_POSTGRESQL_STATIC == 1 |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
35 # include <c.h> // PostgreSQL includes |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
36 |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
37 TEST(PostgreSQL, Version) |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
38 { |
172
8c7bb94adff7
trying upgrade from libpq 9.6.1 to 13.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
39 ASSERT_STREQ("13.1", PG_VERSION); |
14
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
40 } |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
41 #endif |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
42 |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
43 |
0 | 44 TEST(PostgreSQLParameters, Basic) |
45 { | |
46 OrthancDatabases::PostgreSQLParameters p; | |
47 p.SetDatabase("world"); | |
48 | |
49 ASSERT_EQ("postgresql://localhost:5432/world", p.GetConnectionUri()); | |
50 | |
51 p.ResetDatabase(); | |
52 ASSERT_EQ("postgresql://localhost:5432/", p.GetConnectionUri()); | |
53 | |
54 p.SetDatabase("hello"); | |
55 ASSERT_EQ("postgresql://localhost:5432/hello", p.GetConnectionUri()); | |
56 | |
57 p.SetHost("server"); | |
58 ASSERT_EQ("postgresql://server:5432/hello", p.GetConnectionUri()); | |
59 | |
60 p.SetPortNumber(1234); | |
61 ASSERT_EQ("postgresql://server:1234/hello", p.GetConnectionUri()); | |
62 | |
63 p.SetPortNumber(5432); | |
64 ASSERT_EQ("postgresql://server:5432/hello", p.GetConnectionUri()); | |
65 | |
66 p.SetUsername("user"); | |
67 p.SetPassword("pass"); | |
68 ASSERT_EQ("postgresql://user:pass@server:5432/hello", p.GetConnectionUri()); | |
69 | |
70 p.SetPassword(""); | |
71 ASSERT_EQ("postgresql://user@server:5432/hello", p.GetConnectionUri()); | |
72 | |
73 p.SetUsername(""); | |
74 p.SetPassword("pass"); | |
75 ASSERT_EQ("postgresql://server:5432/hello", p.GetConnectionUri()); | |
76 | |
77 p.SetUsername(""); | |
78 p.SetPassword(""); | |
79 ASSERT_EQ("postgresql://server:5432/hello", p.GetConnectionUri()); | |
80 | |
81 p.SetConnectionUri("hello://world"); | |
82 ASSERT_EQ("hello://world", p.GetConnectionUri()); | |
83 } | |
84 | |
85 | |
86 TEST(PostgreSQLIndex, Lock) | |
87 { | |
88 OrthancDatabases::PostgreSQLParameters noLock = globalParameters_; | |
89 noLock.SetLock(false); | |
90 | |
91 OrthancDatabases::PostgreSQLParameters lock = globalParameters_; | |
92 lock.SetLock(true); | |
93 | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
94 OrthancDatabases::PostgreSQLIndex db1(NULL, noLock); |
0 | 95 db1.SetClearAll(true); |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
96 |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
97 std::unique_ptr<OrthancDatabases::DatabaseManager> manager1(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db1)); |
0 | 98 |
99 { | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
100 OrthancDatabases::PostgreSQLIndex db2(NULL, lock); |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
101 std::unique_ptr<OrthancDatabases::DatabaseManager> manager2(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db2)); |
0 | 102 |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
103 OrthancDatabases::PostgreSQLIndex db3(NULL, lock); |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
104 ASSERT_THROW(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db3), Orthanc::OrthancException); |
0 | 105 } |
106 | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
107 OrthancDatabases::PostgreSQLIndex db4(NULL, lock); |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
108 std::unique_ptr<OrthancDatabases::DatabaseManager> manager4(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db4)); |
0 | 109 } |
110 | |
111 | |
112 int main(int argc, char **argv) | |
113 { | |
114 if (argc < 6) | |
115 { | |
116 std::cerr << "Usage: " << argv[0] << " <host> <port> <username> <password> <database>" | |
117 << std::endl << std::endl | |
118 << "Example: " << argv[0] << " localhost 5432 postgres postgres orthanctest" | |
119 << std::endl << std::endl; | |
120 return -1; | |
121 } | |
122 | |
123 globalParameters_.SetHost(argv[1]); | |
124 globalParameters_.SetPortNumber(boost::lexical_cast<uint16_t>(argv[2])); | |
125 globalParameters_.SetUsername(argv[3]); | |
126 globalParameters_.SetPassword(argv[4]); | |
127 globalParameters_.SetDatabase(argv[5]); | |
128 | |
129 ::testing::InitGoogleTest(&argc, argv); | |
267 | 130 Orthanc::Toolbox::InitializeOpenSsl(); |
0 | 131 Orthanc::Logging::Initialize(); |
132 Orthanc::Logging::EnableInfoLevel(true); | |
335
7ec461718edb
unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
267
diff
changeset
|
133 //Orthanc::Logging::EnableTraceLevel(true); |
0 | 134 |
135 int result = RUN_ALL_TESTS(); | |
136 | |
137 Orthanc::Logging::Finalize(); | |
267 | 138 Orthanc::Toolbox::FinalizeOpenSsl(); |
0 | 139 |
140 return result; | |
141 } |