From c083cf65bc6a7df2528a5fe41112fb1806755463 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 22 Apr 2018 13:29:45 +0100 Subject: Variadic mock pool constructor Support for variadic constructor arguments for MockPool. Irritatingly breaks the signature by having to move the varargs to the end from the front. --- libdbpp/mockDatabase.h | 5 +++-- libdbpp/unittests/testConnectionPool.cpp | 2 +- libdbpp/unittests/testPatch.cpp | 2 +- libdbpp/unittests/testUtils.cpp | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/libdbpp/mockDatabase.h b/libdbpp/mockDatabase.h index 2510c73..d3e5bff 100644 --- a/libdbpp/mockDatabase.h +++ b/libdbpp/mockDatabase.h @@ -63,10 +63,11 @@ class DLL_PUBLIC MockServerDatabase : public MockDatabase { template class PluginMock { public: - PluginMock(const std::string & m, const std::string & name, const std::vector & s) : + template + PluginMock(const std::string & name, const std::initializer_list & s, const Args & ... args) : mockName(name) { - AdHoc::PluginManager::getDefault()->create(mockName, __FILE__, __LINE__, m, name, s); + AdHoc::PluginManager::getDefault()->create(mockName, __FILE__, __LINE__, args..., name, s); } ~PluginMock() { diff --git a/libdbpp/unittests/testConnectionPool.cpp b/libdbpp/unittests/testConnectionPool.cpp index 124df5b..de3de79 100644 --- a/libdbpp/unittests/testConnectionPool.cpp +++ b/libdbpp/unittests/testConnectionPool.cpp @@ -8,7 +8,7 @@ class MockPool : public DB::PluginMock, public DB::ConnectionPool { public: MockPool() : - PluginMock("user=postgres dbname=postgres", "pqmock", { }), + PluginMock("pqmock", { }, "user=postgres dbname=postgres"), DB::ConnectionPool(4, 2, "postgresql", stringbf("user=postgres dbname=%s", databaseName())) { } diff --git a/libdbpp/unittests/testPatch.cpp b/libdbpp/unittests/testPatch.cpp index b9ede04..a1c77d3 100644 --- a/libdbpp/unittests/testPatch.cpp +++ b/libdbpp/unittests/testPatch.cpp @@ -13,7 +13,7 @@ class Mock : public DB::PluginMock { public: Mock() : - DB::PluginMock("user=postgres dbname=postgres", "pqmock", { rootDir / "patch.sql" }) + DB::PluginMock("pqmock", { rootDir / "patch.sql" }, "user=postgres dbname=postgres") { } }; diff --git a/libdbpp/unittests/testUtils.cpp b/libdbpp/unittests/testUtils.cpp index c926a47..04fad4f 100644 --- a/libdbpp/unittests/testUtils.cpp +++ b/libdbpp/unittests/testUtils.cpp @@ -15,8 +15,8 @@ class StandardMockDatabase : public DB::PluginMock { public: - StandardMockDatabase() : DB::PluginMock("user=postgres dbname=postgres", "pqmock", { - rootDir / "util.sql" }) + StandardMockDatabase() : DB::PluginMock("pqmock", { + rootDir / "util.sql" }, "user=postgres dbname=postgres") { } }; -- cgit v1.2.3