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