diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-09-20 21:27:20 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-09-20 21:27:20 +0100 |
commit | af1f9f124cc3889ebef11d19e36e79e51c9652fa (patch) | |
tree | 1fd829d8aac8380639b9493544745b26d781f424 | |
parent | Switch columns collection to forward declared pointer and add helper function... (diff) | |
download | libdbpp-af1f9f124cc3889ebef11d19e36e79e51c9652fa.tar.bz2 libdbpp-af1f9f124cc3889ebef11d19e36e79e51c9652fa.tar.xz libdbpp-af1f9f124cc3889ebef11d19e36e79e51c9652fa.zip |
Add basic unit test beginnings
-rw-r--r-- | libdbpp/Jamfile.jam | 3 | ||||
-rw-r--r-- | libdbpp/unittests/Jamfile.jam | 20 | ||||
-rw-r--r-- | libdbpp/unittests/testConnection.cpp | 57 |
3 files changed, 80 insertions, 0 deletions
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 : <library>glibmm <library>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 : : <name>boost_unit_test_framework ; +lib boost_filesystem ; +lib boost_system ; + +run + testConnection.cpp + : : : + <define>ROOT=\"$(me)\" + <define>BOOST_TEST_DYN_LINK + <library>..//dbppcore + <library>..//adhocutil + <library>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 <boost/test/unit_test.hpp> + +#include <factory.h> +#include <connection.h> + +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<DB::ConnectionFactory>().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); +} + |