From 41b302488e82097c3043d71b405e7ba930151a76 Mon Sep 17 00:00:00 2001
From: Dan Goodliffe <dan@randomdan.homeip.net>
Date: Fri, 6 Jan 2017 02:40:56 +0000
Subject: Minor updates/tweaks to increase test coverage

---
 libpqpp/pq-column.cpp        |  5 +----
 libpqpp/unittests/testpq.cpp | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 4 deletions(-)

(limited to 'libpqpp')

diff --git a/libpqpp/pq-column.cpp b/libpqpp/pq-column.cpp
index a073f26..bb09c45 100644
--- a/libpqpp/pq-column.cpp
+++ b/libpqpp/pq-column.cpp
@@ -50,10 +50,7 @@ PQ::Column::apply(DB::HandleField & h) const
 			{
 				int days = 0, hours = 0, minutes = 0, seconds = 0, fractions = 0, flen1 = 0, flen2 = 0;
 				const char * val = PQgetvalue(sc->execRes, sc->tuple, colNo);
-				if (sscanf(val, "%d days %d:%d:%d.%n%d%n", &days, &hours, &minutes, &seconds, &flen1, &fractions, &flen2) >= 4) {
-					h.interval(boost::posix_time::time_duration((24 * days) + hours, minutes, seconds, fractions * pow(10, boost::posix_time::time_res_traits::num_fractional_digits() + flen1 - flen2)));
-				}
-				else if (sscanf(val, "%d day %d:%d:%d.%n%d%n", &days, &hours, &minutes, &seconds, &flen1, &fractions, &flen2) >= 4) {
+				if (sscanf(val, "%d %*[days] %d:%d:%d.%n%d%n", &days, &hours, &minutes, &seconds, &flen1, &fractions, &flen2) >= 4) {
 					h.interval(boost::posix_time::time_duration((24 * days) + hours, minutes, seconds, fractions * pow(10, boost::posix_time::time_res_traits::num_fractional_digits() + flen1 - flen2)));
 				}
 				else {
diff --git a/libpqpp/unittests/testpq.cpp b/libpqpp/unittests/testpq.cpp
index fcf01e3..2944676 100644
--- a/libpqpp/unittests/testpq.cpp
+++ b/libpqpp/unittests/testpq.cpp
@@ -308,6 +308,34 @@ BOOST_AUTO_TEST_CASE( bulkSelect )
 	delete ro;
 }
 
+BOOST_AUTO_TEST_CASE( selectWithSmallPages )
+{
+	auto ro = DB::MockDatabase::openConnectionTo("PQmock");
+	PQ::CommandOptions co(0, 1, true);
+	auto sel = ro->newSelectCommand("SELECT * FROM test WHERE id > ?", &co);
+	sel->bindParamI(0, 1);
+	int totalInt = 0, count = 0;
+	sel->forEachRow<int64_t>([&totalInt, &count](auto i) {
+			totalInt += i;
+			count += 1;
+		});
+	delete sel;
+	BOOST_REQUIRE_EQUAL(20, totalInt);
+	BOOST_REQUIRE_EQUAL(8, count);
+	delete ro;
+}
+
+BOOST_AUTO_TEST_CASE( dateoid )
+{
+	auto ro = DB::MockDatabase::openConnectionTo("PQmock");
+	PQ::CommandOptions co(0, 1, false);
+	auto sel = ro->newSelectCommand("SELECT '2017-01-08'::date", &co);
+	for (const auto & r : sel->as<boost::posix_time::ptime>()) {
+		BOOST_REQUIRE_EQUAL(boost::posix_time::ptime(boost::gregorian::date(2017, 1, 8)), r.value<0>());
+	}
+	delete ro;
+}
+
 BOOST_AUTO_TEST_CASE( insertReturning )
 {
 	auto ro = DB::MockDatabase::openConnectionTo("PQmock");
@@ -360,6 +388,12 @@ BOOST_AUTO_TEST_SUITE_END();
 BOOST_AUTO_TEST_CASE( connfail )
 {
 	BOOST_REQUIRE_THROW(DB::ConnectionFactory::createNew("postgresql", "host=localhost user=no"), DB::ConnectionError);
+	try {
+		DB::ConnectionFactory::createNew("postgresql", "host=localhost user=no");
+	}
+	catch (const DB::ConnectionError & e) {
+		BOOST_REQUIRE_EQUAL(e.what(), "FATAL:  role \"no\" does not exist\n");
+	}
 }
 
 BOOST_AUTO_TEST_CASE( ssl )
-- 
cgit v1.2.3