From af1f9f124cc3889ebef11d19e36e79e51c9652fa Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 20 Sep 2015 21:27:20 +0100 Subject: Add basic unit test beginnings --- libdbpp/Jamfile.jam | 3 ++ libdbpp/unittests/Jamfile.jam | 20 +++++++++++++ libdbpp/unittests/testConnection.cpp | 57 ++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 libdbpp/unittests/Jamfile.jam create mode 100644 libdbpp/unittests/testConnection.cpp diff --git a/libdbpp/Jamfile.jam b/libdbpp/Jamfile.jam index ffa8103..5f252c6 100644 --- a/libdbpp/Jamfile.jam +++ b/libdbpp/Jamfile.jam @@ -16,3 +16,6 @@ lib dbppcore : glibmm boost_date_time ; + +build-project unittests ; + diff --git a/libdbpp/unittests/Jamfile.jam b/libdbpp/unittests/Jamfile.jam new file mode 100644 index 0000000..ef19211 --- /dev/null +++ b/libdbpp/unittests/Jamfile.jam @@ -0,0 +1,20 @@ +import testing ; + +path-constant me : . ; + +lib boost_utf : : boost_unit_test_framework ; +lib boost_filesystem ; +lib boost_system ; + +run + testConnection.cpp + : : : + ROOT=\"$(me)\" + BOOST_TEST_DYN_LINK + ..//dbppcore + ..//adhocutil + boost_utf + : + testConnection + ; + diff --git a/libdbpp/unittests/testConnection.cpp b/libdbpp/unittests/testConnection.cpp new file mode 100644 index 0000000..3472dde --- /dev/null +++ b/libdbpp/unittests/testConnection.cpp @@ -0,0 +1,57 @@ +#define BOOST_TEST_MODULE DbConnection +#include + +#include +#include + +class MockDb : public DB::Connection { + public: + MockDb(const std::string &) {} + + void finish() const {} + int beginTx() const { return 0; } + 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; } + + void execute(const std::string &) const {} + DB::SelectCommand * newSelectCommand(const std::string &) const { return nullptr; } + DB::ModifyCommand * newModifyCommand(const std::string &) const { return nullptr; } + + void beginBulkUpload(const char *, const char *) const {} + void endBulkUpload(const char *) const {} + size_t bulkUploadData(const char *, size_t) const {return 0;} +}; + +FACTORY(MockDb, DB::ConnectionFactory); + +BOOST_AUTO_TEST_CASE( plugins ) +{ + auto pm = AdHoc::PluginManager::getDefault(); + BOOST_REQUIRE(pm); + BOOST_REQUIRE_EQUAL(1, pm->count()); + BOOST_REQUIRE_EQUAL(1, pm->getAll().size()); + BOOST_REQUIRE_EQUAL(1, pm->getAll().size()); +} + +BOOST_AUTO_TEST_CASE( create ) +{ + auto mock = DB::ConnectionFactory::create("MockDb", "doesn't matter"); + BOOST_REQUIRE(mock); + // MockDb is fake, just returns nullptr, but the call should otherwise succeed. + BOOST_REQUIRE(!mock->newModifyCommand("")); + BOOST_REQUIRE(!mock->newSelectCommand("")); + delete mock; +} + +BOOST_AUTO_TEST_CASE( resolve ) +{ + BOOST_REQUIRE_THROW(DB::ConnectionFactory::create("otherdb", "doesn't matter"), AdHoc::LoadLibraryException); +} + -- cgit v1.2.3