From ffd3c8e7dcf3bee3304d7c28d8102bf343b64c76 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 22 Apr 2018 15:13:33 +0100 Subject: C++17 Updates code largely in-keeping with updates to be C++17 in line with libadhocutil and libdbpp. --- libodbcpp/unittests/testodbc.cpp | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) (limited to 'libodbcpp/unittests/testodbc.cpp') diff --git a/libodbcpp/unittests/testodbc.cpp b/libodbcpp/unittests/testodbc.cpp index 77f0a71..f235cfb 100644 --- a/libodbcpp/unittests/testodbc.cpp +++ b/libodbcpp/unittests/testodbc.cpp @@ -11,18 +11,12 @@ #include #include -class StandardMockDatabase : public ODBC::Mock { +class StandardMockDatabase : public DB::PluginMock { public: - StandardMockDatabase() : ODBC::Mock("Driver=psqlodbcw.so;uid=postgres;servername=/run/postgresql", "Database=postgres", "odbcmock", { - rootDir / "odbcschema.sql" }) + StandardMockDatabase() : DB::PluginMock( "odbcmock", { rootDir / "odbcschema.sql" }, + "Driver=psqlodbcw.so;uid=postgres;servername=/run/postgresql", "Database=postgres") { } - - void DropDatabase() const override - { - master->execute("SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '" + testDbName + "'"); - ODBC::Mock::DropDatabase(); - } }; BOOST_GLOBAL_FIXTURE( StandardMockDatabase ); @@ -43,30 +37,26 @@ BOOST_AUTO_TEST_CASE( transactions ) BOOST_REQUIRE_EQUAL(true, ro->inTx()); ro->commitTx(); BOOST_REQUIRE_EQUAL(false, ro->inTx()); - - delete ro; } BOOST_AUTO_TEST_CASE( bindAndSend ) { auto rw = DB::MockDatabase::openConnectionTo("odbcmock"); - auto mod = rw->newModifyCommand("INSERT INTO test VALUES(?, ?, ?, ?, ?)"); + auto mod = rw->modify("INSERT INTO test VALUES(?, ?, ?, ?, ?)"); mod->bindParamI(0, testInt); mod->bindParamF(1, testDouble); mod->bindParamS(2, testString); mod->bindParamB(3, testBool); mod->bindParamT(4, testDateTime); mod->execute(); - delete mod; - delete rw; } BOOST_AUTO_TEST_CASE( bindAndSelect ) { auto ro = DB::MockDatabase::openConnectionTo("odbcmock"); - auto select = ro->newSelectCommand("SELECT * FROM test WHERE id = ?"); + auto select = ro->select("SELECT * FROM test WHERE id = ?"); select->bindParamI(0, testInt); select->execute(); int rows = 0; @@ -78,16 +68,14 @@ BOOST_AUTO_TEST_CASE( bindAndSelect ) assertColumnValueHelper(*select, 4, testDateTime); rows += 1; } - delete select; BOOST_REQUIRE_EQUAL(1, rows); - delete ro; } BOOST_AUTO_TEST_CASE( bindAndSelectOther ) { auto ro = DB::MockDatabase::openConnectionTo("odbcmock"); - auto select = ro->newSelectCommand("SELECT * FROM test WHERE id != ?"); + auto select = ro->select("SELECT * FROM test WHERE id != ?"); select->bindParamI(0, testInt); select->execute(); int rows = 0; @@ -99,9 +87,7 @@ BOOST_AUTO_TEST_CASE( bindAndSelectOther ) assertColumnValueHelper(*select, 4, boost::posix_time::ptime_from_tm({ 3, 6, 23, 27, 3, 115, 0, 0, 0, 0, 0})); rows += 1; } - delete select; BOOST_REQUIRE_EQUAL(1, rows); - delete ro; } BOOST_AUTO_TEST_SUITE_END(); -- cgit v1.2.3