comparison UnitTestsSources/ServerIndexTests.cpp @ 3017:517fc4767ae0 db-changes

renamed class DatabaseWrapper as SQLiteDatabaseWrapper
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 14 Dec 2018 14:55:49 +0100
parents 7695a9c81099
children e3b5c07146a3
comparison
equal deleted inserted replaced
3016:777762336381 3017:517fc4767ae0
35 #include "gtest/gtest.h" 35 #include "gtest/gtest.h"
36 36
37 #include "../Core/FileStorage/FilesystemStorage.h" 37 #include "../Core/FileStorage/FilesystemStorage.h"
38 #include "../Core/FileStorage/MemoryStorageArea.h" 38 #include "../Core/FileStorage/MemoryStorageArea.h"
39 #include "../Core/Logging.h" 39 #include "../Core/Logging.h"
40 #include "../OrthancServer/DatabaseWrapper.h" 40 #include "../OrthancServer/SQLiteDatabaseWrapper.h"
41 #include "../OrthancServer/Search/LookupIdentifierQuery.h" 41 #include "../OrthancServer/Search/LookupIdentifierQuery.h"
42 #include "../OrthancServer/ServerContext.h" 42 #include "../OrthancServer/ServerContext.h"
43 #include "../OrthancServer/ServerIndex.h" 43 #include "../OrthancServer/ServerIndex.h"
44 #include "../OrthancServer/ServerToolbox.h" 44 #include "../OrthancServer/ServerToolbox.h"
45 45
115 listener_.reset(new TestDatabaseListener); 115 listener_.reset(new TestDatabaseListener);
116 116
117 switch (GetParam()) 117 switch (GetParam())
118 { 118 {
119 case DatabaseWrapperClass_SQLite: 119 case DatabaseWrapperClass_SQLite:
120 index_.reset(new DatabaseWrapper()); 120 index_.reset(new SQLiteDatabaseWrapper());
121 break; 121 break;
122 122
123 default: 123 default:
124 throw OrthancException(ErrorCode_InternalError); 124 throw OrthancException(ErrorCode_InternalError);
125 } 125 }
139 { 139 {
140 switch (GetParam()) 140 switch (GetParam())
141 { 141 {
142 case DatabaseWrapperClass_SQLite: 142 case DatabaseWrapperClass_SQLite:
143 { 143 {
144 DatabaseWrapper* sqlite = dynamic_cast<DatabaseWrapper*>(index_.get()); 144 SQLiteDatabaseWrapper* sqlite = dynamic_cast<SQLiteDatabaseWrapper*>(index_.get());
145 ASSERT_EQ(expected, sqlite->GetTableRecordCount(table)); 145 ASSERT_EQ(expected, sqlite->GetTableRecordCount(table));
146 break; 146 break;
147 } 147 }
148 148
149 default: 149 default:
157 157
158 switch (GetParam()) 158 switch (GetParam())
159 { 159 {
160 case DatabaseWrapperClass_SQLite: 160 case DatabaseWrapperClass_SQLite:
161 { 161 {
162 DatabaseWrapper* sqlite = dynamic_cast<DatabaseWrapper*>(index_.get()); 162 SQLiteDatabaseWrapper* sqlite = dynamic_cast<SQLiteDatabaseWrapper*>(index_.get());
163 ASSERT_FALSE(sqlite->GetParentPublicId(s, id)); 163 ASSERT_FALSE(sqlite->GetParentPublicId(s, id));
164 break; 164 break;
165 } 165 }
166 166
167 default: 167 default:
175 175
176 switch (GetParam()) 176 switch (GetParam())
177 { 177 {
178 case DatabaseWrapperClass_SQLite: 178 case DatabaseWrapperClass_SQLite:
179 { 179 {
180 DatabaseWrapper* sqlite = dynamic_cast<DatabaseWrapper*>(index_.get()); 180 SQLiteDatabaseWrapper* sqlite = dynamic_cast<SQLiteDatabaseWrapper*>(index_.get());
181 ASSERT_TRUE(sqlite->GetParentPublicId(s, id)); 181 ASSERT_TRUE(sqlite->GetParentPublicId(s, id));
182 ASSERT_EQ(expected, s); 182 ASSERT_EQ(expected, s);
183 break; 183 break;
184 } 184 }
185 185
194 194
195 switch (GetParam()) 195 switch (GetParam())
196 { 196 {
197 case DatabaseWrapperClass_SQLite: 197 case DatabaseWrapperClass_SQLite:
198 { 198 {
199 DatabaseWrapper* sqlite = dynamic_cast<DatabaseWrapper*>(index_.get()); 199 SQLiteDatabaseWrapper* sqlite = dynamic_cast<SQLiteDatabaseWrapper*>(index_.get());
200 sqlite->GetChildren(j, id); 200 sqlite->GetChildren(j, id);
201 ASSERT_EQ(0u, j.size()); 201 ASSERT_EQ(0u, j.size());
202 break; 202 break;
203 } 203 }
204 204
213 213
214 switch (GetParam()) 214 switch (GetParam())
215 { 215 {
216 case DatabaseWrapperClass_SQLite: 216 case DatabaseWrapperClass_SQLite:
217 { 217 {
218 DatabaseWrapper* sqlite = dynamic_cast<DatabaseWrapper*>(index_.get()); 218 SQLiteDatabaseWrapper* sqlite = dynamic_cast<SQLiteDatabaseWrapper*>(index_.get());
219 sqlite->GetChildren(j, id); 219 sqlite->GetChildren(j, id);
220 ASSERT_EQ(1u, j.size()); 220 ASSERT_EQ(1u, j.size());
221 ASSERT_EQ(expected, j.front()); 221 ASSERT_EQ(expected, j.front());
222 break; 222 break;
223 } 223 }
235 235
236 switch (GetParam()) 236 switch (GetParam())
237 { 237 {
238 case DatabaseWrapperClass_SQLite: 238 case DatabaseWrapperClass_SQLite:
239 { 239 {
240 DatabaseWrapper* sqlite = dynamic_cast<DatabaseWrapper*>(index_.get()); 240 SQLiteDatabaseWrapper* sqlite = dynamic_cast<SQLiteDatabaseWrapper*>(index_.get());
241 sqlite->GetChildren(j, id); 241 sqlite->GetChildren(j, id);
242 ASSERT_EQ(2u, j.size()); 242 ASSERT_EQ(2u, j.size());
243 ASSERT_TRUE((expected1 == j.front() && expected2 == j.back()) || 243 ASSERT_TRUE((expected1 == j.front() && expected2 == j.back()) ||
244 (expected1 == j.back() && expected2 == j.front())); 244 (expected1 == j.back() && expected2 == j.front()));
245 break; 245 break;
674 { 674 {
675 const std::string path = "UnitTestsStorage"; 675 const std::string path = "UnitTestsStorage";
676 676
677 SystemToolbox::RemoveFile(path + "/index"); 677 SystemToolbox::RemoveFile(path + "/index");
678 FilesystemStorage storage(path); 678 FilesystemStorage storage(path);
679 DatabaseWrapper db; // The SQLite DB is in memory 679 SQLiteDatabaseWrapper db; // The SQLite DB is in memory
680 db.Open(); 680 db.Open();
681 ServerContext context(db, storage, true /* running unit tests */, 10); 681 ServerContext context(db, storage, true /* running unit tests */, 10);
682 context.SetupJobsEngine(true, false); 682 context.SetupJobsEngine(true, false);
683 683
684 ServerIndex& index = context.GetIndex(); 684 ServerIndex& index = context.GetIndex();
774 { 774 {
775 const std::string path = "UnitTestsStorage"; 775 const std::string path = "UnitTestsStorage";
776 776
777 SystemToolbox::RemoveFile(path + "/index"); 777 SystemToolbox::RemoveFile(path + "/index");
778 FilesystemStorage storage(path); 778 FilesystemStorage storage(path);
779 DatabaseWrapper db; // The SQLite DB is in memory 779 SQLiteDatabaseWrapper db; // The SQLite DB is in memory
780 db.Open(); 780 db.Open();
781 ServerContext context(db, storage, true /* running unit tests */, 10); 781 ServerContext context(db, storage, true /* running unit tests */, 10);
782 context.SetupJobsEngine(true, false); 782 context.SetupJobsEngine(true, false);
783 ServerIndex& index = context.GetIndex(); 783 ServerIndex& index = context.GetIndex();
784 784
862 for (unsigned int i = 0; i < 2; i++) 862 for (unsigned int i = 0; i < 2; i++)
863 { 863 {
864 bool overwrite = (i == 0); 864 bool overwrite = (i == 0);
865 865
866 MemoryStorageArea storage; 866 MemoryStorageArea storage;
867 DatabaseWrapper db; // The SQLite DB is in memory 867 SQLiteDatabaseWrapper db; // The SQLite DB is in memory
868 db.Open(); 868 db.Open();
869 ServerContext context(db, storage, true /* running unit tests */, 10); 869 ServerContext context(db, storage, true /* running unit tests */, 10);
870 context.SetupJobsEngine(true, false); 870 context.SetupJobsEngine(true, false);
871 context.SetCompressionEnabled(true); 871 context.SetCompressionEnabled(true);
872 872