diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-01-04 19:46:34 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-01-04 19:46:34 +0000 |
commit | dcf0c906a22e7f23495ee8fe5c30c2d1870f7639 (patch) | |
tree | 666533e14c2fdca28df953a3d060b9aa592ee050 | |
parent | Fix error message creation in exception (diff) | |
download | libdbpp-odbc-1.0.1.tar.bz2 libdbpp-odbc-1.0.1.tar.xz libdbpp-odbc-1.0.1.zip |
Take an extra argument to mock to allow for specifying which driver to use, etc. Move all the PostgreSQL specific bits into the unit test itself. Reference the driver library by filename thus not requiring configuration for the test to run.libdbpp-odbc-1.0.1
-rw-r--r-- | libodbcpp/odbc-mock.cpp | 8 | ||||
-rw-r--r-- | libodbcpp/odbc-mock.h | 4 | ||||
-rw-r--r-- | libodbcpp/unittests/testodbc.cpp | 8 |
3 files changed, 14 insertions, 6 deletions
diff --git a/libodbcpp/odbc-mock.cpp b/libodbcpp/odbc-mock.cpp index 71c4c56..2799fb3 100644 --- a/libodbcpp/odbc-mock.cpp +++ b/libodbcpp/odbc-mock.cpp @@ -4,8 +4,9 @@ namespace ODBC { -Mock::Mock(const std::string & masterdb, const std::string & name, const std::vector<boost::filesystem::path> & ss) : - MockServerDatabase(masterdb, name, "odbc") +Mock::Mock(const std::string & b, const std::string & masterdb, const std::string & name, const std::vector<boost::filesystem::path> & ss) : + MockServerDatabase(b + ";" + masterdb, name, "odbc"), + base(b) { CreateNewDatabase(); PlaySchemaScripts(ss); @@ -14,7 +15,7 @@ Mock::Mock(const std::string & masterdb, const std::string & name, const std::ve DB::Connection * Mock::openConnection() const { - return new Connection(stringbf("Driver=postgresql;Database=%s;uid=postgres;servername=/run/postgresql", testDbName)); + return new Connection(stringbf("%s;Database=%s", base, testDbName)); } Mock::~Mock() @@ -24,7 +25,6 @@ Mock::~Mock() void Mock::DropDatabase() const { - master->execute("SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '" + testDbName + "'"); MockServerDatabase::DropDatabase(); } diff --git a/libodbcpp/odbc-mock.h b/libodbcpp/odbc-mock.h index d2bcbfe..f66d09d 100644 --- a/libodbcpp/odbc-mock.h +++ b/libodbcpp/odbc-mock.h @@ -9,9 +9,11 @@ namespace ODBC { class DLL_PUBLIC Mock : public DB::MockServerDatabase { public: - Mock(const std::string & master, const std::string & name, const std::vector<boost::filesystem::path> & ss); + Mock(const std::string & base, const std::string & master, const std::string & name, const std::vector<boost::filesystem::path> & ss); ~Mock(); + const std::string base; + protected: void DropDatabase() const override; diff --git a/libodbcpp/unittests/testodbc.cpp b/libodbcpp/unittests/testodbc.cpp index f288bf8..77f0a71 100644 --- a/libodbcpp/unittests/testodbc.cpp +++ b/libodbcpp/unittests/testodbc.cpp @@ -13,10 +13,16 @@ class StandardMockDatabase : public ODBC::Mock { public: - StandardMockDatabase() : ODBC::Mock("Driver=postgresql;Database=postgres;uid=postgres;servername=/run/postgresql", "odbcmock", { + StandardMockDatabase() : ODBC::Mock("Driver=psqlodbcw.so;uid=postgres;servername=/run/postgresql", "Database=postgres", "odbcmock", { rootDir / "odbcschema.sql" }) { } + + 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 ); |