From 6910c9b15d1173f1c7e3c3c799bdaf7bbce46d6a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 24 Sep 2015 02:55:01 +0100 Subject: Add the core test library for testing connector implementations --- libdbpp/Jamfile.jam | 18 ++++++++++-- libdbpp/testCore.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ libdbpp/testCore.h | 29 +++++++++++++++++++ 3 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 libdbpp/testCore.cpp create mode 100644 libdbpp/testCore.h diff --git a/libdbpp/Jamfile.jam b/libdbpp/Jamfile.jam index 3eedb10..5aaa15f 100644 --- a/libdbpp/Jamfile.jam +++ b/libdbpp/Jamfile.jam @@ -9,9 +9,10 @@ lib boost_date_time : : boost_date_time ; lib boost_filesystem ; lib boost_system ; lib adhocutil : : : : /usr/include/adhocutil ; +lib boost_utf : : boost_unit_test_framework ; lib dbppcore : - [ glob *.cpp *.ll ] : + [ glob *.cpp *.ll : test*.cpp ] : glibmm adhocutil boost_system @@ -27,7 +28,20 @@ lib dbppcore : boost_filesystem ; +lib dbpptestcore : + [ glob test*.cpp ] + : + BOOST_TEST_DYN_LINK + dbppcore + boost_utf + -fvisibility=hidden + release:-flto + : : + . + ; + build-project unittests ; -package.install install : . : : dbppcore : [ glob *.h ] ; +package.install install : . : : dbppcore : [ glob *.h : test*.h ] ; +package.install install : . : : dbpptestcore : [ glob test*.h ] ; diff --git a/libdbpp/testCore.cpp b/libdbpp/testCore.cpp new file mode 100644 index 0000000..5029025 --- /dev/null +++ b/libdbpp/testCore.cpp @@ -0,0 +1,81 @@ +#include "testCore.h" +#include +#include +#include +#include + +namespace DB { + +TestCore::TestCore() : + testInt(43), + testDouble(3.14), + testString("Some C String"), + testBool(false), + testDateTime(boost::posix_time::from_time_t(1430530593)), + testInterval(boost::posix_time::time_duration(1, 2, 3)) +{ +} + +template +class Assert : public DB::HandleField { + public: + Assert(const T & e) : expected(e) { } + + void floatingpoint(double v) override { (*this)(v); } + void integer(int64_t v) override { (*this)(v); } + void boolean(bool v) override { (*this)(v); } + void string(const char * v, size_t len) override { (*this)(std::string(v, len)); } + void timestamp(const boost::posix_time::ptime & v) override { (*this)(v); } + void interval(const boost::posix_time::time_duration & v) override { (*this)(v); } + void null() override { } + + template + void operator()(const D &, + typename boost::disable_if, dummy>::type = 0) { + BOOST_ERROR("Unexpected column type " << typeid(D).name()); + } + + template + void operator()(const D & v, + typename boost::enable_if, dummy>::type = 0) { + BOOST_REQUIRE_EQUAL(expected, v); + } + + const T & expected; +}; + +template +void +TestCore::assertScalarValueHelper(DB::SelectCommand & sel, const T & t) const +{ + while (sel.fetch()) { + assertColumnValueHelper(sel, 0, t); + } +} + +template +void +TestCore::assertColumnValueHelper(DB::SelectCommand & sel, unsigned int col, const T & t) const +{ + Assert a(t); + sel[col].apply(a); +} + +template void TestCore::assertScalarValueHelper(SelectCommand &, const bool &) const; +template void TestCore::assertScalarValueHelper(SelectCommand &, const int64_t &) const; +template void TestCore::assertScalarValueHelper(SelectCommand &, const int &) const; +template void TestCore::assertScalarValueHelper(SelectCommand &, const double &) const; +template void TestCore::assertScalarValueHelper(SelectCommand &, const std::string &) const; +template void TestCore::assertScalarValueHelper(SelectCommand &, const boost::posix_time::ptime &) const; +template void TestCore::assertScalarValueHelper(SelectCommand &, const boost::posix_time::time_duration &) const; + +template void TestCore::assertColumnValueHelper(SelectCommand &, unsigned int, const bool &) const; +template void TestCore::assertColumnValueHelper(SelectCommand &, unsigned int, const int &) const; +template void TestCore::assertColumnValueHelper(SelectCommand &, unsigned int, const int64_t &) const; +template void TestCore::assertColumnValueHelper(SelectCommand &, unsigned int, const double &) const; +template void TestCore::assertColumnValueHelper(SelectCommand &, unsigned int, const std::string &) const; +template void TestCore::assertColumnValueHelper(SelectCommand &, unsigned int, const boost::posix_time::ptime &) const; +template void TestCore::assertColumnValueHelper(SelectCommand &, unsigned int, const boost::posix_time::time_duration &) const; + +} + diff --git a/libdbpp/testCore.h b/libdbpp/testCore.h new file mode 100644 index 0000000..81dac8a --- /dev/null +++ b/libdbpp/testCore.h @@ -0,0 +1,29 @@ +#ifndef DB_TESTCORE_H +#define DB_TESTCORE_H + +#include +#include + +namespace DB { + +class SelectCommand; + +class DLL_PUBLIC TestCore { + protected: + TestCore(); + + int64_t testInt; + double testDouble; + std::string testString; + bool testBool; + boost::posix_time::ptime testDateTime; + boost::posix_time::time_duration testInterval; + + template void assertScalarValueHelper(SelectCommand & sel, const T & t) const; + template void assertColumnValueHelper(SelectCommand & sel, unsigned int col, const T & t) const; +}; + +} + +#endif + -- cgit v1.2.3