diff options
Diffstat (limited to 'libdbpp/unittests')
-rw-r--r-- | libdbpp/unittests/Jamfile.jam | 13 | ||||
-rw-r--r-- | libdbpp/unittests/testConnectionPool.cpp | 41 |
2 files changed, 54 insertions, 0 deletions
diff --git a/libdbpp/unittests/Jamfile.jam b/libdbpp/unittests/Jamfile.jam index b7b2170..aa6c195 100644 --- a/libdbpp/unittests/Jamfile.jam +++ b/libdbpp/unittests/Jamfile.jam @@ -24,6 +24,19 @@ run ; run + testConnectionPool.cpp + : : : + <define>ROOT=\"$(me)\" + <define>BOOST_TEST_DYN_LINK + <library>..//dbppcore + <library>..//adhocutil + <library>../../libpqpp//dbpp-postgresql + <library>boost_utf + : + testConnectionPool + ; + +run testUtils.cpp : : : <define>ROOT=\"$(me)\" diff --git a/libdbpp/unittests/testConnectionPool.cpp b/libdbpp/unittests/testConnectionPool.cpp new file mode 100644 index 0000000..ebe22d1 --- /dev/null +++ b/libdbpp/unittests/testConnectionPool.cpp @@ -0,0 +1,41 @@ +#define BOOST_TEST_MODULE DbConnectionPool +#include <boost/test/unit_test.hpp> + +#include <connectionPool.h> +#include <mock.h> +#include <buffer.h> + +class MockPool : public PQ::Mock, public DB::ConnectionPool { + public: + MockPool() : + PQ::Mock("user=postgres dbname=postgres", "pqmock", { }), + DB::ConnectionPool(4, 2, "postgresql", stringbf("user=postgres dbname=%s", databaseName())) + { + } +}; + +BOOST_AUTO_TEST_CASE( basic ) +{ + MockPool pool; + DB::Connection * cr; + { + auto c = pool.get(); + c->beginTx(); + c->commitTx(); + cr = c.get(); + } + { + auto c = pool.get(); + BOOST_REQUIRE_EQUAL(cr, c.get()); + } + { + auto c1 = pool.get(); + auto c2 = pool.get(); + auto c3 = pool.get(); + auto c4 = pool.get(); + BOOST_REQUIRE_EQUAL(4, pool.inUseCount()); + } + BOOST_REQUIRE_EQUAL(0, pool.inUseCount()); + BOOST_REQUIRE_EQUAL(2, pool.availableCount()); +} + |