diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-04-22 15:13:33 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-04-22 15:13:33 +0100 |
commit | ffd3c8e7dcf3bee3304d7c28d8102bf343b64c76 (patch) | |
tree | 78f3cc6ce79e1aad4da917865c4a2669aac90e93 /libodbcpp/unittests | |
parent | Mark potential fall-through (diff) | |
download | libdbpp-odbc-1.2.0.tar.bz2 libdbpp-odbc-1.2.0.tar.xz libdbpp-odbc-1.2.0.zip |
C++17libdbpp-odbc-1.2.0
Updates code largely in-keeping with updates to be C++17 in line with
libadhocutil and libdbpp.
Diffstat (limited to 'libodbcpp/unittests')
-rw-r--r-- | libodbcpp/unittests/Jamfile.jam | 1 | ||||
-rw-r--r-- | libodbcpp/unittests/testodbc.cpp | 26 |
2 files changed, 7 insertions, 20 deletions
diff --git a/libodbcpp/unittests/Jamfile.jam b/libodbcpp/unittests/Jamfile.jam index 1d64f69..523c64a 100644 --- a/libodbcpp/unittests/Jamfile.jam +++ b/libodbcpp/unittests/Jamfile.jam @@ -13,6 +13,7 @@ run <define>ROOT=\"$(me)\" <define>BOOST_TEST_DYN_LINK <library>..//dbpp-odbc + <library>..//adhocutil <library>dbpptestcore <library>boost_utf <library>boost_filesystem 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 <definedDirs.h> #include <boost/date_time/posix_time/posix_time.hpp> -class StandardMockDatabase : public ODBC::Mock { +class StandardMockDatabase : public DB::PluginMock<ODBC::Mock> { public: - StandardMockDatabase() : ODBC::Mock("Driver=psqlodbcw.so;uid=postgres;servername=/run/postgresql", "Database=postgres", "odbcmock", { - rootDir / "odbcschema.sql" }) + StandardMockDatabase() : DB::PluginMock<ODBC::Mock>( "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(); |