From cf83772205629933e82363144fcc61fe306c323d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 17 Oct 2015 15:46:08 +0100 Subject: Test savepoints --- libdbpp/unittests/testConnection.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/libdbpp/unittests/testConnection.cpp b/libdbpp/unittests/testConnection.cpp index 883c09a..bcfadeb 100644 --- a/libdbpp/unittests/testConnection.cpp +++ b/libdbpp/unittests/testConnection.cpp @@ -17,9 +17,6 @@ class MockDb : public DB::Connection { int commitTx() const { return 0; } int rollbackTx() const { return 0; } bool inTx() const { return false; } - void savepoint(const std::string &) const {} - void rollbackToSavepoint(const std::string &) const {} - void releaseSavepoint(const std::string &) const {} void ping() const {} DB::BulkDeleteStyle bulkDeleteStyle() const { return DB::BulkDeleteUsingUsing; } DB::BulkUpdateStyle bulkUpdateStyle() const { return DB::BulkUpdateUsingJoin; } @@ -77,3 +74,21 @@ BOOST_AUTO_TEST_CASE( parse ) delete mock; } +BOOST_AUTO_TEST_CASE( savepoints ) +{ + auto mock = DB::ConnectionFactory::createNew("MockDb", "doesn't matter"); + MockDb * mockdb = dynamic_cast(mock); + BOOST_REQUIRE(mockdb); + mock->savepoint("sp"); + BOOST_REQUIRE_EQUAL("SAVEPOINT sp", *mockdb->executed.rbegin()); + mock->releaseSavepoint("sp"); + BOOST_REQUIRE_EQUAL("RELEASE SAVEPOINT sp", *mockdb->executed.rbegin()); + mock->savepoint("sp1"); + BOOST_REQUIRE_EQUAL("SAVEPOINT sp1", *mockdb->executed.rbegin()); + mock->savepoint("sp2"); + BOOST_REQUIRE_EQUAL("SAVEPOINT sp2", *mockdb->executed.rbegin()); + mock->rollbackToSavepoint("sp1"); + BOOST_REQUIRE_EQUAL("ROLLBACK TO SAVEPOINT sp1", *mockdb->executed.rbegin()); + delete mock; +} + -- cgit v1.2.3