diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-01-06 02:40:56 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-01-08 19:33:31 +0000 |
commit | 41b302488e82097c3043d71b405e7ba930151a76 (patch) | |
tree | bd048b5c887690c826b2b72d806932b849a8723f /libpqpp/unittests/testpq.cpp | |
parent | Use SQL hash for prepared statement names, increases reuse and avoids random ... (diff) | |
download | libdbpp-postgresql-41b302488e82097c3043d71b405e7ba930151a76.tar.bz2 libdbpp-postgresql-41b302488e82097c3043d71b405e7ba930151a76.tar.xz libdbpp-postgresql-41b302488e82097c3043d71b405e7ba930151a76.zip |
Minor updates/tweaks to increase test coverage
Diffstat (limited to 'libpqpp/unittests/testpq.cpp')
-rw-r--r-- | libpqpp/unittests/testpq.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
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 ) |