From 0c63b72bfdf4e1efba15549bc077bdfcd39ad123 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 5 Jun 2017 19:47:08 +0100 Subject: Add a test case for a genuine large binary object (the memmapped test binary) --- libpqpp/unittests/Jamfile.jam | 2 ++ libpqpp/unittests/testpq.cpp | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/libpqpp/unittests/Jamfile.jam b/libpqpp/unittests/Jamfile.jam index 66c4b49..85abb80 100644 --- a/libpqpp/unittests/Jamfile.jam +++ b/libpqpp/unittests/Jamfile.jam @@ -6,6 +6,7 @@ lib boost_utf : : boost_unit_test_framework ; lib boost_filesystem ; lib boost_system ; lib dbpptestcore : : : : /usr/include/dbpp ; +lib adhocutil : : : : /usr/include/adhocutil ; run testpq.cpp @@ -14,6 +15,7 @@ run BOOST_TEST_DYN_LINK ..//dbpp-postgresql dbpptestcore + adhocutil boost_utf boost_filesystem boost_system diff --git a/libpqpp/unittests/testpq.cpp b/libpqpp/unittests/testpq.cpp index 9fb5f98..476c3a2 100644 --- a/libpqpp/unittests/testpq.cpp +++ b/libpqpp/unittests/testpq.cpp @@ -13,6 +13,7 @@ #include #include #include +#include class StandardMockDatabase : public PQ::Mock { public: @@ -451,6 +452,27 @@ BOOST_AUTO_TEST_CASE( fetchAsBinary ) } } +BOOST_AUTO_TEST_CASE( largeBlob ) +{ + auto ro = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("PQmock")); + ro->execute("TRUNCATE TABLE blobtest"); + AdHoc::FileUtils::MemMap f("/proc/self/exe"); + DB::Blob blob(f.data, f.getStat().st_size); + BOOST_REQUIRE(blob.len > 200000); // Just assert the mapped file is actually "large" + auto ins = ro->modify("INSERT INTO blobtest(data) VALUES(?)"); + ins->bindParamBLOB(0, blob); + ins->execute(); + + PQ::CommandOptions opts(0); + opts.fetchBinary = true; + opts.useCursor = false; + auto sel = ro->select("SELECT data, length(data) FROM blobtest", &opts); + for (const auto & r : sel->as()) { + BOOST_REQUIRE_EQUAL(r.value<1>(), f.getStat().st_size); + BOOST_REQUIRE_EQUAL(r.value<0>(), blob); + } +} + BOOST_AUTO_TEST_SUITE_END(); BOOST_AUTO_TEST_CASE( connfail ) -- cgit v1.2.3