From cfd858844abc039923d7dd92027e71aebf87d2a9 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 21 Jul 2017 21:49:05 +0100 Subject: Remove pointless implementations of bind1 for optionals (there's a gneric one in the header) and refactor the test to cover much more combinations --- icetray/icetray/abstractDatabaseClient.cpp | 22 --------------------- icetray/unittests/testIceTrayServiceI.cpp | 31 +++++++++++++++++++++--------- icetray/unittests/testIceTrayServiceI.h | 3 +++ 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/icetray/icetray/abstractDatabaseClient.cpp b/icetray/icetray/abstractDatabaseClient.cpp index 8bac22f..064e0e2 100644 --- a/icetray/icetray/abstractDatabaseClient.cpp +++ b/icetray/icetray/abstractDatabaseClient.cpp @@ -15,28 +15,6 @@ namespace IceTray { AbstractDatabaseClient::bind1(int o, DB::Command * cmd, const T & p) \ { \ cmd->bindFunc(o, p); \ - } \ - template<> \ - void \ - AbstractDatabaseClient::bind1(int o, DB::Command * cmd, const IceUtil::Optional & p) \ - { \ - if (p) { \ - cmd->bindFunc(o, *p); \ - } \ - else { \ - cmd->bindNull(o); \ - } \ - } \ - template<> \ - void \ - AbstractDatabaseClient::bind1(int o, DB::Command * cmd, const boost::optional & p) \ - { \ - if (p) { \ - cmd->bindFunc(o, *p); \ - } \ - else { \ - cmd->bindNull(o); \ - } \ } PARAMBINDER(std::string, bindParamS); PARAMBINDER(Ice::Byte, bindParamI); diff --git a/icetray/unittests/testIceTrayServiceI.cpp b/icetray/unittests/testIceTrayServiceI.cpp index 138e87b..141bdf7 100644 --- a/icetray/unittests/testIceTrayServiceI.cpp +++ b/icetray/unittests/testIceTrayServiceI.cpp @@ -6,6 +6,7 @@ #include #include #include +#include class Foo { }; @@ -23,25 +24,37 @@ namespace TestIceTray { IceTray::AbstractCachingDatabaseClient(d) { } + template + void + TestIceTrayServiceI::fetchTest(const Type & value) + { + BOOST_REQUIRE_EQUAL(0, (fetch(sql::testIceTrayServiceTestSql, 1, value))); + BOOST_REQUIRE_EQUAL(0, (fetch, boost::optional>(sql::testIceTrayServiceTestSql, boost::optional(), value))); + BOOST_REQUIRE_EQUAL(0, (fetch, IceUtil::Optional>(sql::testIceTrayServiceTestSql, IceUtil::None, value))); + } void TestIceTrayServiceI::method1(const Ice::Current &) { fetch(sql::subdir::some); fetch(sql::subdir::a::more); // Just check we can bind all the ICE types - fetch(sql::testIceTrayServiceTestSql, 1, true); - fetch(sql::testIceTrayServiceTestSql, 1, 0.1f); - fetch(sql::testIceTrayServiceTestSql, 100000, 3.14); + fetchTest(true); + fetchTest(1); + fetchTest(1); + fetchTest(100000); + fetchTest(10000000); + fetchTest(0.1f); + fetchTest(3.14); + fetchTest("some string"); + fetchTest(20000000); // BLOB Ice::ByteSeq blob; - fetch(sql::testIceTrayServiceTestSql, blob, blob.size()); - // Test we can bind optionals and nulls - fetch, IceUtil::Optional> - (sql::testIceTrayServiceTestSql, boost::optional(10), IceUtil::Optional()); - fetch(sql::testIceTrayServiceTestSql, 10, nullptr); + fetchTest(blob); + // Test we can bind nulls + fetchTest(nullptr); // Test we can extend to bind other things Foo foo; - fetch(sql::testIceTrayServiceTestSql, Foo(), foo); + fetchTest(foo); // Test we can provide our own DB connection auto dbc = db->get(); fetch(dbc.get(), sql::testIceTrayServiceTestSql, 1, 1); diff --git a/icetray/unittests/testIceTrayServiceI.h b/icetray/unittests/testIceTrayServiceI.h index 193a92b..355b7e5 100644 --- a/icetray/unittests/testIceTrayServiceI.h +++ b/icetray/unittests/testIceTrayServiceI.h @@ -12,6 +12,9 @@ namespace TestIceTray { void method1(const Ice::Current &) override; void method2(Ice::Int id, const std::string & name, const Ice::Current &) override; + + private: + template void fetchTest(const Type & value); }; class TestService : public IceTray::Service { -- cgit v1.2.3