summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-09-24 02:55:01 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2015-09-24 03:05:59 +0100
commit6910c9b15d1173f1c7e3c3c799bdaf7bbce46d6a (patch)
tree1849002d20e572f5c83b961fd05317c5af6cebea
parentAdd operator>> support to columns (diff)
downloadlibdbpp-6910c9b15d1173f1c7e3c3c799bdaf7bbce46d6a.tar.bz2
libdbpp-6910c9b15d1173f1c7e3c3c799bdaf7bbce46d6a.tar.xz
libdbpp-6910c9b15d1173f1c7e3c3c799bdaf7bbce46d6a.zip
Add the core test library for testing connector implementations
-rw-r--r--libdbpp/Jamfile.jam18
-rw-r--r--libdbpp/testCore.cpp81
-rw-r--r--libdbpp/testCore.h29
3 files changed, 126 insertions, 2 deletions
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 : : <name>boost_date_time ;
lib boost_filesystem ;
lib boost_system ;
lib adhocutil : : : : <include>/usr/include/adhocutil ;
+lib boost_utf : : <name>boost_unit_test_framework ;
lib dbppcore :
- [ glob *.cpp *.ll ] :
+ [ glob *.cpp *.ll : test*.cpp ] :
<library>glibmm
<library>adhocutil
<library>boost_system
@@ -27,7 +28,20 @@ lib dbppcore :
<library>boost_filesystem
;
+lib dbpptestcore :
+ [ glob test*.cpp ]
+ :
+ <define>BOOST_TEST_DYN_LINK
+ <library>dbppcore
+ <library>boost_utf
+ <cflags>-fvisibility=hidden
+ <variant>release:<cflags>-flto
+ : :
+ <include>.
+ ;
+
build-project unittests ;
-package.install install : <install-source-root>. : : dbppcore : [ glob *.h ] ;
+package.install install : <install-source-root>. : : dbppcore : [ glob *.h : test*.h ] ;
+package.install install : <install-source-root>. : : 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 <selectcommand.h>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/test/test_tools.hpp>
+#include <boost/utility/enable_if.hpp>
+
+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<typename T>
+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 <typename D, typename dummy = int>
+ void operator()(const D &,
+ typename boost::disable_if<std::is_convertible<D, T>, dummy>::type = 0) {
+ BOOST_ERROR("Unexpected column type " << typeid(D).name());
+ }
+
+ template <typename D, typename dummy = int>
+ void operator()(const D & v,
+ typename boost::enable_if<std::is_convertible<D, T>, dummy>::type = 0) {
+ BOOST_REQUIRE_EQUAL(expected, v);
+ }
+
+ const T & expected;
+};
+
+template<typename T>
+void
+TestCore::assertScalarValueHelper(DB::SelectCommand & sel, const T & t) const
+{
+ while (sel.fetch()) {
+ assertColumnValueHelper(sel, 0, t);
+ }
+}
+
+template<typename T>
+void
+TestCore::assertColumnValueHelper(DB::SelectCommand & sel, unsigned int col, const T & t) const
+{
+ Assert<T> a(t);
+ sel[col].apply(a);
+}
+
+template void TestCore::assertScalarValueHelper<bool>(SelectCommand &, const bool &) const;
+template void TestCore::assertScalarValueHelper<int64_t>(SelectCommand &, const int64_t &) const;
+template void TestCore::assertScalarValueHelper<int>(SelectCommand &, const int &) const;
+template void TestCore::assertScalarValueHelper<double>(SelectCommand &, const double &) const;
+template void TestCore::assertScalarValueHelper<std::string>(SelectCommand &, const std::string &) const;
+template void TestCore::assertScalarValueHelper<boost::posix_time::ptime>(SelectCommand &, const boost::posix_time::ptime &) const;
+template void TestCore::assertScalarValueHelper<boost::posix_time::time_duration>(SelectCommand &, const boost::posix_time::time_duration &) const;
+
+template void TestCore::assertColumnValueHelper<bool>(SelectCommand &, unsigned int, const bool &) const;
+template void TestCore::assertColumnValueHelper<int>(SelectCommand &, unsigned int, const int &) const;
+template void TestCore::assertColumnValueHelper<int64_t>(SelectCommand &, unsigned int, const int64_t &) const;
+template void TestCore::assertColumnValueHelper<double>(SelectCommand &, unsigned int, const double &) const;
+template void TestCore::assertColumnValueHelper<std::string>(SelectCommand &, unsigned int, const std::string &) const;
+template void TestCore::assertColumnValueHelper<boost::posix_time::ptime>(SelectCommand &, unsigned int, const boost::posix_time::ptime &) const;
+template void TestCore::assertColumnValueHelper<boost::posix_time::time_duration>(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 <command.h>
+#include <visibility.h>
+
+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<typename T> void assertScalarValueHelper(SelectCommand & sel, const T & t) const;
+ template<typename T> void assertColumnValueHelper(SelectCommand & sel, unsigned int col, const T & t) const;
+};
+
+}
+
+#endif
+