comparison MySQL/UnitTests/UnitTestsMain.cpp @ 157:275e14f57f1e

replacing deprecated std::auto_ptr by std::unique_ptr
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 06 Jul 2020 12:45:58 +0200
parents 063aa53b5917
children 3236894320d6
comparison
equal deleted inserted replaced
156:710537acb488 157:275e14f57f1e
29 #include "../../Framework/MySQL/MySQLResult.h" 29 #include "../../Framework/MySQL/MySQLResult.h"
30 #include "../../Framework/MySQL/MySQLStatement.h" 30 #include "../../Framework/MySQL/MySQLStatement.h"
31 #include "../../Framework/MySQL/MySQLTransaction.h" 31 #include "../../Framework/MySQL/MySQLTransaction.h"
32 #include "../../Framework/Plugins/IndexUnitTests.h" 32 #include "../../Framework/Plugins/IndexUnitTests.h"
33 33
34 #include <Compatibility.h> // For std::unique_ptr<>
34 #include <HttpClient.h> 35 #include <HttpClient.h>
35 #include <Logging.h> 36 #include <Logging.h>
36 #include <Toolbox.h> 37 #include <Toolbox.h>
37 38
38 #include <gtest/gtest.h> 39 #include <gtest/gtest.h>
136 { 137 {
137 OrthancDatabases::Query query("SELECT COUNT(*) FROM StorageArea", true); 138 OrthancDatabases::Query query("SELECT COUNT(*) FROM StorageArea", true);
138 OrthancDatabases::MySQLStatement s(db, query); 139 OrthancDatabases::MySQLStatement s(db, query);
139 OrthancDatabases::MySQLTransaction t(db); 140 OrthancDatabases::MySQLTransaction t(db);
140 OrthancDatabases::Dictionary d; 141 OrthancDatabases::Dictionary d;
141 std::auto_ptr<OrthancDatabases::IResult> result(s.Execute(t, d)); 142 std::unique_ptr<OrthancDatabases::IResult> result(s.Execute(t, d));
142 return dynamic_cast<const OrthancDatabases::Integer64Value&>(result->GetField(0)).GetValue(); 143 return dynamic_cast<const OrthancDatabases::Integer64Value&>(result->GetField(0)).GetValue();
143 } 144 }
144 145
145 146
146 TEST(MySQL, StorageArea) 147 TEST(MySQL, StorageArea)
213 ASSERT_FALSE(db.DoesTableExist(t, "test")); 214 ASSERT_FALSE(db.DoesTableExist(t, "test"));
214 ASSERT_FALSE(db.DoesTableExist(t, "test2")); 215 ASSERT_FALSE(db.DoesTableExist(t, "test2"));
215 } 216 }
216 217
217 { 218 {
218 std::auto_ptr<OrthancDatabases::ITransaction> t(db.CreateTransaction(false)); 219 std::unique_ptr<OrthancDatabases::ITransaction> t(db.CreateTransaction(false));
219 ASSERT_FALSE(t->IsImplicit()); 220 ASSERT_FALSE(t->IsImplicit());
220 } 221 }
221 222
222 { 223 {
223 OrthancDatabases::Query query("CREATE TABLE test(id INT)", false); 224 OrthancDatabases::Query query("CREATE TABLE test(id INT)", false);
224 std::auto_ptr<OrthancDatabases::IPrecompiledStatement> s(db.Compile(query)); 225 std::unique_ptr<OrthancDatabases::IPrecompiledStatement> s(db.Compile(query));
225 226
226 std::auto_ptr<OrthancDatabases::ITransaction> t(db.CreateTransaction(true)); 227 std::unique_ptr<OrthancDatabases::ITransaction> t(db.CreateTransaction(true));
227 ASSERT_TRUE(t->IsImplicit()); 228 ASSERT_TRUE(t->IsImplicit());
228 ASSERT_THROW(t->Commit(), Orthanc::OrthancException); 229 ASSERT_THROW(t->Commit(), Orthanc::OrthancException);
229 ASSERT_THROW(t->Rollback(), Orthanc::OrthancException); 230 ASSERT_THROW(t->Rollback(), Orthanc::OrthancException);
230 231
231 OrthancDatabases::Dictionary args; 232 OrthancDatabases::Dictionary args;
237 } 238 }
238 239
239 { 240 {
240 // An implicit transaction does not need to be explicitely committed 241 // An implicit transaction does not need to be explicitely committed
241 OrthancDatabases::Query query("CREATE TABLE test2(id INT)", false); 242 OrthancDatabases::Query query("CREATE TABLE test2(id INT)", false);
242 std::auto_ptr<OrthancDatabases::IPrecompiledStatement> s(db.Compile(query)); 243 std::unique_ptr<OrthancDatabases::IPrecompiledStatement> s(db.Compile(query));
243 244
244 std::auto_ptr<OrthancDatabases::ITransaction> t(db.CreateTransaction(true)); 245 std::unique_ptr<OrthancDatabases::ITransaction> t(db.CreateTransaction(true));
245 246
246 OrthancDatabases::Dictionary args; 247 OrthancDatabases::Dictionary args;
247 t->ExecuteWithoutResult(*s, args); 248 t->ExecuteWithoutResult(*s, args);
248 } 249 }
249 250