summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-07-21 21:49:05 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2017-07-21 21:49:05 +0100
commitcfd858844abc039923d7dd92027e71aebf87d2a9 (patch)
tree4571a090ad6f545c215cfcefdcf3d9c6f41249f2
parentFix up unittest Jamfile (diff)
downloadicetray-cfd858844abc039923d7dd92027e71aebf87d2a9.tar.bz2
icetray-cfd858844abc039923d7dd92027e71aebf87d2a9.tar.xz
icetray-cfd858844abc039923d7dd92027e71aebf87d2a9.zip
Remove pointless implementations of bind1 for optionals (there's a gneric one in the header) and refactor the test to cover much more combinations
-rw-r--r--icetray/icetray/abstractDatabaseClient.cpp22
-rw-r--r--icetray/unittests/testIceTrayServiceI.cpp31
-rw-r--r--icetray/unittests/testIceTrayServiceI.h3
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<T> & p) \
- { \
- if (p) { \
- cmd->bindFunc(o, *p); \
- } \
- else { \
- cmd->bindNull(o); \
- } \
- } \
- template<> \
- void \
- AbstractDatabaseClient::bind1(int o, DB::Command * cmd, const boost::optional<T> & 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 <testIceTrayServiceTestSql.sql.h>
#include <subdir/some.sql.h>
#include <subdir/a/more.sql.h>
+#include <boost/test/test_tools.hpp>
class Foo { };
@@ -23,25 +24,37 @@ namespace TestIceTray {
IceTray::AbstractCachingDatabaseClient(d)
{
}
+ template<typename Type>
+ void
+ TestIceTrayServiceI::fetchTest(const Type & value)
+ {
+ BOOST_REQUIRE_EQUAL(0, (fetch<int, int, Type>(sql::testIceTrayServiceTestSql, 1, value)));
+ BOOST_REQUIRE_EQUAL(0, (fetch<int, boost::optional<Type>, boost::optional<Type>>(sql::testIceTrayServiceTestSql, boost::optional<Type>(), value)));
+ BOOST_REQUIRE_EQUAL(0, (fetch<int, IceUtil::Optional<Type>, IceUtil::Optional<Type>>(sql::testIceTrayServiceTestSql, IceUtil::None, value)));
+ }
void TestIceTrayServiceI::method1(const Ice::Current &)
{
fetch<int>(sql::subdir::some);
fetch<int>(sql::subdir::a::more);
// Just check we can bind all the ICE types
- fetch<int, Ice::Byte, bool>(sql::testIceTrayServiceTestSql, 1, true);
- fetch<int, Ice::Short, Ice::Float>(sql::testIceTrayServiceTestSql, 1, 0.1f);
- fetch<int, Ice::Long, Ice::Double>(sql::testIceTrayServiceTestSql, 100000, 3.14);
+ fetchTest<bool>(true);
+ fetchTest<Ice::Byte>(1);
+ fetchTest<Ice::Short>(1);
+ fetchTest<Ice::Int>(100000);
+ fetchTest<Ice::Long>(10000000);
+ fetchTest<Ice::Float>(0.1f);
+ fetchTest<Ice::Double>(3.14);
+ fetchTest<std::string>("some string");
+ fetchTest<unsigned long>(20000000);
// BLOB
Ice::ByteSeq blob;
- fetch<int>(sql::testIceTrayServiceTestSql, blob, blob.size());
- // Test we can bind optionals and nulls
- fetch<int, boost::optional<Ice::Byte>, IceUtil::Optional<bool>>
- (sql::testIceTrayServiceTestSql, boost::optional<Ice::Byte>(10), IceUtil::Optional<bool>());
- fetch<int>(sql::testIceTrayServiceTestSql, 10, nullptr);
+ fetchTest<Ice::ByteSeq>(blob);
+ // Test we can bind nulls
+ fetchTest<std::nullptr_t>(nullptr);
// Test we can extend to bind other things
Foo foo;
- fetch<int>(sql::testIceTrayServiceTestSql, Foo(), foo);
+ fetchTest<Foo>(foo);
// Test we can provide our own DB connection
auto dbc = db->get();
fetch<int>(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<typename Type> void fetchTest(const Type & value);
};
class TestService : public IceTray::Service {