Mercurial > hg > orthanc-databases
annotate PostgreSQL/UnitTests/UnitTestsMain.cpp @ 72:8dd29af7c844 db-changes
new extension: FastTotalSize
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 04 Jan 2019 14:43:35 +0100 |
parents | 714c5d2bee76 |
children | 4cd7e45b671e |
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 | |
67 | 5 * Copyright (C) 2017-2019 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 | |
24 #include <Core/Logging.h> | |
25 #include <gtest/gtest.h> | |
26 | |
27 OrthancDatabases::PostgreSQLParameters globalParameters_; | |
28 | |
29 #include "../../Framework/Plugins/IndexUnitTests.h" | |
30 | |
31 | |
14
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
32 #if ORTHANC_POSTGRESQL_STATIC == 1 |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
33 # include <c.h> // PostgreSQL includes |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
34 |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
35 TEST(PostgreSQL, Version) |
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 ASSERT_STREQ("9.6.1", PG_VERSION); |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
38 } |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
39 #endif |
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 |
0 | 42 TEST(PostgreSQLParameters, Basic) |
43 { | |
44 OrthancDatabases::PostgreSQLParameters p; | |
45 p.SetDatabase("world"); | |
46 | |
47 ASSERT_EQ("postgresql://localhost:5432/world", p.GetConnectionUri()); | |
48 | |
49 p.ResetDatabase(); | |
50 ASSERT_EQ("postgresql://localhost:5432/", p.GetConnectionUri()); | |
51 | |
52 p.SetDatabase("hello"); | |
53 ASSERT_EQ("postgresql://localhost:5432/hello", p.GetConnectionUri()); | |
54 | |
55 p.SetHost("server"); | |
56 ASSERT_EQ("postgresql://server:5432/hello", p.GetConnectionUri()); | |
57 | |
58 p.SetPortNumber(1234); | |
59 ASSERT_EQ("postgresql://server:1234/hello", p.GetConnectionUri()); | |
60 | |
61 p.SetPortNumber(5432); | |
62 ASSERT_EQ("postgresql://server:5432/hello", p.GetConnectionUri()); | |
63 | |
64 p.SetUsername("user"); | |
65 p.SetPassword("pass"); | |
66 ASSERT_EQ("postgresql://user:pass@server:5432/hello", p.GetConnectionUri()); | |
67 | |
68 p.SetPassword(""); | |
69 ASSERT_EQ("postgresql://user@server:5432/hello", p.GetConnectionUri()); | |
70 | |
71 p.SetUsername(""); | |
72 p.SetPassword("pass"); | |
73 ASSERT_EQ("postgresql://server:5432/hello", p.GetConnectionUri()); | |
74 | |
75 p.SetUsername(""); | |
76 p.SetPassword(""); | |
77 ASSERT_EQ("postgresql://server:5432/hello", p.GetConnectionUri()); | |
78 | |
79 p.SetConnectionUri("hello://world"); | |
80 ASSERT_EQ("hello://world", p.GetConnectionUri()); | |
81 } | |
82 | |
83 | |
84 TEST(PostgreSQLIndex, Lock) | |
85 { | |
86 OrthancDatabases::PostgreSQLParameters noLock = globalParameters_; | |
87 noLock.SetLock(false); | |
88 | |
89 OrthancDatabases::PostgreSQLParameters lock = globalParameters_; | |
90 lock.SetLock(true); | |
91 | |
92 OrthancDatabases::PostgreSQLIndex db1(noLock); | |
93 db1.SetClearAll(true); | |
94 db1.Open(); | |
95 | |
96 { | |
97 OrthancDatabases::PostgreSQLIndex db2(lock); | |
98 db2.Open(); | |
99 | |
100 OrthancDatabases::PostgreSQLIndex db3(lock); | |
101 ASSERT_THROW(db3.Open(), Orthanc::OrthancException); | |
102 } | |
103 | |
104 OrthancDatabases::PostgreSQLIndex db4(lock); | |
105 db4.Open(); | |
106 } | |
107 | |
108 | |
109 int main(int argc, char **argv) | |
110 { | |
111 if (argc < 6) | |
112 { | |
113 std::cerr << "Usage: " << argv[0] << " <host> <port> <username> <password> <database>" | |
114 << std::endl << std::endl | |
115 << "Example: " << argv[0] << " localhost 5432 postgres postgres orthanctest" | |
116 << std::endl << std::endl; | |
117 return -1; | |
118 } | |
119 | |
120 globalParameters_.SetHost(argv[1]); | |
121 globalParameters_.SetPortNumber(boost::lexical_cast<uint16_t>(argv[2])); | |
122 globalParameters_.SetUsername(argv[3]); | |
123 globalParameters_.SetPassword(argv[4]); | |
124 globalParameters_.SetDatabase(argv[5]); | |
125 | |
126 ::testing::InitGoogleTest(&argc, argv); | |
127 Orthanc::Logging::Initialize(); | |
128 Orthanc::Logging::EnableInfoLevel(true); | |
129 Orthanc::Logging::EnableTraceLevel(true); | |
130 | |
131 int result = RUN_ALL_TESTS(); | |
132 | |
133 Orthanc::Logging::Finalize(); | |
134 | |
135 return result; | |
136 } |