summaryrefslogtreecommitdiff
path: root/libpqpp/unittests/testpq.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-06-05 19:47:08 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2017-06-05 19:47:08 +0100
commit0c63b72bfdf4e1efba15549bc077bdfcd39ad123 (patch)
treebf5f73384b37523ea4de6862e81b8d3885e71cc7 /libpqpp/unittests/testpq.cpp
parentUse DB::Blob's own comparator (diff)
downloadlibdbpp-postgresql-0c63b72bfdf4e1efba15549bc077bdfcd39ad123.tar.bz2
libdbpp-postgresql-0c63b72bfdf4e1efba15549bc077bdfcd39ad123.tar.xz
libdbpp-postgresql-0c63b72bfdf4e1efba15549bc077bdfcd39ad123.zip
Add a test case for a genuine large binary object (the memmapped test binary)libdbpp-postgresql-1.1.3
Diffstat (limited to 'libpqpp/unittests/testpq.cpp')
-rw-r--r--libpqpp/unittests/testpq.cpp22
1 files changed, 22 insertions, 0 deletions
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 <pq-connection.h>
#include <pq-command.h>
#include <selectcommandUtil.impl.h>
+#include <fileUtils.h>
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<DB::Blob, int64_t>()) {
+ 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 )